Skip to content

Commit

Permalink
feat: add diagnostic data and extra containers (#67)
Browse files Browse the repository at this point in the history
* feat: add diagnostic data and extra containers

* fix: lint

* fix: dock summary as roborockbase

* fix: make deviceprop RoborockBase

* merge in changes

* fix: lint
  • Loading branch information
Lash-L authored Jun 5, 2023
1 parent 22ff7f4 commit 59ef6f4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
11 changes: 11 additions & 0 deletions roborock/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
DeviceData,
DnDTimer,
DustCollectionMode,
FlowLedStatus,
HomeData,
ModelStatus,
MultiMapsList,
Expand Down Expand Up @@ -101,10 +102,15 @@ def __init__(self, endpoint: str, device_info: DeviceData) -> None:
self._last_device_msg_in = self.time_func()
self._last_disconnection = self.time_func()
self.keep_alive = KEEPALIVE
self._diagnostic_data: dict[str, dict[str, Any]] = {}

def __del__(self) -> None:
self.sync_disconnect()

@property
def diagnostic_data(self) -> dict:
return self._diagnostic_data

@property
def time_func(self) -> Callable[[], float]:
try:
Expand Down Expand Up @@ -364,6 +370,11 @@ async def get_child_lock_status(self) -> ChildLockStatus | None:
"""Gets current child lock status."""
return await self.send_command(RoborockCommand.GET_CHILD_LOCK_STATUS, return_type=ChildLockStatus)

@fallback_cache
async def get_flow_led_status(self) -> FlowLedStatus | None:
"""Gets current flow led status."""
return await self.send_command(RoborockCommand.GET_FLOW_LED_STATUS, return_type=FlowLedStatus)

@fallback_cache
async def get_sound_volume(self) -> int | None:
"""Gets current volume level."""
Expand Down
1 change: 1 addition & 0 deletions roborock/cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ async def send_command(
msg = MessageParser.build(roborock_message, local_key, False)
self._send_msg_raw(msg)
(response, err) = await self._async_response(request_id, response_protocol)
self._diagnostic_data[method.name] = {"params": params, "response": response, "error": err}
if err:
raise CommandVacuumError(method, err) from err
if response_protocol == 301:
Expand Down
5 changes: 5 additions & 0 deletions roborock/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ class ChildLockStatus(RoborockBase):
lock_status: int


@dataclass
class FlowLedStatus(RoborockBase):
status: int


@dataclass
class BroadcastMessage(RoborockBase):
duid: str
Expand Down
5 changes: 5 additions & 0 deletions roborock/local_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ async def async_local_response(self, roborock_message: RoborockMessage):
if request_id is None:
raise RoborockException(f"Failed build message {roborock_message}")
(response, err) = await self._async_response(request_id, response_protocol)
self._diagnostic_data[method if method is not None else "unknown"] = {
"params": roborock_message.get_params(),
"response": response,
"error": err,
}
if err:
raise CommandVacuumError("", err) from err
if roborock_message.protocol == 4:
Expand Down
5 changes: 3 additions & 2 deletions roborock/roborock_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Consumable,
DnDTimer,
DustCollectionMode,
RoborockBase,
SmartWashParams,
Status,
WashTowelMode,
Expand Down Expand Up @@ -301,14 +302,14 @@ class CommandInfo:


@dataclass
class DockSummary:
class DockSummary(RoborockBase):
dust_collection_mode: Optional[DustCollectionMode] = None
wash_towel_mode: Optional[WashTowelMode] = None
smart_wash_params: Optional[SmartWashParams] = None


@dataclass
class DeviceProp:
class DeviceProp(RoborockBase):
status: Optional[Status] = None
dnd_timer: Optional[DnDTimer] = None
clean_summary: Optional[CleanSummary] = None
Expand Down

0 comments on commit 59ef6f4

Please sign in to comment.