Skip to content

Commit 900ed38

Browse files
committed
chore: add self.send
1 parent d026b67 commit 900ed38

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

roborock/devices/traits/b01/q7/__init__.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,27 @@ def __init__(self, channel: MqttChannel) -> None:
2828
"""Initialize the B01Props API."""
2929
self._channel = channel
3030

31-
async def query_values(self, props: list[RoborockB01Props]) -> B01Props | None:
32-
"""Query the device for the values of the given Q7 properties."""
33-
result = await send_decoded_command(
31+
async def send(self, command: RoborockB01Q7Methods, params: dict) -> Any:
32+
return await send_decoded_command(
3433
self._channel,
3534
dps=10000,
36-
command=RoborockB01Q7Methods.GET_PROP,
37-
params={"property": props},
35+
command=command,
36+
params=params,
37+
)
38+
39+
async def query_values(self, props: list[RoborockB01Props]) -> B01Props | None:
40+
"""Query the device for the values of the given Q7 properties."""
41+
result = await self.send(
42+
RoborockB01Q7Methods.GET_PROP,
43+
{"property": props},
3844
)
3945
if not isinstance(result, dict):
4046
raise TypeError(f"Unexpected response type for GET_PROP: {type(result).__name__}: {result!r}")
4147
return B01Props.from_dict(result)
4248

4349
async def set_prop(self, prop: RoborockB01Props, value: Any) -> Any:
4450
"""Set a property on the device."""
45-
return await send_decoded_command(
46-
self._channel,
47-
dps=10000,
51+
await self.send(
4852
command=RoborockB01Q7Methods.SET_PROP,
4953
params={prop: value},
5054
)
@@ -59,9 +63,7 @@ async def set_water_level(self, water_level: WaterLevelMapping) -> Any:
5963

6064
async def start_clean(self) -> Any:
6165
"""Start cleaning."""
62-
return await send_decoded_command(
63-
self._channel,
64-
dps=10000,
66+
return await self.send(
6567
command=RoborockB01Q7Methods.SET_ROOM_CLEAN,
6668
params={
6769
"clean_type": CleanTaskTypeMapping.ALL.code,
@@ -72,9 +74,7 @@ async def start_clean(self) -> Any:
7274

7375
async def pause_clean(self) -> Any:
7476
"""Pause cleaning."""
75-
return await send_decoded_command(
76-
self._channel,
77-
dps=10000,
77+
return await self.send(
7878
command=RoborockB01Q7Methods.SET_ROOM_CLEAN,
7979
params={
8080
"clean_type": CleanTaskTypeMapping.ALL.code,
@@ -85,9 +85,7 @@ async def pause_clean(self) -> Any:
8585

8686
async def stop_clean(self) -> Any:
8787
"""Stop cleaning."""
88-
return await send_decoded_command(
89-
self._channel,
90-
dps=10000,
88+
return await self.send(
9189
command=RoborockB01Q7Methods.SET_ROOM_CLEAN,
9290
params={
9391
"clean_type": CleanTaskTypeMapping.ALL.code,
@@ -98,18 +96,14 @@ async def stop_clean(self) -> Any:
9896

9997
async def return_to_dock(self) -> Any:
10098
"""Return to dock."""
101-
return await send_decoded_command(
102-
self._channel,
103-
dps=10000,
99+
return await self.send(
104100
command=RoborockB01Q7Methods.START_RECHARGE,
105101
params={},
106102
)
107103

108104
async def find_me(self) -> Any:
109105
"""Locate the robot."""
110-
return await send_decoded_command(
111-
self._channel,
112-
dps=10000,
106+
return await self.send(
113107
command=RoborockB01Q7Methods.FIND_DEVICE,
114108
params={},
115109
)

0 commit comments

Comments
 (0)