@@ -55,40 +55,7 @@ async def test_set_settings_publishes_then_requests_full_settings(
5555 (B01_Q10_DP .COMMON , {"62" : encode_room_clean_settings (settings )}),
5656 (B01_Q10_DP .COMMON , {"63" : 0 }),
5757 ]
58- assert q10_api .room_cleaning .settings == ()
59-
60-
61- async def test_clean_rooms_sends_settings_mode_and_start_in_order (
62- q10_api : Q10PropertiesApi , fake_channel : FakeB01Q10Channel
63- ) -> None :
64- settings = (_settings (3 ), _settings (9 ))
65- await q10_api .vacuum .clean_rooms (settings )
66- assert fake_channel .published_commands == [
67- (B01_Q10_DP .COMMON , {"62" : encode_room_clean_settings (settings )}),
68- (B01_Q10_DP .CLEAN_MODE , 4 ),
69- (B01_Q10_DP .START_CLEAN , {"cmd" : 2 , "clean_paramters" : [3 , 9 ]}),
70- ]
71-
72-
73- @pytest .mark .parametrize ("fail_on" , [1 , 2 , 3 ])
74- async def test_publish_failure_stops_remaining_clean_commands (
75- q10_api : Q10PropertiesApi , fake_channel : FakeB01Q10Channel , fail_on : int , monkeypatch : pytest .MonkeyPatch
76- ) -> None :
77- original = fake_channel .send_command
78- calls = 0
79-
80- async def send (command , params = None ):
81- nonlocal calls
82- calls += 1
83- if calls == fail_on :
84- raise RoborockException ("publish failed" )
85- await original (command , params )
86-
87- monkeypatch .setattr (fake_channel , "send_command" , send )
88- with pytest .raises (RoborockException , match = "publish failed" ):
89- await q10_api .room_cleaning .clean ((_settings (),))
90- assert calls == fail_on
91- assert len (fake_channel .published_commands ) == fail_on - 1
58+ assert q10_api .room_cleaning .settings is None
9259
9360
9461async def test_set_settings_failure_does_not_request_refresh (
@@ -109,30 +76,64 @@ def test_full_push_replaces_and_compact_push_upserts(q10_api: Q10PropertiesApi)
10976 trait .add_update_listener (lambda : notified .append (True ))
11077 trait .update_from_dps ({B01_Q10_DP .CUSTOMER_CLEAN : _complete_payload (_settings (3 ))})
11178 trait .update_from_dps ({B01_Q10_DP .CUSTOMER_CLEAN : encode_room_clean_settings ((_settings (9 ),))})
112- assert trait .settings == ( _settings (3 ), _settings (9 ))
79+ assert trait .settings == [ _settings (3 ), _settings (9 )]
11380 changed = _settings (3 , fan = Q10RoomFanLevel .MAX )
11481 trait .update_from_dps ({B01_Q10_DP .CUSTOMER_CLEAN : encode_room_clean_settings ((changed ,))})
115- assert trait .settings == ( changed , _settings (9 ))
82+ assert trait .settings == [ changed , _settings (9 )]
11683 assert trait .settings_for_room (3 ) == changed
11784 trait .update_from_dps ({B01_Q10_DP .CUSTOMER_CLEAN : _complete_payload (_settings (1 ))})
118- assert trait .settings == ( _settings (1 ),)
85+ assert trait .settings == [ _settings (1 )]
11986 trait .update_from_dps ({B01_Q10_DP .CUSTOMER_CLEAN : "invalid" })
120- assert trait .settings == ( _settings (1 ),)
87+ assert trait .settings == [ _settings (1 )]
12188 trait .update_from_dps ({B01_Q10_DP .CUSTOMER_CLEAN : "AA==" })
122- assert trait .settings == ()
123- assert trait .settings_available
89+ assert trait .settings == []
12490 assert len (notified ) == 5
12591
12692
127- @pytest .mark .parametrize ("field" , ["fan_level" , "water_level" , "clean_type" , "clean_count" , "clean_line" ])
128- def test_unknown_setting_cannot_be_written (field : str ) -> None :
129- settings = _settings ()
130- setattr (settings , field , type (getattr (settings , field )).UNKNOWN )
131- with pytest .raises (ValueError , match = field ):
132- encode_room_clean_settings ((settings ,))
93+ async def test_refresh_requests_complete_settings (q10_api : Q10PropertiesApi , fake_channel : FakeB01Q10Channel ) -> None :
94+ await q10_api .room_cleaning .refresh ()
95+ assert fake_channel .published_commands == [(B01_Q10_DP .COMMON , {"63" : 0 })]
96+ assert q10_api .room_cleaning .settings is None
13397
13498
135- @pytest .mark .parametrize ("rooms" , [(), (_settings (- 1 ),), (_settings (256 ),), (_settings (), _settings ())])
136- def test_semantic_room_guards (rooms : tuple [Q10RoomCleanSettings , ...]) -> None :
137- with pytest .raises (ValueError ):
138- encode_room_clean_settings (rooms )
99+ def test_settings_for_room_unpopulated (q10_api : Q10PropertiesApi ) -> None :
100+ assert q10_api .room_cleaning .settings_for_room (3 ) is None
101+ assert q10_api .room_cleaning .as_dict () == {}
102+ assert q10_api .as_dict ()["room_cleaning" ] == {}
103+
104+
105+ def test_settings_for_room_missing (q10_api : Q10PropertiesApi ) -> None :
106+ q10_api .room_cleaning .update_from_dps ({B01_Q10_DP .CUSTOMER_CLEAN : _complete_payload (_settings (3 ))})
107+ assert q10_api .room_cleaning .settings_for_room (9 ) is None
108+
109+
110+ def test_repeated_pushes_do_not_notify (q10_api : Q10PropertiesApi ) -> None :
111+ trait = q10_api .room_cleaning
112+ notified : list [bool ] = []
113+ trait .add_update_listener (lambda : notified .append (True ))
114+ trait .update_from_dps ({B01_Q10_DP .CUSTOMER_CLEAN : "invalid" })
115+ assert trait .settings is None
116+ assert not notified
117+ compact = encode_room_clean_settings ((_settings (3 ),))
118+ trait .update_from_dps ({B01_Q10_DP .CUSTOMER_CLEAN : compact })
119+ trait .update_from_dps ({B01_Q10_DP .CUSTOMER_CLEAN : compact })
120+ trait .update_from_dps ({B01_Q10_DP .CUSTOMER_CLEAN : _complete_payload (_settings (3 ))})
121+ assert trait .settings == [_settings (3 )]
122+ assert len (notified ) == 1
123+ assert isinstance (trait .as_dict ()["settings" ], list )
124+ trait .update_from_dps ({B01_Q10_DP .CUSTOMER_CLEAN : "AA==" })
125+ trait .update_from_dps ({B01_Q10_DP .CUSTOMER_CLEAN : "AA==" })
126+ assert trait .settings == []
127+ assert trait .as_dict () == {"settings" : []}
128+ assert trait .settings_for_room (3 ) is None
129+ assert len (notified ) == 2
130+
131+
132+ def test_first_empty_push_is_reported (q10_api : Q10PropertiesApi ) -> None :
133+ trait = q10_api .room_cleaning
134+ notified : list [bool ] = []
135+ trait .add_update_listener (lambda : notified .append (True ))
136+ trait .update_from_dps ({B01_Q10_DP .CUSTOMER_CLEAN : "AA==" })
137+ assert trait .settings == []
138+ assert trait .as_dict () == {"settings" : []}
139+ assert notified == [True ]
0 commit comments