File tree 4 files changed +21
-4
lines changed 4 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 10
10
# data: 650000cd802b6300
11
11
# data: 658000c9802b6300
12
12
13
+
13
14
# Low: 658000c5222b6300
14
15
# Med: 658000c5432b6300
15
16
# High: 658000c5642b6300
Original file line number Diff line number Diff line change @@ -27,7 +27,6 @@ class SwitchbotAccountConnectionError(RuntimeError):
27
27
28
28
29
29
class SwitchbotModel (StrEnum ):
30
-
31
30
BOT = "WoHand"
32
31
CURTAIN = "WoCurtain"
33
32
HUMIDIFIER = "WoHumi"
Original file line number Diff line number Diff line change 26
26
from ..const import DEFAULT_RETRY_COUNT , DEFAULT_SCAN_TIMEOUT
27
27
from ..discovery import GetSwitchbotDevices
28
28
from ..models import SwitchBotAdvertisement
29
+ from ..util import execute_task
29
30
30
31
_LOGGER = logging .getLogger (__name__ )
31
32
48
49
49
50
50
51
class ColorMode (Enum ):
51
-
52
52
OFF = 0
53
53
COLOR_TEMP = 1
54
54
RGB = 2
@@ -331,7 +331,7 @@ def _disconnect_from_timer(self):
331
331
self ._reset_disconnect_timer ()
332
332
return
333
333
self ._cancel_disconnect_timer ()
334
- asyncio . create_task (self ._execute_timed_disconnect ())
334
+ execute_task (self ._execute_timed_disconnect ())
335
335
336
336
def _cancel_disconnect_timer (self ):
337
337
"""Cancel disconnect timer."""
@@ -375,7 +375,7 @@ async def _execute_disconnect_with_lock(self) -> None:
375
375
self ._client = None
376
376
self ._read_char = None
377
377
self ._write_char = None
378
- if client and client . is_connected :
378
+ if client :
379
379
_LOGGER .debug ("%s: Disconnecting" , self .name )
380
380
await client .disconnect ()
381
381
_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