Skip to content

Commit

Permalink
Merge pull request #1 from St4n/St4n-patch-1
Browse files Browse the repository at this point in the history
Adapt to 2023.6
  • Loading branch information
St4n authored Jul 9, 2023
2 parents 7b0af96 + 69231db commit 52b1a51
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions custom_components/signal_ecogaz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,21 @@ def restored(self):
async def async_added_to_hass(self):
await super().async_added_to_hass()
_LOGGER.debug("starting to restore sensor from previous data")
if (last_stored_state := await self._async_get_restored_data()) is not None:
old_state = last_stored_state.state.as_dict()
_LOGGER.debug(f"restored state: {old_state}")
self._state = old_state["state"]
for key, value in old_state["attributes"].items():
self._attr_extra_state_attributes[key] = value
self.coordinator.last_update_success = True

if (extra_stored_data := await self.async_get_last_sensor_data()) is not None:
if (
extra_stored_data.native_value != "unknown"
or self.restore_even_if_unknown()
):
_LOGGER.debug(f"Restoring state for {self.unique_id}")
self._attr_native_value = extra_stored_data.native_value
self._attr_native_unit_of_measurement = extra_stored_data.native_unit_of_measurement
# sadly it seems as of 2023.6 we don't have any way to get back the additional attributes
self.coordinator.last_update_success = True
else:
# by not restoring state, we allow the Coordinator to fetch data again and fill
# data as soon as possible
_LOGGER.debug(f"Stored state was 'unknown', starting from scratch")
# signal restoration happened
self._restored = True

Expand Down

0 comments on commit 52b1a51

Please sign in to comment.