Skip to content

Commit ee41488

Browse files
klowdopaulleonartcalvo
authored andcommitted
fix(v1): notify listeners and guard unloaded status in set_clean_then_mop
1 parent 1203f56 commit ee41488

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
resolve_cleaning_mode,
2222
)
2323
from roborock.devices.traits.common import DpsDataConverter, TraitUpdateListener
24-
from roborock.exceptions import RoborockUnsupportedFeature
24+
from roborock.exceptions import RoborockException, RoborockUnsupportedFeature
2525
from roborock.roborock_message import RoborockDataProtocol
2626
from roborock.roborock_typing import RoborockCommand
2727

@@ -145,8 +145,15 @@ def clean_then_mop(self) -> bool | None:
145145
This is a separate axis from ``current_cleaning_mode``. The cleaning
146146
mode is derived from ``fan_power``, ``water_box_mode`` and ``mop_mode``
147147
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``.
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.
150157
151158
``None`` means the device does not support the feature.
152159
"""
@@ -201,8 +208,10 @@ async def set_clean_then_mop(self, enabled: bool) -> None:
201208
"""
202209
if not self._device_features_trait.is_clean_then_mop_mode_supported:
203210
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")
204213
seq_type = _SEQ_TYPE_CLEAN_THEN_MOP if enabled else 0
205-
params: dict[str, int | None] = {
214+
params: dict[str, int] = {
206215
"type": seq_type,
207216
"fan_power": self.fan_power,
208217
"water_box_mode": self.water_box_mode,
@@ -213,6 +222,7 @@ async def set_clean_then_mop(self, enabled: bool) -> None:
213222
params["repeat"] = 1
214223
await self.rpc_channel.send_command(RoborockCommand.APP_SET_CLEAN_SEQUENCE_TYPE, params=params)
215224
self.seq_type = seq_type
225+
self._notify_update()
216226

217227
def update_from_dps(self, decoded_dps: dict[RoborockDataProtocol, Any]) -> None:
218228
"""Update the trait from data protocol push message data.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,12 +966,17 @@ async def test_set_clean_then_mop(
966966
status_trait.mop_mode = 300
967967
status_trait.seq_type = 0 if enabled else 1
968968

969+
event = asyncio.Event()
970+
unsubscribe = status_trait.add_update_listener(event.set)
971+
969972
await status_trait.set_clean_then_mop(enabled)
970973

971974
mock_rpc_channel.send_command.assert_called_once_with(
972975
RoborockCommand.APP_SET_CLEAN_SEQUENCE_TYPE, params=expected_params
973976
)
974977
assert status_trait.clean_then_mop is enabled
978+
assert event.is_set()
979+
unsubscribe()
975980

976981

977982
async def test_set_clean_then_mop_unsupported(mock_rpc_channel: AsyncMock) -> None:
@@ -983,3 +988,14 @@ async def test_set_clean_then_mop_unsupported(mock_rpc_channel: AsyncMock) -> No
983988
await status_trait.set_clean_then_mop(True)
984989

985990
mock_rpc_channel.send_command.assert_not_called()
991+
992+
993+
async def test_set_clean_then_mop_requires_loaded_status(mock_rpc_channel: AsyncMock) -> None:
994+
"""The setter needs the current motor modes, so it refuses to run before a refresh."""
995+
status_trait = _create_cleaning_mode_status_trait(is_clean_then_mop_mode_supported=True)
996+
status_trait._rpc_channel = mock_rpc_channel # type: ignore[assignment]
997+
998+
with pytest.raises(RoborockException, match="refresh"):
999+
await status_trait.set_clean_then_mop(True)
1000+
1001+
mock_rpc_channel.send_command.assert_not_called()

0 commit comments

Comments
 (0)