Skip to content

Commit

Permalink
Roll back restore state
Browse files Browse the repository at this point in the history
  • Loading branch information
bruxy70 committed Jul 14, 2022
1 parent acdf930 commit b48238b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 0 additions & 4 deletions custom_components/garbage_collection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,6 @@ async def async_migrate_entry(_: HomeAssistant, config_entry: ConfigEntry) -> bo

async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Update listener - to re-create device after options update."""
for entity in hass.data["garbage_collection"]["sensor"].values():
if entity.unique_id == entry.entry_id:
entity.clear_state()
break
await hass.config_entries.async_forward_entry_unload(entry, const.SENSOR_PLATFORM)
hass.async_add_job(
hass.config_entries.async_forward_entry_setup(entry, const.SENSOR_PLATFORM)
Expand Down
9 changes: 5 additions & 4 deletions custom_components/garbage_collection/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ async def async_added_to_hass(self) -> None:

# Restore stored state
if (state := await self.async_get_last_state()) is not None:
self._attr_state = state.state
self._days = state.attributes[const.ATTR_DAYS]
next_date = helpers.parse_datetime(state.attributes[const.ATTR_NEXT_DATE])
self._next_date = None if next_date is None else next_date.date()
# TBD - This will prevent update when options change
# self._attr_state = state.state
# self._days = state.attributes[const.ATTR_DAYS]
# next_date = helpers.parse_datetime(state.attributes[const.ATTR_NEXT_DATE])
# self._next_date = None if next_date is None else next_date.date()
self.last_collection = helpers.parse_datetime(
state.attributes[const.ATTR_LAST_COLLECTION]
)
Expand Down

0 comments on commit b48238b

Please sign in to comment.