Fix switchbot failing to setup when last_run_success is not saved (#75887)

pull/75945/head
J. Nick Koston 2022-07-29 18:33:29 -10:00 committed by GitHub
parent 80a9659524
commit bb3e094552
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -80,9 +80,12 @@ class SwitchBotCurtainEntity(SwitchbotEntity, CoverEntity, RestoreEntity):
if not last_state or ATTR_CURRENT_POSITION not in last_state.attributes:
return
self._attr_current_cover_position = last_state.attributes[ATTR_CURRENT_POSITION]
self._last_run_success = last_state.attributes["last_run_success"]
self._attr_is_closed = last_state.attributes[ATTR_CURRENT_POSITION] <= 20
self._attr_current_cover_position = last_state.attributes.get(
ATTR_CURRENT_POSITION
)
self._last_run_success = last_state.attributes.get("last_run_success")
if self._attr_current_cover_position is not None:
self._attr_is_closed = self._attr_current_cover_position <= 20
async def async_open_cover(self, **kwargs: Any) -> None:
"""Open the curtain."""

View File

@ -69,7 +69,7 @@ class SwitchBotBotEntity(SwitchbotEntity, SwitchEntity, RestoreEntity):
if not (last_state := await self.async_get_last_state()):
return
self._attr_is_on = last_state.state == STATE_ON
self._last_run_success = last_state.attributes["last_run_success"]
self._last_run_success = last_state.attributes.get("last_run_success")
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn device on."""