Skip to content

Commit ab217db

Browse files
authored
Simplify holding a reference to a background task (#190)
1 parent 1ac426c commit ab217db

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

switchbot/devices/device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from ..const import DEFAULT_RETRY_COUNT, DEFAULT_SCAN_TIMEOUT
2727
from ..discovery import GetSwitchbotDevices
2828
from ..models import SwitchBotAdvertisement
29-
from ..util import execute_task
3029

3130
_LOGGER = logging.getLogger(__name__)
3231

@@ -144,6 +143,7 @@ def __init__(
144143
self._callbacks: list[Callable[[], None]] = []
145144
self._notify_future: asyncio.Future[bytearray] | None = None
146145
self._last_full_update: float = -PASSIVE_POLL_INTERVAL
146+
self._timed_disconnect_task: asyncio.Task[None] | None = None
147147

148148
def advertisement_changed(self, advertisement: SwitchBotAdvertisement) -> bool:
149149
"""Check if the advertisement has changed."""
@@ -331,7 +331,7 @@ def _disconnect_from_timer(self):
331331
self._reset_disconnect_timer()
332332
return
333333
self._cancel_disconnect_timer()
334-
execute_task(self._execute_timed_disconnect())
334+
self._timed_disconnect_task = self._execute_timed_disconnect()
335335

336336
def _cancel_disconnect_timer(self):
337337
"""Cancel disconnect timer."""

switchbot/util.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)