Skip to content

Commit 6bbd0cc

Browse files
committed
feat: add Q7 remote control trait
Add a `RemoteTrait` to the Q7 properties API, mirroring the Q10 remote API. Manual mode is entered with `prop.set sweep_type=5` and the robot is driven with `service.set_direction` (1 forward, 2 left, 3 right, 0 exit). Each command moves the robot for a short burst, so callers repeat it while a direction is held. Leaving remote mode restores `sweep_type=0`.
1 parent 67ce5a1 commit 6bbd0cc

4 files changed

Lines changed: 118 additions & 0 deletions

File tree

‎roborock/data/b01_q7/b01_q7_code_mappings.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ class SCDeviceCleanParam(RoborockModeEnum):
7777
PAUSE = ("pause", 2)
7878

7979

80+
class Q7RemoteDirection(RoborockModeEnum):
81+
"""Direction codes for ``service.set_direction`` (remote / manual control).
82+
83+
Verified live on a Q7 (sc05): the robot must first be in manual mode
84+
(``prop.set sweep_type=5`` -> ``work_mode`` 2). Each command moves the robot
85+
for a short burst, so callers repeat it while a direction is held. Code 0
86+
leaves manual mode.
87+
"""
88+
89+
EXIT = ("exit", 0)
90+
FORWARD = ("forward", 1)
91+
LEFT = ("left", 2)
92+
RIGHT = ("right", 3)
93+
94+
8095
class WorkModeMapping(RoborockModeEnum):
8196
"""Maps the detailed work modes of the robot."""
8297

‎roborock/devices/traits/b01/q7/__init__.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
from .clean_summary import CleanSummaryTrait
2828
from .map import MapTrait
2929
from .map_content import MapContentTrait
30+
from .remote import RemoteTrait
3031

3132
__all__ = [
3233
"Q7PropertiesApi",
3334
"CleanSummaryTrait",
3435
"MapTrait",
3536
"MapContentTrait",
37+
"RemoteTrait",
3638
"Q7MapList",
3739
"Q7MapListEntry",
3840
"Q7RoborockPoint",
@@ -54,6 +56,9 @@ class Q7PropertiesApi(Trait):
5456
map_content: MapContentTrait
5557
"""Trait for fetching parsed current map content."""
5658

59+
remote: RemoteTrait
60+
"""Trait for remote (manual) control of the robot."""
61+
5762
def __init__(
5863
self,
5964
rpc_channel: Q7RpcChannel,
@@ -71,6 +76,7 @@ def __init__(
7176
raise ValueError("B01 Q7 map content requires device serial number and product model metadata")
7277

7378
self.clean_summary = CleanSummaryTrait(rpc_channel)
79+
self.remote = RemoteTrait(rpc_channel)
7480
self.map = MapTrait(rpc_channel)
7581
self.map_content = MapContentTrait(
7682
self._map_rpc_channel,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Remote (manual) control trait for B01 Q7 devices."""
2+
3+
from roborock.data.b01_q7.b01_q7_code_mappings import Q7RemoteDirection
4+
from roborock.devices.rpc.b01_q7_channel import Q7RpcChannel
5+
from roborock.roborock_message import RoborockB01Props
6+
from roborock.roborock_typing import RoborockB01Q7Methods
7+
8+
# ``sweep_type`` values observed while the official app drives the remote control.
9+
_MANUAL_SWEEP_TYPE = 5
10+
_NORMAL_SWEEP_TYPE = 0
11+
12+
13+
class RemoteTrait:
14+
"""Trait for driving a Q7 manually, mirroring the Q10 ``RemoteTrait`` API.
15+
16+
Manual mode is entered with ``prop.set sweep_type=5`` (the device then reports
17+
``work_mode`` manual). Each movement command only moves the robot for a short
18+
burst, so callers repeat it (the official app sends several per second) while
19+
a direction is held.
20+
"""
21+
22+
def __init__(self, channel: Q7RpcChannel) -> None:
23+
"""Initialize the RemoteTrait."""
24+
self._channel = channel
25+
26+
async def _send_direction(self, direction: Q7RemoteDirection) -> None:
27+
await self._channel.send_command(RoborockB01Q7Methods.SET_DIRECTION, {"direction": direction.code})
28+
29+
async def stop(self) -> None:
30+
"""Stop moving, entering manual (remote control) mode if needed."""
31+
await self._channel.send_command(
32+
RoborockB01Q7Methods.SET_PROP,
33+
{RoborockB01Props.SWEEP_TYPE: _MANUAL_SWEEP_TYPE},
34+
)
35+
36+
async def forward(self) -> None:
37+
"""Move forward."""
38+
await self._send_direction(Q7RemoteDirection.FORWARD)
39+
40+
async def left(self) -> None:
41+
"""Turn left."""
42+
await self._send_direction(Q7RemoteDirection.LEFT)
43+
44+
async def right(self) -> None:
45+
"""Turn right."""
46+
await self._send_direction(Q7RemoteDirection.RIGHT)
47+
48+
async def exit_remote(self) -> None:
49+
"""Exit remote control and return to the normal idle state."""
50+
await self._send_direction(Q7RemoteDirection.EXIT)
51+
await self._channel.send_command(
52+
RoborockB01Q7Methods.SET_PROP,
53+
{RoborockB01Props.SWEEP_TYPE: _NORMAL_SWEEP_TYPE},
54+
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from collections.abc import Awaitable, Callable
2+
from typing import Any
3+
4+
import pytest
5+
6+
from roborock.devices.traits.b01.q7 import Q7PropertiesApi, RemoteTrait
7+
from roborock.roborock_message import RoborockB01Props
8+
from roborock.roborock_typing import RoborockB01Q7Methods
9+
10+
from .conftest import FakeQ7Channel
11+
12+
13+
@pytest.fixture(name="remote")
14+
def remote_fixture(q7_api: Q7PropertiesApi) -> RemoteTrait:
15+
return q7_api.remote
16+
17+
18+
@pytest.mark.parametrize(
19+
("command_fn", "expected_commands"),
20+
[
21+
(lambda x: x.stop(), [(RoborockB01Q7Methods.SET_PROP, {RoborockB01Props.SWEEP_TYPE: 5})]),
22+
(lambda x: x.forward(), [(RoborockB01Q7Methods.SET_DIRECTION, {"direction": 1})]),
23+
(lambda x: x.left(), [(RoborockB01Q7Methods.SET_DIRECTION, {"direction": 2})]),
24+
(lambda x: x.right(), [(RoborockB01Q7Methods.SET_DIRECTION, {"direction": 3})]),
25+
(
26+
lambda x: x.exit_remote(),
27+
[
28+
(RoborockB01Q7Methods.SET_DIRECTION, {"direction": 0}),
29+
(RoborockB01Q7Methods.SET_PROP, {RoborockB01Props.SWEEP_TYPE: 0}),
30+
],
31+
),
32+
],
33+
)
34+
async def test_remote_commands(
35+
remote: RemoteTrait,
36+
fake_channel: FakeQ7Channel,
37+
command_fn: Callable[[RemoteTrait], Awaitable[None]],
38+
expected_commands: list[tuple[Any, Any]],
39+
) -> None:
40+
"""Test remote control commands are sent with the verified Q7 payloads."""
41+
await command_fn(remote)
42+
43+
assert fake_channel.published_commands == expected_commands

0 commit comments

Comments
 (0)