33
33
"mapFlag" : 123 ,
34
34
"add_time" : 1747132930 ,
35
35
"length" : 0 ,
36
- "name" : "Map 1 " ,
36
+ "name" : "Map 2 " ,
37
37
"bak_maps" : [{"mapFlag" : 4 , "add_time" : 1747132936 }],
38
38
},
39
39
],
@@ -58,31 +58,48 @@ def maps_trait(device: RoborockDevice) -> MapsTrait:
58
58
async def test_refresh_maps_trait (
59
59
maps_trait : MapsTrait ,
60
60
mock_rpc_channel : AsyncMock ,
61
+ status_trait : StatusTrait ,
61
62
) -> None :
62
63
"""Test successfully getting multi maps list."""
63
64
# 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
65
74
66
- # Call the method
75
+ # Load the maps information
67
76
await maps_trait .refresh ()
68
77
69
78
assert maps_trait .max_multi_map == 1
70
79
assert maps_trait .max_bak_map == 1
71
80
assert maps_trait .multi_map_count == 1
72
81
assert maps_trait .map_info
82
+
73
83
assert len (maps_trait .map_info ) == 2
74
84
map_infos = maps_trait .map_info
75
85
assert len (map_infos ) == 2
76
86
assert map_infos [0 ].map_flag == 0
77
87
assert map_infos [0 ].name == "Map 1"
78
88
assert map_infos [0 ].add_time == 1747132930
79
89
assert map_infos [1 ].map_flag == 123
80
- assert map_infos [1 ].name == "Map 1 "
90
+ assert map_infos [1 ].name == "Map 2 "
81
91
assert map_infos [1 ].add_time == 1747132930
82
92
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"
85
97
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
+
86
103
87
104
async def test_set_current_map (
88
105
status_trait : StatusTrait ,
@@ -101,17 +118,28 @@ async def test_set_current_map(
101
118
# First refresh to populate initial state
102
119
await maps_trait .refresh ()
103
120
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
+
104
128
# Call the method to set current map
105
129
await maps_trait .set_current_map (123 )
106
130
107
131
# Verify the current map is updated
108
132
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"
109
136
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:
113
138
# 1. GET_STATUS to get initial status
114
139
# 2. GET_MULTI_MAPS_LIST to get the map list
115
140
# 3. LOAD_MULTI_MAP to set the map
116
141
# 4. GET_STATUS to refresh the current map in status
117
142
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