Skip to content

Commit

Permalink
native_value() now returns None when it is unable to find the expected
Browse files Browse the repository at this point in the history
field from the PVS (indicating the sensor is unavailable). Continue to
skip over these entities.
  • Loading branch information
bakerkj committed May 15, 2023
1 parent 4f78621 commit b3f27bf
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions custom_components/sunpower/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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)

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit b3f27bf

Please sign in to comment.