Skip to content

Commit

Permalink
set timers to None after cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
chemwolf6922 committed Dec 22, 2024
1 parent fb46bc6 commit f614181
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions custom_components/xiaomi_home/miot/miot_lan.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,10 @@ def unsubscribe(self) -> None:
def on_delete(self) -> None:
if self._ka_timer:
self._ka_timer.cancel()
self._ka_timer = None
if self._online_offline_timer:
self._online_offline_timer.cancel()
self._online_offline_timer = None
_LOGGER.debug('miot lan device delete, %s', self.did)

def update_info(self, info: dict) -> None:
Expand Down Expand Up @@ -404,6 +406,7 @@ def __change_online(self, online: bool) -> None:
self._online_offline_history.pop(0)
if self._online_offline_timer:
self._online_offline_timer.cancel()
self._online_offline_timer = None
if not online:
self.online = False
else:
Expand Down Expand Up @@ -1133,6 +1136,7 @@ def __deinit(self) -> None:
for req_data in self._pending_requests.values():
if req_data.timeout:
req_data.timeout.cancel()
req_data.timeout = None
self._pending_requests.clear()
for timer in self._reply_msg_buffer.values():
timer.cancel()
Expand Down Expand Up @@ -1252,6 +1256,7 @@ def __message_handler(self, did: str, msg: dict) -> None:
if req:
if req.timeout:
req.timeout.cancel()
req.timeout = None
if req.handler is not None:
self._main_loop.call_soon_threadsafe(
req.handler, msg, req.handler_ctx)
Expand Down Expand Up @@ -1326,6 +1331,7 @@ def __sendto(
def __scan_devices(self) -> None:
if self._scan_timer:
self._scan_timer.cancel()
self._scan_timer = None
try:
# Scan devices
self.ping(if_name=None, target_ip='255.255.255.255')
Expand Down

0 comments on commit f614181

Please sign in to comment.