-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathcontainers.py
More file actions
1009 lines (831 loc) · 28.6 KB
/
containers.py
File metadata and controls
1009 lines (831 loc) · 28.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import dataclasses
import datetime
import json
import logging
import re
import types
from dataclasses import asdict, dataclass, field
from enum import Enum
from functools import cached_property
from typing import Any, NamedTuple, get_args, get_origin
from .code_mappings import (
SHORT_MODEL_TO_ENUM,
ClearWaterBoxStatus,
DirtyWaterBoxStatus,
DustBagStatus,
RoborockCategory,
RoborockCleanType,
RoborockDockDustCollectionModeCode,
RoborockDockErrorCode,
RoborockDockTypeCode,
RoborockDockWashTowelModeCode,
RoborockErrorCode,
RoborockFanPowerCode,
RoborockFanSpeedP10,
RoborockFanSpeedQ7Max,
RoborockFanSpeedQRevoCurv,
RoborockFanSpeedQRevoMaster,
RoborockFanSpeedQRevoMaxV,
RoborockFanSpeedS6Pure,
RoborockFanSpeedS7,
RoborockFanSpeedS7MaxV,
RoborockFanSpeedS8MaxVUltra,
RoborockFanSpeedSaros10,
RoborockFanSpeedSaros10R,
RoborockFinishReason,
RoborockInCleaning,
RoborockModeEnum,
RoborockMopIntensityCode,
RoborockMopIntensityP10,
RoborockMopIntensityQ7Max,
RoborockMopIntensityQRevoCurv,
RoborockMopIntensityQRevoMaster,
RoborockMopIntensityQRevoMaxV,
RoborockMopIntensityS5Max,
RoborockMopIntensityS6MaxV,
RoborockMopIntensityS7,
RoborockMopIntensityS8MaxVUltra,
RoborockMopIntensitySaros10,
RoborockMopIntensitySaros10R,
RoborockMopModeCode,
RoborockMopModeQRevoCurv,
RoborockMopModeQRevoMaster,
RoborockMopModeQRevoMaxV,
RoborockMopModeS7,
RoborockMopModeS8MaxVUltra,
RoborockMopModeS8ProUltra,
RoborockMopModeSaros10,
RoborockMopModeSaros10R,
RoborockProductNickname,
RoborockStartType,
RoborockStateCode,
)
from .const import (
CLEANING_BRUSH_REPLACE_TIME,
DUST_COLLECTION_REPLACE_TIME,
FILTER_REPLACE_TIME,
MAIN_BRUSH_REPLACE_TIME,
MOP_ROLLER_REPLACE_TIME,
NO_MAP,
ROBOROCK_G10S_PRO,
ROBOROCK_P10,
ROBOROCK_Q7_MAX,
ROBOROCK_QREVO_CURV,
ROBOROCK_QREVO_MASTER,
ROBOROCK_QREVO_MAXV,
ROBOROCK_QREVO_PRO,
ROBOROCK_QREVO_S,
ROBOROCK_S4_MAX,
ROBOROCK_S5_MAX,
ROBOROCK_S6,
ROBOROCK_S6_MAXV,
ROBOROCK_S6_PURE,
ROBOROCK_S7,
ROBOROCK_S7_MAXV,
ROBOROCK_S8,
ROBOROCK_S8_MAXV_ULTRA,
ROBOROCK_S8_PRO_ULTRA,
ROBOROCK_SAROS_10,
ROBOROCK_SAROS_10R,
SENSOR_DIRTY_REPLACE_TIME,
SIDE_BRUSH_REPLACE_TIME,
STRAINER_REPLACE_TIME,
ROBOROCK_G20S_Ultra,
)
from .device_features import DeviceFeatures
from .exceptions import RoborockException
_LOGGER = logging.getLogger(__name__)
def _camelize(s: str):
first, *others = s.split("_")
if len(others) == 0:
return s
return "".join([first.lower(), *map(str.title, others)])
def _decamelize(s: str):
return re.sub("([A-Z]+)", "_\\1", s).lower()
def _attr_repr(obj: Any) -> str:
"""Return a string representation of the object including specified attributes.
This reproduces the default repr behavior of dataclasses, but also includes
properties. This must be called by the child class's __repr__ method since
the parent RoborockBase class does not know about the child class's attributes.
"""
# Reproduce default repr behavior
parts = []
for k in dir(obj):
if k.startswith("_"):
continue
try:
v = getattr(obj, k)
except (RuntimeError, Exception):
continue
if callable(v):
continue
parts.append(f"{k}={v!r}")
return f"{type(obj).__name__}({', '.join(parts)})"
@dataclass(repr=False)
class RoborockBase:
"""Base class for all Roborock data classes."""
@staticmethod
def _convert_to_class_obj(class_type: type, value):
if get_origin(class_type) is list:
sub_type = get_args(class_type)[0]
return [RoborockBase._convert_to_class_obj(sub_type, obj) for obj in value]
if get_origin(class_type) is dict:
_, value_type = get_args(class_type) # assume keys are only basic types
return {k: RoborockBase._convert_to_class_obj(value_type, v) for k, v in value.items()}
if issubclass(class_type, RoborockBase):
return class_type.from_dict(value)
if issubclass(class_type, RoborockModeEnum):
return class_type.from_code(value)
if class_type is Any:
return value
return class_type(value) # type: ignore[call-arg]
@classmethod
def from_dict(cls, data: dict[str, Any]):
"""Create an instance of the class from a dictionary."""
if not isinstance(data, dict):
return None
field_types = {field.name: field.type for field in dataclasses.fields(cls)}
result: dict[str, Any] = {}
for orig_key, value in data.items():
key = _decamelize(orig_key)
if (field_type := field_types.get(key)) is None:
continue
if value == "None" or value is None:
result[key] = None
continue
if isinstance(field_type, types.UnionType):
for subtype in get_args(field_type):
if subtype is types.NoneType:
continue
try:
result[key] = RoborockBase._convert_to_class_obj(subtype, value)
break
except Exception:
_LOGGER.exception(f"Failed to convert {key} with value {value} to type {subtype}")
continue
else:
try:
result[key] = RoborockBase._convert_to_class_obj(field_type, value)
except Exception:
_LOGGER.exception(f"Failed to convert {key} with value {value} to type {field_type}")
continue
return cls(**result)
def as_dict(self) -> dict:
return asdict(
self,
dict_factory=lambda _fields: {
_camelize(key): value.value if isinstance(value, Enum) else value
for (key, value) in _fields
if value is not None
},
)
@dataclass
class RoborockBaseTimer(RoborockBase):
start_hour: int | None = None
start_minute: int | None = None
end_hour: int | None = None
end_minute: int | None = None
enabled: int | None = None
@property
def start_time(self) -> datetime.time | None:
return (
datetime.time(hour=self.start_hour, minute=self.start_minute)
if self.start_hour is not None and self.start_minute is not None
else None
)
@property
def end_time(self) -> datetime.time | None:
return (
datetime.time(hour=self.end_hour, minute=self.end_minute)
if self.end_hour is not None and self.end_minute is not None
else None
)
def __repr__(self) -> str:
return _attr_repr(self)
@dataclass
class Reference(RoborockBase):
r: str | None = None
a: str | None = None
m: str | None = None
l: str | None = None
@dataclass
class RRiot(RoborockBase):
u: str
s: str
h: str
k: str
r: Reference
@dataclass
class UserData(RoborockBase):
rriot: RRiot
uid: int | None = None
tokentype: str | None = None
token: str | None = None
rruid: str | None = None
region: str | None = None
countrycode: str | None = None
country: str | None = None
nickname: str | None = None
tuya_device_state: int | None = None
avatarurl: str | None = None
@dataclass
class HomeDataProductSchema(RoborockBase):
id: Any | None = None
name: Any | None = None
code: Any | None = None
mode: Any | None = None
type: Any | None = None
product_property: Any | None = None
property: Any | None = None
desc: Any | None = None
@dataclass
class HomeDataProduct(RoborockBase):
id: str
name: str
model: str
category: RoborockCategory
code: str | None = None
icon_url: str | None = None
attribute: Any | None = None
capability: int | None = None
schema: list[HomeDataProductSchema] | None = None
@dataclass
class HomeDataDevice(RoborockBase):
duid: str
name: str
local_key: str
fv: str
product_id: str
attribute: Any | None = None
active_time: int | None = None
runtime_env: Any | None = None
time_zone_id: str | None = None
icon_url: str | None = None
lon: Any | None = None
lat: Any | None = None
share: Any | None = None
share_time: Any | None = None
online: bool | None = None
pv: str | None = None
room_id: Any | None = None
tuya_uuid: Any | None = None
tuya_migrated: bool | None = None
extra: Any | None = None
sn: str | None = None
feature_set: str | None = None
new_feature_set: str | None = None
device_status: dict | None = None
silent_ota_switch: bool | None = None
setting: Any | None = None
f: bool | None = None
@dataclass
class HomeDataRoom(RoborockBase):
id: int
name: str
@dataclass
class HomeDataScene(RoborockBase):
id: int
name: str
@dataclass
class HomeData(RoborockBase):
id: int
name: str
products: list[HomeDataProduct] = field(default_factory=lambda: [])
devices: list[HomeDataDevice] = field(default_factory=lambda: [])
received_devices: list[HomeDataDevice] = field(default_factory=lambda: [])
lon: Any | None = None
lat: Any | None = None
geo_name: Any | None = None
rooms: list[HomeDataRoom] = field(default_factory=list)
def get_all_devices(self) -> list[HomeDataDevice]:
devices = []
if self.devices is not None:
devices += self.devices
if self.received_devices is not None:
devices += self.received_devices
return devices
@cached_property
def product_map(self) -> dict[str, HomeDataProduct]:
"""Returns a dictionary of product IDs to HomeDataProduct objects."""
return {product.id: product for product in self.products}
@cached_property
def device_products(self) -> dict[str, tuple[HomeDataDevice, HomeDataProduct]]:
"""Returns a dictionary of device DUIDs to HomeDataDeviceProduct objects."""
product_map = self.product_map
return {
device.duid: (device, product)
for device in self.get_all_devices()
if (product := product_map.get(device.product_id)) is not None
}
@dataclass
class LoginData(RoborockBase):
user_data: UserData
email: str
home_data: HomeData | None = None
@dataclass
class Status(RoborockBase):
msg_ver: int | None = None
msg_seq: int | None = None
state: RoborockStateCode | None = None
battery: int | None = None
clean_time: int | None = None
clean_area: int | None = None
error_code: RoborockErrorCode | None = None
map_present: int | None = None
in_cleaning: RoborockInCleaning | None = None
in_returning: int | None = None
in_fresh_state: int | None = None
lab_status: int | None = None
water_box_status: int | None = None
back_type: int | None = None
wash_phase: int | None = None
wash_ready: int | None = None
fan_power: RoborockFanPowerCode | None = None
dnd_enabled: int | None = None
map_status: int | None = None
is_locating: int | None = None
lock_status: int | None = None
water_box_mode: RoborockMopIntensityCode | None = None
water_box_carriage_status: int | None = None
mop_forbidden_enable: int | None = None
camera_status: int | None = None
is_exploring: int | None = None
home_sec_status: int | None = None
home_sec_enable_password: int | None = None
adbumper_status: list[int] | None = None
water_shortage_status: int | None = None
dock_type: RoborockDockTypeCode | None = None
dust_collection_status: int | None = None
auto_dust_collection: int | None = None
avoid_count: int | None = None
mop_mode: RoborockMopModeCode | None = None
debug_mode: int | None = None
collision_avoid_status: int | None = None
switch_map_mode: int | None = None
dock_error_status: RoborockDockErrorCode | None = None
charge_status: int | None = None
unsave_map_reason: int | None = None
unsave_map_flag: int | None = None
wash_status: int | None = None
distance_off: int | None = None
in_warmup: int | None = None
dry_status: int | None = None
rdt: int | None = None
clean_percent: int | None = None
rss: int | None = None
dss: int | None = None
common_status: int | None = None
corner_clean_mode: int | None = None
last_clean_t: int | None = None
replenish_mode: int | None = None
repeat: int | None = None
kct: int | None = None
subdivision_sets: int | None = None
@property
def square_meter_clean_area(self) -> float | None:
return round(self.clean_area / 1000000, 1) if self.clean_area is not None else None
@property
def error_code_name(self) -> str | None:
return self.error_code.name if self.error_code else None
@property
def state_name(self) -> str | None:
return self.state.name if self.state else None
@property
def water_box_mode_name(self) -> str | None:
return self.water_box_mode.name if self.water_box_mode else None
@property
def fan_power_options(self) -> list[str]:
if self.fan_power is None:
return []
return list(self.fan_power.keys())
@property
def fan_power_name(self) -> str | None:
return self.fan_power.name if self.fan_power else None
@property
def mop_mode_name(self) -> str | None:
return self.mop_mode.name if self.mop_mode else None
def get_fan_speed_code(self, fan_speed: str) -> int:
if self.fan_power is None:
raise RoborockException("Attempted to get fan speed before status has been updated.")
return self.fan_power.as_dict().get(fan_speed)
def get_mop_intensity_code(self, mop_intensity: str) -> int:
if self.water_box_mode is None:
raise RoborockException("Attempted to get mop_intensity before status has been updated.")
return self.water_box_mode.as_dict().get(mop_intensity)
def get_mop_mode_code(self, mop_mode: str) -> int:
if self.mop_mode is None:
raise RoborockException("Attempted to get mop_mode before status has been updated.")
return self.mop_mode.as_dict().get(mop_mode)
@property
def current_map(self) -> int | None:
"""Returns the current map ID if the map is present."""
if self.map_status is not None:
map_flag = self.map_status >> 2
if map_flag != NO_MAP:
return map_flag
return None
@property
def clear_water_box_status(self) -> ClearWaterBoxStatus | None:
if self.dss:
return ClearWaterBoxStatus((self.dss >> 2) & 3)
return None
@property
def dirty_water_box_status(self) -> DirtyWaterBoxStatus | None:
if self.dss:
return DirtyWaterBoxStatus((self.dss >> 4) & 3)
return None
@property
def dust_bag_status(self) -> DustBagStatus | None:
if self.dss:
return DustBagStatus((self.dss >> 6) & 3)
return None
@property
def water_box_filter_status(self) -> int | None:
if self.dss:
return (self.dss >> 8) & 3
return None
@property
def clean_fluid_status(self) -> int | None:
if self.dss:
return (self.dss >> 10) & 3
return None
@property
def hatch_door_status(self) -> int | None:
if self.dss:
return (self.dss >> 12) & 7
return None
@property
def dock_cool_fan_status(self) -> int | None:
if self.dss:
return (self.dss >> 15) & 3
return None
def __repr__(self) -> str:
return _attr_repr(self)
@dataclass
class S4MaxStatus(Status):
fan_power: RoborockFanSpeedS6Pure | None = None
water_box_mode: RoborockMopIntensityS7 | None = None
mop_mode: RoborockMopModeS7 | None = None
@dataclass
class S5MaxStatus(Status):
fan_power: RoborockFanSpeedS6Pure | None = None
water_box_mode: RoborockMopIntensityS5Max | None = None
@dataclass
class Q7MaxStatus(Status):
fan_power: RoborockFanSpeedQ7Max | None = None
water_box_mode: RoborockMopIntensityQ7Max | None = None
@dataclass
class QRevoMasterStatus(Status):
fan_power: RoborockFanSpeedQRevoMaster | None = None
water_box_mode: RoborockMopIntensityQRevoMaster | None = None
mop_mode: RoborockMopModeQRevoMaster | None = None
@dataclass
class QRevoCurvStatus(Status):
fan_power: RoborockFanSpeedQRevoCurv | None = None
water_box_mode: RoborockMopIntensityQRevoCurv | None = None
mop_mode: RoborockMopModeQRevoCurv | None = None
@dataclass
class QRevoMaxVStatus(Status):
fan_power: RoborockFanSpeedQRevoMaxV | None = None
water_box_mode: RoborockMopIntensityQRevoMaxV | None = None
mop_mode: RoborockMopModeQRevoMaxV | None = None
@dataclass
class S6MaxVStatus(Status):
fan_power: RoborockFanSpeedS7MaxV | None = None
water_box_mode: RoborockMopIntensityS6MaxV | None = None
@dataclass
class S6PureStatus(Status):
fan_power: RoborockFanSpeedS6Pure | None = None
@dataclass
class S7MaxVStatus(Status):
fan_power: RoborockFanSpeedS7MaxV | None = None
water_box_mode: RoborockMopIntensityS7 | None = None
mop_mode: RoborockMopModeS7 | None = None
@dataclass
class S7Status(Status):
fan_power: RoborockFanSpeedS7 | None = None
water_box_mode: RoborockMopIntensityS7 | None = None
mop_mode: RoborockMopModeS7 | None = None
@dataclass
class S8ProUltraStatus(Status):
fan_power: RoborockFanSpeedS7MaxV | None = None
water_box_mode: RoborockMopIntensityS7 | None = None
mop_mode: RoborockMopModeS8ProUltra | None = None
@dataclass
class S8Status(Status):
fan_power: RoborockFanSpeedS7MaxV | None = None
water_box_mode: RoborockMopIntensityS7 | None = None
mop_mode: RoborockMopModeS8ProUltra | None = None
@dataclass
class P10Status(Status):
fan_power: RoborockFanSpeedP10 | None = None
water_box_mode: RoborockMopIntensityP10 | None = None
mop_mode: RoborockMopModeS8ProUltra | None = None
@dataclass
class S8MaxvUltraStatus(Status):
fan_power: RoborockFanSpeedS8MaxVUltra | None = None
water_box_mode: RoborockMopIntensityS8MaxVUltra | None = None
mop_mode: RoborockMopModeS8MaxVUltra | None = None
@dataclass
class Saros10RStatus(Status):
fan_power: RoborockFanSpeedSaros10R | None = None
water_box_mode: RoborockMopIntensitySaros10R | None = None
mop_mode: RoborockMopModeSaros10R | None = None
@dataclass
class Saros10Status(Status):
fan_power: RoborockFanSpeedSaros10 | None = None
water_box_mode: RoborockMopIntensitySaros10 | None = None
mop_mode: RoborockMopModeSaros10 | None = None
ModelStatus: dict[str, type[Status]] = {
ROBOROCK_S4_MAX: S4MaxStatus,
ROBOROCK_S5_MAX: S5MaxStatus,
ROBOROCK_Q7_MAX: Q7MaxStatus,
ROBOROCK_QREVO_MASTER: QRevoMasterStatus,
ROBOROCK_QREVO_CURV: QRevoCurvStatus,
ROBOROCK_S6: S6PureStatus,
ROBOROCK_S6_MAXV: S6MaxVStatus,
ROBOROCK_S6_PURE: S6PureStatus,
ROBOROCK_S7_MAXV: S7MaxVStatus,
ROBOROCK_S7: S7Status,
ROBOROCK_S8: S8Status,
ROBOROCK_S8_PRO_ULTRA: S8ProUltraStatus,
ROBOROCK_G10S_PRO: S7MaxVStatus,
ROBOROCK_G20S_Ultra: QRevoMasterStatus,
ROBOROCK_P10: P10Status,
# These likely are not correct,
# but i am currently unable to do my typical reverse engineering/ get any data from users on this,
# so this will be here in the mean time.
ROBOROCK_QREVO_S: P10Status,
ROBOROCK_QREVO_MAXV: QRevoMaxVStatus,
ROBOROCK_QREVO_PRO: P10Status,
ROBOROCK_S8_MAXV_ULTRA: S8MaxvUltraStatus,
ROBOROCK_SAROS_10R: Saros10RStatus,
ROBOROCK_SAROS_10: Saros10Status,
}
@dataclass
class DnDTimer(RoborockBaseTimer):
"""DnDTimer"""
@dataclass
class ValleyElectricityTimer(RoborockBaseTimer):
"""ValleyElectricityTimer"""
@dataclass
class CleanSummary(RoborockBase):
clean_time: int | None = None
clean_area: int | None = None
clean_count: int | None = None
dust_collection_count: int | None = None
records: list[int] | None = None
last_clean_t: int | None = None
@property
def square_meter_clean_area(self) -> float | None:
"""Returns the clean area in square meters."""
if isinstance(self.clean_area, list | str):
_LOGGER.warning(f"Clean area is a unexpected type! Please give the following in a issue: {self.clean_area}")
return None
return round(self.clean_area / 1000000, 1) if self.clean_area is not None else None
def __repr__(self) -> str:
"""Return a string representation of the object including all attributes."""
return _attr_repr(self)
@dataclass
class CleanRecord(RoborockBase):
begin: int | None = None
end: int | None = None
duration: int | None = None
area: int | None = None
error: int | None = None
complete: int | None = None
start_type: RoborockStartType | None = None
clean_type: RoborockCleanType | None = None
finish_reason: RoborockFinishReason | None = None
dust_collection_status: int | None = None
avoid_count: int | None = None
wash_count: int | None = None
map_flag: int | None = None
@property
def square_meter_area(self) -> float | None:
return round(self.area / 1000000, 1) if self.area is not None else None
@property
def begin_datetime(self) -> datetime.datetime | None:
return datetime.datetime.fromtimestamp(self.begin).astimezone(datetime.UTC) if self.begin else None
@property
def end_datetime(self) -> datetime.datetime | None:
return datetime.datetime.fromtimestamp(self.end).astimezone(datetime.UTC) if self.end else None
def __repr__(self) -> str:
return _attr_repr(self)
@dataclass
class Consumable(RoborockBase):
main_brush_work_time: int | None = None
side_brush_work_time: int | None = None
filter_work_time: int | None = None
filter_element_work_time: int | None = None
sensor_dirty_time: int | None = None
strainer_work_times: int | None = None
dust_collection_work_times: int | None = None
cleaning_brush_work_times: int | None = None
moproller_work_time: int | None = None
@property
def main_brush_time_left(self) -> int | None:
return MAIN_BRUSH_REPLACE_TIME - self.main_brush_work_time if self.main_brush_work_time is not None else None
@property
def side_brush_time_left(self) -> int | None:
return SIDE_BRUSH_REPLACE_TIME - self.side_brush_work_time if self.side_brush_work_time is not None else None
@property
def filter_time_left(self) -> int | None:
return FILTER_REPLACE_TIME - self.filter_work_time if self.filter_work_time is not None else None
@property
def sensor_time_left(self) -> int | None:
return SENSOR_DIRTY_REPLACE_TIME - self.sensor_dirty_time if self.sensor_dirty_time is not None else None
@property
def strainer_time_left(self) -> int | None:
return STRAINER_REPLACE_TIME - self.strainer_work_times if self.strainer_work_times is not None else None
@property
def dust_collection_time_left(self) -> int | None:
return (
DUST_COLLECTION_REPLACE_TIME - self.dust_collection_work_times
if self.dust_collection_work_times is not None
else None
)
@property
def cleaning_brush_time_left(self) -> int | None:
return (
CLEANING_BRUSH_REPLACE_TIME - self.cleaning_brush_work_times
if self.cleaning_brush_work_times is not None
else None
)
@property
def mop_roller_time_left(self) -> int | None:
return MOP_ROLLER_REPLACE_TIME - self.moproller_work_time if self.moproller_work_time is not None else None
def __repr__(self) -> str:
return _attr_repr(self)
@dataclass
class MultiMapsListMapInfoBakMaps(RoborockBase):
mapflag: Any | None = None
add_time: Any | None = None
@dataclass
class MultiMapsListMapInfo(RoborockBase):
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):
max_multi_map: int | None = None
max_bak_map: int | None = None
multi_map_count: int | None = None
map_info: list[MultiMapsListMapInfo] | None = None
@dataclass
class SmartWashParams(RoborockBase):
smart_wash: int | None = None
wash_interval: int | None = None
@dataclass
class DustCollectionMode(RoborockBase):
mode: RoborockDockDustCollectionModeCode | None = None
@dataclass
class WashTowelMode(RoborockBase):
wash_mode: RoborockDockWashTowelModeCode | None = None
@dataclass
class NetworkInfo(RoborockBase):
ip: str
ssid: str | None = None
mac: str | None = None
bssid: str | None = None
rssi: int | None = None
@dataclass
class AppInitStatusLocalInfo(RoborockBase):
location: str
bom: str | None = None
featureset: int | None = None
language: str | None = None
logserver: str | None = None
wifiplan: str | None = None
timezone: str | None = None
name: str | None = None
@dataclass
class AppInitStatus(RoborockBase):
local_info: AppInitStatusLocalInfo
feature_info: list[int]
new_feature_info: int
new_feature_info_str: str
new_feature_info_2: int | None = None
carriage_type: int | None = None
dsp_version: int | None = None
@dataclass
class DeviceData(RoborockBase):
device: HomeDataDevice
model: str
host: str | None = None
device_features: DeviceFeatures | None = None
@property
def product_nickname(self) -> RoborockProductNickname:
return SHORT_MODEL_TO_ENUM.get(self.model.split(".")[-1], RoborockProductNickname.PEARLPLUS)
def __repr__(self) -> str:
return _attr_repr(self)
@dataclass
class RoomMapping(RoborockBase):
segment_id: int
iot_id: str
@dataclass
class ChildLockStatus(RoborockBase):
lock_status: int
@dataclass
class FlowLedStatus(RoborockBase):
status: int
@dataclass
class BroadcastMessage(RoborockBase):
duid: str
ip: str
version: bytes
class ServerTimer(NamedTuple):
id: str
status: str
dontknow: int
@dataclass
class RoborockProductStateValue(RoborockBase):
value: list
desc: dict
@dataclass
class RoborockProductState(RoborockBase):
dps: int
desc: dict
value: list[RoborockProductStateValue]
@dataclass
class RoborockProductSpec(RoborockBase):
state: RoborockProductState
battery: dict | None = None
dry_countdown: dict | None = None
extra: dict | None = None
offpeak: dict | None = None
countdown: dict | None = None
mode: dict | None = None
ota_nfo: dict | None = None
pause: dict | None = None
program: dict | None = None
shutdown: dict | None = None
washing_left: dict | None = None
@dataclass
class RoborockProduct(RoborockBase):
id: int | None = None
name: str | None = None
model: str | None = None
packagename: str | None = None
ssid: str | None = None
picurl: str | None = None
cardpicurl: str | None = None
mediumCardpicurl: str | None = None
resetwifipicurl: str | None = None
configPicUrl: str | None = None
pluginPicUrl: str | None = None
resetwifitext: dict | None = None
tuyaid: str | None = None
status: int | None = None
rriotid: str | None = None
pictures: list | None = None
ncMode: str | None = None
scope: str | None = None
product_tags: list | None = None
agreements: list | None = None
cardspec: str | None = None
plugin_pic_url: str | None = None
@property
def product_nickname(self) -> RoborockProductNickname | None:
if self.cardspec:
return RoborockProductSpec.from_dict(json.loads(self.cardspec).get("data"))
return None
def __repr__(self) -> str:
return _attr_repr(self)
@dataclass
class RoborockProductCategory(RoborockBase):
id: int
display_name: str
icon_url: str
@dataclass
class RoborockCategoryDetail(RoborockBase):
category: RoborockProductCategory
product_list: list[RoborockProduct]
@dataclass
class ProductResponse(RoborockBase):
category_detail_list: list[RoborockCategoryDetail]
@dataclass
class DyadProductInfo(RoborockBase):
sn: str
ssid: str
timezone: str
posix_timezone: str
ip: str
mac: str
oba: dict
@dataclass
class DyadSndState(RoborockBase):
sid_in_use: int