2525
2626def 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
3133def 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
4247class 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
279285class 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
288296class 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