Skip to content

Commit 1203f56

Browse files
klowdopaulleonartcalvo
authored andcommitted
feat(v1): add set_clean_then_mop and document how it relates to CleaningMode
1 parent 71b033c commit 1203f56

3 files changed

Lines changed: 79 additions & 3 deletions

File tree

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
resolve_cleaning_mode,
2222
)
2323
from roborock.devices.traits.common import DpsDataConverter, TraitUpdateListener
24+
from roborock.exceptions import RoborockUnsupportedFeature
2425
from roborock.roborock_message import RoborockDataProtocol
2526
from roborock.roborock_typing import RoborockCommand
2627

@@ -51,6 +52,7 @@ class StatusTrait(StatusV2, common.V1TraitMixin, TraitUpdateListener):
5152
- Fan Speed
5253
- Water Mode
5354
- Mop Route
55+
- Clean then mop (``clean_then_mop``, independent of the cleaning mode)
5456
5557
You should use the _options version of the attribute to know which are
5658
supported for your device (i.e. fan_speed_options)
@@ -135,10 +137,18 @@ def mop_route_name(self) -> str | None:
135137

136138
@property
137139
def clean_then_mop(self) -> bool | None:
138-
"""Whether the current run vacuums each room fully before mopping it.
140+
"""Whether each room is vacuumed fully before it is mopped.
139141
140-
Reported by the device as ``seq_type``. It describes the run in
141-
progress; it is not a persisted setting and cannot be set directly.
142+
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. Changing one leaves the
149+
other untouched; set it with ``set_clean_then_mop``.
150+
151+
``None`` means the device does not support the feature.
142152
"""
143153
if self.seq_type is None:
144154
return None
@@ -183,6 +193,27 @@ async def resolve_error(self, error_code: int | None = None) -> None:
183193
await self.rpc_channel.send_command(RoborockCommand.RESOLVE_ERROR, params={"error_code": error_code})
184194
await self.refresh()
185195

196+
async def set_clean_then_mop(self, enabled: bool) -> None:
197+
"""Set whether each room is vacuumed fully before it is mopped.
198+
199+
Independent of ``set_cleaning_mode``. The firmware requires the current
200+
motor-mode values in this request, so they are echoed back unchanged.
201+
"""
202+
if not self._device_features_trait.is_clean_then_mop_mode_supported:
203+
raise RoborockUnsupportedFeature("Clean then mop is not supported")
204+
seq_type = _SEQ_TYPE_CLEAN_THEN_MOP if enabled else 0
205+
params: dict[str, int | None] = {
206+
"type": seq_type,
207+
"fan_power": self.fan_power,
208+
"water_box_mode": self.water_box_mode,
209+
}
210+
if self.mop_mode is not None:
211+
params["mop_mode"] = self.mop_mode
212+
if enabled and self._device_features_trait.is_ctm_with_repeat_supported:
213+
params["repeat"] = 1
214+
await self.rpc_channel.send_command(RoborockCommand.APP_SET_CLEAN_SEQUENCE_TYPE, params=params)
215+
self.seq_type = seq_type
216+
186217
def update_from_dps(self, decoded_dps: dict[RoborockDataProtocol, Any]) -> None:
187218
"""Update the trait from data protocol push message data.
188219

‎roborock/roborock_typing.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class RoborockCommand(str, Enum):
3434
APP_SET_CROSS_CARPET_CLEANING_STATUS = "app_set_cross_carpet_cleaning_status"
3535
APP_SET_DOOR_SILL_BLOCKS = "app_set_door_sill_blocks"
3636
APP_SET_DIRTY_REPLENISH_CLEAN_STATUS = "app_set_dirty_replenish_clean_status"
37+
APP_SET_CLEAN_SEQUENCE_TYPE = "app_set_clean_sequence_type"
3738
APP_SET_DRYER_SETTING = "app_set_dryer_setting"
3839
APP_SET_DRYER_STATUS = "app_set_dryer_status"
3940
APP_SET_DYNAMIC_CONFIG = "app_set_dynamic_config"

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,3 +939,47 @@ def test_status_parses_seq_type() -> None:
939939
status = StatusV2.from_dict({**STATUS, "seq_type": 1})
940940

941941
assert status.seq_type == 1
942+
943+
944+
@pytest.mark.parametrize(
945+
("enabled", "ctm_with_repeat", "expected_params"),
946+
[
947+
(True, True, {"type": 1, "fan_power": 102, "water_box_mode": 202, "mop_mode": 300, "repeat": 1}),
948+
(True, False, {"type": 1, "fan_power": 102, "water_box_mode": 202, "mop_mode": 300}),
949+
(False, True, {"type": 0, "fan_power": 102, "water_box_mode": 202, "mop_mode": 300}),
950+
],
951+
)
952+
async def test_set_clean_then_mop(
953+
mock_rpc_channel: AsyncMock,
954+
enabled: bool,
955+
ctm_with_repeat: bool,
956+
expected_params: dict[str, int],
957+
) -> None:
958+
"""The setter echoes the current motor modes and updates seq_type optimistically."""
959+
status_trait = _create_cleaning_mode_status_trait(
960+
is_clean_then_mop_mode_supported=True,
961+
is_ctm_with_repeat_supported=ctm_with_repeat,
962+
)
963+
status_trait._rpc_channel = mock_rpc_channel # type: ignore[assignment]
964+
status_trait.fan_power = 102
965+
status_trait.water_box_mode = 202
966+
status_trait.mop_mode = 300
967+
status_trait.seq_type = 0 if enabled else 1
968+
969+
await status_trait.set_clean_then_mop(enabled)
970+
971+
mock_rpc_channel.send_command.assert_called_once_with(
972+
RoborockCommand.APP_SET_CLEAN_SEQUENCE_TYPE, params=expected_params
973+
)
974+
assert status_trait.clean_then_mop is enabled
975+
976+
977+
async def test_set_clean_then_mop_unsupported(mock_rpc_channel: AsyncMock) -> None:
978+
"""Devices without the feature reject the setter before sending anything."""
979+
status_trait = _create_cleaning_mode_status_trait(is_clean_then_mop_mode_supported=False)
980+
status_trait._rpc_channel = mock_rpc_channel # type: ignore[assignment]
981+
982+
with pytest.raises(RoborockUnsupportedFeature):
983+
await status_trait.set_clean_then_mop(True)
984+
985+
mock_rpc_channel.send_command.assert_not_called()

0 commit comments

Comments
 (0)