Skip to content

Commit e432a86

Browse files
committed
feat: Expose device and product information on the new Device API
1 parent a6f889d commit e432a86

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

roborock/devices/device.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from abc import ABC
99
from collections.abc import Callable
1010

11-
from roborock.containers import HomeDataDevice
11+
from roborock.containers import HomeDataDevice, HomeDataProduct
1212
from roborock.roborock_message import RoborockMessage
1313

1414
from .channel import Channel
@@ -37,6 +37,7 @@ class RoborockDevice(ABC, TraitsMixin):
3737
def __init__(
3838
self,
3939
device_info: HomeDataDevice,
40+
product: HomeDataProduct,
4041
channel: Channel,
4142
trait: Trait,
4243
) -> None:
@@ -49,6 +50,8 @@ def __init__(
4950
TraitsMixin.__init__(self, trait)
5051
self._duid = device_info.duid
5152
self._name = device_info.name
53+
self._device_info = device_info
54+
self._product = product
5255
self._channel = channel
5356
self._unsub: Callable[[], None] | None = None
5457

@@ -62,6 +65,23 @@ def name(self) -> str:
6265
"""Return the device name."""
6366
return self._name
6467

68+
@property
69+
def device_info(self) -> HomeDataDevice:
70+
"""Return the device information.
71+
72+
This includes information specific to the device like its identifier or
73+
firmware version.
74+
"""
75+
return self._device_info
76+
77+
@property
78+
def product(self) -> HomeDataProduct:
79+
"""Return the device product name.
80+
81+
This returns product level information such as the model name.
82+
"""
83+
return self._product
84+
6585
@property
6686
def is_connected(self) -> bool:
6787
"""Return whether the device is connected."""

roborock/devices/device_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def device_creator(home_data: HomeData, device: HomeDataDevice, product: HomeDat
168168
trait = b01.create(channel)
169169
case _:
170170
raise NotImplementedError(f"Device {device.name} has unsupported version {device.pv}")
171-
return RoborockDevice(device, channel, trait)
171+
return RoborockDevice(device, product, channel, trait)
172172

173173
manager = DeviceManager(home_data_api, device_creator, mqtt_session=mqtt_session, cache=cache)
174174
await manager.discover_devices()

tests/devices/test_v1_device.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def device_fixture(channel: AsyncMock, rpc_channel: AsyncMock, mqtt_rpc_channel:
5353
"""Fixture to set up the device for tests."""
5454
return RoborockDevice(
5555
device_info=HOME_DATA.devices[0],
56+
product=HOME_DATA.products[0],
5657
channel=channel,
5758
trait=v1.create(HOME_DATA.products[0], HOME_DATA, rpc_channel, mqtt_rpc_channel, AsyncMock(), NoCache()),
5859
)

tests/devices/traits/v1/fixtures.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def device_fixture(
4747
"""Fixture to set up the device for tests."""
4848
return RoborockDevice(
4949
device_info=HOME_DATA.devices[0],
50+
product=HOME_DATA.products[0],
5051
channel=channel,
5152
trait=v1.create(
5253
HOME_DATA.products[0],

0 commit comments

Comments
 (0)