From cf3b2a205e5183e75023364fe8a92b3a8af7070b Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Wed, 3 Dec 2025 18:20:27 -0800 Subject: [PATCH] fix: Update logging to be more conservative We currently log warning logs on local disconnects. This is moved to log info and instead we should let the caller log warnings when RPCs fail etc. This will log at the info level only after failures to reconnect, but then logs again when reconnect happens. --- roborock/devices/local_channel.py | 2 +- roborock/devices/v1_channel.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/roborock/devices/local_channel.py b/roborock/devices/local_channel.py index eb94646c..f7500b91 100644 --- a/roborock/devices/local_channel.py +++ b/roborock/devices/local_channel.py @@ -186,7 +186,7 @@ def close(self) -> None: def _connection_lost(self, exc: Exception | None) -> None: """Handle connection loss.""" - _LOGGER.warning("Connection lost to %s", self._host, exc_info=exc) + _LOGGER.debug("Local connection lost to %s", self._host, exc_info=exc) self._transport = None self._is_connected = False diff --git a/roborock/devices/v1_channel.py b/roborock/devices/v1_channel.py index 1f016aa9..20fc7631 100644 --- a/roborock/devices/v1_channel.py +++ b/roborock/devices/v1_channel.py @@ -371,8 +371,15 @@ async def _background_reconnect(self) -> None: # Not connected, so wait with backoff before trying to connect. # The first time through, we don't sleep, we just try to connect. + # We also only log after the first retry to avoid spamming logs. local_connect_failures += 1 if local_connect_failures > 1: + if local_connect_failures == 2: + _LOGGER.info( + "Local connection to device %s failed, retrying in %s seconds", + self._device_uid, + reconnect_backoff.total_seconds(), + ) await asyncio.sleep(reconnect_backoff.total_seconds()) reconnect_backoff = min(reconnect_backoff * RECONNECT_MULTIPLIER, MAX_RECONNECT_INTERVAL) @@ -380,6 +387,8 @@ async def _background_reconnect(self) -> None: await self._local_connect(prefer_cache=use_cache) # Reset backoff and failures on success reconnect_backoff = MIN_RECONNECT_INTERVAL + if local_connect_failures >= 2: + _LOGGER.info("Local connection to device %s re-established", self._device_uid) local_connect_failures = 0 except asyncio.CancelledError: