Repository navigation
Expand file tree
/
Copy pathdo_not_disturb.py
More file actions
68 lines (56 loc) · 2.61 KB
/
Copy pathdo_not_disturb.py
File metadata and controls
68 lines (56 loc) · 2.61 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
import datetime
from roborock.data import DnDTimer
from roborock.devices.traits.v1 import common
from roborock.roborock_typing import RoborockCommand
_ENABLED_PARAM = "enabled"
class DoNotDisturbTrait(DnDTimer, common.V1TraitMixin, common.RoborockSwitchBase):
"""Trait for managing Do Not Disturb (DND) settings on Roborock devices."""
command = RoborockCommand.GET_DND_TIMER
converter = common.DefaultConverter(DnDTimer)
@property
def is_on(self) -> bool:
"""Return whether the Do Not Disturb (DND) timer is enabled."""
return self.enabled == 1
async def set_dnd_timer(self, dnd_timer: DnDTimer) -> None:
"""Set the Do Not Disturb (DND) timer settings of the device."""
await self.rpc_channel.send_command(RoborockCommand.SET_DND_TIMER, params=dnd_timer.as_list())
await self.refresh()
async def set_start_time(self, start_time: datetime.time) -> None:
"""Set the start time of the Do Not Disturb (DND) timer."""
timer = DnDTimer(
start_hour=start_time.hour,
start_minute=start_time.minute,
end_hour=self.end_hour,
end_minute=self.end_minute,
enabled=self.enabled,
)
await self.rpc_channel.send_command(RoborockCommand.SET_DND_TIMER, params=timer.as_list())
await self.refresh()
async def set_end_time(self, end_time: datetime.time) -> None:
"""Set the end time of the Do Not Disturb (DND) timer."""
timer = DnDTimer(
start_hour=self.start_hour,
start_minute=self.start_minute,
end_hour=end_time.hour,
end_minute=end_time.minute,
enabled=self.enabled,
)
await self.rpc_channel.send_command(RoborockCommand.SET_DND_TIMER, params=timer.as_list())
await self.refresh()
async def clear_dnd_timer(self) -> None:
"""Clear the Do Not Disturb (DND) timer settings of the device."""
await self.rpc_channel.send_command(RoborockCommand.CLOSE_DND_TIMER)
await self.refresh()
async def enable(self) -> None:
"""Set the Do Not Disturb (DND) timer settings of the device."""
await self.rpc_channel.send_command(
RoborockCommand.SET_DND_TIMER,
params=self.as_list(),
)
# Optimistic update to avoid an extra refresh
self.enabled = 1
async def disable(self) -> None:
"""Disable the Do Not Disturb (DND) timer settings of the device."""
await self.rpc_channel.send_command(RoborockCommand.CLOSE_DND_TIMER)
# Optimistic update to avoid an extra refresh
self.enabled = 0