Skip to content

Commit d79ea3b

Browse files
authored
fix: Fix bug parsing MultiMapsListMapInfo (#474)
1 parent cce1c1b commit d79ea3b

File tree

3 files changed

+65
-8
lines changed

3 files changed

+65
-8
lines changed

roborock/containers.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ def _decamelize(s: str):
109109

110110
@dataclass
111111
class RoborockBase:
112-
_ignore_keys = [] # type: ignore
113-
114112
@staticmethod
115113
def _convert_to_class_obj(class_type: type, value):
116114
if get_origin(class_type) is list:
@@ -686,19 +684,20 @@ class MultiMapsListMapInfoBakMaps(RoborockBase):
686684

687685
@dataclass
688686
class MultiMapsListMapInfo(RoborockBase):
689-
_ignore_keys = ["mapFlag"]
690-
691-
mapFlag: int
687+
map_flag: int
692688
name: str
693689
add_time: Any | None = None
694690
length: Any | None = None
695691
bak_maps: list[MultiMapsListMapInfoBakMaps] | None = None
696692

693+
@property
694+
def mapFlag(self) -> int:
695+
"""Alias for map_flag, returns the map flag as an integer."""
696+
return self.map_flag
697+
697698

698699
@dataclass
699700
class MultiMapsList(RoborockBase):
700-
_ignore_keys = ["mapFlag"]
701-
702701
max_multi_map: int | None = None
703702
max_bak_map: int | None = None
704703
multi_map_count: int | None = None
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# serializer version: 1
2+
# name: test_multi_maps_list_info
3+
MultiMapsList(max_multi_map=4, max_bak_map=1, multi_map_count=2, map_info=[MultiMapsListMapInfo(map_flag=0, name='Downstairs', add_time=1757636125, length=10, bak_maps=[MultiMapsListMapInfoBakMaps(mapflag=None, add_time=1739205442)]), MultiMapsListMapInfo(map_flag=1, name='Foyer', add_time=1734283706, length=5, bak_maps=[MultiMapsListMapInfoBakMaps(mapflag=None, add_time=1728184107)])])
4+
# ---

tests/test_containers.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from dataclasses import dataclass
44
from typing import Any
55

6+
from syrupy import SnapshotAssertion
7+
68
from roborock import CleanRecord, CleanSummary, Consumable, DnDTimer, HomeData, S7MaxVStatus, UserData
79
from roborock.b01_containers import (
810
B01Fault,
@@ -20,7 +22,7 @@
2022
RoborockMopModeS7,
2123
RoborockStateCode,
2224
)
23-
from roborock.containers import RoborockBase
25+
from roborock.containers import MultiMapsList, RoborockBase
2426

2527
from .mock_data import (
2628
CLEAN_RECORD,
@@ -427,3 +429,55 @@ def test_b01props_deserialization():
427429
assert deserialized.status == WorkStatusMapping.SWEEP_MOPING_2
428430
assert deserialized.wind == SCWindMapping.SUPER_STRONG
429431
assert deserialized.net_status.ip == "192.168.1.102"
432+
433+
434+
def test_multi_maps_list_info(snapshot: SnapshotAssertion) -> None:
435+
"""Test that MultiMapsListInfo can be deserialized correctly."""
436+
data = {
437+
"max_multi_map": 4,
438+
"max_bak_map": 1,
439+
"multi_map_count": 2,
440+
"map_info": [
441+
{
442+
"mapFlag": 0,
443+
"add_time": 1757636125,
444+
"length": 10,
445+
"name": "Downstairs",
446+
"bak_maps": [{"mapFlag": 4, "add_time": 1739205442}],
447+
"rooms": [
448+
{"id": 16, "tag": 12, "iot_name_id": "6990322", "iot_name": "Room"},
449+
{"id": 17, "tag": 15, "iot_name_id": "7140977", "iot_name": "Room"},
450+
{"id": 18, "tag": 12, "iot_name_id": "6985623", "iot_name": "Room"},
451+
{"id": 19, "tag": 14, "iot_name_id": "6990378", "iot_name": "Room"},
452+
{"id": 20, "tag": 10, "iot_name_id": "7063728", "iot_name": "Room"},
453+
{"id": 22, "tag": 12, "iot_name_id": "6995506", "iot_name": "Room"},
454+
{"id": 23, "tag": 15, "iot_name_id": "7140979", "iot_name": "Room"},
455+
{"id": 25, "tag": 13, "iot_name_id": "6990383", "iot_name": "Room"},
456+
{"id": 24, "tag": -1, "iot_name_id": "-1", "iot_name": "Room"},
457+
],
458+
"furnitures": [
459+
{"id": 1, "type": 46, "subtype": 2},
460+
{"id": 2, "type": 47, "subtype": 0},
461+
{"id": 3, "type": 56, "subtype": 0},
462+
{"id": 4, "type": 43, "subtype": 0},
463+
{"id": 5, "type": 44, "subtype": 0},
464+
{"id": 6, "type": 44, "subtype": 0},
465+
{"id": 7, "type": 44, "subtype": 0},
466+
{"id": 8, "type": 46, "subtype": 0},
467+
{"id": 9, "type": 46, "subtype": 0},
468+
],
469+
},
470+
{
471+
"mapFlag": 1,
472+
"add_time": 1734283706,
473+
"length": 5,
474+
"name": "Foyer",
475+
"bak_maps": [{"mapFlag": 5, "add_time": 1728184107}],
476+
"rooms": [],
477+
"furnitures": [],
478+
},
479+
],
480+
}
481+
deserialized = MultiMapsList.from_dict(data)
482+
assert isinstance(deserialized, MultiMapsList)
483+
assert deserialized == snapshot

0 commit comments

Comments
 (0)