|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import datetime |
3 | 4 | import logging |
4 | 5 | import re |
5 | 6 | from dataclasses import asdict, dataclass |
6 | | -from datetime import time |
7 | 7 | from enum import Enum |
8 | 8 | from typing import Any, Optional, Type |
9 | 9 |
|
|
45 | 45 | SENSOR_DIRTY_REPLACE_TIME, |
46 | 46 | SIDE_BRUSH_REPLACE_TIME, |
47 | 47 | ) |
| 48 | +from .util import parse_time_to_datetime |
48 | 49 |
|
49 | 50 | _LOGGER = logging.getLogger(__name__) |
50 | 51 |
|
@@ -95,6 +96,29 @@ def as_dict(self) -> dict: |
95 | 96 | ) |
96 | 97 |
|
97 | 98 |
|
| 99 | +@dataclass |
| 100 | +class RoborockBaseTimer(RoborockBase): |
| 101 | + start_hour: Optional[int] = None |
| 102 | + start_minute: Optional[int] = None |
| 103 | + end_hour: Optional[int] = None |
| 104 | + end_minute: Optional[int] = None |
| 105 | + enabled: Optional[int] = None |
| 106 | + start_time: Optional[datetime.datetime] = None |
| 107 | + end_time: Optional[datetime.datetime] = None |
| 108 | + |
| 109 | + def __post_init__(self) -> None: |
| 110 | + self.start_time = ( |
| 111 | + parse_time_to_datetime(datetime.time(hour=self.start_hour, minute=self.start_minute)) |
| 112 | + if self.start_hour is not None and self.start_minute is not None |
| 113 | + else None |
| 114 | + ) |
| 115 | + self.end_time = ( |
| 116 | + parse_time_to_datetime(datetime.time(hour=self.end_hour, minute=self.end_minute)) |
| 117 | + if self.end_hour is not None and self.end_minute is not None |
| 118 | + else None |
| 119 | + ) |
| 120 | + |
| 121 | + |
98 | 122 | @dataclass |
99 | 123 | class Reference(RoborockBase): |
100 | 124 | r: Optional[str] = None |
@@ -338,49 +362,13 @@ class S8Status(Status): |
338 | 362 |
|
339 | 363 |
|
340 | 364 | @dataclass |
341 | | -class DnDTimer(RoborockBase): |
342 | | - start_hour: Optional[int] = None |
343 | | - start_minute: Optional[int] = None |
344 | | - end_hour: Optional[int] = None |
345 | | - end_minute: Optional[int] = None |
346 | | - enabled: Optional[int] = None |
347 | | - start_time: Optional[time] = None |
348 | | - end_time: Optional[time] = None |
349 | | - |
350 | | - def __post_init__(self) -> None: |
351 | | - self.start_time = ( |
352 | | - time(hour=self.start_hour, minute=self.start_minute) |
353 | | - if self.start_hour is not None and self.start_minute is not None |
354 | | - else None |
355 | | - ) |
356 | | - self.end_time = ( |
357 | | - time(hour=self.end_hour, minute=self.end_minute) |
358 | | - if self.end_hour is not None and self.end_minute is not None |
359 | | - else None |
360 | | - ) |
| 365 | +class DnDTimer(RoborockBaseTimer): |
| 366 | + """DnDTimer""" |
361 | 367 |
|
362 | 368 |
|
363 | 369 | @dataclass |
364 | | -class ValleyElectricityTimer(RoborockBase): |
365 | | - start_hour: Optional[int] = None |
366 | | - start_minute: Optional[int] = None |
367 | | - end_hour: Optional[int] = None |
368 | | - end_minute: Optional[int] = None |
369 | | - enabled: Optional[int] = None |
370 | | - start_time: Optional[time] = None |
371 | | - end_time: Optional[time] = None |
372 | | - |
373 | | - def __post_init__(self) -> None: |
374 | | - self.start_time = ( |
375 | | - time(hour=self.start_hour, minute=self.start_minute) |
376 | | - if self.start_hour is not None and self.start_minute is not None |
377 | | - else None |
378 | | - ) |
379 | | - self.end_time = ( |
380 | | - time(hour=self.end_hour, minute=self.end_minute) |
381 | | - if self.end_hour is not None and self.end_minute is not None |
382 | | - else None |
383 | | - ) |
| 370 | +class ValleyElectricityTimer(RoborockBaseTimer): |
| 371 | + """ValleyElectricityTimer""" |
384 | 372 |
|
385 | 373 |
|
386 | 374 | @dataclass |
|
0 commit comments