Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions roborock/data/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,14 @@ def convert_dict(types_map: dict[Any, type], data: dict[Any, Any]) -> dict[Any,

return result

def as_dict(self) -> dict:
def as_dict(self, exclude: set[str] | None = None) -> dict:
exclude_set = exclude or set()
return asdict(
self,
dict_factory=lambda _fields: {
_camelize(key): value.value if isinstance(value, Enum) else value
for (key, value) in _fields
if value is not None
if value is not None and key not in exclude_set
},
)

Expand Down
2 changes: 2 additions & 0 deletions roborock/devices/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ def diagnostic_data(self) -> dict[str, Any]:
extra: dict[str, Any] = {}
if self.v1_properties:
extra["traits"] = self.v1_properties.as_dict()
elif self.b01_q10_properties:
extra["traits"] = self.b01_q10_properties.as_dict()
return redact_device_data(
{
"device": self.device_info.as_dict(),
Expand Down
12 changes: 12 additions & 0 deletions roborock/devices/traits/b01/q10/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import asyncio
import logging
from typing import Any

from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP
from roborock.data.containers import RoborockBase
from roborock.devices.rpc.b01_q10_channel import B01Q10Channel
from roborock.devices.traits import Trait
from roborock.map.b01_q10_map_parser import Q10MapPacket, Q10TracePacket
Expand Down Expand Up @@ -160,6 +162,16 @@ def _handle_message(self, message: Q10Message) -> None:
for trait in self._updatable_traits:
trait.update_from_dps(message.dps)

def as_dict(self) -> dict[str, Any]:
"""Return the trait data as a dictionary."""
result: dict[str, Any] = {}
for name, value in self.__dict__.items():
if isinstance(value, RoborockBase):
result[name] = value.as_dict()
if hasattr(self, "map") and hasattr(self.map, "as_dict"):
result["map"] = self.map.as_dict()
return result


def create(channel: B01Q10Channel) -> Q10PropertiesApi:
"""Create traits for B01 devices."""
Expand Down
15 changes: 15 additions & 0 deletions roborock/devices/traits/b01/q10/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,18 @@ def _render(self) -> None:
except RoborockException as ex:
_LOGGER.debug("Failed to render Q10 map packet: %s", ex)
self._image_content = None

def as_dict(self, exclude: set[str] | None = None) -> dict[str, Any]:
"""Return the trait data as a dictionary, excluding large binary data."""
import dataclasses

exclude_set = exclude or set()
data = {
"rooms": [dataclasses.asdict(room) for room in self.rooms],
"path": [dataclasses.asdict(point) for point in self.path],
"robotPosition": dataclasses.asdict(self.robot_position) if self.robot_position is not None else None,
"robotHeading": self.robot_heading,
}
for key in exclude_set:
data.pop(key, None)
return data
Loading
Loading