From 97b4029a751a1a384485442ee7d5a83cef669b9e Mon Sep 17 00:00:00 2001 From: Keith Baker Date: Sun, 14 May 2023 17:58:26 -0400 Subject: [PATCH 1/5] This never worked.. its supposed to throw away sensors it cant find, this never calls the function --- custom_components/sunpower/sensor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/sunpower/sensor.py b/custom_components/sunpower/sensor.py index 69f629e..755925e 100644 --- a/custom_components/sunpower/sensor.py +++ b/custom_components/sunpower/sensor.py @@ -54,7 +54,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): PVS_SENSORS[sensor][5], ) try: - spb.native_value + spb.native_value() # ensure we can pull a value here, otherwise throw out this value entities.append(spb) except KeyError: pass @@ -80,7 +80,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): METER_SENSORS[sensor][5], ) try: - smb.native_value + smb.native_value() # ensure we can pull a value here, otherwise throw out this value entities.append(smb) except KeyError: pass @@ -106,7 +106,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): INVERTER_SENSORS[sensor][5] ) try: - sib.native_value + sib.native_value() # ensure we can pull a value here, otherwise throw out this value entities.append(sib) except KeyError: pass From 0d80b434800b6778e250a2d3b8ed9f1338bdb6ab Mon Sep 17 00:00:00 2001 From: Keith Baker Date: Sun, 14 May 2023 18:09:10 -0400 Subject: [PATCH 2/5] add the combined amperage data - looks like some firmwares report a merged value here --- custom_components/sunpower/const.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/custom_components/sunpower/const.py b/custom_components/sunpower/const.py index f4d4446..2735451 100644 --- a/custom_components/sunpower/const.py +++ b/custom_components/sunpower/const.py @@ -64,6 +64,8 @@ DEVICE_CLASS_POWER_FACTOR, STATE_CLASS_MEASUREMENT], "METER_L1_A": ["i1_a", "Leg 1 Amps", ELECTRIC_CURRENT_AMPERE, "mdi:flash", DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT], + "METER_L1_A": ["i_a", "Amps", ELECTRIC_CURRENT_AMPERE, "mdi:flash", + DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT], "METER_L2_A": ["i2_a", "Leg 2 Amps", ELECTRIC_CURRENT_AMPERE, "mdi:flash", DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT], "METER_L1_KW": ["p1_kw", "Leg 1 KW", POWER_KILO_WATT, "mdi:flash", From 6ae2dfb1a28184bf58bae1b35c8fce4ae9fa0e99 Mon Sep 17 00:00:00 2001 From: Keith Baker Date: Sun, 14 May 2023 18:14:35 -0400 Subject: [PATCH 3/5] fix name of meter --- 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 2735451..59fb1de 100644 --- a/custom_components/sunpower/const.py +++ b/custom_components/sunpower/const.py @@ -64,7 +64,7 @@ DEVICE_CLASS_POWER_FACTOR, STATE_CLASS_MEASUREMENT], "METER_L1_A": ["i1_a", "Leg 1 Amps", ELECTRIC_CURRENT_AMPERE, "mdi:flash", DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT], - "METER_L1_A": ["i_a", "Amps", ELECTRIC_CURRENT_AMPERE, "mdi:flash", + "METER_A": ["i_a", "Amps", ELECTRIC_CURRENT_AMPERE, "mdi:flash", DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT], "METER_L2_A": ["i2_a", "Leg 2 Amps", ELECTRIC_CURRENT_AMPERE, "mdi:flash", DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT], From 8aef21b6b75eeed0d82299917c3dc6795d310928 Mon Sep 17 00:00:00 2001 From: Keith Baker Date: Sun, 14 May 2023 18:58:25 -0400 Subject: [PATCH 4/5] quick skim missed these are properties so it was correct before --- custom_components/sunpower/sensor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/sunpower/sensor.py b/custom_components/sunpower/sensor.py index 755925e..402a5d3 100644 --- a/custom_components/sunpower/sensor.py +++ b/custom_components/sunpower/sensor.py @@ -54,7 +54,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): PVS_SENSORS[sensor][5], ) try: - spb.native_value() # ensure we can pull a value here, otherwise throw out this value + spb.native_value # ensure we can pull a value here, otherwise throw out this value entities.append(spb) except KeyError: pass @@ -80,7 +80,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): METER_SENSORS[sensor][5], ) try: - smb.native_value() # ensure we can pull a value here, otherwise throw out this value + smb.native_value # ensure we can pull a value here, otherwise throw out this value entities.append(smb) except KeyError: pass @@ -106,7 +106,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): INVERTER_SENSORS[sensor][5] ) try: - sib.native_value() # ensure we can pull a value here, otherwise throw out this value + sib.native_value # ensure we can pull a value here, otherwise throw out this value entities.append(sib) except KeyError: pass From b3f27bf68e28d4fa2184a9fe5ccb6b4d926ef3a5 Mon Sep 17 00:00:00 2001 From: Kenneth J Baker Date: Mon, 15 May 2023 13:31:05 -0400 Subject: [PATCH 5/5] native_value() now returns None when it is unable to find the expected field from the PVS (indicating the sensor is unavailable). Continue to skip over these entities. --- custom_components/sunpower/sensor.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/custom_components/sunpower/sensor.py b/custom_components/sunpower/sensor.py index 402a5d3..71fb42c 100644 --- a/custom_components/sunpower/sensor.py +++ b/custom_components/sunpower/sensor.py @@ -53,11 +53,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): PVS_SENSORS[sensor][4], PVS_SENSORS[sensor][5], ) - try: - spb.native_value # ensure we can pull a value here, otherwise throw out this value + if spb.native_value is not None: # ensure we can pull a value here, otherwise throw out this value entities.append(spb) - except KeyError: - pass if METER_DEVICE_TYPE not in sunpower_data: _LOGGER.error("Cannot find any power meters") @@ -79,11 +76,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): METER_SENSORS[sensor][4], METER_SENSORS[sensor][5], ) - try: - smb.native_value # ensure we can pull a value here, otherwise throw out this value + if smb.native_value is not None: # ensure we can pull a value here, otherwise throw out this value entities.append(smb) - except KeyError: - pass if INVERTER_DEVICE_TYPE not in sunpower_data: _LOGGER.error("Cannot find any power inverters") @@ -105,11 +99,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): INVERTER_SENSORS[sensor][4], INVERTER_SENSORS[sensor][5] ) - try: - sib.native_value # ensure we can pull a value here, otherwise throw out this value + if sib.native_value is not None: # ensure we can pull a value here, otherwise throw out this value entities.append(sib) - except KeyError: - pass async_add_entities(entities, True) @@ -160,7 +151,7 @@ def unique_id(self): @property def native_value(self): """Get the current value""" - return self.coordinator.data[PVS_DEVICE_TYPE][self.base_unique_id][self._field] + return self.coordinator.data[PVS_DEVICE_TYPE][self.base_unique_id].get(self._field, None) class SunPowerMeterBasic(SunPowerMeterEntity, SensorEntity): @@ -210,7 +201,7 @@ def unique_id(self): @property def native_value(self): """Get the current value""" - return self.coordinator.data[METER_DEVICE_TYPE][self.base_unique_id][self._field] + return self.coordinator.data[METER_DEVICE_TYPE][self.base_unique_id].get(self._field, None) class SunPowerInverterBasic(SunPowerInverterEntity, SensorEntity): @@ -260,4 +251,4 @@ def unique_id(self): @property def native_value(self): """Get the current value""" - return self.coordinator.data[INVERTER_DEVICE_TYPE][self.base_unique_id][self._field] + return self.coordinator.data[INVERTER_DEVICE_TYPE][self.base_unique_id].get(self._field, None)