mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix switchbot failing to setup when last_run_success is not saved (#75887)
This commit is contained in:
parent
80a9659524
commit
bb3e094552
@ -80,9 +80,12 @@ class SwitchBotCurtainEntity(SwitchbotEntity, CoverEntity, RestoreEntity):
|
|||||||
if not last_state or ATTR_CURRENT_POSITION not in last_state.attributes:
|
if not last_state or ATTR_CURRENT_POSITION not in last_state.attributes:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._attr_current_cover_position = last_state.attributes[ATTR_CURRENT_POSITION]
|
self._attr_current_cover_position = last_state.attributes.get(
|
||||||
self._last_run_success = last_state.attributes["last_run_success"]
|
ATTR_CURRENT_POSITION
|
||||||
self._attr_is_closed = last_state.attributes[ATTR_CURRENT_POSITION] <= 20
|
)
|
||||||
|
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:
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||||
"""Open the curtain."""
|
"""Open the curtain."""
|
||||||
|
@ -69,7 +69,7 @@ class SwitchBotBotEntity(SwitchbotEntity, SwitchEntity, RestoreEntity):
|
|||||||
if not (last_state := await self.async_get_last_state()):
|
if not (last_state := await self.async_get_last_state()):
|
||||||
return
|
return
|
||||||
self._attr_is_on = last_state.state == STATE_ON
|
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:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn device on."""
|
"""Turn device on."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user