Skip to content

Commit c965862

Browse files
authored
feat: add time datetime for valley (#65)
1 parent 3653df7 commit c965862

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

roborock/api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
SmartWashParams,
3636
Status,
3737
UserData,
38+
ValleyElectricityTimer,
3839
WashTowelMode,
3940
)
4041
from .exceptions import (
@@ -46,6 +47,7 @@
4647
RoborockNoUserAgreement,
4748
RoborockTimeout,
4849
RoborockUrlException,
50+
UnknownMethodError,
4951
VacuumError,
5052
)
5153
from .protocol import Utils
@@ -189,6 +191,8 @@ async def _async_response(self, request_id: int, protocol_id: int = 0) -> tuple[
189191
queue = RoborockFuture(protocol_id)
190192
self._waiting_queue[request_id] = queue
191193
(response, err) = await queue.async_get(QUEUE_TIMEOUT)
194+
if response == "unknown_method":
195+
raise UnknownMethodError("Unknown method")
192196
return response, err
193197
except (asyncio.TimeoutError, asyncio.CancelledError):
194198
raise RoborockTimeout(f"id={request_id} Timeout after {QUEUE_TIMEOUT} seconds") from None
@@ -244,6 +248,13 @@ async def get_dnd_timer(self) -> DnDTimer | None:
244248
return DnDTimer.from_dict(dnd_timer)
245249
return None
246250

251+
@fallback_cache
252+
async def get_valley_electricity_timer(self) -> ValleyElectricityTimer | None:
253+
valley_electricity_timer = await self.send_command(RoborockCommand.GET_VALLEY_ELECTRICITY_TIMER)
254+
if isinstance(valley_electricity_timer, dict):
255+
return ValleyElectricityTimer.from_dict(valley_electricity_timer)
256+
return None
257+
247258
@fallback_cache
248259
async def get_clean_summary(self) -> CleanSummary | None:
249260
clean_summary = await self.send_command(RoborockCommand.GET_CLEAN_SUMMARY)

roborock/containers.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import re
55
from dataclasses import asdict, dataclass
6+
from datetime import time
67
from enum import Enum
78
from typing import Any, Optional, Type
89

@@ -342,6 +343,39 @@ class DnDTimer(RoborockBase):
342343
end_hour: Optional[int] = None
343344
end_minute: Optional[int] = None
344345
enabled: Optional[int] = None
346+
start_time: Optional[time] = None
347+
end_time: Optional[time] = None
348+
349+
def __post_init__(self) -> None:
350+
self.start_time = (
351+
time(hour=self.start_hour, minute=self.start_minute) if self.start_hour and self.start_minute else None
352+
)
353+
self.end_time = (
354+
time(hour=self.end_hour, minute=self.end_minute)
355+
if self.end_hour is not None and self.end_minute is not None
356+
else None
357+
)
358+
359+
360+
@dataclass
361+
class ValleyElectricityTimer(RoborockBase):
362+
start_hour: Optional[int] = None
363+
start_minute: Optional[int] = None
364+
end_hour: Optional[int] = None
365+
end_minute: Optional[int] = None
366+
enabled: Optional[int] = None
367+
start_time: Optional[time] = None
368+
end_time: Optional[time] = None
369+
370+
def __post_init__(self) -> None:
371+
self.start_time = (
372+
time(hour=self.start_hour, minute=self.start_minute) if self.start_hour and self.start_minute else None
373+
)
374+
self.end_time = (
375+
time(hour=self.end_hour, minute=self.end_minute)
376+
if self.end_hour is not None and self.end_minute is not None
377+
else None
378+
)
345379

346380

347381
@dataclass

roborock/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def __init__(self, command: str, vacuum_error: VacuumError):
2929
super().__init__(self.message)
3030

3131

32+
class UnknownMethodError(RoborockException):
33+
"""Class for an invalid method being sent."""
34+
35+
3236
class RoborockAccountDoesNotExist(RoborockException):
3337
"""Class for Roborock account does not exist exceptions."""
3438

0 commit comments

Comments
 (0)