33from typing import Any
44
55from roborock import (
6+ SEQ_TYPE_CLEAN_THEN_MOP ,
67 CleaningMode ,
78 CleanRoutes ,
89 RoborockDockState ,
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 ,
2123 resolve_cleaning_mode ,
2224)
2325from roborock .devices .traits .common import DpsDataConverter , TraitUpdateListener
24- from roborock .exceptions import RoborockException , RoborockUnsupportedFeature
2526from roborock .roborock_message import RoborockDataProtocol
2627from roborock .roborock_typing import RoborockCommand
2728
3233
3334_DPS_CONVERTER = DpsDataConverter .from_dataclass (StatusV2 )
3435
35- _SEQ_TYPE_CLEAN_THEN_MOP = 1
36-
3736
3837class 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