Switchbot "in memory" state for push mode switch (#58750)

* Add in memory state tracking to Switchbot switch.

* Switchbot assumed state

* Add in memory state when Bot is in push mode.

* Cleanup
This commit is contained in:
RenierM26 2021-11-13 19:21:37 +02:00 committed by GitHub
parent 0ba45e4db4
commit 6749930736
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -130,6 +130,8 @@ class SwitchBotBotEntity(SwitchbotEntity, SwitchEntity, RestoreEntity):
self._last_run_success = bool(
await self.hass.async_add_executor_job(self._device.turn_on)
)
if self._last_run_success:
self._attr_is_on = True
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn device off."""
@ -139,6 +141,8 @@ class SwitchBotBotEntity(SwitchbotEntity, SwitchEntity, RestoreEntity):
self._last_run_success = bool(
await self.hass.async_add_executor_job(self._device.turn_off)
)
if self._last_run_success:
self._attr_is_on = False
@property
def assumed_state(self) -> bool:
@ -150,6 +154,8 @@ class SwitchBotBotEntity(SwitchbotEntity, SwitchEntity, RestoreEntity):
@property
def is_on(self) -> bool:
"""Return true if device is on."""
if not self.data["data"]["switchMode"]:
return self._attr_is_on
return self.data["data"]["isOn"]
@property