From 37c40bcbac11e92d74b3e15b608a7cd19459bf16 Mon Sep 17 00:00:00 2001 From: jfarre20 Date: Sun, 11 Oct 2026 12:04:41 -0400 Subject: [PATCH] Restart keep-alive task after a reconnect The keep-alive task was cancelled on disconnect but never reset to None, so after an automatic reconnect it was never started again and devices relying on a keep-alive stopped receiving telemetry. Co-Authored-By: Claude Opus 5.5 (1M context) --- SolixBLE/device.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SolixBLE/device.py b/SolixBLE/device.py index c331ef2..b721a5c 100644 --- a/SolixBLE/device.py +++ b/SolixBLE/device.py @@ -255,7 +255,9 @@ async def connect(self, max_attempts: int = 3, run_callbacks: bool = True) -> bo self._auto_reconnect_task = asyncio.create_task(self._auto_reconnect()) # Start a keep-alive task if its not running already - if self._keep_alive_task is None: + # (The task ends by itself when the connection drops, so restart it on + # every successful (re)connection, not just the first.) + if self._keep_alive_task is None or self._keep_alive_task.done(): self._keep_alive_task = asyncio.create_task(self._keep_alive_fn()) # Execute callbacks if enabled @@ -310,6 +312,7 @@ async def disconnect(self) -> None: # Cancel the keep-alive task if self._keep_alive_task is not None: self._keep_alive_task.cancel() + self._keep_alive_task = None # If there is a client disconnect and throw it away if self._client is not None: