3
3
from __future__ import annotations
4
4
5
5
import logging
6
+ from datetime import timedelta
6
7
from enum import IntEnum
7
8
from typing import Annotated
8
9
@@ -54,6 +55,17 @@ class FanSpeed(IntEnum):
54
55
Max = 4
55
56
56
57
58
+ class AreaUnit (IntEnum ):
59
+ """Area unit."""
60
+
61
+ #: Square meter
62
+ Sqm = 0
63
+ #: Square feet
64
+ Sqft = 1
65
+ #: Taiwanese unit: https://en.wikipedia.org/wiki/Taiwanese_units_of_measurement#Area
66
+ Ping = 2
67
+
68
+
57
69
class Clean (SmartModule ):
58
70
"""Implementation of vacuum clean module."""
59
71
@@ -145,6 +157,41 @@ def _initialize_features(self) -> None:
145
157
type = Feature .Type .Choice ,
146
158
)
147
159
)
160
+ self ._add_feature (
161
+ Feature (
162
+ self ._device ,
163
+ id = "clean_area" ,
164
+ name = "Cleaning area" ,
165
+ container = self ,
166
+ attribute_getter = "clean_area" ,
167
+ unit_getter = "area_unit" ,
168
+ category = Feature .Category .Info ,
169
+ type = Feature .Type .Sensor ,
170
+ )
171
+ )
172
+ self ._add_feature (
173
+ Feature (
174
+ self ._device ,
175
+ id = "clean_time" ,
176
+ name = "Cleaning time" ,
177
+ container = self ,
178
+ attribute_getter = "clean_time" ,
179
+ category = Feature .Category .Info ,
180
+ type = Feature .Type .Sensor ,
181
+ )
182
+ )
183
+ self ._add_feature (
184
+ Feature (
185
+ self ._device ,
186
+ id = "clean_progress" ,
187
+ name = "Cleaning progress" ,
188
+ container = self ,
189
+ attribute_getter = "clean_progress" ,
190
+ unit_getter = lambda : "%" ,
191
+ category = Feature .Category .Info ,
192
+ type = Feature .Type .Sensor ,
193
+ )
194
+ )
148
195
149
196
async def _post_update_hook (self ) -> None :
150
197
"""Set error code after update."""
@@ -171,9 +218,11 @@ async def _post_update_hook(self) -> None:
171
218
def query (self ) -> dict :
172
219
"""Query to execute during the update cycle."""
173
220
return {
174
- "getVacStatus" : None ,
175
- "getBatteryInfo" : None ,
176
- "getCleanStatus" : None ,
221
+ "getVacStatus" : {},
222
+ "getCleanInfo" : {},
223
+ "getAreaUnit" : {},
224
+ "getBatteryInfo" : {},
225
+ "getCleanStatus" : {},
177
226
"getCleanAttr" : {"type" : "global" },
178
227
}
179
228
@@ -248,6 +297,11 @@ def _vac_status(self) -> dict:
248
297
"""Return vac status container."""
249
298
return self .data ["getVacStatus" ]
250
299
300
+ @property
301
+ def _info (self ) -> dict :
302
+ """Return current cleaning info."""
303
+ return self .data ["getCleanInfo" ]
304
+
251
305
@property
252
306
def _settings (self ) -> dict :
253
307
"""Return cleaning settings."""
@@ -265,3 +319,23 @@ def status(self) -> Status:
265
319
except ValueError :
266
320
_LOGGER .warning ("Got unknown status code: %s (%s)" , status_code , self .data )
267
321
return Status .UnknownInternal
322
+
323
+ @property
324
+ def area_unit (self ) -> AreaUnit :
325
+ """Return area unit."""
326
+ return AreaUnit (self .data ["getAreaUnit" ]["area_unit" ])
327
+
328
+ @property
329
+ def clean_area (self ) -> Annotated [int , FeatureAttribute ()]:
330
+ """Return currently cleaned area."""
331
+ return self ._info ["clean_area" ]
332
+
333
+ @property
334
+ def clean_time (self ) -> timedelta :
335
+ """Return current cleaning time."""
336
+ return timedelta (minutes = self ._info ["clean_time" ])
337
+
338
+ @property
339
+ def clean_progress (self ) -> int :
340
+ """Return amount of currently cleaned area."""
341
+ return self ._info ["clean_percent" ]
0 commit comments