|
63 | 63 | from roborock.devices.device import RoborockDevice |
64 | 64 | from roborock.devices.device_manager import DeviceManager, DeviceVersion, UserParams, create_device_manager |
65 | 65 | from roborock.devices.traits import Trait |
| 66 | +from roborock.devices.traits.b01.q7 import Q7PropertiesApi |
66 | 67 | from roborock.devices.traits.b01.q10 import Q10PropertiesApi |
67 | 68 | from roborock.devices.traits.b01.q10.vacuum import VacuumTrait |
68 | 69 | from roborock.devices.traits.v1 import V1TraitMixin |
69 | 70 | from roborock.devices.traits.v1.consumeable import ConsumableAttribute |
70 | 71 | from roborock.devices.traits.v1.map_content import MapContentTrait |
71 | 72 | from roborock.exceptions import RoborockException, RoborockUnsupportedFeature |
72 | 73 | from roborock.protocol import MessageParser |
| 74 | +from roborock.roborock_message import RoborockB01Props |
| 75 | +from roborock.roborock_typing import RoborockB01Q7Methods |
73 | 76 | from roborock.web_api import RoborockApiClient |
74 | 77 |
|
75 | 78 | _LOGGER = logging.getLogger(__name__) |
@@ -494,6 +497,44 @@ async def _q10_vacuum_trait(context: RoborockContext, device_id: str) -> VacuumT |
494 | 497 | return (await _q10_properties(context, device_id)).vacuum |
495 | 498 |
|
496 | 499 |
|
| 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 | + |
497 | 538 | async def _display_q10_status(context: RoborockContext, device_id: str) -> None: |
498 | 539 | """Refresh and display the full status of a B01 Q10 device. |
499 | 540 |
|
@@ -556,6 +597,8 @@ async def status(ctx, device_id: str): |
556 | 597 | await _display_v1_trait(context, device_id, lambda v1: v1.status) |
557 | 598 | elif device.b01_q10_properties is not None: |
558 | 599 | await _display_q10_status(context, device_id) |
| 600 | + elif device.b01_q7_properties is not None: |
| 601 | + await _display_q7_status(context, device_id) |
559 | 602 | else: |
560 | 603 | click.echo("Feature not supported by device") |
561 | 604 |
|
@@ -1002,6 +1045,17 @@ async def command(ctx, cmd, device_id, params): |
1002 | 1045 | click.echo("Command sent successfully; Enable debug logging (-d) to see responses.") |
1003 | 1046 | # Q10 commands don't have a specific time to respond, so wait a bit and log |
1004 | 1047 | 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.") |
1005 | 1059 |
|
1006 | 1060 |
|
1007 | 1061 | @click.command() |
@@ -1730,6 +1784,117 @@ async def q10_set_fan_level(ctx: click.Context, device_id: str, level: str) -> N |
1730 | 1784 | click.echo(f"Error: {e}") |
1731 | 1785 |
|
1732 | 1786 |
|
| 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 | + |
1733 | 1898 | def main(): |
1734 | 1899 | return cli() |
1735 | 1900 |
|
|
0 commit comments