Add messages to all task cancels (#497)

This commit is contained in:
J. Nick Koston 2023-07-19 15:37:59 -05:00 committed by GitHub
parent d63b9bbf5d
commit 82ab7e489d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 7 deletions

View File

@ -1417,7 +1417,7 @@ class APIClient:
)
if start_task is not None and not start_task.cancelled():
start_task.cancel()
start_task.cancel("Unsubscribing from voice assistant")
return unsub

View File

@ -211,7 +211,7 @@ class APIConnection:
# need to make sure we don't cancel the task
# that called us
if self._connect_task is not None and not in_do_connect.get(False):
self._connect_task.cancel()
self._connect_task.cancel("Connection cleanup")
self._connect_task = None
if self._frame_helper is not None:

View File

@ -141,7 +141,7 @@ class ReconnectLogic(zeroconf.RecordUpdateListener):
def _schedule_connect(self, delay: float) -> None:
"""Schedule a connect attempt."""
self._cancel_connect()
self._cancel_connect("Scheduling new connect attempt")
if not delay:
self._call_connect_once()
return
@ -157,13 +157,13 @@ class ReconnectLogic(zeroconf.RecordUpdateListener):
name=f"{self._log_name}: aioesphomeapi connect",
)
def _cancel_connect(self) -> None:
def _cancel_connect(self, msg: str) -> None:
"""Cancel the connect."""
if self._connect_timer:
self._connect_timer.cancel()
self._connect_timer = None
if self._connect_task:
self._connect_task.cancel()
self._connect_task.cancel(msg)
self._connect_task = None
async def _connect_once_or_reschedule(self) -> None:
@ -219,11 +219,11 @@ class ReconnectLogic(zeroconf.RecordUpdateListener):
async def stop(self) -> None:
"""Stop the connecting logic background task. Does not disconnect the client."""
self._cancel_connect()
self._cancel_connect("Stopping")
async with self._connected_lock:
self._is_stopped = True
# Cancel again while holding the lock
self._cancel_connect()
self._cancel_connect("Stopping")
self._stop_zc_listen()
def _start_zc_listen(self) -> None: