|
16 | 16 | from roborock.devices.rpc.b01_q7_channel import send_decoded_command |
17 | 17 | from roborock.devices.traits.b01.q7 import Q7PropertiesApi |
18 | 18 | from roborock.exceptions import RoborockException |
| 19 | +from roborock.map.b01_map_parser import B01MapData |
19 | 20 | from roborock.protocols.b01_q7_protocol import B01_VERSION, Q7RequestMessage |
20 | | -from roborock.roborock_message import RoborockB01Props, RoborockMessageProtocol |
| 21 | +from roborock.roborock_message import RoborockB01Props, RoborockMessage, RoborockMessageProtocol |
21 | 22 | from tests.fixtures.channel_fixtures import FakeChannel |
22 | 23 |
|
23 | 24 | from . import B01MessageBuilder |
@@ -257,3 +258,70 @@ async def test_q7_api_find_me(q7_api: Q7PropertiesApi, fake_channel: FakeChannel |
257 | 258 | payload_data = json.loads(unpad(message.payload, AES.block_size)) |
258 | 259 | assert payload_data["dps"]["10000"]["method"] == "service.find_device" |
259 | 260 | assert payload_data["dps"]["10000"]["params"] == {} |
| 261 | + |
| 262 | + |
| 263 | +async def test_q7_api_clean_segments( |
| 264 | + q7_api: Q7PropertiesApi, fake_channel: FakeChannel, message_builder: B01MessageBuilder |
| 265 | +): |
| 266 | + """Test room/segment cleaning helper for Q7.""" |
| 267 | + fake_channel.response_queue.append(message_builder.build({"result": "ok"})) |
| 268 | + await q7_api.clean_segments([10, 11]) |
| 269 | + |
| 270 | + assert len(fake_channel.published_messages) == 1 |
| 271 | + message = fake_channel.published_messages[0] |
| 272 | + payload_data = json.loads(unpad(message.payload, AES.block_size)) |
| 273 | + assert payload_data["dps"]["10000"]["method"] == "service.set_room_clean" |
| 274 | + assert payload_data["dps"]["10000"]["params"] == { |
| 275 | + "clean_type": CleanTaskTypeMapping.ROOM.code, |
| 276 | + "ctrl_value": SCDeviceCleanParam.START.code, |
| 277 | + "room_ids": [10, 11], |
| 278 | + } |
| 279 | + |
| 280 | + |
| 281 | +async def test_q7_map_content_refresh_from_map_response( |
| 282 | + q7_api: Q7PropertiesApi, |
| 283 | + fake_channel: FakeChannel, |
| 284 | + message_builder: B01MessageBuilder, |
| 285 | + monkeypatch: pytest.MonkeyPatch, |
| 286 | +): |
| 287 | + """Test Q7 map content refresh wiring through map list + MAP_RESPONSE payload path.""" |
| 288 | + |
| 289 | + fake_channel.response_queue.append(message_builder.build({"map_list": [{"id": 1772093512, "cur": True}]})) |
| 290 | + fake_channel.response_queue.append( |
| 291 | + RoborockMessage( |
| 292 | + protocol=RoborockMessageProtocol.MAP_RESPONSE, |
| 293 | + payload=b"raw-map-payload", |
| 294 | + version=b"B01", |
| 295 | + seq=message_builder.seq + 1, |
| 296 | + ) |
| 297 | + ) |
| 298 | + |
| 299 | + monkeypatch.setattr( |
| 300 | + "roborock.devices.traits.b01.q7.map_content.decode_b01_map_payload", |
| 301 | + lambda raw_payload, **kwargs: b"inflated-payload", |
| 302 | + ) |
| 303 | + monkeypatch.setattr( |
| 304 | + "roborock.devices.traits.b01.q7.map_content.parse_scmap_payload", |
| 305 | + lambda payload: B01MapData(size_x=1, size_y=1, map_data=b"\x01"), |
| 306 | + ) |
| 307 | + monkeypatch.setattr( |
| 308 | + "roborock.devices.traits.b01.q7.map_content.render_map_png", |
| 309 | + lambda parsed: b"\x89PNG-test", |
| 310 | + ) |
| 311 | + |
| 312 | + result = await q7_api.map_content.refresh() |
| 313 | + |
| 314 | + assert result.image_content == b"\x89PNG-test" |
| 315 | + assert result.raw_api_response == b"raw-map-payload" |
| 316 | + |
| 317 | + assert len(fake_channel.published_messages) == 2 |
| 318 | + |
| 319 | + first = fake_channel.published_messages[0] |
| 320 | + first_payload = json.loads(unpad(first.payload, AES.block_size)) |
| 321 | + assert first_payload["dps"]["10000"]["method"] == "service.get_map_list" |
| 322 | + assert first_payload["dps"]["10000"]["params"] == {} |
| 323 | + |
| 324 | + second = fake_channel.published_messages[1] |
| 325 | + second_payload = json.loads(unpad(second.payload, AES.block_size)) |
| 326 | + assert second_payload["dps"]["10000"]["method"] == "service.upload_by_mapid" |
| 327 | + assert second_payload["dps"]["10000"]["params"] == {"map_id": 1772093512} |
0 commit comments