Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to 2023.6 #5

Merged
merged 3 commits into from
Jul 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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