1717from roborock .devices .traits .b01 .q7 import Q7PropertiesApi
1818from roborock .exceptions import RoborockException
1919from roborock .protocols .b01_q7_protocol import B01_VERSION , Q7RequestMessage
20- from roborock .roborock_message import RoborockB01Props , RoborockMessage , RoborockMessageProtocol
20+ from roborock .roborock_message import RoborockB01Props , RoborockMessageProtocol
2121from tests .fixtures .channel_fixtures import FakeChannel
2222
2323from . import B01MessageBuilder
@@ -27,16 +27,12 @@ async def test_q7_api_query_values(
2727 q7_api : Q7PropertiesApi , fake_channel : FakeChannel , message_builder : B01MessageBuilder
2828):
2929 """Test that Q7PropertiesApi correctly converts raw values."""
30- # We need to construct the expected result based on the mappings
31- # status: 1 -> WAITING_FOR_ORDERS
32- # wind: 2 -> STANDARD
3330 response_data = {
3431 "status" : 1 ,
3532 "wind" : 2 ,
3633 "battery" : 100 ,
3734 }
3835
39- # Queue the response
4036 fake_channel .response_queue .append (message_builder .build (response_data ))
4137
4238 result = await q7_api .query_values (
@@ -48,23 +44,15 @@ async def test_q7_api_query_values(
4844
4945 assert result is not None
5046 assert result .status == WorkStatusMapping .WAITING_FOR_ORDERS
51- # wind might be mapped to SCWindMapping.STANDARD (2)
52- # let's verify checking the prop definition in B01Props
53- # wind: SCWindMapping | None = None
54- # SCWindMapping.STANDARD is 2 ('balanced')
55- from roborock .data .b01_q7 import SCWindMapping
56-
5747 assert result .wind == SCWindMapping .STANDARD
5848
5949 assert len (fake_channel .published_messages ) == 1
6050 message = fake_channel .published_messages [0 ]
6151 assert message .protocol == RoborockMessageProtocol .RPC_REQUEST
6252 assert message .version == B01_VERSION
6353
64- # Verify request payload
6554 assert message .payload is not None
6655 payload_data = json .loads (unpad (message .payload , AES .block_size ))
67- # {"dps": {"10000": {"method": "prop.get", "msgId": "123456789", "params": {"property": ["status", "wind"]}}}}
6856 assert "dps" in payload_data
6957 assert "10000" in payload_data ["dps" ]
7058 inner = payload_data ["dps" ]["10000" ]
@@ -110,8 +98,6 @@ async def test_send_decoded_command_non_dict_response(fake_channel: FakeChannel,
11098 message = message_builder .build ("some_string_error" )
11199 fake_channel .response_queue .append (message )
112100
113- # Use a random string for command type to avoid needing import
114-
115101 with pytest .raises (RoborockException , match = "Unexpected data type for response" ):
116102 await send_decoded_command (fake_channel , Q7RequestMessage (dps = 10000 , command = "prop.get" , params = [])) # type: ignore[arg-type]
117103
@@ -275,90 +261,3 @@ async def test_q7_api_clean_segments(
275261 "ctrl_value" : SCDeviceCleanParam .START .code ,
276262 "room_ids" : [10 , 11 ],
277263 }
278-
279-
280- async def test_q7_api_get_current_map_payload (
281- q7_api : Q7PropertiesApi ,
282- fake_channel : FakeChannel ,
283- message_builder : B01MessageBuilder ,
284- ):
285- """Fetch current map by map-list lookup, then upload_by_mapid."""
286- fake_channel .response_queue .append (message_builder .build ({"map_list" : [{"id" : 1772093512 , "cur" : True }]}))
287- fake_channel .response_queue .append (
288- RoborockMessage (
289- protocol = RoborockMessageProtocol .MAP_RESPONSE ,
290- payload = b"raw-map-payload" ,
291- version = b"B01" ,
292- seq = message_builder .seq + 1 ,
293- )
294- )
295-
296- raw_payload = await q7_api .map .get_current_map_payload ()
297- assert raw_payload == b"raw-map-payload"
298-
299- assert len (fake_channel .published_messages ) == 2
300-
301- first = fake_channel .published_messages [0 ]
302- first_payload = json .loads (unpad (first .payload , AES .block_size ))
303- assert first_payload ["dps" ]["10000" ]["method" ] == "service.get_map_list"
304- assert first_payload ["dps" ]["10000" ]["params" ] == {}
305-
306- second = fake_channel .published_messages [1 ]
307- second_payload = json .loads (unpad (second .payload , AES .block_size ))
308- assert second_payload ["dps" ]["10000" ]["method" ] == "service.upload_by_mapid"
309- assert second_payload ["dps" ]["10000" ]["params" ] == {"map_id" : 1772093512 }
310-
311-
312- async def test_q7_api_map_trait_refresh_populates_cached_values (
313- q7_api : Q7PropertiesApi ,
314- fake_channel : FakeChannel ,
315- message_builder : B01MessageBuilder ,
316- ):
317- """Map trait follows refresh + cached-value access pattern."""
318- fake_channel .response_queue .append (message_builder .build ({"map_list" : [{"id" : 101 , "cur" : True }]}))
319-
320- assert q7_api .map .map_list is None
321- assert q7_api .map .current_map_id is None
322-
323- await q7_api .map .refresh ()
324-
325- assert len (fake_channel .published_messages ) == 1
326- assert q7_api .map .map_list is not None
327- assert q7_api .map .map_list .map_list [0 ].id == 101
328- assert q7_api .map .map_list .map_list [0 ].cur is True
329- assert q7_api .map .current_map_id == 101
330-
331-
332- async def test_q7_api_get_current_map_payload_falls_back_to_first_map (
333- q7_api : Q7PropertiesApi ,
334- fake_channel : FakeChannel ,
335- message_builder : B01MessageBuilder ,
336- ):
337- """If no current map marker exists, first map in list is used."""
338- fake_channel .response_queue .append (message_builder .build ({"map_list" : [{"id" : 111 }, {"id" : 222 , "cur" : False }]}))
339- fake_channel .response_queue .append (
340- RoborockMessage (
341- protocol = RoborockMessageProtocol .MAP_RESPONSE ,
342- payload = b"raw-map-payload" ,
343- version = b"B01" ,
344- seq = message_builder .seq + 1 ,
345- )
346- )
347-
348- await q7_api .map .get_current_map_payload ()
349-
350- second = fake_channel .published_messages [1 ]
351- second_payload = json .loads (unpad (second .payload , AES .block_size ))
352- assert second_payload ["dps" ]["10000" ]["params" ] == {"map_id" : 111 }
353-
354-
355- async def test_q7_api_get_current_map_payload_errors_without_map_list (
356- q7_api : Q7PropertiesApi ,
357- fake_channel : FakeChannel ,
358- message_builder : B01MessageBuilder ,
359- ):
360- """Current-map payload fetch should fail clearly when map list is unusable."""
361- fake_channel .response_queue .append (message_builder .build ({"map_list" : []}))
362-
363- with pytest .raises (RoborockException , match = "Unable to determine map_id" ):
364- await q7_api .map .get_current_map_payload ()
0 commit comments