88from freezegun import freeze_time
99
1010from roborock .data import DyadScheduleTask
11+ from roborock .data .dyad .dyad_code_mappings import DyadDryingMode , DyadSelfCleanIntensity , DyadSuction
1112from roborock .devices .traits .a01 import DyadApi , ZeoApi , create
1213from roborock .devices .traits .a01 .device_feature import build_force_load_dp_list
1314from 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+
541655async 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