From e17d69e83e5272a652dfba43da40740a4dfa6b20 Mon Sep 17 00:00:00 2001 From: Alvaro Duarte <59612788+ad-ha@users.noreply.github.com> Date: Tue, 8 Feb 2022 23:20:27 +0100 Subject: [PATCH] Restore sensor state on restart Changes to restore last reading available on HA restart, in case a new reading fails during startup. --- custom_components/ide/sensor.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/custom_components/ide/sensor.py b/custom_components/ide/sensor.py index d3c79ef..ce89cfe 100644 --- a/custom_components/ide/sensor.py +++ b/custom_components/ide/sensor.py @@ -29,6 +29,7 @@ ConfigType, DiscoveryInfoType, ) +from homeassistant.helpers.dispatcher import async_dispatcher_connect import homeassistant.helpers.config_validation as cv __VERSION__ = "0.2.1" @@ -121,7 +122,9 @@ async def async_added_to_hass(self) -> None: return self._state = state.state _LOGGER.warning( - "i-DE Meter could not be updated. Last data restored {}".format(self._state) + "i-DE Meter could not be updated. Last reading available was restored: {}".format( + self._state + ) ) async_dispatcher_connect( @@ -132,7 +135,7 @@ async def async_added_to_hass(self) -> None: def _schedule_immediate_update(self): """Schedule Update when possible""" self.async_schedule_update_ha_state(True) - + @property def name(self): """Return the name of the sensor."""