Skip to content

Conversation

allenporter
Copy link
Contributor

The new v1 channel will:

  • prefer local connection, using cached network information
  • establish mqtt connections on demand only when needed on first subscription. we can decide to poke the mqtt session explicitly if we prefer, but it won't be done by the device manager now
  • refresh network information on the first failed attempt, then once every 12 hours
  • retry local connections with backoff

This makes the local background task (per device0 now work similarly to the mqtt session task.

The background logic is difficult to unit test without races, so it is not tested. I will do additional manual testing of complex scenarios for errors when this is integrated into Home Assistant.

Lash-L
Lash-L previously approved these changes Sep 21, 2025
Copy link
Collaborator

@Lash-L Lash-L left a comment

Choose a reason for hiding this comment

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

Honestly looks good, one small nitpick, feel free to ignore.

establish mqtt connections on demand only when needed on first subscription. we can decide to poke the mqtt session explicitly if we prefer, but it won't be done by the device manager now

We may want to poke it explicitly in HA for the sake of getting protocol updates, but I think this good library wise and we can figure out protocol updates later.

Comment on lines 219 to 227
if local_connect_failures > 1:
await asyncio.sleep(reconnect_backoff.total_seconds())
reconnect_backoff = min(reconnect_backoff * RECONNECT_MULTIPLIER, MAX_RECONNECT_INTERVAL)

# First failure refreshes cache. Subsequent failures use the cache
# until the refresh interval expires.
use_cache = True
if local_connect_failures == 1:
use_cache = False
Copy link
Collaborator

Choose a reason for hiding this comment

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

could simplify by setting use_cache = True inside the if statement for >1. One fewer if statement

Copy link
Collaborator

Choose a reason for hiding this comment

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

although i guess you'll have to move that elif below.

You don't have to do this if you don't want to. If you think it hurts readability or understandability, just ignore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah i looked at doing that before, but its like this because there are a couple scenarios for deciding if cache should be used that it makes sense to do them at once. So, I decided to instead extract to a helper function so at least this flow is a little easier to read.

@allenporter allenporter merged commit d0212e5 into Python-roborock:main Sep 22, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants