Skip to content

Commit f6261c7

Browse files
committed
fix(v1): list supported cleaning settings in a stable order
1 parent a13b6f4 commit f6261c7

4 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎docs/V1_API_COMMANDS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ A mop route is sent only when the model supports both route setting (`is_clean_r
11971197

11981198
Parameters: List with a dictionary, e.g. `[{"fan_power": 102, "water_box_mode": 202}]`. `mop_mode` is added where the table says so.
11991199

1200-
`StatusTrait.supported_cleaning_settings` (helper `get_supported_settings`) lists the cleaning settings a model has at all, independent of the current cleaning mode, so a consumer can decide which settings to offer without combining feature flags. It is the set of settings that are adjustable in at least one regular cleaning mode: the fan speed always; the water mode when the model has a mop (`is_support_water_mode`); the mop route when the model has a mop and the shake module (`is_shake_mop_set_supported`) and either a mop-only mode (`is_pure_clean_mop_supported`) or the fast route outside mopping (`is_clean_route_fast_mode_supported` with route setting). The `fan_speed_options`/`water_mode_options`/`mop_route_options` lists and their `_mapping` dicts are empty for a setting the model does not have (the fan speed is never empty). The cleaning mode select has no entry in the set: it exists exactly when `cleaning_mode_options` is not empty, which is the case when `is_support_water_mode` is true. Whether a setting can be changed right now is still `is_fan_speed_adjustable`, `is_water_mode_adjustable` and `is_mop_route_adjustable`.
1200+
`StatusTrait.supported_cleaning_settings` (helper `get_supported_settings`) lists the cleaning settings a model has at all, independent of the current cleaning mode, so a consumer can decide which settings to offer without combining feature flags. It is the list, in the order fan speed, water mode, mop route, of the settings that are adjustable in at least one regular cleaning mode: the fan speed always; the water mode when the model has a mop (`is_support_water_mode`); the mop route when the model has a mop and the shake module (`is_shake_mop_set_supported`) and either a mop-only mode (`is_pure_clean_mop_supported`) or the fast route outside mopping (`is_clean_route_fast_mode_supported` with route setting). The `fan_speed_options`/`water_mode_options`/`mop_route_options` lists and their `_mapping` dicts are empty for a setting the model does not have (the fan speed is never empty). The cleaning mode select has no entry in the set: it exists exactly when `cleaning_mode_options` is not empty, which is the case when `is_support_water_mode` is true. Whether a setting can be changed right now is still `is_fan_speed_adjustable`, `is_water_mode_adjustable` and `is_mop_route_adjustable`.
12011201

12021202
When the robot reports SmartPlan or custom codes (for example `106`/`204`/`302` or `110`/`209`/`306`) the adjustable, display and setter rules treat it as being in that mode, even if the model lacks the SmartPlan or custom support flags and `current_cleaning_mode` is therefore `None` (helper `get_reported_special_mode`). In that state the display options show only the SmartPlan or custom value, the settings are not adjustable and the setters raise `RoborockUnsupportedFeature`. `current_cleaning_mode` itself is unchanged.
12031203

‎roborock/devices/traits/v1/status.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,19 @@ def fan_speed_mapping(self) -> dict[int, str]:
103103
return {fan.code: fan.value for fan in self.fan_speed_options}
104104

105105
@property
106-
def supported_cleaning_settings(self) -> frozenset[CleaningSetting]:
106+
def supported_cleaning_settings(self) -> list[CleaningSetting]:
107107
"""The cleaning settings this model has at all, independent of the current cleaning mode.
108108
109109
Use it to decide which settings to offer. Whether a setting can be changed right
110110
now is is_fan_speed_adjustable, is_water_mode_adjustable and is_mop_route_adjustable.
111111
The options and mapping of a setting the model does not have are empty. The cleaning
112112
mode has no entry here: it exists exactly when cleaning_mode_options is not empty,
113113
which is the case for models with a mop (is_support_water_mode).
114+
115+
The list is in the definition order of CleaningSetting, so it is stable across runs.
114116
"""
115-
return get_supported_settings(self._device_features_trait)
117+
supported = get_supported_settings(self._device_features_trait)
118+
return [setting for setting in CleaningSetting if setting in supported]
116119

117120
@cached_property
118121
def water_mode_options(self) -> list[WaterModes]:

‎tests/devices/__snapshots__/test_v1_device.ambr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@
878878
})
879879
# ---
880880
# name: test_device_trait_command_parsing[status]
881-
StatusTrait(adbumper_status=None, auto_dust_collection=None, avoid_count=None, back_type=None, battery=100, camera_status=None, charge_status=None, clean_area=91287500, clean_fluid_status=None, clean_percent=None, clean_time=5405, cleaning_mode_options=[<CleaningMode.VACUUM: 'vacuum'>, <CleaningMode.VAC_AND_MOP: 'vac_and_mop'>, <CleaningMode.MOP: 'mop'>, <CleaningMode.CUSTOM: 'custom'>], clear_water_box_status=None, collision_avoid_status=None, command=<RoborockCommand.GET_STATUS: 'get_status'>, common_status=None, converter=DefaultConverter, corner_clean_mode=None, current_cleaning_mode=<CleaningMode.CUSTOM: 'custom'>, current_cleaning_mode_name='custom', current_map=0, debug_mode=None, dirty_water_box_status=None, distance_off=0, dnd_enabled=1, dock_cool_fan_status=None, dock_error_status=None, dock_state=<RoborockDockState.full: 'full'>, dock_type=None, dry_status=None, dss=None, dust_bag_status=None, dust_collection_status=None, error_code=<RoborockErrorCode.none: 0>, error_code_name='none', fan_power=106, fan_speed_display_options=[<VacuumModes.CUSTOMIZED: 'custom'>], fan_speed_mapping={101: 'quiet', 102: 'balanced', 103: 'turbo', 104: 'max', 108: 'max_plus'}, fan_speed_name='custom', fan_speed_options=[<VacuumModes.QUIET: 'quiet'>, <VacuumModes.BALANCED: 'balanced'>, <VacuumModes.TURBO: 'turbo'>, <VacuumModes.MAX: 'max'>, <VacuumModes.MAX_PLUS: 'max_plus'>], has_am=None, hatch_door_status=None, home_sec_enable_password=None, home_sec_status=None, in_cleaning=<RoborockInCleaning.complete: 0>, in_fresh_state=1, in_returning=0, in_warmup=None, is_battery_charging=False, is_exploring=None, is_fan_speed_adjustable=False, is_locating=0, is_mop_route_adjustable=False, is_water_mode_adjustable=False, kct=None, lab_status=1, last_clean_t=None, lock_status=0, map_present=1, map_status=3, mop_forbidden_enable=0, mop_mode=None, mop_route_display_options=[], mop_route_mapping={}, mop_route_name=None, mop_route_options=[], msg_seq=515, msg_ver=2, rdt=None, repeat=None, replenish_mode=None, rss=None, square_meter_clean_area=91.3, state=<RoborockStateCode.charging: 8>, state_name='charging', subdivision_sets=None, supported_cleaning_settings=frozenset({<CleaningSetting.WATER_MODE: 'water_mode'>, <CleaningSetting.FAN_SPEED: 'fan_speed'>}), switch_map_mode=None, unsave_map_flag=0, unsave_map_reason=4, wash_phase=None, wash_ready=None, wash_status=None, water_box_carriage_status=0, water_box_filter_status=None, water_box_mode=204, water_box_status=0, water_mode_display_options=[<WaterModes.CUSTOMIZED: 'custom'>], water_mode_mapping={200: 'off', 201: 'mild', 202: 'standard', 203: 'intense', 207: 'custom_water_flow'}, water_mode_name='custom', water_mode_options=[<WaterModes.OFF: 'off'>, <WaterModes.MILD: 'mild'>, <WaterModes.STANDARD: 'standard'>, <WaterModes.INTENSE: 'intense'>, <WaterModes.CUSTOM: 'custom_water_flow'>], water_shortage_status=None)
881+
StatusTrait(adbumper_status=None, auto_dust_collection=None, avoid_count=None, back_type=None, battery=100, camera_status=None, charge_status=None, clean_area=91287500, clean_fluid_status=None, clean_percent=None, clean_time=5405, cleaning_mode_options=[<CleaningMode.VACUUM: 'vacuum'>, <CleaningMode.VAC_AND_MOP: 'vac_and_mop'>, <CleaningMode.MOP: 'mop'>, <CleaningMode.CUSTOM: 'custom'>], clear_water_box_status=None, collision_avoid_status=None, command=<RoborockCommand.GET_STATUS: 'get_status'>, common_status=None, converter=DefaultConverter, corner_clean_mode=None, current_cleaning_mode=<CleaningMode.CUSTOM: 'custom'>, current_cleaning_mode_name='custom', current_map=0, debug_mode=None, dirty_water_box_status=None, distance_off=0, dnd_enabled=1, dock_cool_fan_status=None, dock_error_status=None, dock_state=<RoborockDockState.full: 'full'>, dock_type=None, dry_status=None, dss=None, dust_bag_status=None, dust_collection_status=None, error_code=<RoborockErrorCode.none: 0>, error_code_name='none', fan_power=106, fan_speed_display_options=[<VacuumModes.CUSTOMIZED: 'custom'>], fan_speed_mapping={101: 'quiet', 102: 'balanced', 103: 'turbo', 104: 'max', 108: 'max_plus'}, fan_speed_name='custom', fan_speed_options=[<VacuumModes.QUIET: 'quiet'>, <VacuumModes.BALANCED: 'balanced'>, <VacuumModes.TURBO: 'turbo'>, <VacuumModes.MAX: 'max'>, <VacuumModes.MAX_PLUS: 'max_plus'>], has_am=None, hatch_door_status=None, home_sec_enable_password=None, home_sec_status=None, in_cleaning=<RoborockInCleaning.complete: 0>, in_fresh_state=1, in_returning=0, in_warmup=None, is_battery_charging=False, is_exploring=None, is_fan_speed_adjustable=False, is_locating=0, is_mop_route_adjustable=False, is_water_mode_adjustable=False, kct=None, lab_status=1, last_clean_t=None, lock_status=0, map_present=1, map_status=3, mop_forbidden_enable=0, mop_mode=None, mop_route_display_options=[], mop_route_mapping={}, mop_route_name=None, mop_route_options=[], msg_seq=515, msg_ver=2, rdt=None, repeat=None, replenish_mode=None, rss=None, square_meter_clean_area=91.3, state=<RoborockStateCode.charging: 8>, state_name='charging', subdivision_sets=None, supported_cleaning_settings=[<CleaningSetting.FAN_SPEED: 'fan_speed'>, <CleaningSetting.WATER_MODE: 'water_mode'>], switch_map_mode=None, unsave_map_flag=0, unsave_map_reason=4, wash_phase=None, wash_ready=None, wash_status=None, water_box_carriage_status=0, water_box_filter_status=None, water_box_mode=204, water_box_status=0, water_mode_display_options=[<WaterModes.CUSTOMIZED: 'custom'>], water_mode_mapping={200: 'off', 201: 'mild', 202: 'standard', 203: 'intense', 207: 'custom_water_flow'}, water_mode_name='custom', water_mode_options=[<WaterModes.OFF: 'off'>, <WaterModes.MILD: 'mild'>, <WaterModes.STANDARD: 'standard'>, <WaterModes.INTENSE: 'intense'>, <WaterModes.CUSTOM: 'custom_water_flow'>], water_shortage_status=None)
882882
# ---
883883
# name: test_device_trait_command_parsing[status].1
884884
dict({

‎tests/devices/traits/v1/test_status.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@ def test_mop_route_special_values_need_shake(codes: tuple[int, int, int]) -> Non
16391639
def test_supported_cleaning_settings(overrides: dict[str, bool], expected: set[CleaningSetting]) -> None:
16401640
"""The option lists and mappings are empty exactly for the settings the model does not have."""
16411641
trait = _create_cleaning_mode_status_trait(**overrides)
1642-
assert trait.supported_cleaning_settings == frozenset(expected)
1642+
assert trait.supported_cleaning_settings == [setting for setting in CleaningSetting if setting in expected]
16431643
assert bool(trait.fan_speed_options) and bool(trait.fan_speed_mapping)
16441644
assert bool(trait.water_mode_options) is (_WATER in expected)
16451645
assert bool(trait.water_mode_mapping) is (_WATER in expected)

0 commit comments

Comments
 (0)