Skip to content

Commit

Permalink
#439 Check for attributes on restore
Browse files Browse the repository at this point in the history
  • Loading branch information
bruxy70 committed Nov 21, 2022
1 parent 232bdbd commit 04005c2
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions custom_components/garbage_collection/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,21 @@ async def async_added_to_hass(self) -> None:
if (state := await self.async_get_last_state()) is not None:
self._last_updated = None # Unblock update - after 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._days = (
state.attributes[const.ATTR_DAYS]
if const.ATTR_DAYS in state.attributes
else None
)
next_date = (
helpers.parse_datetime(state.attributes[const.ATTR_NEXT_DATE])
if const.ATTR_NEXT_DATE in state.attributes
else None
)
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]
self.last_collection = (
helpers.parse_datetime(state.attributes[const.ATTR_LAST_COLLECTION])
if const.ATTR_LAST_COLLECTION in state.attributes
else None
)

# Create device
Expand Down

0 comments on commit 04005c2

Please sign in to comment.