Repository navigation
fix(v1): give VacuumModes.OFF a distinct code from GENTLE #1066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
saruk-vedant
wants to merge
11
commits into
Python-roborock:main
Choose a base branch
from
saruk-vedant:roborock-999-vacuum-modes-distinct-codes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d8ad245
fix(v1): give VacuumModes.OFF a distinct code from GENTLE
saruk-vedant 32e242f
fix(v1): give VacuumModes.OFF a distinct code from GENTLE
saruk-vedant 0c181f7
fix(v1): give VacuumModes.OFF a distinct code from GENTLE
saruk-vedant 58adf0a
fix(v1): give VacuumModes.OFF a distinct code from GENTLE
saruk-vedant f871c44
fix(v1): give VacuumModes.OFF a distinct code from GENTLE
saruk-vedant 7dd93bb
fix(v1): give VacuumModes.OFF a distinct code from GENTLE
saruk-vedant 5103d33
fix(v1): give VacuumModes.OFF a distinct code from GENTLE
saruk-vedant 54cf6cc
fix(v1): give VacuumModes.OFF a distinct code from GENTLE
saruk-vedant b49f51c
fix(v1): give VacuumModes.OFF a distinct code from GENTLE
saruk-vedant 94bbee9
test(status): dedent nested fan speed name test so pytest collects it
saruk-vedant 61ffd44
style(v1): fix trailing whitespace and formatting in customize clean …
saruk-vedant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| """Tests for the V1 clean mode enums and wire-code helpers.""" | ||
|
|
||
| from roborock.data.v1.v1_clean_modes import VacuumModes, vacuum_mode_wire_code | ||
|
|
||
|
|
||
| def test_vacuum_modes_have_distinct_codes() -> None: | ||
| """Every VacuumModes member must keep a distinct code.""" | ||
| codes = [mode.code for mode in VacuumModes] | ||
| assert len(codes) == len(set(codes)) | ||
|
|
||
|
|
||
| def test_vacuum_modes_gentle_and_off_have_distinct_codes() -> None: | ||
| """GENTLE and OFF must not share a code.""" | ||
| assert VacuumModes.GENTLE.code != VacuumModes.OFF.code | ||
|
|
||
|
|
||
| def test_vacuum_modes_code_lookup_is_unambiguous() -> None: | ||
| """Each code must resolve to exactly one member.""" | ||
| assert VacuumModes.from_code(105) is VacuumModes.GENTLE | ||
| assert VacuumModes.from_code(VacuumModes.OFF.code) is VacuumModes.OFF | ||
| assert VacuumModes.from_code_optional(105) is VacuumModes.GENTLE | ||
| assert VacuumModes.from_code_optional(VacuumModes.OFF.code) is VacuumModes.OFF | ||
|
|
||
|
|
||
| def test_vacuum_modes_int_equality_is_unambiguous() -> None: | ||
| """Only GENTLE equals the shared wire code 105.""" | ||
| assert VacuumModes.GENTLE == 105 | ||
| assert VacuumModes.OFF != 105 | ||
| assert VacuumModes.OFF == VacuumModes.OFF.code | ||
|
|
||
|
|
||
| def test_vacuum_mode_wire_code() -> None: | ||
| """OFF sends the shared wire code 105; every other mode sends its own code.""" | ||
| assert vacuum_mode_wire_code(VacuumModes.OFF) == 105 | ||
| assert vacuum_mode_wire_code(VacuumModes.GENTLE) == 105 | ||
| for mode in VacuumModes: | ||
| if mode is VacuumModes.OFF: | ||
| continue | ||
| assert vacuum_mode_wire_code(mode) == mode.code |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Priority 1 & 3 — Breaking Consumer Contract & Wire-Code Collision Risk]
VacuumModes.OFFandVacuumModes.GENTLEalready have distinct.valuestrings ("off"vs"gentle"), so they are not PythonStrEnumvalue aliases (unlike theWaterModesbug addressed bydisplay_namein #990). Sharing.code = 105reflects the real V1 wire protocol (CleanModeZero = 105incom.roborock.tanos) and matches the exact pattern used inWaterModesbelow (LOW/MILD = 201,MEDIUM/STANDARD = 202,HIGH/INTENSE = 203).Assigning a synthetic code
107has two concrete downsides:mode.codefromStatusTrait.fan_speed_optionsto callSET_CUSTOM_MODE, or comparesstatus.fan_power == VacuumModes.OFF/VacuumModes.OFF.code, will now send invalid wire code107(or fail equality against105) unless updated to callvacuum_mode_wire_code().107is an unassigned slot in Roborock's active101–110fan_powerrange. If future firmware assigns107to a new suction mode,VacuumModes.from_code_optional(107)and_resolve_clean_mode(107, features)will silently misclassify it asVacuumModes.OFFinstead of returningNone.Consider keeping
OFF = ("off", 105)(matchingWaterModes) and documenting that code105requiresDeviceFeaturescontext (_resolve_clean_mode/StatusTrait.fan_speed_mapping) to disambiguate, rather than inventing a synthetic wire code.