Skip to content

Commit 0c763e6

Browse files
committed
chore: refactor to seperate b01 ss and sc logic
1 parent b48121f commit 0c763e6

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

roborock/devices/device_manager.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,12 @@ def device_creator(home_data: HomeData, device: HomeDataDevice, product: HomeDat
196196
trait = a01.create(product, channel)
197197
case DeviceVersion.B01:
198198
channel = create_mqtt_channel(user_data, mqtt_params, mqtt_session, device)
199-
trait = b01.create(channel)
199+
if "ss" in product.model.strip(".")[-1]:
200+
raise NotImplementedError(
201+
f"Device {device.name} has unsupported version B01_{product.model.strip('.')[-1]}"
202+
)
203+
elif "sc" in product.model.strip(".")[-1]:
204+
trait = b01.sc.create(channel)
200205
case _:
201206
raise NotImplementedError(f"Device {device.name} has unsupported version {device.pv}")
202207
return RoborockDevice(device, product, channel, trait)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Traits for SC B01 devices.
2+
Right now, the only known Q7 devices are sc devices."""
3+
4+
from roborock import RoborockB01Methods
5+
from roborock.devices.b01_channel import send_decoded_command
6+
from roborock.devices.mqtt_channel import MqttChannel
7+
from roborock.devices.traits import Trait
8+
from roborock.roborock_message import RoborockB01Props
9+
10+
__all__ = [
11+
"PropertiesApi",
12+
]
13+
14+
15+
class PropertiesApi(Trait):
16+
"""API for interacting with B01 devices."""
17+
18+
def __init__(self, channel: MqttChannel) -> None:
19+
"""Initialize the B01Props API."""
20+
self._channel = channel
21+
22+
async def query_values(self, props: list[RoborockB01Props]) -> None:
23+
"""Query the device for the values of the given Dyad protocols."""
24+
await send_decoded_command(
25+
self._channel, dps=10000, command=RoborockB01Methods.GET_PROP, params={"property": props}
26+
)
27+
28+
29+
def create(channel: MqttChannel) -> PropertiesApi:
30+
"""Create traits for B01 devices."""
31+
return PropertiesApi(channel)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Q10"""

0 commit comments

Comments
 (0)