refactor: Centralize trait utilities#820
Merged
allenporter merged 1 commit intoPython-roborock:mainfrom Apr 26, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors trait infrastructure by moving the trait update listener and DPS-to-dataclass conversion logic into a shared module, reducing duplication and preparing for upcoming protocol/streaming work.
Changes:
- Generalize
DpsDataConverterandTraitUpdateListenerintoroborock/devices/traits/common.py. - Update Q10 status trait to import shared utilities from the centralized module.
- Refresh module docstring to reflect broader “device traits” scope.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
roborock/devices/traits/common.py |
Centralizes and generalizes trait utilities; updates docs and typing around DPS conversion. |
roborock/devices/traits/b01/q10/status.py |
Switches imports to use the new centralized trait utilities module. |
Comments suppressed due to low confidence (2)
roborock/devices/traits/common.py:44
TDpsis currently declared asTypeVar(..., bound=int), but existing callers (e.g. B01 Q10) useB01_Q10_DPkeys, which areRoborockModeEnum(aStrEnum), notint. This bound makes the shared converter’s type contract misleading and may block correct generic usage for enum-keyed DPS maps; consider widening the bound (e.g., toHashable) or removing it so bothint- and enum-keyed DPS dictionaries are supported.
roborock/devices/traits/common.py:24- The update-lifecycle docstring example says the transport layer decodes DPS into a dict like
{"101": 80}(string keys), but for B01 Q10 the protocol layer converts DPS keys toB01_Q10_DPenums (seeroborock/protocols/b01_q10_protocol.py). Consider rewording to reflect that decoded DPS keys are normalized (e.g.,intfor A01/B01-Q7,B01_Q10_DPfor B01-Q10) so trait code knows what key type to expect.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Lash-L
approved these changes
Apr 26, 2026
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.
This extracts the core trait listener and data converter mechanisms into a shared module to eliminate duplication and establish a cleaner base for upcoming protocol features. This will be used by the upcoming v1 streaming updates feature.
Pulled out from #799 as a separate PR