Skip to content

Comments

Update the status listener API#771

Merged
allenporter merged 3 commits intoPython-roborock:mainfrom
allenporter:dev
Feb 22, 2026
Merged

Update the status listener API#771
allenporter merged 3 commits intoPython-roborock:mainfrom
allenporter:dev

Conversation

@allenporter
Copy link
Contributor

This removes the datapoints argument from the update listener since the caller is supposed to review the contents of the trait rather than the raw data.

This removes the datapoints argument from the update listener since the caller is supposed to review the contents of the trait rather than the raw data.
Copilot AI review requested due to automatic review settings February 21, 2026 23:22
@greptile-apps
Copy link

greptile-apps bot commented Feb 21, 2026

Greptile Summary

Refactored the status update listener API to remove the decoded_dps parameter from callbacks. Callers now read trait properties directly instead of receiving raw datapoints. This is a cleaner API that encapsulates implementation details.

Key changes:

  • Introduced TraitUpdateListener base class to standardize update notifications across traits
  • Modified DpsDataConverter.update_from_dps to return bool indicating whether any fields were updated
  • Callbacks now only fire when relevant status fields change (filters out unrelated DPS updates like HEARTBEAT)
  • Updated tests to verify new callback signature and behavior

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The refactoring is well-designed with proper abstraction, comprehensive test coverage for both the new behavior and edge cases, and all tests verify the new API works correctly. The change is backwards-incompatible but appears to only affect internal tests.
  • No files require special attention

Important Files Changed

Filename Overview
roborock/devices/traits/b01/q10/common.py Adds TraitUpdateListener base class and modifies DpsDataConverter.update_from_dps to return bool indicating if updates occurred
roborock/devices/traits/b01/q10/status.py Refactored to use TraitUpdateListener base class, removing datapoints from callback signature
tests/devices/traits/b01/q10/test_status.py Updated tests to use new callback API without datapoints, added test for ignoring non-status updates

Sequence Diagram

sequenceDiagram
    participant Device
    participant DpsDataConverter
    participant StatusTrait
    participant Callback
    participant Client

    Device->>StatusTrait: update_from_dps(decoded_dps)
    StatusTrait->>DpsDataConverter: update_from_dps(self, decoded_dps)
    DpsDataConverter->>DpsDataConverter: convert_dict(type_map, decoded_dps)
    DpsDataConverter->>StatusTrait: setattr(field_name, value)
    DpsDataConverter-->>StatusTrait: return bool (has_updates)
    alt has_updates == True
        StatusTrait->>Callback: _notify_update()
        Callback->>Client: callback() [no parameters]
        Client->>StatusTrait: read trait properties
    end
Loading

Last reviewed commit: 7be9023

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 pull request refactors the status listener API to improve separation of concerns by removing the raw datapoints argument from update callbacks. Instead of receiving raw DPS data, listeners are now notified without arguments and must read the trait's properties directly to access updated values.

Changes:

  • Introduces a new TraitUpdateListener base class to standardize the listener pattern across traits
  • Updates StatusTrait to use the new listener pattern and only notify listeners when actual trait values change
  • Modifies DpsDataConverter.update_from_dps() to return a boolean indicating whether any values were updated

Reviewed changes

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

File Description
roborock/devices/traits/b01/q10/common.py Adds TraitUpdateListener base class with no-argument callback pattern and updates DpsDataConverter.update_from_dps() to return boolean
roborock/devices/traits/b01/q10/status.py Migrates StatusTrait to use TraitUpdateListener and conditionally notifies listeners only when values change
tests/devices/traits/b01/q10/test_status.py Updates tests to use new callback API and adds test for filtering non-status DPS values

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

allenporter and others added 2 commits February 21, 2026 15:26
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@allenporter allenporter merged commit e72d5ca into Python-roborock:main Feb 22, 2026
6 of 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