Skip to content

Commit 486d32b

Browse files
authored
Fix plug stale state while connected (#115)
1 parent 0b7c736 commit 486d32b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

switchbot/devices/plug.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""Library to handle connection with Switchbot."""
22
from __future__ import annotations
33

4-
from .device import REQ_HEADER, SwitchbotDevice
4+
from .device import REQ_HEADER, SwitchbotDeviceOverrideStateDuringConnection
55

66
# Plug Mini keys
77
PLUG_ON_KEY = f"{REQ_HEADER}50010180"
88
PLUG_OFF_KEY = f"{REQ_HEADER}50010100"
99

1010

11-
class SwitchbotPlugMini(SwitchbotDevice):
11+
class SwitchbotPlugMini(SwitchbotDeviceOverrideStateDuringConnection):
1212
"""Representation of a Switchbot plug mini."""
1313

1414
async def update(self, interface: int | None = None) -> None:
@@ -18,12 +18,18 @@ async def update(self, interface: int | None = None) -> None:
1818
async def turn_on(self) -> bool:
1919
"""Turn device on."""
2020
result = await self._send_command(PLUG_ON_KEY)
21-
return self._check_command_result(result, 1, {0x80})
21+
ret = self._check_command_result(result, 1, {0x80})
22+
self._override_adv_data = {"isOn": True}
23+
self._fire_callbacks()
24+
return ret
2225

2326
async def turn_off(self) -> bool:
2427
"""Turn device off."""
2528
result = await self._send_command(PLUG_OFF_KEY)
26-
return self._check_command_result(result, 1, {0x00})
29+
ret = self._check_command_result(result, 1, {0x80})
30+
self._override_adv_data = {"isOn": False}
31+
self._fire_callbacks()
32+
return ret
2733

2834
def is_on(self) -> bool | None:
2935
"""Return switch state from cache."""

0 commit comments

Comments
 (0)