Skip to content

Commit 829251d

Browse files
authored
feat(q7): add CLI vacuum commands for B01 Q7 devices (#1075)
* feat(q7): add CLI vacuum commands for B01 Q7 devices * fix(cli): default omitted Q7 command params to {} and drop rooms pointer from q7-clean-segments * docs(cli): reword Q7 resume comment to note the app's unconfirmed puaseFalse value
1 parent cd6f263 commit 829251d

3 files changed

Lines changed: 459 additions & 3 deletions

File tree

‎roborock/cli.py‎

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@
6363
from roborock.devices.device import RoborockDevice
6464
from roborock.devices.device_manager import DeviceManager, DeviceVersion, UserParams, create_device_manager
6565
from roborock.devices.traits import Trait
66+
from roborock.devices.traits.b01.q7 import Q7PropertiesApi
6667
from roborock.devices.traits.b01.q10 import Q10PropertiesApi
6768
from roborock.devices.traits.b01.q10.vacuum import VacuumTrait
6869
from roborock.devices.traits.v1 import V1TraitMixin
6970
from roborock.devices.traits.v1.consumeable import ConsumableAttribute
7071
from roborock.devices.traits.v1.map_content import MapContentTrait
7172
from roborock.exceptions import RoborockException, RoborockUnsupportedFeature
7273
from roborock.protocol import MessageParser
74+
from roborock.roborock_message import RoborockB01Props
75+
from roborock.roborock_typing import RoborockB01Q7Methods
7376
from roborock.web_api import RoborockApiClient
7477

7578
_LOGGER = logging.getLogger(__name__)
@@ -494,6 +497,44 @@ async def _q10_vacuum_trait(context: RoborockContext, device_id: str) -> VacuumT
494497
return (await _q10_properties(context, device_id)).vacuum
495498

496499

500+
async def _q7_properties(context: RoborockContext, device_id: str) -> Q7PropertiesApi:
501+
"""Get the B01 Q7 properties API for a device."""
502+
device_manager = await context.get_device_manager()
503+
device = await device_manager.get_device(device_id)
504+
if device.b01_q7_properties is None:
505+
raise RoborockUnsupportedFeature("Device does not support B01 Q7 protocol. Is it a Q7?")
506+
return device.b01_q7_properties
507+
508+
509+
async def _display_q7_status(context: RoborockContext, device_id: str) -> None:
510+
"""Query and display the current status of a B01 Q7 device.
511+
512+
Unlike V1 devices, the Q7 reports its state through ``prop.get``: the
513+
requested properties come back in a single response, so there is no
514+
push stream to wait on as with the Q10.
515+
"""
516+
properties = await _q7_properties(context, device_id)
517+
props = await properties.query_values(
518+
[
519+
RoborockB01Props.STATUS,
520+
RoborockB01Props.FAULT,
521+
RoborockB01Props.QUANTITY,
522+
RoborockB01Props.WORK_MODE,
523+
RoborockB01Props.STATION_ACT,
524+
RoborockB01Props.CHARGE_STATE,
525+
RoborockB01Props.CLEANING_TIME,
526+
RoborockB01Props.CLEANING_AREA,
527+
RoborockB01Props.WIND,
528+
RoborockB01Props.WATER,
529+
RoborockB01Props.MODE,
530+
]
531+
)
532+
if props is None:
533+
click.echo("Feature not supported by device")
534+
return
535+
click.echo(dump_json(props.as_dict()))
536+
537+
497538
async def _display_q10_status(context: RoborockContext, device_id: str) -> None:
498539
"""Refresh and display the full status of a B01 Q10 device.
499540
@@ -556,6 +597,8 @@ async def status(ctx, device_id: str):
556597
await _display_v1_trait(context, device_id, lambda v1: v1.status)
557598
elif device.b01_q10_properties is not None:
558599
await _display_q10_status(context, device_id)
600+
elif device.b01_q7_properties is not None:
601+
await _display_q7_status(context, device_id)
559602
else:
560603
click.echo("Feature not supported by device")
561604

@@ -1002,6 +1045,17 @@ async def command(ctx, cmd, device_id, params):
10021045
click.echo("Command sent successfully; Enable debug logging (-d) to see responses.")
10031046
# Q10 commands don't have a specific time to respond, so wait a bit and log
10041047
await asyncio.sleep(5)
1048+
elif device.b01_q7_properties is not None:
1049+
try:
1050+
method = RoborockB01Q7Methods(cmd)
1051+
except ValueError as err:
1052+
raise RoborockException(f"Invalid command {cmd} for B01_Q7 device") from err
1053+
properties = device.b01_q7_properties
1054+
result = await properties.send(method, json.loads(params) if params is not None else {})
1055+
if result:
1056+
click.echo(dump_json(result))
1057+
else:
1058+
click.echo("Command sent successfully; Enable debug logging (-d) to see responses.")
10051059

10061060

10071061
@click.command()
@@ -1730,6 +1784,117 @@ async def q10_set_fan_level(ctx: click.Context, device_id: str, level: str) -> N
17301784
click.echo(f"Error: {e}")
17311785

17321786

1787+
# --- Q7 session commands ---
1788+
#
1789+
# The Q7 API exposes its cleaning commands directly on Q7PropertiesApi
1790+
# (there is no separate vacuum trait as on the Q10), so these commands call
1791+
# the API methods. There is intentionally no resume or spot command: the
1792+
# library does not map a resume value yet (the app defines an unconfirmed
1793+
# puaseFalse = 3) and no spot clean task type, so a paused clean is
1794+
# restarted with q7-vacuum-start.
1795+
1796+
1797+
@session.command()
1798+
@click.option("--device_id", required=True, help="Device ID")
1799+
@click.pass_context
1800+
@async_command
1801+
async def q7_vacuum_start(ctx: click.Context, device_id: str) -> None:
1802+
"""Start vacuum cleaning on Q7 device."""
1803+
context: RoborockContext = ctx.obj
1804+
try:
1805+
properties = await _q7_properties(context, device_id)
1806+
await properties.start_clean()
1807+
click.echo("Starting vacuum cleaning...")
1808+
except RoborockUnsupportedFeature:
1809+
click.echo("Device does not support B01 Q7 protocol. Is it a Q7?")
1810+
except RoborockException as e:
1811+
click.echo(f"Error: {e}")
1812+
1813+
1814+
@session.command()
1815+
@click.option("--device_id", required=True, help="Device ID")
1816+
@click.pass_context
1817+
@async_command
1818+
async def q7_vacuum_pause(ctx: click.Context, device_id: str) -> None:
1819+
"""Pause vacuum cleaning on Q7 device."""
1820+
context: RoborockContext = ctx.obj
1821+
try:
1822+
properties = await _q7_properties(context, device_id)
1823+
await properties.pause_clean()
1824+
click.echo("Pausing vacuum cleaning...")
1825+
except RoborockUnsupportedFeature:
1826+
click.echo("Device does not support B01 Q7 protocol. Is it a Q7?")
1827+
except RoborockException as e:
1828+
click.echo(f"Error: {e}")
1829+
1830+
1831+
@session.command()
1832+
@click.option("--device_id", required=True, help="Device ID")
1833+
@click.pass_context
1834+
@async_command
1835+
async def q7_vacuum_stop(ctx: click.Context, device_id: str) -> None:
1836+
"""Stop vacuum cleaning on Q7 device."""
1837+
context: RoborockContext = ctx.obj
1838+
try:
1839+
properties = await _q7_properties(context, device_id)
1840+
await properties.stop_clean()
1841+
click.echo("Stopping vacuum cleaning...")
1842+
except RoborockUnsupportedFeature:
1843+
click.echo("Device does not support B01 Q7 protocol. Is it a Q7?")
1844+
except RoborockException as e:
1845+
click.echo(f"Error: {e}")
1846+
1847+
1848+
@session.command()
1849+
@click.option("--device_id", required=True, help="Device ID")
1850+
@click.pass_context
1851+
@async_command
1852+
async def q7_vacuum_dock(ctx: click.Context, device_id: str) -> None:
1853+
"""Return vacuum to dock on Q7 device."""
1854+
context: RoborockContext = ctx.obj
1855+
try:
1856+
properties = await _q7_properties(context, device_id)
1857+
await properties.return_to_dock()
1858+
click.echo("Returning vacuum to dock...")
1859+
except RoborockUnsupportedFeature:
1860+
click.echo("Device does not support B01 Q7 protocol. Is it a Q7?")
1861+
except RoborockException as e:
1862+
click.echo(f"Error: {e}")
1863+
1864+
1865+
@session.command()
1866+
@click.option("--device_id", required=True, help="Device ID")
1867+
@click.option(
1868+
"--segments",
1869+
required=True,
1870+
help="Comma-separated room/segment ids to clean, e.g. 9,2",
1871+
)
1872+
@click.pass_context
1873+
@async_command
1874+
async def q7_clean_segments(ctx: click.Context, device_id: str, segments: str) -> None:
1875+
"""Start a room / segment clean on a Q7 device.
1876+
1877+
Room ids are the segment ids from the device's map rooms.
1878+
"""
1879+
context: RoborockContext = ctx.obj
1880+
try:
1881+
segment_ids = [int(s) for s in segments.split(",") if s.strip()]
1882+
except ValueError:
1883+
click.echo("--segments must be comma-separated integers, e.g. 9,2")
1884+
return
1885+
if not segment_ids:
1886+
click.echo("No segment ids provided")
1887+
return
1888+
try:
1889+
properties = await _q7_properties(context, device_id)
1890+
await properties.clean_segments(segment_ids)
1891+
click.echo(f"Starting room clean of segments {segment_ids}...")
1892+
except RoborockUnsupportedFeature:
1893+
click.echo("Device does not support B01 Q7 protocol. Is it a Q7?")
1894+
except RoborockException as e:
1895+
click.echo(f"Error: {e}")
1896+
1897+
17331898
def main():
17341899
return cli()
17351900

‎roborock/const.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
ROBOROCK_Q5_PRO = "roborock.vacuum.a72"
3030
ROBOROCK_Q7 = "roborock.vacuum.a40"
3131
ROBOROCK_Q7_MAX = "roborock.vacuum.a38"
32+
ROBOROCK_Q7_TF_PLUS = "roborock.vacuum.sc05"
3233
ROBOROCK_Q7PLUS = "roborock.vacuum.a40"
3334
ROBOROCK_QREVO_MASTER = "roborock.vacuum.a117"
3435
ROBOROCK_QREVO_CURV = "roborock.vacuum.a135"
@@ -67,6 +68,7 @@
6768
ROBOROCK_Q5,
6869
ROBOROCK_Q7,
6970
ROBOROCK_Q7_MAX,
71+
ROBOROCK_Q7_TF_PLUS,
7072
ROBOROCK_S4,
7173
ROBOROCK_S5_MAX,
7274
ROBOROCK_S6,

0 commit comments

Comments
 (0)