Skip to content

Cache miIO protocol sequence IDs across CLI invocations#2063

Merged
syssi merged 4 commits into
rytilahti:masterfrom
Acrobot:miiocli-cache
Jun 27, 2026
Merged

Cache miIO protocol sequence IDs across CLI invocations#2063
syssi merged 4 commits into
rytilahti:masterfrom
Acrobot:miiocli-cache

Conversation

@Acrobot

@Acrobot Acrobot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Devices track message sequence IDs and ignore duplicates. Without persisting the counter, restarting the CLI resets it to 0, causing devices to silently drop messages and time out (#1750).

This generalizes the approach already used by the roborock vacuum CLI (vacuum_cli.py) into the shared DeviceGroup infrastructure, so all device types benefit automatically.

  • device_cache.py: Per-device cache using hashed IPs (safe for IPv6) under platformdirs.user_cache_dir
  • click_common.py: DeviceGroup.group_callback loads cached start_id on init, saves raw_id via ctx.call_on_close
  • 12 tests covering path generation, read/write, corruption handling

Full test suite: 1298 passed (same as master), no new failures. Ruff clean.

Closes #1751

@Acrobot

Acrobot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

These changes were generated using Claude Code under my supervision. I reviewed and approved all code before submitting. I'm not very familiar with this codebase, so apologies in advance for any mistakes.

@Acrobot Acrobot marked this pull request as ready for review March 27, 2026 00:51
@Acrobot Acrobot mentioned this pull request Mar 27, 2026
22 tasks
@codecov

codecov Bot commented Mar 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.48718% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.29%. Comparing base (f697e85) to head (9064869).

Files with missing lines Patch % Lines
miio/click_common.py 11.11% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2063      +/-   ##
==========================================
- Coverage   83.30%   83.29%   -0.01%     
==========================================
  Files         198      199       +1     
  Lines       19436    19475      +39     
  Branches     1056     1058       +2     
==========================================
+ Hits        16191    16222      +31     
- Misses       3063     3071       +8     
  Partials      182      182              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@rytilahti rytilahti left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

We could store some more information in the device cache, but this is a great starting point & is immediately useful for any cli users.

Comment thread miio/tests/test_device_cache.py Outdated
Comment thread miio/click_common.py
Comment thread miio/click_common.py
@rytilahti rytilahti added this to the 0.6.0 milestone Jun 27, 2026
Acrobot and others added 3 commits June 27, 2026 16:50
Devices track message sequence IDs and ignore duplicates. Without
persisting the counter, restarting the CLI resets it to 0, causing
devices to silently drop messages and time out.

This generalizes the approach already used by the roborock vacuum CLI
into the shared DeviceGroup infrastructure, so all device types benefit.

Cache files are stored per-device (keyed by hashed IP) under the
platformdirs user cache directory.

Closes rytilahti#1751
@syssi syssi merged commit bacf59f into rytilahti:master Jun 27, 2026
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modify miiocli to store connection settings inside cache

3 participants