Skip to content

Commit 9a1a360

Browse files
Lash-LCopilotallenporter
authored
chore: refactor to separate b01 q7 and q10 logic (#635)
* chore: refactor to seperate b01 ss and sc logic * chore: refactor to seperate b01 ss and sc logic * fix: clean up some naming * fix: update roborock/devices/traits/b01/__init__.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: update roborock/devices/traits/b01/q7/__init__.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: update roborock/devices/device_manager.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: use strip not split * chore: share duplicated code Co-authored-by: Allen Porter <allen.porter@gmail.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Allen Porter <allen.porter@gmail.com>
1 parent 3d95a17 commit 9a1a360

File tree

7 files changed

+50
-34
lines changed

7 files changed

+50
-34
lines changed

roborock/devices/device_manager.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,16 @@ def device_creator(home_data: HomeData, device: HomeDataDevice, product: HomeDat
199199
trait = a01.create(product, channel)
200200
case DeviceVersion.B01:
201201
channel = create_mqtt_channel(user_data, mqtt_params, mqtt_session, device)
202-
trait = b01.create(channel)
202+
model_part = product.model.split(".")[-1]
203+
if "ss" in model_part:
204+
raise NotImplementedError(
205+
f"Device {device.name} has unsupported version B01_{product.model.strip('.')[-1]}"
206+
)
207+
elif "sc" in model_part:
208+
# Q7 devices start with 'sc' in their model naming.
209+
trait = b01.q7.create(channel)
210+
else:
211+
raise NotImplementedError(f"Device {device.name} has unsupported B01 model: {product.model}")
203212
case _:
204213
raise NotImplementedError(f"Device {device.name} has unsupported version {device.pv}")
205214
return RoborockDevice(device, product, channel, trait)
Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,5 @@
11
"""Traits for B01 devices."""
22

3-
from roborock import RoborockB01Methods
4-
from roborock.devices.b01_channel import send_decoded_command
5-
from roborock.devices.mqtt_channel import MqttChannel
6-
from roborock.devices.traits import Trait
7-
from roborock.roborock_message import RoborockB01Props
3+
from .q7 import Q7PropertiesApi
84

9-
__all__ = [
10-
"PropertiesApi",
11-
]
12-
13-
14-
class PropertiesApi(Trait):
15-
"""API for interacting with B01 devices."""
16-
17-
def __init__(self, channel: MqttChannel) -> None:
18-
"""Initialize the B01Props API."""
19-
self._channel = channel
20-
21-
async def query_values(self, props: list[RoborockB01Props]) -> None:
22-
"""Query the device for the values of the given Dyad protocols."""
23-
await send_decoded_command(
24-
self._channel, dps=10000, command=RoborockB01Methods.GET_PROP, params={"property": props}
25-
)
26-
27-
28-
def create(channel: MqttChannel) -> PropertiesApi:
29-
"""Create traits for B01 devices."""
30-
return PropertiesApi(channel)
5+
__all__ = ["Q7PropertiesApi", "q7", "q10"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Q10"""
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Traits for Q7 B01 devices.
2+
Potentially other devices may fall into this category in the future."""
3+
4+
from roborock.devices.b01_channel import send_decoded_command
5+
from roborock.devices.mqtt_channel import MqttChannel
6+
from roborock.devices.traits import Trait
7+
from roborock.roborock_message import RoborockB01Props
8+
from roborock.roborock_typing import RoborockB01Q7Methods
9+
10+
__all__ = [
11+
"Q7PropertiesApi",
12+
]
13+
14+
15+
class Q7PropertiesApi(Trait):
16+
"""API for interacting with Q7 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 Q7 properties."""
24+
await send_decoded_command(
25+
self._channel, dps=10000, command=RoborockB01Q7Methods.GET_PROP, params={"property": props}
26+
)
27+
28+
29+
def create(channel: MqttChannel) -> Q7PropertiesApi:
30+
"""Create traits for B01 devices."""
31+
return Q7PropertiesApi(channel)

roborock/devices/traits/traits_mixin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class TraitsMixin:
3131
zeo: a01.ZeoApi | None = None
3232
"""Zeo API, if supported."""
3333

34-
b01_properties: b01.PropertiesApi | None = None
35-
"""B01 properties trait, if supported."""
34+
b01_q7_properties: b01.Q7PropertiesApi | None = None
35+
"""B01 Q7 properties trait, if supported."""
3636

3737
def __init__(self, trait: Trait) -> None:
3838
"""Initialize the TraitsMixin with the given trait.

roborock/protocols/b01_protocol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from Crypto.Cipher import AES
88
from Crypto.Util.Padding import pad, unpad
99

10-
from roborock import RoborockB01Methods
10+
from roborock import RoborockB01Q7Methods
1111
from roborock.exceptions import RoborockException
1212
from roborock.roborock_message import (
1313
RoborockMessage,
@@ -18,7 +18,7 @@
1818
_LOGGER = logging.getLogger(__name__)
1919

2020
B01_VERSION = b"B01"
21-
CommandType = RoborockB01Methods | str
21+
CommandType = RoborockB01Q7Methods | str
2222
ParamsType = list | dict | int | None
2323

2424

roborock/roborock_typing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ class RoborockCommand(str, Enum):
271271
APP_GET_ROBOT_SETTING = "app_get_robot_setting"
272272

273273

274-
class RoborockB01Methods(StrEnum):
275-
"""Methods used by the Roborock B01 model."""
274+
class RoborockB01Q7Methods(StrEnum):
275+
"""Methods used by the Roborock Q7 model."""
276276

277277
GET_PROP = "prop.get"
278278
GET_MAP_LIST = "service.get_map_list"

0 commit comments

Comments
 (0)