Skip to content

feat: track A01 device state from push updates - #941

Open
piitaya wants to merge 2 commits into
Python-roborock:mainfrom
piitaya:feat/a01-state-tracking
Open

feat: track A01 device state from push updates#941
piitaya wants to merge 2 commits into
Python-roborock:mainfrom
piitaya:feat/a01-state-tracking

Conversation

@piitaya

@piitaya piitaya commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

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 pushes
  • add_update_listener(callback): called when a value changes
  • last_message_time: time of the last message received from the device

query_values and set_value are unchanged.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 A01Api base with values, add_update_listener(), and last_message_time, and wire Dyad/Zeo APIs to merge push + query updates.
  • Seed initial values from the cloud device_status snapshot via device_managera01.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 into values but leaves last_message_time unchanged, 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.

Comment thread roborock/devices/traits/a01/__init__.py
Comment thread roborock/devices/traits/a01/__init__.py Outdated
Comment thread roborock/devices/traits/a01/__init__.py
@piitaya piitaya changed the title Track A01 device state from push updates feat: track A01 device state from push updates Sep 1, 2026
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