From b8a8ee438eca934736f53d753a0f52f12ad15907 Mon Sep 17 00:00:00 2001 From: Chistopher Kochan <5183896+crkochan@users.noreply.github.com> Date: Sun, 5 Sep 2021 23:35:33 -0700 Subject: [PATCH 1/9] Miscellaneous clean up. Removed unused imports, and some commented code lines. --- custom_components/sunpower/__init__.py | 2 -- custom_components/sunpower/binary_sensor.py | 2 -- custom_components/sunpower/const.py | 1 - custom_components/sunpower/sensor.py | 4 +--- custom_components/sunpower/sunpower.py | 2 +- custom_components/sunpower/translations/en.json | 2 +- 6 files changed, 3 insertions(+), 10 deletions(-) diff --git a/custom_components/sunpower/__init__.py b/custom_components/sunpower/__init__.py index 656c082..2874802 100644 --- a/custom_components/sunpower/__init__.py +++ b/custom_components/sunpower/__init__.py @@ -10,7 +10,6 @@ from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.core import HomeAssistant -from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import ( @@ -20,7 +19,6 @@ SUNPOWER_COORDINATOR, SUNPOWER_HOST, SETUP_TIMEOUT_MIN, - PVS_DEVICE_TYPE, ) _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/sunpower/binary_sensor.py b/custom_components/sunpower/binary_sensor.py index 9cb2c95..00367d1 100644 --- a/custom_components/sunpower/binary_sensor.py +++ b/custom_components/sunpower/binary_sensor.py @@ -6,8 +6,6 @@ from .const import ( DOMAIN, SUNPOWER_COORDINATOR, - # SUNPOWER_DATA, - # SUNPOWER_OBJECT, PVS_DEVICE_TYPE, INVERTER_DEVICE_TYPE, METER_DEVICE_TYPE, diff --git a/custom_components/sunpower/const.py b/custom_components/sunpower/const.py index 31db244..204cf5a 100644 --- a/custom_components/sunpower/const.py +++ b/custom_components/sunpower/const.py @@ -20,7 +20,6 @@ SUNPOWER_COORDINATOR = "coordinator" UPDATE_INTERVAL = 120 SETUP_TIMEOUT_MIN = 5 -# SUNPOWER_DATA = "data" PVS_DEVICE_TYPE = "PVS" INVERTER_DEVICE_TYPE = "Inverter" diff --git a/custom_components/sunpower/sensor.py b/custom_components/sunpower/sensor.py index c875fb6..d228c17 100644 --- a/custom_components/sunpower/sensor.py +++ b/custom_components/sunpower/sensor.py @@ -6,8 +6,6 @@ from .const import ( DOMAIN, SUNPOWER_COORDINATOR, - # SUNPOWER_DATA, - # SUNPOWER_OBJECT, PVS_DEVICE_TYPE, INVERTER_DEVICE_TYPE, METER_DEVICE_TYPE, @@ -102,7 +100,7 @@ def __init__(self, coordinator, pvs_info, field, title, unit, icon): self._field = field self._unit = unit self._icon = icon - + @property def unit_of_measurement(self): """Return the unit of measurement.""" diff --git a/custom_components/sunpower/sunpower.py b/custom_components/sunpower/sunpower.py index fd97f85..93873ca 100644 --- a/custom_components/sunpower/sunpower.py +++ b/custom_components/sunpower/sunpower.py @@ -30,4 +30,4 @@ def device_list(self): def network_status(self): """Get a list of network interfaces on the PVS""" - return self.generic_command("Get_Comm") \ No newline at end of file + return self.generic_command("Get_Comm") diff --git a/custom_components/sunpower/translations/en.json b/custom_components/sunpower/translations/en.json index 9116abc..2910448 100644 --- a/custom_components/sunpower/translations/en.json +++ b/custom_components/sunpower/translations/en.json @@ -16,4 +16,4 @@ } }, "title": "SunPower" -} \ No newline at end of file +} From 34c1cde44212e4bc2e2e60db7e7c180962b6fe1d Mon Sep 17 00:00:00 2001 From: Chistopher Kochan <5183896+crkochan@users.noreply.github.com> Date: Sun, 5 Sep 2021 23:44:24 -0700 Subject: [PATCH 2/9] Added option for descriptive entity names. * Updates strings/translation with new option and description. * Modified config_flow to present a tick box to enable descriptive names, disabled by default to avoid breaking existing users. * Updated async_setup_entry() in sensor and binary_sensor to create long named entities if feature is enabled. * Added SUNPOWER_DESCRIPTIVE_NAMES to const. --- custom_components/sunpower/binary_sensor.py | 47 +++++++++++++++---- custom_components/sunpower/config_flow.py | 10 +++- custom_components/sunpower/const.py | 2 +- custom_components/sunpower/sensor.py | 20 ++++++-- custom_components/sunpower/strings.json | 6 ++- .../sunpower/translations/en.json | 6 ++- 6 files changed, 73 insertions(+), 18 deletions(-) diff --git a/custom_components/sunpower/binary_sensor.py b/custom_components/sunpower/binary_sensor.py index 00367d1..af576f9 100644 --- a/custom_components/sunpower/binary_sensor.py +++ b/custom_components/sunpower/binary_sensor.py @@ -6,6 +6,7 @@ from .const import ( DOMAIN, SUNPOWER_COORDINATOR, + SUNPOWER_DESCRIPTIVE_NAMES, PVS_DEVICE_TYPE, INVERTER_DEVICE_TYPE, METER_DEVICE_TYPE, @@ -23,6 +24,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Sunpower sensors.""" sunpower_state = hass.data[DOMAIN][config_entry.entry_id] _LOGGER.error("Sunpower_state: %s", sunpower_state) + do_descriptive_names = config_entry.data[SUNPOWER_DESCRIPTIVE_NAMES] coordinator = sunpower_state[SUNPOWER_COORDINATOR] sunpower_data = coordinator.data @@ -32,19 +34,23 @@ async def async_setup_entry(hass, config_entry, async_add_entities): else: pvs = next(iter(sunpower_data[PVS_DEVICE_TYPE].values())) - entities = [SunPowerPVSState(coordinator, pvs)] + entities = [SunPowerPVSState(coordinator, pvs, do_descriptive_names)] if METER_DEVICE_TYPE not in sunpower_data: _LOGGER.error("Cannot find any power meters") else: for data in sunpower_data[METER_DEVICE_TYPE].values(): - entities.append(SunPowerMeterState(coordinator, data, pvs)) + entities.append( + SunPowerMeterState(coordinator, data, pvs, do_descriptive_names) + ) if INVERTER_DEVICE_TYPE not in sunpower_data: _LOGGER.error("Cannot find any power inverters") else: for data in sunpower_data[INVERTER_DEVICE_TYPE].values(): - entities.append(SunPowerInverterState(coordinator, data, pvs)) + entities.append( + SunPowerInverterState(coordinator, data, pvs, do_descriptive_names) + ) async_add_entities(entities, True) @@ -52,10 +58,17 @@ async def async_setup_entry(hass, config_entry, async_add_entities): class SunPowerPVSState(SunPowerPVSEntity): """Representation of SunPower PVS Working State""" + def __init__(self, coordinator, pvs_info, do_descriptive_names): + super().__init__(coordinator, pvs_info) + self._do_descriptive_names = do_descriptive_names + @property def name(self): """Device Name.""" - return "System State" + if self._do_descriptive_names: + return "PVS System State" + else: + return "System State" @property def device_class(self): @@ -81,10 +94,17 @@ def is_on(self): class SunPowerMeterState(SunPowerMeterEntity): """Representation of SunPower Meter Working State""" + def __init__(self, coordinator, meter_info, pvs_info, do_descriptive_names): + super().__init__(coordinator, meter_info, pvs_info) + self._do_descriptive_names = do_descriptive_names + @property def name(self): """Device Name.""" - return "System State" + if self._do_descriptive_names: + return f"{self._meter_info['DESCR']} System State" + else: + return "System State" @property def device_class(self): @@ -99,7 +119,9 @@ def unique_id(self): @property def state(self): """Get the current value""" - return self.coordinator.data[METER_DEVICE_TYPE][self.base_unique_id][METER_STATE] + return self.coordinator.data[METER_DEVICE_TYPE][self.base_unique_id][ + METER_STATE + ] @property def is_on(self): @@ -110,10 +132,17 @@ def is_on(self): class SunPowerInverterState(SunPowerInverterEntity): """Representation of SunPower Inverter Working State""" + def __init__(self, coordinator, inverter_info, pvs_info, do_descriptive_names): + super().__init__(coordinator, inverter_info, pvs_info) + self._do_descriptive_names = do_descriptive_names + @property def name(self): """Device Name.""" - return "System State" + if self._do_descriptive_names: + return f"{self._inverter_info['DESCR']} System State" + else: + return "System State" @property def device_class(self): @@ -128,7 +157,9 @@ def unique_id(self): @property def state(self): """Get the current value""" - return self.coordinator.data[INVERTER_DEVICE_TYPE][self.base_unique_id][INVERTER_STATE] + return self.coordinator.data[INVERTER_DEVICE_TYPE][self.base_unique_id][ + INVERTER_STATE + ] @property def is_on(self): diff --git a/custom_components/sunpower/config_flow.py b/custom_components/sunpower/config_flow.py index d0bdc50..68223ed 100644 --- a/custom_components/sunpower/config_flow.py +++ b/custom_components/sunpower/config_flow.py @@ -4,12 +4,18 @@ import voluptuous as vol from homeassistant import config_entries, core, exceptions +from homeassistant.const import CONF_HOST -from .const import DOMAIN, SUNPOWER_HOST # pylint:disable=unused-import +from .const import DOMAIN, SUNPOWER_HOST, SUNPOWER_DESCRIPTIVE_NAMES _LOGGER = logging.getLogger(__name__) -DATA_SCHEMA = vol.Schema({"host": str}) +DATA_SCHEMA = vol.Schema( + { + vol.Required(CONF_HOST): str, + vol.Required(SUNPOWER_DESCRIPTIVE_NAMES, default=False): bool, + } +) async def validate_input(hass: core.HomeAssistant, data): diff --git a/custom_components/sunpower/const.py b/custom_components/sunpower/const.py index 204cf5a..a9a9d8a 100644 --- a/custom_components/sunpower/const.py +++ b/custom_components/sunpower/const.py @@ -14,7 +14,7 @@ DOMAIN = "sunpower" - +SUNPOWER_DESCRIPTIVE_NAMES = "use_descriptive_names" SUNPOWER_OBJECT = "sunpower" SUNPOWER_HOST = "host" SUNPOWER_COORDINATOR = "coordinator" diff --git a/custom_components/sunpower/sensor.py b/custom_components/sunpower/sensor.py index d228c17..88c01a9 100644 --- a/custom_components/sunpower/sensor.py +++ b/custom_components/sunpower/sensor.py @@ -6,6 +6,7 @@ from .const import ( DOMAIN, SUNPOWER_COORDINATOR, + SUNPOWER_DESCRIPTIVE_NAMES, PVS_DEVICE_TYPE, INVERTER_DEVICE_TYPE, METER_DEVICE_TYPE, @@ -22,6 +23,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Sunpower sensors.""" sunpower_state = hass.data[DOMAIN][config_entry.entry_id] _LOGGER.error("Sunpower_state: %s", sunpower_state) + do_descriptive_names = config_entry.data[SUNPOWER_DESCRIPTIVE_NAMES] coordinator = sunpower_state[SUNPOWER_COORDINATOR] sunpower_data = coordinator.data @@ -33,11 +35,15 @@ async def async_setup_entry(hass, config_entry, async_add_entities): entities = [] for sensor in PVS_SENSORS: + if do_descriptive_names: + title = f"{pvs['DEVICE_TYPE']} {PVS_SENSORS[sensor][1]}" + else: + title = PVS_SENSORS[sensor][1] spb = SunPowerPVSBasic( coordinator, pvs, PVS_SENSORS[sensor][0], - PVS_SENSORS[sensor][1], + title, PVS_SENSORS[sensor][2], PVS_SENSORS[sensor][3], ) @@ -52,12 +58,16 @@ async def async_setup_entry(hass, config_entry, async_add_entities): else: for data in sunpower_data[METER_DEVICE_TYPE].values(): for sensor in METER_SENSORS: + if do_descriptive_names: + title = f"{data['DESCR']} {METER_SENSORS[sensor][1]}" + else: + title = METER_SENSORS[sensor][1] smb = SunPowerMeterBasic( coordinator, data, pvs, METER_SENSORS[sensor][0], - METER_SENSORS[sensor][1], + title, METER_SENSORS[sensor][2], METER_SENSORS[sensor][3], ) @@ -72,12 +82,16 @@ async def async_setup_entry(hass, config_entry, async_add_entities): else: for data in sunpower_data[INVERTER_DEVICE_TYPE].values(): for sensor in INVERTER_SENSORS: + if do_descriptive_names: + title = f"{data['DESCR']} {INVERTER_SENSORS[sensor][1]}" + else: + title = INVERTER_SENSORS[sensor][1] sib = SunPowerInverterBasic( coordinator, data, pvs, INVERTER_SENSORS[sensor][0], - INVERTER_SENSORS[sensor][1], + title, INVERTER_SENSORS[sensor][2], INVERTER_SENSORS[sensor][3], ) diff --git a/custom_components/sunpower/strings.json b/custom_components/sunpower/strings.json index 63b29de..02a0a40 100644 --- a/custom_components/sunpower/strings.json +++ b/custom_components/sunpower/strings.json @@ -4,8 +4,10 @@ "step": { "user": { "data": { - "host": "host" - } + "host": "Host", + "use_descriptive_names": "Use descriptive entity names" + }, + "description": "If 'Use descriptive entity names' is selected, device names\nwill be prepended on all entity names." } }, "error": { diff --git a/custom_components/sunpower/translations/en.json b/custom_components/sunpower/translations/en.json index 2910448..b63ec86 100644 --- a/custom_components/sunpower/translations/en.json +++ b/custom_components/sunpower/translations/en.json @@ -10,8 +10,10 @@ "step": { "user": { "data": { - "host": "host" - } + "host": "Host", + "use_descriptive_names": "Use descriptive entity names" + }, + "description": "If 'Use descriptive entity names' is selected, device names\nwill be prepended on all entity names." } } }, From 8ff0e869eab83b9ccd656fedfaef83d21f28c99b Mon Sep 17 00:00:00 2001 From: Chistopher Kochan <5183896+crkochan@users.noreply.github.com> Date: Sun, 5 Sep 2021 23:46:13 -0700 Subject: [PATCH 3/9] Use unit-neutral temparature icon. Data is recorded in Celsius, but HA will convert to local units leading to a Celsius icon with a Fahrenheit unit. --- custom_components/sunpower/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/sunpower/const.py b/custom_components/sunpower/const.py index a9a9d8a..46b94f3 100644 --- a/custom_components/sunpower/const.py +++ b/custom_components/sunpower/const.py @@ -74,7 +74,7 @@ "t_htsnk_degc", "Temperature", TEMP_CELSIUS, - "mdi:temperature-celsius", + "mdi:thermometer", ], "INVERTER_FREQUENCY": ["freq_hz", "Frequency", FREQUENCY_HERTZ, "mdi:flash"], } From aae3a032f8f89f799751cc3ce2238075db3f1252 Mon Sep 17 00:00:00 2001 From: Chistopher Kochan <5183896+crkochan@users.noreply.github.com> Date: Sun, 5 Sep 2021 23:49:01 -0700 Subject: [PATCH 4/9] Revised logging. Lowered logging level of debugging logging from error or info level down to debug. --- custom_components/sunpower/__init__.py | 6 +++--- custom_components/sunpower/binary_sensor.py | 3 ++- custom_components/sunpower/config_flow.py | 2 +- custom_components/sunpower/sensor.py | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/custom_components/sunpower/__init__.py b/custom_components/sunpower/__init__.py index 2874802..f4cf4ba 100644 --- a/custom_components/sunpower/__init__.py +++ b/custom_components/sunpower/__init__.py @@ -32,7 +32,7 @@ def sunpower_fetch(sunpower_monitor): """Basic data fetch routine to get and reformat sunpower data to a dict of device type and serial #""" try: sunpower_data = sunpower_monitor.device_list() - _LOGGER.info("got data %s", sunpower_data) + _LOGGER.debug("got data %s", sunpower_data) data = {} # Convert data into indexable format data[device_type][serial] for device in sunpower_data["devices"]: @@ -72,7 +72,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): async def async_update_data(): """Fetch data from API endpoint, used by coordinator to get mass data updates""" - _LOGGER.info("Updating all sunpower data") + _LOGGER.debug("Updating SunPower data") return await hass.async_add_executor_job(sunpower_fetch, sunpower_monitor) coordinator = DataUpdateCoordinator( @@ -91,7 +91,7 @@ async def async_update_data(): start = time.time() # Need to make sure this data loads on setup, be aggressive about retries while not coordinator.data: - _LOGGER.info("Config Update Attempt") + _LOGGER.debug("Config Update Attempt") await coordinator.async_refresh() if (time.time() - start) > (SETUP_TIMEOUT_MIN * 60): _LOGGER.error("Failed to update data") diff --git a/custom_components/sunpower/binary_sensor.py b/custom_components/sunpower/binary_sensor.py index af576f9..b42002c 100644 --- a/custom_components/sunpower/binary_sensor.py +++ b/custom_components/sunpower/binary_sensor.py @@ -23,7 +23,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Sunpower sensors.""" sunpower_state = hass.data[DOMAIN][config_entry.entry_id] - _LOGGER.error("Sunpower_state: %s", sunpower_state) + _LOGGER.debug("Sunpower_state: %s", sunpower_state) + do_descriptive_names = config_entry.data[SUNPOWER_DESCRIPTIVE_NAMES] coordinator = sunpower_state[SUNPOWER_COORDINATOR] diff --git a/custom_components/sunpower/config_flow.py b/custom_components/sunpower/config_flow.py index 68223ed..1372345 100644 --- a/custom_components/sunpower/config_flow.py +++ b/custom_components/sunpower/config_flow.py @@ -28,7 +28,7 @@ async def validate_input(hass: core.HomeAssistant, data): name = "PVS {}".format(data["host"]) try: response = await hass.async_add_executor_job(spm.network_status) - _LOGGER.info("Got from %s %s", data["host"], response) + _LOGGER.debug("Got from %s %s", data["host"], response) except ConnectionException as error: raise CannotConnect from error diff --git a/custom_components/sunpower/sensor.py b/custom_components/sunpower/sensor.py index 88c01a9..4f7b625 100644 --- a/custom_components/sunpower/sensor.py +++ b/custom_components/sunpower/sensor.py @@ -22,7 +22,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Sunpower sensors.""" sunpower_state = hass.data[DOMAIN][config_entry.entry_id] - _LOGGER.error("Sunpower_state: %s", sunpower_state) + _LOGGER.debug("Sunpower_state: %s", sunpower_state) + do_descriptive_names = config_entry.data[SUNPOWER_DESCRIPTIVE_NAMES] coordinator = sunpower_state[SUNPOWER_COORDINATOR] From c22a6b7f1e1d0e2873b6bfe5f9ffcd1f96c4de34 Mon Sep 17 00:00:00 2001 From: Chistopher Kochan <5183896+crkochan@users.noreply.github.com> Date: Sun, 5 Sep 2021 23:49:22 -0700 Subject: [PATCH 5/9] Correct case on SunPower name. --- custom_components/sunpower/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/sunpower/__init__.py b/custom_components/sunpower/__init__.py index f4cf4ba..00df8df 100644 --- a/custom_components/sunpower/__init__.py +++ b/custom_components/sunpower/__init__.py @@ -78,7 +78,7 @@ async def async_update_data(): coordinator = DataUpdateCoordinator( hass, _LOGGER, - name="Sunpower PVS", + name="SunPower PVS", update_method=async_update_data, update_interval=timedelta(seconds=UPDATE_INTERVAL), ) From a324b196ea20e7b6ab7e5133a15c480ce6a907d4 Mon Sep 17 00:00:00 2001 From: Chistopher Kochan <5183896+crkochan@users.noreply.github.com> Date: Sun, 5 Sep 2021 23:50:05 -0700 Subject: [PATCH 6/9] Updated README file. * Whitespace trimming. * Added section describing descriptive entity names feature. --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3714c8d..9c25e8b 100644 --- a/README.md +++ b/README.md @@ -16,17 +16,15 @@ Platform | Description `sensor` | Most data available from the PVS system including per-panel data. ## Installation - 1. Click install. -1. In the HA UI go to "Configuration" -> "Integrations" click "+" and search for "Sunpower". - - +2. In the HA UI go to "Configuration" -> "Integrations" click "+" and search for "Sunpower". ## Configuration is done in the UI * it will ask for a host (ip works) * hint: most sunpower systems are at 172.27.153.1 - +## Use descriptive entity names +When selected during installation, entities added for each device will have the device descriptor added onto the front of their name. The device descriptor is a combination of device type (e.g., Inverter) and serial number. This guarantees unique entity IDs and names at the expense of making said names very long. ## Network Setup This integration requires connectivity to the management interface used for installing the system. The PVS systems have a second lan interface in the box. *DO NOT PLUG THIS INTO YOUR LAN!!!* it is running its own DHCP server which will cause all sorts of IP addressing issues. I run a Linux router with a spare ethernet port and route to the sunpower interface and allow my home assistant system to connect directly to the PVS. Also note that the command used to dump data 'device list' is very slow and sometimes times out. I've built in some retry logic so setup passes pretty reliably. Sometimes you may see data go blank if the fetch times out. From 16393ca12820343b15cce1097f1d50fa245eaf44 Mon Sep 17 00:00:00 2001 From: Chistopher Kochan <5183896+crkochan@users.noreply.github.com> Date: Sun, 5 Sep 2021 23:50:15 -0700 Subject: [PATCH 7/9] Incremented version. --- custom_components/sunpower/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/sunpower/manifest.json b/custom_components/sunpower/manifest.json index b821826..0578dc5 100644 --- a/custom_components/sunpower/manifest.json +++ b/custom_components/sunpower/manifest.json @@ -1,5 +1,5 @@ { - "version": "0.0.9", + "version": "0.0.10", "domain": "sunpower", "name": "sunpower", "config_flow": true, From 50d686505d541f8b9d716490dc8a877b7444315a Mon Sep 17 00:00:00 2001 From: Chistopher Kochan <5183896+crkochan@users.noreply.github.com> Date: Sun, 5 Sep 2021 23:59:07 -0700 Subject: [PATCH 8/9] Revise integration name in hacs manifest. --- hacs.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hacs.json b/hacs.json index 1c802e6..9d5aefb 100644 --- a/hacs.json +++ b/hacs.json @@ -1,5 +1,5 @@ { - "name": "HACS Sunpower Integration", + "name": "SunPower", "country": "US", "domains": ["binary_sensor", "sensor"], "homeassistant": "2021.8.0", From 73e331465d998f09b4da10bc19efec5c245e394f Mon Sep 17 00:00:00 2001 From: Chistopher Kochan <5183896+crkochan@users.noreply.github.com> Date: Mon, 6 Sep 2021 00:30:02 -0700 Subject: [PATCH 9/9] Revert some VS Code line breakage. --- custom_components/sunpower/binary_sensor.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/custom_components/sunpower/binary_sensor.py b/custom_components/sunpower/binary_sensor.py index b42002c..bb795d9 100644 --- a/custom_components/sunpower/binary_sensor.py +++ b/custom_components/sunpower/binary_sensor.py @@ -41,17 +41,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities): _LOGGER.error("Cannot find any power meters") else: for data in sunpower_data[METER_DEVICE_TYPE].values(): - entities.append( - SunPowerMeterState(coordinator, data, pvs, do_descriptive_names) - ) + entities.append(SunPowerMeterState(coordinator, data, pvs, do_descriptive_names)) if INVERTER_DEVICE_TYPE not in sunpower_data: _LOGGER.error("Cannot find any power inverters") else: for data in sunpower_data[INVERTER_DEVICE_TYPE].values(): - entities.append( - SunPowerInverterState(coordinator, data, pvs, do_descriptive_names) - ) + entities.append(SunPowerInverterState(coordinator, data, pvs, do_descriptive_names)) async_add_entities(entities, True) @@ -120,9 +116,7 @@ def unique_id(self): @property def state(self): """Get the current value""" - return self.coordinator.data[METER_DEVICE_TYPE][self.base_unique_id][ - METER_STATE - ] + return self.coordinator.data[METER_DEVICE_TYPE][self.base_unique_id][METER_STATE] @property def is_on(self): @@ -158,9 +152,7 @@ def unique_id(self): @property def state(self): """Get the current value""" - return self.coordinator.data[INVERTER_DEVICE_TYPE][self.base_unique_id][ - INVERTER_STATE - ] + return self.coordinator.data[INVERTER_DEVICE_TYPE][self.base_unique_id][INVERTER_STATE] @property def is_on(self):