File tree Expand file tree Collapse file tree 4 files changed +21
-4
lines changed Expand file tree Collapse file tree 4 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 1010# data: 650000cd802b6300
1111# data: 658000c9802b6300
1212
13+
1314# Low: 658000c5222b6300
1415# Med: 658000c5432b6300
1516# High: 658000c5642b6300
Original file line number Diff line number Diff line change @@ -27,7 +27,6 @@ class SwitchbotAccountConnectionError(RuntimeError):
2727
2828
2929class SwitchbotModel (StrEnum ):
30-
3130 BOT = "WoHand"
3231 CURTAIN = "WoCurtain"
3332 HUMIDIFIER = "WoHumi"
Original file line number Diff line number Diff line change 2626from ..const import DEFAULT_RETRY_COUNT , DEFAULT_SCAN_TIMEOUT
2727from ..discovery import GetSwitchbotDevices
2828from ..models import SwitchBotAdvertisement
29+ from ..util import execute_task
2930
3031_LOGGER = logging .getLogger (__name__ )
3132
4849
4950
5051class ColorMode (Enum ):
51-
5252 OFF = 0
5353 COLOR_TEMP = 1
5454 RGB = 2
@@ -331,7 +331,7 @@ def _disconnect_from_timer(self):
331331 self ._reset_disconnect_timer ()
332332 return
333333 self ._cancel_disconnect_timer ()
334- asyncio . create_task (self ._execute_timed_disconnect ())
334+ execute_task (self ._execute_timed_disconnect ())
335335
336336 def _cancel_disconnect_timer (self ):
337337 """Cancel disconnect timer."""
@@ -375,7 +375,7 @@ async def _execute_disconnect_with_lock(self) -> None:
375375 self ._client = None
376376 self ._read_char = None
377377 self ._write_char = None
378- if client and client . is_connected :
378+ if client :
379379 _LOGGER .debug ("%s: Disconnecting" , self .name )
380380 await client .disconnect ()
381381 _LOGGER .debug ("%s: Disconnect completed" , self .name )
Original file line number Diff line number Diff line change 1+ """Library to handle connection with Switchbot."""
2+
3+ import asyncio
4+ from collections .abc import Awaitable
5+ from typing import Any
6+
7+
8+ def execute_task (fut : Awaitable [Any ]) -> None :
9+ """Execute task."""
10+ task = asyncio .create_task (fut )
11+ tasks = [task ]
12+
13+ def _cleanup_task (task : asyncio .Task [Any ]) -> None :
14+ """Cleanup task."""
15+ tasks .remove (task )
16+
17+ task .add_done_callback (_cleanup_task )
You can’t perform that action at this time.
0 commit comments