Skip to content

Commit cf3b2a2

Browse files
committed
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.
1 parent b48121f commit cf3b2a2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

roborock/devices/local_channel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def close(self) -> None:
186186

187187
def _connection_lost(self, exc: Exception | None) -> None:
188188
"""Handle connection loss."""
189-
_LOGGER.warning("Connection lost to %s", self._host, exc_info=exc)
189+
_LOGGER.debug("Local connection lost to %s", self._host, exc_info=exc)
190190
self._transport = None
191191
self._is_connected = False
192192

roborock/devices/v1_channel.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,24 @@ async def _background_reconnect(self) -> None:
371371

372372
# Not connected, so wait with backoff before trying to connect.
373373
# The first time through, we don't sleep, we just try to connect.
374+
# We also only log after the first retry to avoid spamming logs.
374375
local_connect_failures += 1
375376
if local_connect_failures > 1:
377+
if local_connect_failures == 2:
378+
_LOGGER.info(
379+
"Local connection to device %s failed, retrying in %s seconds",
380+
self._device_uid,
381+
reconnect_backoff.total_seconds(),
382+
)
376383
await asyncio.sleep(reconnect_backoff.total_seconds())
377384
reconnect_backoff = min(reconnect_backoff * RECONNECT_MULTIPLIER, MAX_RECONNECT_INTERVAL)
378385

379386
use_cache = self._should_use_cache(local_connect_failures)
380387
await self._local_connect(prefer_cache=use_cache)
381388
# Reset backoff and failures on success
382389
reconnect_backoff = MIN_RECONNECT_INTERVAL
390+
if local_connect_failures >= 2:
391+
_LOGGER.info("Local connection to device %s re-established", self._device_uid)
383392
local_connect_failures = 0
384393

385394
except asyncio.CancelledError:

0 commit comments

Comments
 (0)