Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions homeassistant/components/switchbot/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ async def async_turn_on(self, **kwargs: Any) -> None:
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."""
Expand All @@ -140,6 +142,8 @@ async def async_turn_off(self, **kwargs: Any) -> None:
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:
Expand All @@ -151,6 +155,8 @@ def assumed_state(self) -> bool:
@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
Expand Down