Skip to content
Merged
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
11 changes: 10 additions & 1 deletion roborock/devices/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,16 @@ def device_creator(home_data: HomeData, device: HomeDataDevice, product: HomeDat
trait = a01.create(product, channel)
case DeviceVersion.B01:
channel = create_mqtt_channel(user_data, mqtt_params, mqtt_session, device)
trait = b01.create(channel)
model_part = product.model.split(".")[-1]
if "ss" in model_part:
raise NotImplementedError(
f"Device {device.name} has unsupported version B01_{product.model.strip('.')[-1]}"
)
elif "sc" in model_part:
# Q7 devices start with 'sc' in their model naming.
trait = b01.q7.create(channel)
else:
raise NotImplementedError(f"Device {device.name} has unsupported B01 model: {product.model}")
case _:
raise NotImplementedError(f"Device {device.name} has unsupported version {device.pv}")
return RoborockDevice(device, product, channel, trait)
Expand Down
29 changes: 2 additions & 27 deletions roborock/devices/traits/b01/__init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
"""Traits for B01 devices."""

from roborock import RoborockB01Methods
from roborock.devices.b01_channel import send_decoded_command
from roborock.devices.mqtt_channel import MqttChannel
from roborock.devices.traits import Trait
from roborock.roborock_message import RoborockB01Props
from .q7 import Q7PropertiesApi

__all__ = [
"PropertiesApi",
]


class PropertiesApi(Trait):
"""API for interacting with B01 devices."""

def __init__(self, channel: MqttChannel) -> None:
"""Initialize the B01Props API."""
self._channel = channel

async def query_values(self, props: list[RoborockB01Props]) -> None:
"""Query the device for the values of the given Dyad protocols."""
await send_decoded_command(
self._channel, dps=10000, command=RoborockB01Methods.GET_PROP, params={"property": props}
)


def create(channel: MqttChannel) -> PropertiesApi:
"""Create traits for B01 devices."""
return PropertiesApi(channel)
__all__ = ["Q7PropertiesApi", "q7", "q10"]
1 change: 1 addition & 0 deletions roborock/devices/traits/b01/q10/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Q10"""
31 changes: 31 additions & 0 deletions roborock/devices/traits/b01/q7/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Traits for Q7 B01 devices.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Traits for Q7 B01 devices.
"""Traits for Q7 B01 devices.

Potentially other devices may fall into this category in the future."""

from roborock.devices.b01_channel import send_decoded_command
from roborock.devices.mqtt_channel import MqttChannel
from roborock.devices.traits import Trait
from roborock.roborock_message import RoborockB01Props
from roborock.roborock_typing import RoborockB01Q7Methods

__all__ = [
"Q7PropertiesApi",
]


class Q7PropertiesApi(Trait):
"""API for interacting with Q7 B01 devices."""

def __init__(self, channel: MqttChannel) -> None:
"""Initialize the B01Props API."""
self._channel = channel

async def query_values(self, props: list[RoborockB01Props]) -> None:
"""Query the device for the values of the given Q7 properties."""
await send_decoded_command(
self._channel, dps=10000, command=RoborockB01Q7Methods.GET_PROP, params={"property": props}
)


def create(channel: MqttChannel) -> Q7PropertiesApi:
"""Create traits for B01 devices."""
return Q7PropertiesApi(channel)
4 changes: 2 additions & 2 deletions roborock/devices/traits/traits_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class TraitsMixin:
zeo: a01.ZeoApi | None = None
"""Zeo API, if supported."""

b01_properties: b01.PropertiesApi | None = None
"""B01 properties trait, if supported."""
b01_q7_properties: b01.Q7PropertiesApi | None = None
"""B01 Q7 properties trait, if supported."""

def __init__(self, trait: Trait) -> None:
"""Initialize the TraitsMixin with the given trait.
Expand Down
4 changes: 2 additions & 2 deletions roborock/protocols/b01_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad

from roborock import RoborockB01Methods
from roborock import RoborockB01Q7Methods
from roborock.exceptions import RoborockException
from roborock.roborock_message import (
RoborockMessage,
Expand All @@ -18,7 +18,7 @@
_LOGGER = logging.getLogger(__name__)

B01_VERSION = b"B01"
CommandType = RoborockB01Methods | str
CommandType = RoborockB01Q7Methods | str
ParamsType = list | dict | int | None


Expand Down
4 changes: 2 additions & 2 deletions roborock/roborock_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ class RoborockCommand(str, Enum):
APP_GET_ROBOT_SETTING = "app_get_robot_setting"


class RoborockB01Methods(StrEnum):
"""Methods used by the Roborock B01 model."""
class RoborockB01Q7Methods(StrEnum):
"""Methods used by the Roborock Q7 model."""

GET_PROP = "prop.get"
GET_MAP_LIST = "service.get_map_list"
Expand Down