Skip to content

Commit

Permalink
Use comparitor state if we can't restore state (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommatheussen authored Jun 14, 2022
1 parent 3f65e3c commit 4f42e6f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions custom_components/battery_sim/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,7 @@ def __init__(
self._device_name = device_name
self._type_of_sensor = type_of_sensor
self._last_reset = dt_util.utcnow()
if comparitor_sensor is not None:
self._comparitor_sensor = comparitor_sensor
self._state = float(self._comparitor_sensor.state)
else:
self._state = 0.0
self._comparitor_sensor = comparitor_sensor

async def async_added_to_hass(self):
"""Handle entity which will be added."""
Expand All @@ -154,6 +150,10 @@ async def async_added_to_hass(self):
state = await self.async_get_last_state()
if state:
self._state = float(state.state)
elif self._comparitor_sensor is not None and self._comparitor_sensor.state not in [STATE_UNAVAILABLE, STATE_UNKNOWN]:
self._state = float(self._comparitor_sensor.state)
else:
self._state = 0.0

@callback
def update_value(self, value):
Expand Down

0 comments on commit 4f42e6f

Please sign in to comment.