Skip to content

Commit 87d9c21

Browse files
committed
Fix Q10 diagnostics display in Home Assistant
1 parent 347a8f6 commit 87d9c21

6 files changed

Lines changed: 579 additions & 3 deletions

File tree

roborock/data/containers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,14 @@ def convert_dict(types_map: dict[Any, type], data: dict[Any, Any]) -> dict[Any,
162162

163163
return result
164164

165-
def as_dict(self) -> dict:
165+
def as_dict(self, exclude: set[str] | None = None) -> dict:
166+
exclude_set = exclude or set()
166167
return asdict(
167168
self,
168169
dict_factory=lambda _fields: {
169170
_camelize(key): value.value if isinstance(value, Enum) else value
170171
for (key, value) in _fields
171-
if value is not None
172+
if value is not None and key not in exclude_set
172173
},
173174
)
174175

roborock/devices/device.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ def diagnostic_data(self) -> dict[str, Any]:
243243
extra: dict[str, Any] = {}
244244
if self.v1_properties:
245245
extra["traits"] = self.v1_properties.as_dict()
246+
elif self.b01_q10_properties:
247+
extra["traits"] = self.b01_q10_properties.as_dict()
246248
return redact_device_data(
247249
{
248250
"device": self.device_info.as_dict(),

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import asyncio
44
import logging
5+
from typing import Any
56

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

165+
def as_dict(self) -> dict[str, Any]:
166+
"""Return the trait data as a dictionary."""
167+
result: dict[str, Any] = {}
168+
for name, value in self.__dict__.items():
169+
if isinstance(value, RoborockBase):
170+
result[name] = value.as_dict()
171+
if hasattr(self, "map") and hasattr(self.map, "as_dict"):
172+
result["map"] = self.map.as_dict()
173+
return result
174+
163175

164176
def create(channel: B01Q10Channel) -> Q10PropertiesApi:
165177
"""Create traits for B01 devices."""

roborock/devices/traits/b01/q10/map.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from dataclasses import dataclass, field
1818
from typing import Any
1919

20+
2021
from roborock.data import RoborockBase
2122
from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP
2223
from roborock.devices.traits.common import DpsDataConverter, TraitUpdateListener
@@ -149,3 +150,18 @@ def _render(self) -> None:
149150
except RoborockException as ex:
150151
_LOGGER.debug("Failed to render Q10 map packet: %s", ex)
151152
self._image_content = None
153+
154+
def as_dict(self, exclude: set[str] | None = None) -> dict[str, Any]:
155+
"""Return the trait data as a dictionary, excluding large binary data."""
156+
import dataclasses
157+
158+
exclude_set = exclude or set()
159+
data = {
160+
"rooms": [dataclasses.asdict(room) for room in self.rooms],
161+
"path": [dataclasses.asdict(point) for point in self.path],
162+
"robotPosition": dataclasses.asdict(self.robot_position) if self.robot_position is not None else None,
163+
"robotHeading": self.robot_heading,
164+
}
165+
for key in exclude_set:
166+
data.pop(key, None)
167+
return data

0 commit comments

Comments
 (0)