Skip to content

Commit

Permalink
Merge pull request #72 from tijsverkoyen/69-unavailable
Browse files Browse the repository at this point in the history
Move handling unavailable entity state up
  • Loading branch information
tijsverkoyen authored Feb 28, 2023
2 parents 08b82ac + ef06025 commit de7239c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions custom_components/fusion_solar/fusion_solar/energy_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,17 @@ def state(self) -> float:

if entity is not None:
current_value = entity.state
realtime_power = self.coordinator.data[self._data_name][ATTR_REALTIME_POWER]
if current_value == 'unavailable':
_LOGGER.info(
f'{self.entity_id}: not available.')
return

realtime_power = self.coordinator.data[self._data_name][ATTR_REALTIME_POWER]
if realtime_power == '0.00':
_LOGGER.info(
f'{self.entity_id}: not producing any power, so not updating to prevent positive glitched.')
return float(current_value)

if current_value == 'unavailable':
_LOGGER.info(
f'{self.entity_id}: not available.')
return

if self._data_name not in self.coordinator.data:
return None

Expand Down

0 comments on commit de7239c

Please sign in to comment.