Skip to content

Commit a91c708

Browse files
committed
fix: fix room mapping parsing bug and add addtiional format samples
1 parent eded27d commit a91c708

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

roborock/devices/traits/v1/rooms.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ def _extract_segment_pairs(response: list) -> list[tuple[int, str]]:
7575
list of lists, where each inner list is a pair of [segment_id, iot_id]. This
7676
function normalizes the response into a list of (segment_id, iot_id) tuples
7777
78-
NOTE: We currently only have samples of the list of lists format in
79-
tests/protocols/testdata so improving test coverage with samples from a real
80-
device with this format would be helpful.
78+
NOTE: We currently only partial samples of the room mapping formats, so
79+
improving test coverage with samples from a real device with this format
80+
would be helpful.
8181
"""
8282
if len(response) == 2 and not isinstance(response[0], list):
8383
segment_id, iot_id = response[0], response[1]
8484
return [(segment_id, iot_id)]
8585

8686
segment_pairs: list[tuple[int, str]] = []
8787
for part in response:
88-
if not isinstance(part, list) or len(part) != 2:
88+
if not isinstance(part, list) or len(part) < 2:
8989
_LOGGER.warning("Unexpected room mapping entry format: %r", part)
9090
continue
9191
segment_id, iot_id = part[0], part[1]

tests/devices/traits/v1/test_rooms.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33
from unittest.mock import AsyncMock
44

55
import pytest
6+
from typing import Any
67

78
from roborock.devices.device import RoborockDevice
89
from roborock.devices.traits.v1.rooms import RoomsTrait
910
from roborock.devices.traits.v1.status import StatusTrait
1011
from roborock.roborock_typing import RoborockCommand
1112

12-
# Rooms from mock_data.HOME_DATA
13-
# {"id": 2362048, "name": "Example room 1"},
14-
# {"id": 2362044, "name": "Example room 2"},
15-
# {"id": 2362041, "name": "Example room 3"},
16-
ROOM_MAPPING_DATA = [[16, "2362048"], [17, "2362044"], [18, "2362041"]]
17-
1813

1914
@pytest.fixture
2015
def status_trait(device: RoborockDevice) -> StatusTrait:
@@ -30,15 +25,25 @@ def rooms_trait(device: RoborockDevice) -> RoomsTrait:
3025
return device.v1_properties.rooms
3126

3227

28+
# Rooms from mock_data.HOME_DATA
29+
# {"id": 2362048, "name": "Example room 1"},
30+
# {"id": 2362044, "name": "Example room 2"},
31+
# {"id": 2362041, "name": "Example room 3"},
32+
@pytest.mark.parametrize(
33+
("room_mapping_data"),
34+
[
35+
([[16, "2362048"], [17, "2362044"], [18, "2362041"]]),
36+
([[16, "2362048", 6], [17, "2362044", 14], [18, "2362041", 13]]),
37+
]
38+
)
3339
async def test_refresh_rooms_trait(
3440
rooms_trait: RoomsTrait,
3541
mock_rpc_channel: AsyncMock,
42+
room_mapping_data: list[Any],
3643
) -> None:
3744
"""Test successfully getting room mapping."""
3845
# Setup mock to return the sample room mapping
39-
mock_rpc_channel.send_command.side_effect = [
40-
ROOM_MAPPING_DATA,
41-
]
46+
mock_rpc_channel.send_command.side_effect = [room_mapping_data]
4247
# Before refresh, rooms should be empty
4348
assert not rooms_trait.rooms
4449

0 commit comments

Comments
 (0)