Skip to content

refactor: give water slide modes their own enum values - #993

Open
rohitpatil9121 wants to merge 1 commit into
Python-roborock:mainfrom
rohitpatil9121:refactor/issue-987-water-modes-display-name
Open

rohitpatil9121 wants to merge 1 commit into
Python-roborock:mainfrom
rohitpatil9121:refactor/issue-987-water-modes-display-name

Conversation

@rohitpatil9121

Copy link
Copy Markdown

Summary

Fixes #987

WaterModes water slide members reused the value strings of the legacy modes ("low", "medium", "high", "extreme"). StrEnum deduplicates by value, so these members became aliases of LOW / MEDIUM / HIGH / EXTREME and lost their own codes. For example, WaterModes.PURE_WATER_FLOW_MIDDLE.code was 202 instead of 235, and WaterModes.from_code_optional(235) returned None.

This follows the approach suggested in the issue:

  • Each water slide member now has a unique value, and the shared user-facing name moves to display_name, the same way CleanRoutes.DEEP_PLUS_CN works.
  • The workarounds that existed only to keep the slide codes are removed:
    • the WATER_SLIDE_MODE_MAPPING side table, replaced by a private tuple of slide modes
    • the reverse lookup by name in get_cleaning_mode_parameters, which now uses water_box_mode.code directly
    • the inline isinstance patch in get_current_cleaning_mode, now _resolve_water_mode(value, features), matching _resolve_clean_mode
  • get_water_mode_mapping and get_water_slide_mode_name use display_name, so the user-facing names and the mapping stay the same.
  • A conformance test now fails when members of a RoborockModeEnum alias each other by value. B01Fault already has such aliases, so I added it to a baseline (strict xfail) instead of changing it here.

Behavior change

.value for the four slide modes is now pure_water_flow_small, pure_water_flow_middle, pure_water_super_begin and pure_water_flow_end. Consumers that read mode.value from water_mode_options should switch to mode.display_name. For Home Assistant, that is step 1 of the upgrade plan in the issue. water_mode_mapping and water_mode_name return the same strings as before.

Testing

  • Added a test that the slide codes 225/235/245/250 resolve to their own members with the expected display_name.
  • Updated test_water_slide_mode_mapping to read display_name from water_mode_options.
  • pytest tests/devices tests/conformance tests/data: 1225 passed, 54 xfailed
  • ruff check and ruff format --check pass. mypy reports no errors in the changed files.
  • tests/test_web_api.py::test_url_cycling fails locally on Windows, on main as well, so it is unrelated to this change.

Water slide members of WaterModes reused the value strings of the legacy
modes ("low", "medium", "high", "extreme"), so StrEnum collapsed them into
aliases and dropped their codes (225, 235, 245, 250). Give each a unique
value and keep the shared user-facing name in display_name, like
CleanRoutes.DEEP_PLUS_CN.

This removes the workarounds that existed only to preserve those codes:
the WATER_SLIDE_MODE_MAPPING side table, the reverse lookup in
get_cleaning_mode_parameters, and the inline patch in
get_current_cleaning_mode (now _resolve_water_mode).

Also add a conformance check that fails when RoborockModeEnum members
alias each other by value. B01Fault already has such aliases and is
tracked in a baseline.

Fixes Python-roborock#987

This branch has not been deployed

No deployments
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.

Refactor WaterModes to use display_name instead of StrEnum value aliases

1 participant