3333 "mapFlag" : 123 ,
3434 "add_time" : 1747132930 ,
3535 "length" : 0 ,
36- "name" : "Map 1 " ,
36+ "name" : "Map 2 " ,
3737 "bak_maps" : [{"mapFlag" : 4 , "add_time" : 1747132936 }],
3838 },
3939 ],
@@ -58,31 +58,48 @@ def maps_trait(device: RoborockDevice) -> MapsTrait:
5858async def test_refresh_maps_trait (
5959 maps_trait : MapsTrait ,
6060 mock_rpc_channel : AsyncMock ,
61+ status_trait : StatusTrait ,
6162) -> None :
6263 """Test successfully getting multi maps list."""
6364 # Setup mock to return the sample multi maps list
64- mock_rpc_channel .send_command .return_value = MULTI_MAP_LIST_DATA
65+ mock_rpc_channel .send_command .side_effect = [
66+ mock_data .STATUS , # Initial status fetch
67+ MULTI_MAP_LIST_DATA
68+ ]
69+ await status_trait .refresh ()
70+ # Populating the status information gives us the current map
71+ # flag, but we have not loaded the rest of the information.
72+ assert maps_trait .current_map == 0
73+ assert maps_trait .current_map_info is None
6574
66- # Call the method
75+ # Load the maps information
6776 await maps_trait .refresh ()
6877
6978 assert maps_trait .max_multi_map == 1
7079 assert maps_trait .max_bak_map == 1
7180 assert maps_trait .multi_map_count == 1
7281 assert maps_trait .map_info
82+
7383 assert len (maps_trait .map_info ) == 2
7484 map_infos = maps_trait .map_info
7585 assert len (map_infos ) == 2
7686 assert map_infos [0 ].map_flag == 0
7787 assert map_infos [0 ].name == "Map 1"
7888 assert map_infos [0 ].add_time == 1747132930
7989 assert map_infos [1 ].map_flag == 123
80- assert map_infos [1 ].name == "Map 1 "
90+ assert map_infos [1 ].name == "Map 2 "
8191 assert map_infos [1 ].add_time == 1747132930
8292
83- # Verify the RPC call was made correctly
84- mock_rpc_channel .send_command .assert_called_once_with (RoborockCommand .GET_MULTI_MAPS_LIST )
93+ assert maps_trait .current_map == 0
94+ assert maps_trait .current_map_info is not None
95+ assert maps_trait .current_map_info .map_flag == 0
96+ assert maps_trait .current_map_info .name == "Map 1"
8597
98+ # Verify the RPC call was made correctly
99+ assert mock_rpc_channel .send_command .call_count == 2
100+ mock_rpc_channel .send_command .assert_any_call (RoborockCommand .GET_STATUS )
101+ mock_rpc_channel .send_command .assert_any_call (RoborockCommand .GET_MULTI_MAPS_LIST )
102+
86103
87104async def test_set_current_map (
88105 status_trait : StatusTrait ,
@@ -101,17 +118,28 @@ async def test_set_current_map(
101118 # First refresh to populate initial state
102119 await maps_trait .refresh ()
103120
121+ # Verify current map
122+
123+ assert maps_trait .current_map == 0
124+ assert maps_trait .current_map_info
125+ assert maps_trait .current_map_info .map_flag == 0
126+ assert maps_trait .current_map_info .name == "Map 1"
127+
104128 # Call the method to set current map
105129 await maps_trait .set_current_map (123 )
106130
107131 # Verify the current map is updated
108132 assert maps_trait .current_map == 123
133+ assert maps_trait .current_map_info
134+ assert maps_trait .current_map_info .map_flag == 123
135+ assert maps_trait .current_map_info .name == "Map 2"
109136
110- # Verify the RPC call was made correctly to load the map
111- mock_rpc_channel .send_command .assert_any_call (RoborockCommand .LOAD_MULTI_MAP , params = [123 ])
112- # Command sent are:
137+ # Verify the command sent are:
113138 # 1. GET_STATUS to get initial status
114139 # 2. GET_MULTI_MAPS_LIST to get the map list
115140 # 3. LOAD_MULTI_MAP to set the map
116141 # 4. GET_STATUS to refresh the current map in status
117142 assert mock_rpc_channel .send_command .call_count == 4
143+ mock_rpc_channel .send_command .assert_any_call (RoborockCommand .GET_STATUS )
144+ mock_rpc_channel .send_command .assert_any_call (RoborockCommand .GET_MULTI_MAPS_LIST )
145+ mock_rpc_channel .send_command .assert_any_call (RoborockCommand .LOAD_MULTI_MAP , params = [123 ])
0 commit comments