3939 DyadCleanserAmount ,
4040 DyadDryingMode ,
4141 DyadError ,
42+ DyadFeatureBits ,
43+ DyadFlatStatus ,
4244 DyadPowerwheelDirection ,
4345 DyadSelfCleanIntensity ,
4446 DyadSelfCleanLevel ,
6466)
6567from roborock .devices .rpc .a01_channel import send_decoded_command
6668from roborock .devices .traits import Trait
69+ from roborock .devices .traits .a01 import dyad_feature
6770from roborock .devices .traits .a01 .device_feature import (
6871 build_feature_dp_list ,
6972 build_force_load_dp_list ,
7073 supports_uv_light ,
7174)
7275from roborock .devices .traits .common import TraitUpdateListener
7376from roborock .devices .transport .mqtt_channel import MqttChannel
74- from roborock .exceptions import RoborockException
77+ from roborock .exceptions import RoborockException , RoborockUnsupportedFeature
7578from roborock .protocols .a01_protocol import decode_rpc_response
7679from roborock .roborock_message import (
7780 RoborockDyadDataProtocol ,
@@ -96,12 +99,15 @@ def _decode_dyad_schedule(value: str) -> list[DyadScheduleTask]:
9699 return [DyadScheduleTask .from_dict (task ) for task in json .loads (value )]
97100
98101
99- # The F25 Ultra app pairs each suction level (eco, standard, turbo) with a brush speed.
100- _F25_SUCTION_BRUSH_SPEED = {
102+ # The app pairs each suction level (eco, standard, turbo) with a brush speed.
103+ _PAIRED_SUCTION_BRUSH_SPEED = {
101104 DyadSuction .l2 : DyadBrushSpeed .l1 ,
102105 DyadSuction .l3 : DyadBrushSpeed .l2 ,
103106 DyadSuction .l4 : DyadBrushSpeed .l2 ,
104107}
108+ _WATER_LEVELS = (DyadWaterLevel .l2 , DyadWaterLevel .l3 , DyadWaterLevel .l4 )
109+ _DRYING_MODES = (DyadDryingMode .fast , DyadDryingMode .silent )
110+ _SELF_CLEAN_INTENSITIES = (DyadSelfCleanIntensity .smart , DyadSelfCleanIntensity .standard , DyadSelfCleanIntensity .deep )
105111
106112DYAD_PROTOCOL_ENTRIES : dict [RoborockDyadDataProtocol , Callable ] = {
107113 RoborockDyadDataProtocol .STATUS : lambda val : RoborockDyadStateCode (val ).name ,
@@ -122,7 +128,7 @@ def _decode_dyad_schedule(value: str) -> list[DyadScheduleTask]:
122128 RoborockDyadDataProtocol .STAND_LOCK_AUTO_RUN : lambda val : bool (val ),
123129 RoborockDyadDataProtocol .AUTO_SELF_CLEAN_SET_MODE : lambda val : DyadSelfCleanLevel (val ).name ,
124130 RoborockDyadDataProtocol .AUTO_DRY_MODE : lambda val : bool (val ),
125- RoborockDyadDataProtocol .SILENT_DRY_DURATION : lambda val : int (val ), # minutes, or DyadDryingMode on F25
131+ RoborockDyadDataProtocol .SILENT_DRY_DURATION : lambda val : int (val ), # minutes, or a DyadDryingMode code
126132 RoborockDyadDataProtocol .SILENT_MODE : lambda val : bool (val ),
127133 RoborockDyadDataProtocol .SILENT_MODE_START_TIME : lambda val : time (
128134 hour = int (val / 60 ), minute = val % 60
@@ -144,9 +150,16 @@ def _decode_dyad_schedule(value: str) -> list[DyadScheduleTask]:
144150 RoborockDyadDataProtocol .WATER_MODE_BRUSH_SPEED : lambda val : DyadBrushSpeed (val ).name ,
145151 RoborockDyadDataProtocol .CHARGE_ERROR_STATUS : lambda val : bool (val ),
146152 RoborockDyadDataProtocol .DRYING_RATE : lambda val : int (val ), # percent
147- RoborockDyadDataProtocol .FLAT_STATUS : lambda val : bool (val ),
153+ RoborockDyadDataProtocol .FLAT_STATUS : lambda val : DyadFlatStatus (val ). name ,
148154 RoborockDyadDataProtocol .POWERWHEEL_DIRECTION : lambda val : DyadPowerwheelDirection (val ).name ,
149155 RoborockDyadDataProtocol .POWERWHEEL_SPEED : lambda val : int (val ),
156+ RoborockDyadDataProtocol .FEATURE_INFO : lambda val : int (val ),
157+ RoborockDyadDataProtocol .SELF_CLEAN_PROGRESS : lambda val : int (val ), # percent
158+ RoborockDyadDataProtocol .SPRAY_MODE : lambda val : int (val ),
159+ RoborockDyadDataProtocol .MECHANICAL_ARM : lambda val : bool (val ),
160+ RoborockDyadDataProtocol .TRIGGER_MODE : lambda val : int (val ),
161+ RoborockDyadDataProtocol .SELF_CLEAN_REMINDER : lambda val : int (val ),
162+ RoborockDyadDataProtocol .BATTERY_THRESHOLD : lambda val : int (val ),
150163 RoborockDyadDataProtocol .SELF_CLEAN_CUR_MODE : lambda val : DyadSelfCleanIntensity (val ).name ,
151164 RoborockDyadDataProtocol .SELF_CLEAN_CUR_TEMP : lambda val : DyadSelfCleanWaterTemp (val ).name ,
152165 RoborockDyadDataProtocol .DRY_CUR_MODE : lambda val : DyadDryingMode (val ).name ,
@@ -305,6 +318,27 @@ class DyadApi(A01Api[RoborockDyadDataProtocol]):
305318
306319 name = "dyad"
307320
321+ def __init__ (
322+ self , channel : MqttChannel , model : str | None = None , initial_status : dict [int , Any ] | None = None
323+ ) -> None :
324+ """Initialize the Dyad API."""
325+ self ._model = model
326+ super ().__init__ (channel , initial_status )
327+
328+ def _require_support (self , is_supported : Callable [[str | None ], bool ]) -> None :
329+ """Raise if the device model does not support a command."""
330+ if not is_supported (self ._model ):
331+ raise RoborockUnsupportedFeature (f"Command is not supported on model { self ._model } " )
332+
333+ def supports (self , feature : DyadFeatureBits ) -> bool :
334+ """Return whether the device reported a feature bit on `FEATURE_INFO`.
335+
336+ The result is False until the device has reported `FEATURE_INFO`.
337+ """
338+ if feature == DyadFeatureBits .unknown :
339+ return False
340+ return bool (self ._values .get (RoborockDyadDataProtocol .FEATURE_INFO , 0 ) & (1 << feature .value ))
341+
308342 def _decode_datapoints (self , datapoints : dict [int , Any ]) -> dict [RoborockDyadDataProtocol , Any ]:
309343 """Convert raw datapoints to typed values, skipping unknown codes."""
310344 values : dict [RoborockDyadDataProtocol , Any ] = {}
@@ -327,94 +361,123 @@ async def query_values(self, protocols: list[RoborockDyadDataProtocol]) -> dict[
327361 return values
328362
329363 async def set_value (self , protocol : RoborockDyadDataProtocol , value : Any ) -> dict [RoborockDyadDataProtocol , Any ]:
330- """Set a value for a specific protocol on the device."""
364+ """Set a value for a specific protocol on the device.
365+
366+ The value is sent as is and is not checked against the model. Prefer the
367+ dedicated methods, which accept only what the app offers for the model.
368+ """
331369 params = {protocol : value }
332370 return await send_decoded_command (self ._channel , params )
333371
372+ async def set_clean_mode (self , mode : DyadCleanMode ) -> None :
373+ """Set the clean mode, limited to the modes the app offers for the model."""
374+ if mode not in dyad_feature .clean_modes (self ._model ):
375+ raise RoborockUnsupportedFeature (f"Clean mode { mode !r} is not supported on model { self ._model } " )
376+ await send_decoded_command (self ._channel , {RoborockDyadDataProtocol .CLEAN_MODE : int (mode )})
377+
378+ async def set_water_level (self , level : DyadWaterLevel ) -> None :
379+ """Set the auto mode water level.
380+
381+ Supports `l2`, `l3` and `l4` on models where the app offers these levels.
382+ """
383+ self ._require_support (dyad_feature .supports_clean_intensity )
384+ if level not in _WATER_LEVELS :
385+ raise ValueError (f"Unsupported water level: { level !r} " )
386+ await send_decoded_command (self ._channel , {RoborockDyadDataProtocol .WATER_LEVEL : int (level )})
387+
334388 async def start_drying (self ) -> None :
335389 """Start drying with the drying mode currently set on the device.
336390
337- The app sends the same command for fast and silent drying on the F25 Ultra .
391+ The app sends the same command for fast and silent drying.
338392 """
339393 await send_decoded_command (
340394 self ._channel ,
341395 {RoborockDyadDataProtocol .START : 1 , RoborockDyadDataProtocol .WARM_LEVEL : 1 },
342396 )
343397
344- async def stop_drying (self ) -> None :
345- """Stop a running drying cycle."""
398+ async def stop (self ) -> None :
399+ """Stop a running drying or self-clean cycle.
400+
401+ The device has one stop command for both cycles.
402+ """
346403 await send_decoded_command (self ._channel , {RoborockDyadDataProtocol .START : 0 })
347404
348405 async def set_drying_mode (self , mode : DyadDryingMode ) -> None :
349- """Set the drying mode on the F25 Ultra .
406+ """Set the drying mode on models that have one, such as the F25 series .
350407
351- Do not use this on older Dyad models, where the same data point is the
352- silent drying duration in minutes. The device reports the selected mode
353- on `DRY_CUR_MODE`.
408+ Other models raise `RoborockUnsupportedFeature`: there the same data point is
409+ the silent drying duration in minutes. The device reports the selected mode on
410+ `DRY_CUR_MODE`.
354411 """
355- if mode == DyadDryingMode .unknown :
356- raise ValueError ("Cannot set drying mode to unknown" )
412+ self ._require_support (dyad_feature .supports_drying_mode )
413+ if mode not in _DRYING_MODES :
414+ raise ValueError (f"Unsupported drying mode: { mode !r} " )
357415 await send_decoded_command (self ._channel , {RoborockDyadDataProtocol .SILENT_DRY_DURATION : int (mode )})
358416
359417 async def set_self_clean_intensity (self , intensity : DyadSelfCleanIntensity ) -> None :
360- """Set the self-clean intensity on the F25 Ultra .
418+ """Set the self-clean intensity.
361419
362- The F25 Ultra stores this setting across three data points, and smart differs
363- from standard only in `AUTO_SMART_SELF_CLEAN_SET`. Do not use this on other
364- models. `SELF_CLEAN_CUR_MODE` reports the current or last run, not this setting.
420+ The setting spans several data points, and smart differs from standard only in
421+ `AUTO_SMART_SELF_CLEAN_SET`. Models without smart self-clean raise
422+ `RoborockUnsupportedFeature` for `smart`. `SELF_CLEAN_CUR_MODE` reports the
423+ current or last run, not this setting.
365424 """
366- if intensity == DyadSelfCleanIntensity .unknown :
367- raise ValueError ("Cannot set self-clean intensity to unknown" )
425+ self ._require_support (dyad_feature .is_known_model )
426+ if intensity not in _SELF_CLEAN_INTENSITIES :
427+ raise ValueError (f"Unsupported self-clean intensity: { intensity !r} " )
428+ has_smart = dyad_feature .supports_smart_self_clean (self ._model )
429+ if intensity == DyadSelfCleanIntensity .smart and not has_smart :
430+ raise RoborockUnsupportedFeature (f"Smart self-clean is not supported on model { self ._model } " )
368431 level = DyadSelfCleanLevel .deep if intensity == DyadSelfCleanIntensity .deep else DyadSelfCleanLevel .normal
369- await send_decoded_command (
370- self ._channel ,
371- {
372- RoborockDyadDataProtocol .SELF_CLEAN_LEVEL : int (level ),
373- RoborockDyadDataProtocol .AUTO_SELF_CLEAN_SET_MODE : int (level ),
374- RoborockDyadDataProtocol .AUTO_SMART_SELF_CLEAN_SET : int (intensity == DyadSelfCleanIntensity .smart ),
375- },
376- )
432+ params = {
433+ RoborockDyadDataProtocol .SELF_CLEAN_LEVEL : int (level ),
434+ RoborockDyadDataProtocol .AUTO_SELF_CLEAN_SET_MODE : int (level ),
435+ }
436+ if has_smart :
437+ params [RoborockDyadDataProtocol .AUTO_SMART_SELF_CLEAN_SET ] = int (intensity == DyadSelfCleanIntensity .smart )
438+ await send_decoded_command (self ._channel , params )
377439
378440 async def set_suction (self , suction : DyadSuction ) -> None :
379- """Set the auto mode suction on the F25 Ultra .
441+ """Set the auto mode suction on models that pair it with a brush speed .
380442
381443 Supports `l2` (eco), `l3` (standard) and `l4` (turbo). The device does not
382444 change the brush speed by itself, so it is sent along with the suction.
383445 """
384- await self ._set_f25_suction (
446+ await self ._set_paired_suction (
385447 RoborockDyadDataProtocol .SUCTION ,
386448 RoborockDyadDataProtocol .BRUSH_SPEED ,
387449 suction ,
388450 )
389451
390452 async def set_sponge_suction (self , suction : DyadSuction ) -> None :
391- """Set the sponge mode suction on the F25 Ultra .
453+ """Set the sponge mode suction on models that pair it with a brush speed .
392454
393455 Supports `l2` (eco), `l3` (standard) and `l4` (turbo). The device does not
394456 change the brush speed by itself, so it is sent along with the suction.
395457 """
396- await self ._set_f25_suction (
458+ await self ._set_paired_suction (
397459 RoborockDyadDataProtocol .WATER_MODE_SUCTION ,
398460 RoborockDyadDataProtocol .WATER_MODE_BRUSH_SPEED ,
399461 suction ,
400462 )
401463
402- async def _set_f25_suction (
464+ async def _set_paired_suction (
403465 self ,
404466 suction_protocol : RoborockDyadDataProtocol ,
405467 brush_protocol : RoborockDyadDataProtocol ,
406468 suction : DyadSuction ,
407469 ) -> None :
408- """Send a suction level with the brush speed the F25 Ultra app pairs with it."""
409- if (brush_speed := _F25_SUCTION_BRUSH_SPEED .get (suction )) is None :
410- raise ValueError (f"Unsupported suction level: { suction .name } " )
470+ """Send a suction level with the brush speed the app pairs with it."""
471+ self ._require_support (dyad_feature .supports_clean_intensity )
472+ if (brush_speed := _PAIRED_SUCTION_BRUSH_SPEED .get (suction )) is None :
473+ raise ValueError (f"Unsupported suction level: { suction !r} " )
411474 await send_decoded_command (
412475 self ._channel ,
413476 {suction_protocol : int (suction ), brush_protocol : int (brush_speed )},
414477 )
415478
416479 async def start_self_clean (self ) -> None :
417- """Start self-clean with the settings currently set on the F25 Ultra .
480+ """Start self-clean with the settings currently set on the device .
418481
419482 The app includes the current `SELF_CLEAN_LEVEL` in the start command, so it
420483 is read from the device first. After changing the intensity, wait until the
@@ -433,9 +496,15 @@ async def start_self_clean(self) -> None:
433496 },
434497 )
435498
436- async def stop_self_clean (self ) -> None :
437- """Stop a running self-clean cycle."""
438- await send_decoded_command (self ._channel , {RoborockDyadDataProtocol .START : 0 })
499+ async def pause_self_clean (self ) -> None :
500+ """Pause a running self-clean cycle."""
501+ self ._require_support (dyad_feature .supports_self_clean_pause )
502+ await send_decoded_command (self ._channel , {RoborockDyadDataProtocol .START : 2 })
503+
504+ async def resume_self_clean (self ) -> None :
505+ """Resume a paused self-clean cycle."""
506+ self ._require_support (dyad_feature .supports_self_clean_pause )
507+ await send_decoded_command (self ._channel , {RoborockDyadDataProtocol .START : 1 })
439508
440509 async def reset_filter (self ) -> None :
441510 """Reset the filter usage counter."""
@@ -577,7 +646,7 @@ def create(product: HomeDataProduct, mqtt_channel: MqttChannel, device_status: d
577646 initial_status = _parse_device_status (device_status )
578647 match product .category :
579648 case RoborockCategory .WET_DRY_VAC :
580- return DyadApi (mqtt_channel , initial_status = initial_status )
649+ return DyadApi (mqtt_channel , model = product . model , initial_status = initial_status )
581650 case RoborockCategory .WASHING_MACHINE :
582651 return ZeoApi (mqtt_channel , model = product .model , initial_status = initial_status )
583652 case _:
0 commit comments