feat: track A01 device state from push updates - #941
Open
piitaya wants to merge 2 commits into
Open
Conversation
21 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request adds library-level state tracking for A01 devices (Dyad/Zeo) so consumers no longer need to manually merge partial DPS push updates. It introduces a unified values cache, update notifications when values change, and a last_message_time liveness signal.
Changes:
- Introduce
A01Apibase withvalues,add_update_listener(), andlast_message_time, and wire Dyad/Zeo APIs to merge push + query updates. - Seed initial
valuesfrom the clouddevice_statussnapshot viadevice_manager→a01.create(..., device_status=...). - Add/extend tests to validate push merging, update listeners, query/push ordering, close behavior, and
last_message_time.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/devices/traits/a01/test_init.py | Adds tests for state cache merging, listener behavior, query vs push ordering, seeding, and last-message timestamp. |
| roborock/devices/traits/a01/init.py | Implements shared A01 state tracking (A01Api), updates Dyad/Zeo to use it, and extends create() to accept a cloud status snapshot. |
| roborock/devices/device.py | Ensures Dyad devices call start() on connect and close() on device close, enabling/disabling state tracking. |
| roborock/devices/device_manager.py | Passes cloud device_status into A01 trait creation to seed initial cached state. |
| docs/DEVICES.md | Updates user-facing docs to describe device.dyad/device.zeo, values, and add_update_listener(). |
Suppressed comments (1)
roborock/devices/traits/a01/init.py:393
- Same as DyadApi: when not subscribed (
start()not called),query_values()merges intovaluesbut leaveslast_message_timeunchanged, despite a message having been received.
# When subscribed, the response was already merged in arrival order;
# merging again here could overwrite a push that arrived after it.
if self._unsub is None:
self._merge_values(values)
return values
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change
A01 devices only push the data points that changed, so every client had to merge partial updates itself (see the review on home-assistant/core#180493). This adds state tracking to the library instead, like #895 did for Zeo:
values: latest known device state, merged from query responses and pushesadd_update_listener(callback): called when a value changeslast_message_time: time of the last message received from the devicequery_valuesandset_valueare unchanged.