Skip to content

Commit ee81538

Browse files
fix: get_clean_summary
1 parent 0d3b000 commit ee81538

File tree

4 files changed

+41
-21
lines changed

4 files changed

+41
-21
lines changed

roborock/api.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from .roborock_future import RoborockFuture
4141
from .roborock_message import RoborockMessage
4242
from .typing import RoborockCommand, RoborockDeviceProp, RoborockDockSummary
43+
from .util import unpack_list
4344

4445
_LOGGER = logging.getLogger(__name__)
4546
QUEUE_TIMEOUT = 4
@@ -190,6 +191,14 @@ async def get_clean_summary(self, device_id: str) -> CleanSummary | None:
190191
clean_summary = await self.send_command(device_id, RoborockCommand.GET_CLEAN_SUMMARY)
191192
if isinstance(clean_summary, dict):
192193
return CleanSummary.from_dict(clean_summary)
194+
elif isinstance(clean_summary, list):
195+
clean_time, clean_area, clean_count, records = unpack_list(clean_summary, 4)
196+
return CleanSummary(
197+
clean_time=clean_time,
198+
clean_area=clean_area,
199+
clean_count=clean_count,
200+
records=records
201+
)
193202
elif isinstance(clean_summary, int):
194203
return CleanSummary(clean_time=clean_summary)
195204
except RoborockTimeout as e:
@@ -244,6 +253,7 @@ async def get_smart_wash_params(self, device_id: str) -> SmartWashParams | None:
244253
async def get_dock_summary(self, device_id: str, dock_type: RoborockEnum) -> RoborockDockSummary | None:
245254
"""Gets the status summary from the dock with the methods available for a given dock.
246255
256+
:param device_id: Device id
247257
:param dock_type: RoborockDockTypeCode"""
248258
try:
249259
commands: list[
@@ -258,9 +268,7 @@ async def get_dock_summary(self, device_id: str, dock_type: RoborockEnum) -> Rob
258268
self.get_wash_towel_mode(device_id),
259269
self.get_smart_wash_params(device_id),
260270
]
261-
[dust_collection_mode, wash_towel_mode, smart_wash_params] = (
262-
list(await asyncio.gather(*commands)) + [None, None]
263-
)[:3]
271+
[dust_collection_mode, wash_towel_mode, smart_wash_params] = unpack_list(list(await asyncio.gather(*commands)), 3)
264272

265273
return RoborockDockSummary(dust_collection_mode, wash_towel_mode, smart_wash_params)
266274
except RoborockTimeout as e:

roborock/roborock_message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def get_method(self) -> RoborockCommand | None:
6060
return data_point_response.get("method")
6161
return None
6262

63-
def get_params(self) -> list | None:
63+
def get_params(self) -> list | dict | None:
6464
protocol = self.protocol
6565
if protocol in [4, 101, 102]:
6666
payload = json.loads(self.payload.decode())

roborock/typing.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
import typing
3+
from typing import Optional
44
from dataclasses import dataclass
55
from enum import Enum
66

@@ -117,6 +117,12 @@ class RoborockCommand(str, Enum):
117117
GET_ROOM_MAPPING = "get_room_mapping"
118118
NAME_SEGMENT = "name_segment"
119119
SET_TIMEZONE = "set_timezone"
120+
GET_HOMESEC_CONNECT_STATUS = "get_homesec_connect_status"
121+
START_CAMERA_PREVIEW = "start_camera_preview"
122+
GET_TURN_SERVER = "get_turn_server"
123+
GET_DEVICE_ICE = "get_device_ice"
124+
START_VOICE_CHAT = "start_voice_chat"
125+
SEND_SDP_TO_ROBOT = "send_sdp_to_robot"
120126

121127

122128
@dataclass
@@ -200,7 +206,11 @@ class CommandInfo:
200206
RoborockCommand.SET_SERVER_TIMER: CommandInfo(prefix=b"\x00\x00\x00\xc7"),
201207
RoborockCommand.GET_ROOM_MAPPING: CommandInfo(prefix=b"\x00\x00\x00w"),
202208
RoborockCommand.NAME_SEGMENT: CommandInfo(prefix=b"\x00\x00\x027"),
203-
RoborockCommand.SET_TIMEZONE: CommandInfo(prefix=b"\x00\x00\x00\x97")
209+
RoborockCommand.SET_TIMEZONE: CommandInfo(prefix=b"\x00\x00\x00\x97"),
210+
RoborockCommand.GET_HOMESEC_CONNECT_STATUS: CommandInfo(prefix=b"\x00\x00\x00\x87"),
211+
RoborockCommand.START_CAMERA_PREVIEW: CommandInfo(prefix=b"\x00\x00\x00\x87"),
212+
RoborockCommand.GET_TURN_SERVER: CommandInfo(prefix=b"\x00\x00\x00\x77"),
213+
RoborockCommand.GET_DEVICE_ICE: CommandInfo(prefix=b"\x00\x00\x00\x77"),
204214
# TODO discover prefix for following commands
205215
# RoborockCommand.APP_GET_DRYER_SETTING: CommandInfo(prefix=b'\x00\x00\x00w'),
206216
# RoborockCommand.APP_SET_DRYER_SETTING: CommandInfo(prefix=b'\x00\x00\x00w'),
@@ -214,26 +224,21 @@ class CommandInfo:
214224
}
215225

216226

227+
@dataclass
217228
class RoborockDockSummary:
218-
def __init__(
219-
self,
220-
dust_collection_mode: DustCollectionMode,
221-
wash_towel_mode: WashTowelMode,
222-
smart_wash_params: SmartWashParams,
223-
) -> None:
224-
self.dust_collection_mode = dust_collection_mode
225-
self.wash_towel_mode = wash_towel_mode
226-
self.smart_wash_params = smart_wash_params
229+
dust_collection_mode: Optional[DustCollectionMode] = None
230+
wash_towel_mode: Optional[WashTowelMode] = None
231+
smart_wash_params: Optional[SmartWashParams] = None
227232

228233

229234
@dataclass
230235
class RoborockDeviceProp:
231-
status: typing.Optional[Status] = None
232-
dnd_timer: typing.Optional[DNDTimer] = None
233-
clean_summary: typing.Optional[CleanSummary] = None
234-
consumable: typing.Optional[Consumable] = None
235-
last_clean_record: typing.Optional[CleanRecord] = None
236-
dock_summary: typing.Optional[RoborockDockSummary] = None
236+
status: Optional[Status] = None
237+
dnd_timer: Optional[DNDTimer] = None
238+
clean_summary: Optional[CleanSummary] = None
239+
consumable: Optional[Consumable] = None
240+
last_clean_record: Optional[CleanRecord] = None
241+
dock_summary: Optional[RoborockDockSummary] = None
237242

238243
def update(self, device_prop: "RoborockDeviceProp"):
239244
if device_prop.status:

roborock/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
from __future__ import annotations
2+
13
import asyncio
24
import functools
35
from asyncio import AbstractEventLoop
6+
from typing import TypeVar
7+
8+
T = TypeVar("T")
49

10+
def unpack_list(value: list[T], size: int) -> list[T | None]:
11+
return (value + [None] * size)[:size]
512

613
def get_running_loop_or_create_one() -> AbstractEventLoop:
714
try:

0 commit comments

Comments
 (0)