Update the status listener API#771
Conversation
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.
Greptile SummaryRefactored the status update listener API to remove the Key changes:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
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
Last reviewed commit: 7be9023 |
There was a problem hiding this comment.
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
TraitUpdateListenerbase class to standardize the listener pattern across traits - Updates
StatusTraitto 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.