Skip to content

Commit 0c49cd3

Browse files
committed
feat(dyad): add F25 Ultra setting and self-clean commands
Add typed DyadApi commands for F25 Ultra settings that span several data points or need a value from the device: - set_drying_mode writes DP 225, while the mode is read from DP 272 - set_self_clean_intensity writes DPs 203, 223 and 239 together - set_suction and set_sponge_suction send the brush speed the app pairs with each level, because the device does not change it by itself - start_self_clean sends the current DP 203 with the start command, as the app does - stop_self_clean stops a running cycle
1 parent acd298e commit 0c49cd3

2 files changed

Lines changed: 212 additions & 0 deletions

File tree

‎roborock/devices/traits/a01/__init__.py‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ def _decode_dyad_schedule(value: str) -> list[DyadScheduleTask]:
9696
return [DyadScheduleTask.from_dict(task) for task in json.loads(value)]
9797

9898

99+
# The F25 Ultra app pairs each suction level (eco, standard, turbo) with a brush speed.
100+
_F25_SUCTION_BRUSH_SPEED = {
101+
DyadSuction.l2: DyadBrushSpeed.l1,
102+
DyadSuction.l3: DyadBrushSpeed.l2,
103+
DyadSuction.l4: DyadBrushSpeed.l2,
104+
}
105+
99106
DYAD_PROTOCOL_ENTRIES: dict[RoborockDyadDataProtocol, Callable] = {
100107
RoborockDyadDataProtocol.STATUS: lambda val: RoborockDyadStateCode(val).name,
101108
RoborockDyadDataProtocol.SELF_CLEAN_MODE: lambda val: DyadSelfCleanMode(val).name,
@@ -338,6 +345,97 @@ async def stop_drying(self) -> None:
338345
"""Stop a running drying cycle."""
339346
await send_decoded_command(self._channel, {RoborockDyadDataProtocol.START: 0})
340347

348+
async def set_drying_mode(self, mode: DyadDryingMode) -> None:
349+
"""Set the drying mode on the F25 Ultra.
350+
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`.
354+
"""
355+
if mode == DyadDryingMode.unknown:
356+
raise ValueError("Cannot set drying mode to unknown")
357+
await send_decoded_command(self._channel, {RoborockDyadDataProtocol.SILENT_DRY_DURATION: int(mode)})
358+
359+
async def set_self_clean_intensity(self, intensity: DyadSelfCleanIntensity) -> None:
360+
"""Set the self-clean intensity on the F25 Ultra.
361+
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.
365+
"""
366+
if intensity == DyadSelfCleanIntensity.unknown:
367+
raise ValueError("Cannot set self-clean intensity to unknown")
368+
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+
)
377+
378+
async def set_suction(self, suction: DyadSuction) -> None:
379+
"""Set the auto mode suction on the F25 Ultra.
380+
381+
Supports `l2` (eco), `l3` (standard) and `l4` (turbo). The device does not
382+
change the brush speed by itself, so it is sent along with the suction.
383+
"""
384+
await self._set_f25_suction(
385+
RoborockDyadDataProtocol.SUCTION,
386+
RoborockDyadDataProtocol.BRUSH_SPEED,
387+
suction,
388+
)
389+
390+
async def set_sponge_suction(self, suction: DyadSuction) -> None:
391+
"""Set the sponge mode suction on the F25 Ultra.
392+
393+
Supports `l2` (eco), `l3` (standard) and `l4` (turbo). The device does not
394+
change the brush speed by itself, so it is sent along with the suction.
395+
"""
396+
await self._set_f25_suction(
397+
RoborockDyadDataProtocol.WATER_MODE_SUCTION,
398+
RoborockDyadDataProtocol.WATER_MODE_BRUSH_SPEED,
399+
suction,
400+
)
401+
402+
async def _set_f25_suction(
403+
self,
404+
suction_protocol: RoborockDyadDataProtocol,
405+
brush_protocol: RoborockDyadDataProtocol,
406+
suction: DyadSuction,
407+
) -> 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}")
411+
await send_decoded_command(
412+
self._channel,
413+
{suction_protocol: int(suction), brush_protocol: int(brush_speed)},
414+
)
415+
416+
async def start_self_clean(self) -> None:
417+
"""Start self-clean with the settings currently set on the F25 Ultra.
418+
419+
The app includes the current `SELF_CLEAN_LEVEL` in the start command, so it
420+
is read from the device first.
421+
"""
422+
response = await send_decoded_command(
423+
self._channel,
424+
{RoborockDyadDataProtocol.ID_QUERY: [RoborockDyadDataProtocol.SELF_CLEAN_LEVEL]},
425+
value_encoder=json.dumps,
426+
)
427+
await send_decoded_command(
428+
self._channel,
429+
{
430+
RoborockDyadDataProtocol.START: 1,
431+
RoborockDyadDataProtocol.SELF_CLEAN_LEVEL: response[RoborockDyadDataProtocol.SELF_CLEAN_LEVEL],
432+
},
433+
)
434+
435+
async def stop_self_clean(self) -> None:
436+
"""Stop a running self-clean cycle."""
437+
await send_decoded_command(self._channel, {RoborockDyadDataProtocol.START: 0})
438+
341439
async def reset_filter(self) -> None:
342440
"""Reset the filter usage counter."""
343441
await send_decoded_command(self._channel, {RoborockDyadDataProtocol.MESH_RESET: 1})

‎tests/devices/traits/a01/test_init.py‎

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from freezegun import freeze_time
99

1010
from roborock.data import DyadScheduleTask
11+
from roborock.data.dyad.dyad_code_mappings import DyadDryingMode, DyadSelfCleanIntensity, DyadSuction
1112
from roborock.devices.traits.a01 import DyadApi, ZeoApi, create
1213
from roborock.devices.traits.a01.device_feature import build_force_load_dp_list
1314
from roborock.roborock_message import RoborockDyadDataProtocol, RoborockMessageProtocol, RoborockZeoProtocol
@@ -520,6 +521,7 @@ async def test_dyad_schedule_task_invalid(dyad_api: DyadApi, fake_channel: FakeC
520521
[
521522
("start_drying", {"200": 1, "204": 1}),
522523
("stop_drying", {"200": 0}),
524+
("stop_self_clean", {"200": 0}),
523525
("reset_filter", {"218": 1}),
524526
("reset_brush", {"219": 1}),
525527
],
@@ -538,6 +540,118 @@ async def test_dyad_action_commands(
538540
assert payload_data["dps"] == expected_dps
539541

540542

543+
@pytest.mark.parametrize(
544+
("mode", "expected_dps"),
545+
[
546+
(DyadDryingMode.fast, {"225": 5}),
547+
(DyadDryingMode.silent, {"225": 22}),
548+
],
549+
)
550+
async def test_dyad_set_drying_mode(
551+
mode: DyadDryingMode,
552+
expected_dps: dict[str, int],
553+
dyad_api: DyadApi,
554+
fake_channel: FakeChannel,
555+
):
556+
"""The drying mode is written to the data point used by the app."""
557+
await dyad_api.set_drying_mode(mode)
558+
559+
assert len(fake_channel.published_messages) == 1
560+
payload_data = json.loads(unpad(fake_channel.published_messages[0].payload, AES.block_size))
561+
assert payload_data["dps"] == expected_dps
562+
563+
564+
async def test_dyad_set_drying_mode_unknown(dyad_api: DyadApi, fake_channel: FakeChannel):
565+
"""The unknown placeholder is rejected and nothing is sent to the device."""
566+
with pytest.raises(ValueError):
567+
await dyad_api.set_drying_mode(DyadDryingMode.unknown)
568+
569+
assert fake_channel.published_messages == []
570+
571+
572+
@pytest.mark.parametrize(
573+
("intensity", "expected_dps"),
574+
[
575+
(DyadSelfCleanIntensity.smart, {"203": 1, "223": 1, "239": 1}),
576+
(DyadSelfCleanIntensity.standard, {"203": 1, "223": 1, "239": 0}),
577+
(DyadSelfCleanIntensity.deep, {"203": 2, "223": 2, "239": 0}),
578+
],
579+
)
580+
async def test_dyad_set_self_clean_intensity(
581+
intensity: DyadSelfCleanIntensity,
582+
expected_dps: dict[str, int],
583+
dyad_api: DyadApi,
584+
fake_channel: FakeChannel,
585+
):
586+
"""The intensity is written to all the data points the device reports it on."""
587+
await dyad_api.set_self_clean_intensity(intensity)
588+
589+
assert len(fake_channel.published_messages) == 1
590+
payload_data = json.loads(unpad(fake_channel.published_messages[0].payload, AES.block_size))
591+
assert payload_data["dps"] == expected_dps
592+
593+
594+
async def test_dyad_set_self_clean_intensity_unknown(dyad_api: DyadApi, fake_channel: FakeChannel):
595+
"""The unknown placeholder is rejected and nothing is sent to the device."""
596+
with pytest.raises(ValueError):
597+
await dyad_api.set_self_clean_intensity(DyadSelfCleanIntensity.unknown)
598+
599+
assert fake_channel.published_messages == []
600+
601+
602+
@pytest.mark.parametrize(
603+
("method", "suction", "expected_dps"),
604+
[
605+
("set_suction", DyadSuction.l2, {"206": 2, "208": 1}),
606+
("set_suction", DyadSuction.l3, {"206": 3, "208": 2}),
607+
("set_suction", DyadSuction.l4, {"206": 4, "208": 2}),
608+
("set_sponge_suction", DyadSuction.l2, {"244": 2, "245": 1}),
609+
("set_sponge_suction", DyadSuction.l3, {"244": 3, "245": 2}),
610+
("set_sponge_suction", DyadSuction.l4, {"244": 4, "245": 2}),
611+
],
612+
)
613+
async def test_dyad_set_suction(
614+
method: str,
615+
suction: DyadSuction,
616+
expected_dps: dict[str, int],
617+
dyad_api: DyadApi,
618+
fake_channel: FakeChannel,
619+
):
620+
"""Suction is sent together with the brush speed the app pairs with it."""
621+
await getattr(dyad_api, method)(suction)
622+
623+
assert len(fake_channel.published_messages) == 1
624+
payload_data = json.loads(unpad(fake_channel.published_messages[0].payload, AES.block_size))
625+
assert payload_data["dps"] == expected_dps
626+
627+
628+
@pytest.mark.parametrize("method", ["set_suction", "set_sponge_suction"])
629+
@pytest.mark.parametrize("suction", [DyadSuction.l1, DyadSuction.l5, DyadSuction.l6])
630+
async def test_dyad_set_suction_unsupported(
631+
method: str,
632+
suction: DyadSuction,
633+
dyad_api: DyadApi,
634+
fake_channel: FakeChannel,
635+
):
636+
"""Levels not seen on the F25 Ultra are rejected and nothing is sent."""
637+
with pytest.raises(ValueError):
638+
await getattr(dyad_api, method)(suction)
639+
640+
assert fake_channel.published_messages == []
641+
642+
643+
@pytest.mark.parametrize("level", [1, 2])
644+
async def test_dyad_start_self_clean(level: int, dyad_api: DyadApi, fake_channel: FakeChannel):
645+
"""Self-clean starts with the level currently set on the device."""
646+
fake_channel.response_queue.append(build_a01_message({203: level}))
647+
648+
await dyad_api.start_self_clean()
649+
650+
assert len(fake_channel.published_messages) == 2
651+
payload_data = json.loads(unpad(fake_channel.published_messages[1].payload, AES.block_size))
652+
assert payload_data["dps"] == {"200": 1, "203": level}
653+
654+
541655
async def test_zeo_api_set_value(zeo_api: ZeoApi, fake_channel: FakeChannel):
542656
"""Test ZeoApi set_value sends correct command."""
543657
await zeo_api.set_value(RoborockZeoProtocol.MODE, "standard")

0 commit comments

Comments
 (0)