-
Notifications
You must be signed in to change notification settings - Fork 65
feat: Add initial Q10 support #709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
55e75d6
8e974ba
e0305cf
7a73268
7b5688c
8fe70c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,6 +43,7 @@ | |||||||||||
|
|
||||||||||||
| from roborock import SHORT_MODEL_TO_ENUM, RoborockCommand | ||||||||||||
| from roborock.data import DeviceData, RoborockBase, UserData | ||||||||||||
| from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP | ||||||||||||
| from roborock.device_features import DeviceFeatures | ||||||||||||
| from roborock.devices.cache import Cache, CacheData | ||||||||||||
| from roborock.devices.device import RoborockDevice | ||||||||||||
|
|
@@ -91,7 +92,12 @@ def wrapper(*args, **kwargs): | |||||||||||
| context: RoborockContext = ctx.obj | ||||||||||||
|
|
||||||||||||
| async def run(): | ||||||||||||
| return await func(*args, **kwargs) | ||||||||||||
| try: | ||||||||||||
| await func(*args, **kwargs) | ||||||||||||
| except Exception: | ||||||||||||
| _LOGGER.exception("Uncaught exception in command") | ||||||||||||
| click.echo(f"Error: {sys.exc_info()[1]}", err=True) | ||||||||||||
| await context.cleanup() | ||||||||||||
|
|
||||||||||||
| if context.is_session_mode(): | ||||||||||||
| # Session mode - run in the persistent loop | ||||||||||||
|
|
@@ -739,6 +745,16 @@ async def network_info(ctx, device_id: str): | |||||||||||
| await _display_v1_trait(context, device_id, lambda v1: v1.network_info) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def _parse_b01_q10_command(cmd: str) -> B01_Q10_DP | None: | ||||||||||||
| """Parse B01_Q10 command from either enum name or value.""" | ||||||||||||
| for func in (B01_Q10_DP.from_code, B01_Q10_DP.from_name, B01_Q10_DP.from_value): | ||||||||||||
| try: | ||||||||||||
|
||||||||||||
| try: | |
| try: | |
| if func is B01_Q10_DP.from_code: | |
| # from_code expects an integer code; attempt to convert the string | |
| return func(int(cmd)) |
allenporter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| """Thin wrapper around the MQTT channel for Roborock B01 devices.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from collections.abc import AsyncGenerator | ||
| from typing import Any | ||
|
|
||
| from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP | ||
| from roborock.exceptions import RoborockException | ||
| from roborock.protocols.b01_q10_protocol import ( | ||
| ParamsType, | ||
| decode_rpc_response, | ||
| encode_mqtt_payload, | ||
| ) | ||
|
|
||
| from .mqtt_channel import MqttChannel | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
| _TIMEOUT = 10.0 | ||
|
|
||
|
|
||
| async def send_command( | ||
| mqtt_channel: MqttChannel, | ||
| command: B01_Q10_DP, | ||
| params: ParamsType, | ||
| ) -> None: | ||
| """Send a command on the MQTT channel, without waiting for a response""" | ||
| _LOGGER.debug( | ||
| "Sending B01 MQTT command: cmd=%s params=%s", | ||
| command, | ||
| params, | ||
| ) | ||
| roborock_message = encode_mqtt_payload(command, params) | ||
| _LOGGER.debug("Sending MQTT message: %s", roborock_message) | ||
| try: | ||
| await mqtt_channel.publish(roborock_message) | ||
| except RoborockException as ex: | ||
| _LOGGER.debug( | ||
| "Error sending B01 decoded command (method=%s params=%s): %s", | ||
| command, | ||
| params, | ||
| ex, | ||
| ) | ||
| raise | ||
|
|
||
|
|
||
| async def stream_decoded_responses( | ||
| mqtt_channel: MqttChannel, | ||
| ) -> AsyncGenerator[dict[B01_Q10_DP, Any], None]: | ||
| """Stream decoded DPS messages received via MQTT.""" | ||
|
|
||
| async for response_message in mqtt_channel.subscribe_stream(): | ||
| try: | ||
| decoded_dps = decode_rpc_response(response_message) | ||
| except RoborockException as ex: | ||
| _LOGGER.debug( | ||
| "Failed to decode B01 RPC response: %s: %s", | ||
| response_message, | ||
| ex, | ||
| ) | ||
| continue | ||
| yield decoded_dps |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| """Traits for B01 devices.""" | ||
|
|
||
| from .q7 import Q7PropertiesApi | ||
| from .q10 import Q10PropertiesApi | ||
|
|
||
| __all__ = ["Q7PropertiesApi", "q7", "q10"] | ||
| __all__ = [ | ||
| "Q7PropertiesApi", | ||
| "Q10PropertiesApi", | ||
| "q7", | ||
| "q10", | ||
| ] |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1 +1,104 @@ | ||||||
| """Q10""" | ||||||
| """Traits for Q10 B01 devices.""" | ||||||
|
|
||||||
| import asyncio | ||||||
| import logging | ||||||
| from typing import Any | ||||||
|
|
||||||
| from roborock import B01Props | ||||||
| from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP | ||||||
| from roborock.devices.b01_q10_channel import ParamsType, send_command, stream_decoded_responses | ||||||
| from roborock.devices.mqtt_channel import MqttChannel | ||||||
| from roborock.devices.traits import Trait | ||||||
|
|
||||||
| _LOGGER = logging.getLogger(__name__) | ||||||
|
|
||||||
| __all__ = [ | ||||||
| "Q10PropertiesApi", | ||||||
| ] | ||||||
|
|
||||||
|
|
||||||
| class Q10PropertiesApi(Trait): | ||||||
| """API for interacting with B01 devices.""" | ||||||
|
|
||||||
| def __init__(self, channel: MqttChannel) -> None: | ||||||
| """Initialize the B01Props API.""" | ||||||
| self._channel = channel | ||||||
| self._task: asyncio.Task | None = None | ||||||
|
|
||||||
| async def start(self) -> None: | ||||||
| """Start any necessary subscriptions for the trait.""" | ||||||
| self._task = asyncio.create_task(self._run_loop()) | ||||||
|
|
||||||
| async def close(self) -> None: | ||||||
| """Close any resources held by the trait.""" | ||||||
| if self._task is not None: | ||||||
| self._task.cancel() | ||||||
| try: | ||||||
| await self._task | ||||||
| except asyncio.CancelledError: | ||||||
allenporter marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| pass | ||||||
| self._task = None | ||||||
|
|
||||||
| async def start_clean(self) -> None: | ||||||
| """Start cleaning.""" | ||||||
| await self.send( | ||||||
| command=B01_Q10_DP.START_CLEAN, | ||||||
| # TODO: figure out other commands | ||||||
| # 1 = start cleaning | ||||||
| # 2 = electoral clean, also has "clean_paramters" | ||||||
allenporter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| # 2 = electoral clean, also has "clean_paramters" | |
| # 2 = electoral clean, also has "clean_parameters" |
allenporter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Copilot
AI
Dec 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for the pause_clean, resume_clean, stop_clean, and return_to_dock methods. The Q7 implementation has comprehensive tests for similar methods (test_q7_api_pause_clean, test_q7_api_stop_clean, test_q7_api_return_to_dock). Consider adding equivalent tests for Q10 to ensure these commands work correctly.
Uh oh!
There was an error while loading. Please reload this page.