Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions roborock/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ def _decamelize(s: str):

@dataclass
class RoborockBase:
_ignore_keys = [] # type: ignore

@staticmethod
def _convert_to_class_obj(class_type: type, value):
if get_origin(class_type) is list:
Expand Down Expand Up @@ -684,19 +682,20 @@ class MultiMapsListMapInfoBakMaps(RoborockBase):

@dataclass
class MultiMapsListMapInfo(RoborockBase):
_ignore_keys = ["mapFlag"]

mapFlag: int
map_flag: int
name: str
add_time: Any | None = None
length: Any | None = None
bak_maps: list[MultiMapsListMapInfoBakMaps] | None = None

@property
def mapFlag(self) -> int:
"""Alias for map_flag, returns the map flag as an integer."""
return self.map_flag


@dataclass
class MultiMapsList(RoborockBase):
_ignore_keys = ["mapFlag"]

max_multi_map: int | None = None
max_bak_map: int | None = None
multi_map_count: int | None = None
Expand Down
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_containers.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_multi_maps_list_info
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)])])
# ---
56 changes: 55 additions & 1 deletion tests/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from dataclasses import dataclass
from typing import Any

from syrupy import SnapshotAssertion

from roborock import CleanRecord, CleanSummary, Consumable, DnDTimer, HomeData, S7MaxVStatus, UserData
from roborock.b01_containers import (
B01Fault,
Expand All @@ -20,7 +22,7 @@
RoborockMopModeS7,
RoborockStateCode,
)
from roborock.containers import RoborockBase
from roborock.containers import MultiMapsList, RoborockBase

from .mock_data import (
CLEAN_RECORD,
Expand Down Expand Up @@ -427,3 +429,55 @@ def test_b01props_deserialization():
assert deserialized.status == WorkStatusMapping.SWEEP_MOPING_2
assert deserialized.wind == SCWindMapping.SUPER_STRONG
assert deserialized.net_status.ip == "192.168.1.102"


def test_multi_maps_list_info(snapshot: SnapshotAssertion) -> None:
"""Test that MultiMapsListInfo can be deserialized correctly."""
data = {
"max_multi_map": 4,
"max_bak_map": 1,
"multi_map_count": 2,
"map_info": [
{
"mapFlag": 0,
"add_time": 1757636125,
"length": 10,
"name": "Downstairs",
"bak_maps": [{"mapFlag": 4, "add_time": 1739205442}],
"rooms": [
{"id": 16, "tag": 12, "iot_name_id": "6990322", "iot_name": "Room"},
{"id": 17, "tag": 15, "iot_name_id": "7140977", "iot_name": "Room"},
{"id": 18, "tag": 12, "iot_name_id": "6985623", "iot_name": "Room"},
{"id": 19, "tag": 14, "iot_name_id": "6990378", "iot_name": "Room"},
{"id": 20, "tag": 10, "iot_name_id": "7063728", "iot_name": "Room"},
{"id": 22, "tag": 12, "iot_name_id": "6995506", "iot_name": "Room"},
{"id": 23, "tag": 15, "iot_name_id": "7140979", "iot_name": "Room"},
{"id": 25, "tag": 13, "iot_name_id": "6990383", "iot_name": "Room"},
{"id": 24, "tag": -1, "iot_name_id": "-1", "iot_name": "Room"},
],
"furnitures": [
{"id": 1, "type": 46, "subtype": 2},
{"id": 2, "type": 47, "subtype": 0},
{"id": 3, "type": 56, "subtype": 0},
{"id": 4, "type": 43, "subtype": 0},
{"id": 5, "type": 44, "subtype": 0},
{"id": 6, "type": 44, "subtype": 0},
{"id": 7, "type": 44, "subtype": 0},
{"id": 8, "type": 46, "subtype": 0},
{"id": 9, "type": 46, "subtype": 0},
],
},
{
"mapFlag": 1,
"add_time": 1734283706,
"length": 5,
"name": "Foyer",
"bak_maps": [{"mapFlag": 5, "add_time": 1728184107}],
"rooms": [],
"furnitures": [],
},
],
}
deserialized = MultiMapsList.from_dict(data)
assert isinstance(deserialized, MultiMapsList)
assert deserialized == snapshot