Skip to content

Comments

feat(q10): add status update listener callback API#770

Merged
allenporter merged 3 commits intoPython-roborock:mainfrom
lboue:feat/q10-status-listener-api
Feb 21, 2026
Merged

feat(q10): add status update listener callback API#770
allenporter merged 3 commits intoPython-roborock:mainfrom
lboue:feat/q10-status-listener-api

Conversation

@lboue
Copy link
Contributor

@lboue lboue commented Feb 21, 2026

Summary

Add a small public callback API on StatusTrait for Q10 decoded DPS updates.

  • add StatusTrait.add_update_listener(callback) returning an unsubscribe callable
  • invoke registered callbacks from StatusTrait.update_from_dps(...)
  • keep behavior backward compatible for existing callers
  • add tests for listener registration and unsubscribe behavior

Why

Home Assistant currently has to monkey-patch update_from_dps to capture Q10 push updates. With this API, integrations can subscribe cleanly to status updates without runtime patching.

Test plan

  • ruff check roborock/devices/traits/b01/q10/status.py tests/devices/traits/b01/q10/test_status.py
  • pytest tests/devices/traits/b01/q10/test_status.py
  • pytest tests/devices/traits/b01/q10/test_status.py tests/devices/traits/b01/q10/test_vacuum.py

Copilot AI review requested due to automatic review settings February 21, 2026 09:13
@greptile-apps
Copy link

greptile-apps bot commented Feb 21, 2026

Greptile Summary

Adds a public callback API to StatusTrait for Q10 devices to cleanly subscribe to decoded DPS updates without monkey-patching.

  • Added add_update_listener() returning an unsubscribe callable
  • Introduced __init__() to initialize CallbackList for managing callbacks
  • Callbacks invoked in update_from_dps() after updating trait state
  • Fully backward compatible with existing code
  • Test coverage validates listener registration, callback invocation, and unsubscribe behavior
  • Leverages existing CallbackList infrastructure with built-in exception handling

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • Clean implementation following existing patterns, comprehensive test coverage, backward compatible, uses proven CallbackList infrastructure with exception handling
  • No files require special attention

Important Files Changed

Filename Overview
roborock/devices/traits/b01/q10/status.py Added callback listener API with __init__, add_update_listener, and callback invocation in update_from_dps
tests/devices/traits/b01/q10/test_status.py Added comprehensive test for listener registration, callback invocation, and unsubscribe behavior

Sequence Diagram

sequenceDiagram
    participant Client as Home Assistant
    participant ST as StatusTrait
    participant CL as CallbackList
    participant CB as Callback

    Client->>ST: add_update_listener(callback)
    ST->>CL: add_callback(callback)
    CL-->>ST: unsubscribe function
    ST-->>Client: unsubscribe function

    Note over ST: Device sends DPS update

    ST->>ST: update_from_dps(decoded_dps)
    ST->>ST: Update trait fields
    ST->>CL: __call__(decoded_dps)
    CL->>CB: callback(decoded_dps)
    CB-->>CL: 
    CL-->>ST: 

    Client->>ST: unsubscribe()
    ST->>CL: remove callback
    CL-->>ST: 
    ST-->>Client: 

    Note over ST: Subsequent DPS update

    ST->>ST: update_from_dps(decoded_dps)
    ST->>ST: Update trait fields
    ST->>CL: __call__(decoded_dps)
    Note over CL: No callbacks to invoke
    CL-->>ST:
Loading

Last reviewed commit: 5ca5b6e

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a clean callback API for Q10 devices to receive status updates from decoded DPS (Data Point System) messages. The implementation allows Home Assistant and other integrations to subscribe to status updates without monkey-patching, improving code maintainability and providing a proper public API.

Changes:

  • Added add_update_listener() method to StatusTrait that returns an unsubscribe callable
  • Modified update_from_dps() to invoke registered callbacks after updating status
  • Enhanced type annotations from dict to dict[B01_Q10_DP, Any] for better type safety
  • Added comprehensive test coverage for listener registration and unsubscribe behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
roborock/devices/traits/b01/q10/status.py Implements callback API using CallbackList, adds __init__ to initialize callbacks, updates update_from_dps signature with proper typing, and invokes callbacks on updates
tests/devices/traits/b01/q10/test_status.py Adds test for listener registration, callback invocation, and unsubscribe functionality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@allenporter allenporter merged commit c0a313b into Python-roborock:main Feb 21, 2026
7 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