Skip to content

Commit 046d7f6

Browse files
feat(v1): add CleaningMode.VAC_THEN_MOP
Model the app's "Vacuum then mop" choice as a fourth high-level cleaning mode, as suggested in review of #959, so consumers such as Home Assistant get it through cleaning_mode_options / current_cleaning_mode / set_cleaning_mode without orchestrating a separate control. - Offer VAC_THEN_MOP when is_clean_then_mop_mode_supported. - Report it when vacuum-and-mop settings run with seq_type 1. - set_cleaning_mode writes the vacuum-and-mop motor settings, then app_set_clean_sequence_type with type 1 (repeat 1 when is_ctm_with_repeat_supported); switching to another mode while it is enabled sends type 0, like the app. - clean_then_mop returns None on devices without the feature. - Replace the separate set_clean_then_mop setter with the mode, and share SEQ_TYPE_CLEAN_THEN_MOP with the per-room customize clean mode trait. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ee41488 commit 046d7f6

4 files changed

Lines changed: 205 additions & 88 deletions

File tree

‎roborock/data/v1/v1_clean_modes.py‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,21 @@ class CleaningMode(StrEnum):
8484

8585
VACUUM = "vacuum"
8686
VAC_AND_MOP = "vac_and_mop"
87+
VAC_THEN_MOP = "vac_then_mop"
88+
"""Vacuum first with the mop pads detached, then return for the pads and mop.
89+
90+
Uses the same motor settings as `VAC_AND_MOP`; the order is a separate
91+
device setting (`seq_type`) that the app writes alongside them.
92+
"""
8793
MOP = "mop"
8894
CUSTOM = "custom"
8995
SMART_MODE = "smart_mode"
9096

9197

98+
# `seq_type` value for "vacuum first, then mop"; 0 means both in one pass.
99+
SEQ_TYPE_CLEAN_THEN_MOP = 1
100+
101+
92102
_WATER_SLIDE_MODES: tuple[WaterModes, ...] = (
93103
WaterModes.OFF,
94104
WaterModes.PURE_WATER_FLOW_START,
@@ -241,6 +251,8 @@ def get_cleaning_mode_options(features: DeviceFeatures) -> list[CleaningMode]:
241251

242252
supported_water_modes = get_water_modes(features)
243253
options = [CleaningMode.VACUUM, CleaningMode.VAC_AND_MOP]
254+
if features.is_clean_then_mop_mode_supported:
255+
options.append(CleaningMode.VAC_THEN_MOP)
244256
if features.is_pure_clean_mop_supported:
245257
options.append(CleaningMode.MOP)
246258
if features.is_customized_clean_supported and WaterModes.CUSTOMIZED in supported_water_modes:
@@ -275,7 +287,7 @@ def _get_clean_motor_mode_params(
275287
"""Return (fan_power, water_box_mode, mop_mode) enums for the high-level mode."""
276288
if mode == CleaningMode.VACUUM:
277289
return (VacuumModes.BALANCED, WaterModes.OFF, CleanRoutes.STANDARD)
278-
if mode == CleaningMode.VAC_AND_MOP:
290+
if mode in (CleaningMode.VAC_AND_MOP, CleaningMode.VAC_THEN_MOP):
279291
return (VacuumModes.BALANCED, _get_default_mopping_water_mode(features), CleanRoutes.STANDARD)
280292
if mode == CleaningMode.MOP:
281293
return (
@@ -312,6 +324,27 @@ def get_cleaning_mode_parameters(cleaning_mode: CleaningMode, features: DeviceFe
312324
return [params]
313325

314326

327+
def get_clean_sequence_parameters(
328+
cleaning_mode: CleaningMode,
329+
motor_params: dict[str, int],
330+
features: DeviceFeatures,
331+
) -> dict[str, int]:
332+
"""Get the `app_set_clean_sequence_type` payload for a high-level cleaning mode.
333+
334+
The firmware requires the motor settings (`fan_power`, `water_box_mode` and
335+
`mop_mode`) in the request, so `motor_params` should be the values just sent
336+
with `set_clean_motor_mode`. The app adds `repeat: 1` when enabling the
337+
sequence on devices with `is_ctm_with_repeat_supported`.
338+
"""
339+
if not features.is_clean_then_mop_mode_supported:
340+
raise RoborockUnsupportedFeature("Clean then mop is not supported")
341+
enabled = cleaning_mode == CleaningMode.VAC_THEN_MOP
342+
params = {"type": SEQ_TYPE_CLEAN_THEN_MOP if enabled else 0, **motor_params}
343+
if enabled and features.is_ctm_with_repeat_supported:
344+
params["repeat"] = 1
345+
return params
346+
347+
315348
def _resolve_mode_code(value: int | ModeEnumT | None, mode_cls: type[ModeEnumT]) -> ModeEnumT | None:
316349
"""Resolve a raw code or enum into a RoborockModeEnum."""
317350
if value is None:
@@ -346,8 +379,14 @@ def get_current_cleaning_mode(
346379
water_mode: int | WaterModes | None,
347380
mop_mode: int | CleanRoutes | None,
348381
features: DeviceFeatures,
382+
seq_type: int | None = None,
349383
) -> CleaningMode | None:
350-
"""Classify the current high-level cleaning mode from individual mode codes."""
384+
"""Classify the current high-level cleaning mode from individual mode codes.
385+
386+
`seq_type` is the device's cleaning order (`get_status`); when it is
387+
`SEQ_TYPE_CLEAN_THEN_MOP` on a device that supports it, vacuum-and-mop
388+
settings are reported as `CleaningMode.VAC_THEN_MOP`.
389+
"""
351390
if not features.is_support_water_mode:
352391
return None
353392
clean_mode_enum = _resolve_clean_mode(clean_mode, features)
@@ -368,6 +407,8 @@ def get_current_cleaning_mode(
368407
pass
369408
if water_mode_enum == WaterModes.OFF:
370409
return CleaningMode.VACUUM
410+
if features.is_clean_then_mop_mode_supported and seq_type == SEQ_TYPE_CLEAN_THEN_MOP:
411+
return CleaningMode.VAC_THEN_MOP
371412
return CleaningMode.VAC_AND_MOP
372413

373414

‎roborock/data/v1/v1_containers.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from roborock.roborock_message import RoborockDataProtocol
2020

2121
from ..containers import NamedRoomMapping, RoborockBase, RoborockBaseTimer, _attr_repr, field_metadata
22-
from .v1_clean_modes import WashTowelModes
22+
from .v1_clean_modes import SEQ_TYPE_CLEAN_THEN_MOP, WashTowelModes
2323
from .v1_code_mappings import (
2424
CleanFluidStatus,
2525
ClearWaterBoxStatus,
@@ -517,9 +517,6 @@ class WashTowelMode(RoborockBase):
517517
wash_mode: WashTowelModes | None = None
518518

519519

520-
SEQ_TYPE_CLEAN_THEN_MOP = 1
521-
522-
523520
@dataclass
524521
class SegmentCleanMode(RoborockBase):
525522
"""A single room's clean mode override, as reported by the device.

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

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Any
44

55
from roborock import (
6+
SEQ_TYPE_CLEAN_THEN_MOP,
67
CleaningMode,
78
CleanRoutes,
89
RoborockDockState,
@@ -11,6 +12,7 @@
1112
WaterModes,
1213
get_clean_modes,
1314
get_clean_routes,
15+
get_clean_sequence_parameters,
1416
get_cleaning_mode_options,
1517
get_cleaning_mode_parameters,
1618
get_current_cleaning_mode,
@@ -21,7 +23,6 @@
2123
resolve_cleaning_mode,
2224
)
2325
from roborock.devices.traits.common import DpsDataConverter, TraitUpdateListener
24-
from roborock.exceptions import RoborockException, RoborockUnsupportedFeature
2526
from roborock.roborock_message import RoborockDataProtocol
2627
from roborock.roborock_typing import RoborockCommand
2728

@@ -32,8 +33,6 @@
3233

3334
_DPS_CONVERTER = DpsDataConverter.from_dataclass(StatusV2)
3435

35-
_SEQ_TYPE_CLEAN_THEN_MOP = 1
36-
3736

3837
class StatusTrait(StatusV2, common.V1TraitMixin, TraitUpdateListener):
3938
"""Trait for managing the status of Roborock devices.
@@ -52,7 +51,7 @@ class StatusTrait(StatusV2, common.V1TraitMixin, TraitUpdateListener):
5251
- Fan Speed
5352
- Water Mode
5453
- Mop Route
55-
- Clean then mop (``clean_then_mop``, independent of the cleaning mode)
54+
- Clean then mop (``clean_then_mop``, reported as ``CleaningMode.VAC_THEN_MOP``)
5655
5756
You should use the _options version of the attribute to know which are
5857
supported for your device (i.e. fan_speed_options)
@@ -140,26 +139,19 @@ def clean_then_mop(self) -> bool | None:
140139
"""Whether each room is vacuumed fully before it is mopped.
141140
142141
Reported by the device as ``seq_type`` and persisted on the device: it
143-
tracks the "vacuum then mop" toggle in the vendor app, also while docked.
144-
145-
This is a separate axis from ``current_cleaning_mode``. The cleaning
146-
mode is derived from ``fan_power``, ``water_box_mode`` and ``mop_mode``
147-
and describes *what* the robot does in a room (vacuum, mop, both). This
148-
flag describes the *order* when it does both. On the device the two are
149-
stored independently: writing one leaves the other untouched. Set it
150-
with ``set_clean_then_mop``.
151-
152-
The vendor app presents it as a fourth choice next to "vacuum and mop",
153-
"mop only" and "vacuum only", and clears it when one of those is picked.
154-
A consumer that wants the same experience should turn this off when it
155-
selects a cleaning mode other than vacuum and mop; this library does
156-
not do that implicitly.
157-
158-
``None`` means the device does not support the feature.
142+
tracks the "vacuum then mop" choice in the vendor app, also while docked.
143+
144+
The device stores it separately from ``fan_power``, ``water_box_mode``
145+
and ``mop_mode``, but the app presents it as a fourth cleaning mode, so
146+
``current_cleaning_mode`` reports ``CleaningMode.VAC_THEN_MOP`` when it
147+
is set with vacuum-and-mop settings, and ``set_cleaning_mode`` writes it.
148+
149+
``None`` means the device does not support the feature or has not
150+
reported it.
159151
"""
160-
if self.seq_type is None:
152+
if not self._device_features_trait.is_clean_then_mop_mode_supported or self.seq_type is None:
161153
return None
162-
return self.seq_type == _SEQ_TYPE_CLEAN_THEN_MOP
154+
return self.seq_type == SEQ_TYPE_CLEAN_THEN_MOP
163155

164156
@property
165157
def current_cleaning_mode(self) -> CleaningMode | None:
@@ -168,6 +160,7 @@ def current_cleaning_mode(self) -> CleaningMode | None:
168160
water_mode=self.water_box_mode,
169161
mop_mode=self.mop_mode,
170162
features=self._device_features_trait,
163+
seq_type=self.seq_type,
171164
)
172165

173166
@property
@@ -177,11 +170,23 @@ def current_cleaning_mode_name(self) -> str | None:
177170
return cleaning_mode.value
178171

179172
async def set_cleaning_mode(self, cleaning_mode: str | CleaningMode) -> None:
180-
"""Set the preferred high-level cleaning mode for the device."""
181-
await self.rpc_channel.send_command(
182-
RoborockCommand.SET_CLEAN_MOTOR_MODE,
183-
params=get_cleaning_mode_parameters(resolve_cleaning_mode(cleaning_mode), self._device_features_trait),
184-
)
173+
"""Set the preferred high-level cleaning mode for the device.
174+
175+
Like the app, this also writes the cleaning order on devices that support
176+
clean then mop: it is enabled for ``CleaningMode.VAC_THEN_MOP`` and
177+
cleared when switching to any other mode while it is enabled.
178+
"""
179+
mode = resolve_cleaning_mode(cleaning_mode)
180+
motor_params = get_cleaning_mode_parameters(mode, self._device_features_trait)
181+
await self.rpc_channel.send_command(RoborockCommand.SET_CLEAN_MOTOR_MODE, params=motor_params)
182+
if not self._device_features_trait.is_clean_then_mop_mode_supported:
183+
return
184+
if mode != CleaningMode.VAC_THEN_MOP and not self.clean_then_mop:
185+
return
186+
sequence_params = get_clean_sequence_parameters(mode, motor_params[0], self._device_features_trait)
187+
await self.rpc_channel.send_command(RoborockCommand.APP_SET_CLEAN_SEQUENCE_TYPE, params=sequence_params)
188+
self.seq_type = sequence_params["type"]
189+
self._notify_update()
185190

186191
async def resolve_error(self, error_code: int | None = None) -> None:
187192
"""Resolve an error, like tapping "Resolved" in the Roborock app.
@@ -200,30 +205,6 @@ async def resolve_error(self, error_code: int | None = None) -> None:
200205
await self.rpc_channel.send_command(RoborockCommand.RESOLVE_ERROR, params={"error_code": error_code})
201206
await self.refresh()
202207

203-
async def set_clean_then_mop(self, enabled: bool) -> None:
204-
"""Set whether each room is vacuumed fully before it is mopped.
205-
206-
Independent of ``set_cleaning_mode``. The firmware requires the current
207-
motor-mode values in this request, so they are echoed back unchanged.
208-
"""
209-
if not self._device_features_trait.is_clean_then_mop_mode_supported:
210-
raise RoborockUnsupportedFeature("Clean then mop is not supported")
211-
if self.fan_power is None or self.water_box_mode is None:
212-
raise RoborockException("Status is not loaded, call refresh() first")
213-
seq_type = _SEQ_TYPE_CLEAN_THEN_MOP if enabled else 0
214-
params: dict[str, int] = {
215-
"type": seq_type,
216-
"fan_power": self.fan_power,
217-
"water_box_mode": self.water_box_mode,
218-
}
219-
if self.mop_mode is not None:
220-
params["mop_mode"] = self.mop_mode
221-
if enabled and self._device_features_trait.is_ctm_with_repeat_supported:
222-
params["repeat"] = 1
223-
await self.rpc_channel.send_command(RoborockCommand.APP_SET_CLEAN_SEQUENCE_TYPE, params=params)
224-
self.seq_type = seq_type
225-
self._notify_update()
226-
227208
def update_from_dps(self, decoded_dps: dict[RoborockDataProtocol, Any]) -> None:
228209
"""Update the trait from data protocol push message data.
229210

0 commit comments

Comments
 (0)