Skip to content

Commit 7ade218

Browse files
authored
feat: moving clean area to api (#63)
1 parent 4860ebf commit 7ade218

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

roborock/containers.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class Status(RoborockBase):
221221
battery: Optional[int] = None
222222
clean_time: Optional[int] = None
223223
clean_area: Optional[int] = None
224+
square_meter_clean_area: Optional[float] = None
224225
error_code: Optional[RoborockErrorCode] = None
225226
map_present: Optional[int] = None
226227
in_cleaning: Optional[int] = None
@@ -258,6 +259,9 @@ class Status(RoborockBase):
258259
unsave_map_reason: Optional[int] = None
259260
unsave_map_flag: Optional[int] = None
260261

262+
def __post_init__(self) -> None:
263+
self.square_meter_clean_area = round(self.clean_area / 1000000, 1) if self.clean_area is not None else None
264+
261265

262266
@dataclass
263267
class S4MaxStatus(Status):
@@ -345,17 +349,22 @@ class DnDTimer(RoborockBase):
345349
class CleanSummary(RoborockBase):
346350
clean_time: Optional[int] = None
347351
clean_area: Optional[int] = None
352+
square_meter_clean_area: Optional[float] = None
348353
clean_count: Optional[int] = None
349354
dust_collection_count: Optional[int] = None
350355
records: Optional[list[int]] = None
351356

357+
def __post_init__(self) -> None:
358+
self.square_meter_clean_area = round(self.clean_area / 1000000, 1) if self.clean_area is not None else None
359+
352360

353361
@dataclass
354362
class CleanRecord(RoborockBase):
355363
begin: Optional[int] = None
356364
end: Optional[int] = None
357365
duration: Optional[int] = None
358366
area: Optional[int] = None
367+
square_meter_area: Optional[float] = None
359368
error: Optional[int] = None
360369
complete: Optional[int] = None
361370
start_type: Optional[int] = None
@@ -366,6 +375,9 @@ class CleanRecord(RoborockBase):
366375
wash_count: Optional[int] = None
367376
map_flag: Optional[int] = None
368377

378+
def __post_init__(self) -> None:
379+
self.square_meter_area = round(self.area / 1000000, 1) if self.area is not None else None
380+
369381

370382
@dataclass
371383
class Consumable(RoborockBase):
@@ -382,7 +394,7 @@ class Consumable(RoborockBase):
382394
filter_time_left: Optional[int] = None
383395
sensor_time_left: Optional[int] = None
384396

385-
def __post_init__(self):
397+
def __post_init__(self) -> None:
386398
self.main_brush_time_left = (
387399
MAIN_BRUSH_REPLACE_TIME - self.main_brush_work_time if self.main_brush_work_time is not None else None
388400
)

tests/test_containers.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from roborock.code_mappings import (
33
RoborockDockErrorCode,
44
RoborockDockTypeCode,
5-
RoborockEnum,
65
RoborockErrorCode,
76
RoborockFanSpeedS7MaxV,
87
RoborockMopIntensityS7,
@@ -94,11 +93,6 @@ def test_serialize_and_unserialize():
9493
ud = UserData.from_dict(USER_DATA)
9594
ud_dict = ud.as_dict()
9695
assert ud_dict == USER_DATA
97-
s7_maxv_status = S7MaxVStatus.from_dict(STATUS)
98-
s7_maxv_status_dict = s7_maxv_status.as_dict()
99-
assert not isinstance(s7_maxv_status_dict.get("fanPower"), RoborockEnum)
100-
s7_maxv_status = S7MaxVStatus.from_dict(s7_maxv_status_dict)
101-
assert s7_maxv_status.__dict__ == STATUS
10296

10397

10498
def test_consumable():
@@ -121,6 +115,7 @@ def test_status():
121115
assert s.battery == 100
122116
assert s.clean_time == 1176
123117
assert s.clean_area == 20965000
118+
assert s.square_meter_clean_area == 21.0
124119
assert s.error_code == RoborockErrorCode.none
125120
assert s.map_present == 1
126121
assert s.in_cleaning == 0
@@ -175,6 +170,7 @@ def test_clean_summary():
175170
cs = CleanSummary.from_dict(CLEAN_SUMMARY)
176171
assert cs.clean_time == 74382
177172
assert cs.clean_area == 1159182500
173+
assert cs.square_meter_clean_area == 1159.2
178174
assert cs.clean_count == 31
179175
assert cs.dust_collection_count == 25
180176
assert len(cs.records) == 2
@@ -187,6 +183,7 @@ def test_clean_record():
187183
assert cr.end == 1672544638
188184
assert cr.duration == 1176
189185
assert cr.area == 20965000
186+
assert cr.square_meter_area == 21.0
190187
assert cr.error == 0
191188
assert cr.complete == 1
192189
assert cr.start_type == 2

0 commit comments

Comments
 (0)