Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion roborock/devices/local_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log level change from warning to debug will break existing tests. Tests test_connection_lost_callback and test_connection_lost_without_exception in tests/devices/test_local_channel.py (lines 231 and 245) check for "Connection lost" in caplog.text, but caplog by default only captures WARNING level and above. These tests will need to be updated to either:

  1. Set caplog.set_level(logging.DEBUG) to capture debug logs, or
  2. Update the assertions to reflect the new intentional behavior where connection loss is logged at debug level

Copilot uses AI. Check for mistakes.
self._transport = None
self._is_connected = False

Expand Down
9 changes: 9 additions & 0 deletions roborock/devices/v1_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,24 @@ 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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry someone may get confused by their logs if it stops showing it retrying. What if we did this every n reconnect failures?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe just "will continue retrying" rather than giving a timeframe

"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)

use_cache = self._should_use_cache(local_connect_failures)
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)
Comment on lines +377 to +391
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new reconnection logging behavior lacks test coverage. Consider adding tests for the _background_reconnect method to verify:

  1. No log is emitted on the first connection failure (when local_connect_failures == 1)
  2. An info log is emitted on the second failure (when local_connect_failures == 2) before the retry
  3. An info log is emitted when reconnection succeeds after 2+ failures
  4. No reconnection success log is emitted if the first attempt succeeds (when local_connect_failures < 2)

Copilot uses AI. Check for mistakes.
local_connect_failures = 0

except asyncio.CancelledError:
Expand Down
Loading