Repository navigation
feat(v1): add CleaningMode.VAC_THEN_MOP #1024
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
base: main
Are you sure you want to change the base?
Changes from all commits
71b033c
1203f56
ee41488
046d7f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| from typing import Any | ||
|
|
||
| from roborock import ( | ||
| SEQ_TYPE_CLEAN_THEN_MOP, | ||
| CleaningMode, | ||
| CleanRoutes, | ||
| RoborockDockState, | ||
|
|
@@ -11,6 +12,7 @@ | |
| WaterModes, | ||
| get_clean_modes, | ||
| get_clean_routes, | ||
| get_clean_sequence_parameters, | ||
| get_cleaning_mode_options, | ||
| get_cleaning_mode_parameters, | ||
| get_current_cleaning_mode, | ||
|
|
@@ -49,6 +51,7 @@ class StatusTrait(StatusV2, common.V1TraitMixin, TraitUpdateListener): | |
| - Fan Speed | ||
| - Water Mode | ||
| - Mop Route | ||
| - Clean then mop (``clean_then_mop``, reported as ``CleaningMode.VAC_THEN_MOP``) | ||
|
|
||
| You should use the _options version of the attribute to know which are | ||
| supported for your device (i.e. fan_speed_options) | ||
|
|
@@ -131,13 +134,33 @@ def mop_route_name(self) -> str | None: | |
| return None | ||
| return self.mop_route_mapping.get(self.mop_mode) | ||
|
|
||
| @property | ||
| def clean_then_mop(self) -> bool | None: | ||
| """Whether each room is vacuumed fully before it is mopped. | ||
|
|
||
| Reported by the device as ``seq_type`` and persisted on the device: it | ||
| tracks the "vacuum then mop" choice in the vendor app, also while docked. | ||
|
|
||
| The device stores it separately from ``fan_power``, ``water_box_mode`` | ||
| and ``mop_mode``, but the app presents it as a fourth cleaning mode, so | ||
| ``current_cleaning_mode`` reports ``CleaningMode.VAC_THEN_MOP`` when it | ||
| is set with vacuum-and-mop settings, and ``set_cleaning_mode`` writes it. | ||
|
|
||
| ``None`` means the device does not support the feature or has not | ||
| reported it. | ||
| """ | ||
| if not self._device_features_trait.is_clean_then_mop_mode_supported or self.seq_type is None: | ||
| return None | ||
| return self.seq_type == SEQ_TYPE_CLEAN_THEN_MOP | ||
|
|
||
| @property | ||
| def current_cleaning_mode(self) -> CleaningMode | None: | ||
| return get_current_cleaning_mode( | ||
| clean_mode=self.fan_power, | ||
| water_mode=self.water_box_mode, | ||
| mop_mode=self.mop_mode, | ||
| features=self._device_features_trait, | ||
| seq_type=self.seq_type, | ||
| ) | ||
|
|
||
| @property | ||
|
|
@@ -147,11 +170,23 @@ def current_cleaning_mode_name(self) -> str | None: | |
| return cleaning_mode.value | ||
|
|
||
| async def set_cleaning_mode(self, cleaning_mode: str | CleaningMode) -> None: | ||
| """Set the preferred high-level cleaning mode for the device.""" | ||
| await self.rpc_channel.send_command( | ||
| RoborockCommand.SET_CLEAN_MOTOR_MODE, | ||
| params=get_cleaning_mode_parameters(resolve_cleaning_mode(cleaning_mode), self._device_features_trait), | ||
| ) | ||
| """Set the preferred high-level cleaning mode for the device. | ||
|
|
||
| Like the app, this also writes the cleaning order on devices that support | ||
| clean then mop: it is enabled for ``CleaningMode.VAC_THEN_MOP`` and | ||
| cleared when switching to any other mode while it is enabled. | ||
| """ | ||
| mode = resolve_cleaning_mode(cleaning_mode) | ||
| motor_params = get_cleaning_mode_parameters(mode, self._device_features_trait) | ||
| await self.rpc_channel.send_command(RoborockCommand.SET_CLEAN_MOTOR_MODE, params=motor_params) | ||
| if not self._device_features_trait.is_clean_then_mop_mode_supported: | ||
| return | ||
| if mode != CleaningMode.VAC_THEN_MOP and not self.clean_then_mop: | ||
| return | ||
| sequence_params = get_clean_sequence_parameters(mode, motor_params[0], self._device_features_trait) | ||
| await self.rpc_channel.send_command(RoborockCommand.APP_SET_CLEAN_SEQUENCE_TYPE, params=sequence_params) | ||
| self.seq_type = sequence_params["type"] | ||
| self._notify_update() | ||
|
Comment on lines
+187
to
+189
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Priority 2 (Data Lifecycle & State Management): Partial local state mutation before Updating only
Suggested fix: Update all written motor fields alongside motor = motor_params[0]
self.fan_power = motor["fan_power"]
self.water_box_mode = motor["water_box_mode"]
if "mop_mode" in motor:
self.mop_mode = motor["mop_mode"]
# (and self.seq_type = sequence_params["type"] when APP_SET_CLEAN_SEQUENCE_TYPE is sent)
self._notify_update() |
||
|
|
||
| async def resolve_error(self, error_code: int | None = None) -> None: | ||
| """Resolve an error, like tapping "Resolved" in the Roborock app. | ||
|
|
||
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 3 (Wire Protocol):
app_set_clean_sequence_typereplacesset_clean_motor_modein the official appIn the official Roborock app (
sendCleanWaterMopModeRpc), whencleanThenMopModechanges, the app sends onlyapp_set_clean_sequence_type(which already carriesfan_power,water_box_mode,mop_mode, and optionalrepeat: 1) and skipsset_clean_motor_mode. It only sendsset_clean_motor_modewhen the clean-then-mop state is unchanged.Sending both RPCs adds an extra round-trip and introduces a partial-failure window if
SET_CLEAN_MOTOR_MODEsucceeds andAPP_SET_CLEAN_SEQUENCE_TYPEfails or times out. Consider branching so only one command is sent: