Skip to content

Commit cfaeb41

Browse files
fix: get_multi_map_list
1 parent ff5dac7 commit cfaeb41

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

roborock/containers.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,32 @@
2525

2626
def camelize(s: str):
2727
first, *others = s.split("_")
28+
if len(others) == 0:
29+
return s
2830
return "".join([first.lower(), *map(str.title, others)])
2931

3032

3133
def decamelize(s: str):
3234
return re.sub("([A-Z]+)", "_\\1", s).lower()
3335

3436

35-
def decamelize_obj(d: dict | list):
37+
def decamelize_obj(d: dict | list, ignore_keys: list[str]):
3638
if isinstance(d, list):
37-
return [decamelize_obj(i) if isinstance(i, (dict, list)) else i for i in d]
38-
return {decamelize(a): decamelize_obj(b) if isinstance(b, (dict, list)) else b for a, b in d.items()}
39+
return [decamelize_obj(i, ignore_keys) if isinstance(i, (dict, list)) else i for i in d]
40+
return {
41+
(decamelize(a) if not a in ignore_keys else a): decamelize_obj(b, ignore_keys)
42+
if isinstance(b, (dict, list)) else b for a, b in d.items()
43+
}
3944

4045

4146
@dataclass
4247
class RoborockBase:
4348
@classmethod
4449
def from_dict(cls, data: dict[str, Any]):
45-
return from_dict(cls, decamelize_obj(data), config=Config(cast=[Enum]))
50+
ignore_keys = cls._ignore_keys if hasattr(cls, '_ignore_keys') else []
51+
return from_dict(cls, decamelize_obj(data, ignore_keys), config=Config(cast=[Enum]))
4652

47-
def as_dict(self):
53+
def as_dict(self) -> dict:
4854
return asdict(
4955
self,
5056
dict_factory=lambda _fields: {camelize(key): value for (key, value) in _fields if value is not None},
@@ -277,7 +283,9 @@ class MultiMapsListMapInfoBakMaps(RoborockBase):
277283

278284
@dataclass
279285
class MultiMapsListMapInfo(RoborockBase):
280-
mapflag: Optional[Any] = None
286+
_ignore_keys = ["mapFlag"]
287+
288+
mapFlag: Optional[Any] = None
281289
add_time: Optional[Any] = None
282290
length: Optional[Any] = None
283291
name: Optional[Any] = None
@@ -286,6 +294,8 @@ class MultiMapsListMapInfo(RoborockBase):
286294

287295
@dataclass
288296
class MultiMapsList(RoborockBase):
297+
_ignore_keys = ["mapFlag"]
298+
289299
max_multi_map: Optional[int] = None
290300
max_bak_map: Optional[int] = None
291301
multi_map_count: Optional[int] = None

0 commit comments

Comments
 (0)