Skip to content

Commit

Permalink
Merge pull request #49 from bakerkj/fix-issue-47
Browse files Browse the repository at this point in the history
Fix issue 47
  • Loading branch information
krbaker authored May 15, 2023
2 parents e1e2bf2 + b3f27bf commit f8a9716
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
2 changes: 2 additions & 0 deletions custom_components/sunpower/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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_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",
Expand Down
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
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
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
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 f8a9716

Please sign in to comment.