Skip to content

Commit e88854d

Browse files
fix: improving cache and refactoring
1 parent c8bcc58 commit e88854d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

roborock/api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ async def update_value(self, params):
126126
await self._async_value()
127127
return response
128128

129+
async def close_value(self, params):
130+
if self.attribute.close_command is None:
131+
raise RoborockException(f"{self.attribute.attribute} is not closeable")
132+
response = await self.api._send_command(self.attribute.close_command, params)
133+
await self._async_value()
134+
return response
135+
129136

130137
class RoborockClient:
131138
def __init__(self, endpoint: str, device_info: DeviceData) -> None:

roborock/command_cache.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from dataclasses import dataclass
44
from enum import Enum
5-
from typing import Mapping
5+
from typing import Mapping, Optional
66

77
from roborock import RoborockCommand
88

@@ -37,6 +37,7 @@ class RoborockAttribute:
3737
attribute: str
3838
get_command: RoborockCommand
3939
set_command: RoborockCommand
40+
close_command: Optional[RoborockCommand] = None
4041

4142

4243
def create_cache_map():
@@ -82,7 +83,10 @@ def create_cache_map():
8283
set_command=RoborockCommand.SET_CUSTOM_MODE,
8384
),
8485
CacheableAttribute.dnd_timer: RoborockAttribute(
85-
attribute="dnd_timer", get_command=RoborockCommand.GET_DND_TIMER, set_command=RoborockCommand.SET_DND_TIMER
86+
attribute="dnd_timer",
87+
get_command=RoborockCommand.GET_DND_TIMER,
88+
set_command=RoborockCommand.SET_DND_TIMER,
89+
close_command=RoborockCommand.CLOSE_DND_TIMER,
8690
),
8791
CacheableAttribute.dust_collection_mode: RoborockAttribute(
8892
attribute="dust_collection_mode",
@@ -126,6 +130,7 @@ def create_cache_map():
126130
attribute="valley_electricity_timer",
127131
get_command=RoborockCommand.GET_VALLEY_ELECTRICITY_TIMER,
128132
set_command=RoborockCommand.SET_VALLEY_ELECTRICITY_TIMER,
133+
close_command=RoborockCommand.CLOSE_VALLEY_ELECTRICITY_TIMER,
129134
),
130135
CacheableAttribute.wash_towel_mode: RoborockAttribute(
131136
attribute="wash_towel_mode",

0 commit comments

Comments
 (0)