From 70d21bf3c09ad0cc0c3ab1c0143fabfbbb2a84ed Mon Sep 17 00:00:00 2001 From: RenierM26 <66512715+RenierM26@users.noreply.github.com> Date: Sat, 8 Jan 2022 13:58:31 +0200 Subject: [PATCH] Switchbot Set initial state for switch (#63654) --- homeassistant/components/switchbot/switch.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/homeassistant/components/switchbot/switch.py b/homeassistant/components/switchbot/switch.py index a09255d0392..48dbd8d8cac 100644 --- a/homeassistant/components/switchbot/switch.py +++ b/homeassistant/components/switchbot/switch.py @@ -113,6 +113,7 @@ class SwitchBotBotEntity(SwitchbotEntity, SwitchEntity, RestoreEntity): super().__init__(coordinator, idx, mac, name) self._attr_unique_id = idx self._device = device + self._attr_is_on = False async def async_added_to_hass(self) -> None: """Run when entity about to be added.""" @@ -132,6 +133,7 @@ class SwitchBotBotEntity(SwitchbotEntity, SwitchEntity, RestoreEntity): ) if self._last_run_success: self._attr_is_on = True + self.async_write_ha_state() async def async_turn_off(self, **kwargs: Any) -> None: """Turn device off.""" @@ -143,6 +145,7 @@ class SwitchBotBotEntity(SwitchbotEntity, SwitchEntity, RestoreEntity): ) if self._last_run_success: self._attr_is_on = False + self.async_write_ha_state() @property def assumed_state(self) -> bool: