diff --git a/docs/camera.md b/docs/camera.md index 4402ec65..3e318672 100644 --- a/docs/camera.md +++ b/docs/camera.md @@ -130,6 +130,26 @@ The tested Saros 10R required two-key activation: set the remote-view PIN the two-key request bits set and monitor bit off, then press Power on the robot within about 60 seconds. Activation varies by model. +The QX Revo Ultra 2 (a298, firmware `02.15.44`) uses the same flow, and the +server can drive it: + +```bash +uv run start_local_roborock_server.py camera-activate --config config.toml +``` + +Dock the robot first and clear any error (`error_code` must be 0). The command +reads `camera_status` and writes the two request values — bit 5, then bit 12 — +which for an out-of-box a298 (`385`) is `417` then `4513`. Press the robot's +Power button once while it is polling. The firmware clears bit 12 and sets the +read-only monitor bit 2 itself, and `camera_status` becomes `8613`. Writing the +monitor bit directly is rejected (`-10005`), and writing the result bit +(`8611`) is rejected (`-10007`). + +Activation resets when the robot is re-onboarded or its camera PIN changes, so +rerun the command after either. With the monitor bit set, `start_camera_preview` +reaches the TURN bootstrap above; a viewer that offers an audio track gets no +SDP answer on this firmware, so the offer must be video-only. + A Qrevo Master report observed `set_camera_status` values `[417]` then `[4513]` from an initial status of `385`, followed by a robot-reported status of `8613`, without the Saros-style physical activation. An a226 report started at `257` and diff --git a/docs/tested_vacuums.md b/docs/tested_vacuums.md index 592aafcd..f9bcb830 100644 --- a/docs/tested_vacuums.md +++ b/docs/tested_vacuums.md @@ -145,10 +145,10 @@ Cloudflare can provide DNS validation for several certificate issuers. Its use a | QRevo S Pro (a326) | `02.36.38` | ❓ | ❓ | ✅ | ❓ | [#132](https://github.com/Python-roborock/local_roborock_server/issues/132) | | QRevo S Pro (a326) | `02.49.24` | ✅ | ❓ | ✅ | ❓ | [#156](https://github.com/Python-roborock/local_roborock_server/issues/156), [#186](https://github.com/Python-roborock/local_roborock_server/issues/186) | | QRevo Slim | `02.43.38` | ✅ | ❓ | ❓ | ❓ | [#175](https://github.com/Python-roborock/local_roborock_server/issues/175) | +| QX Revo Ultra 2 (a298) | `02.15.44` | ✅ | ✅ | ✅ | ❓ | [#193](https://github.com/Python-roborock/local_roborock_server/issues/193) | | QX Revo Plus (Costco version) | Not reported | ❓ | ❓ | ✅ | ❓ | [#89](https://github.com/Python-roborock/local_roborock_server/pull/89) | | QX Revo Plus (Costco version) | `02.49.24` | ✅ | ❓ | ❓ | ❓ | [#147](https://github.com/Python-roborock/local_roborock_server/issues/147) | | QX Revo Plus (a168 as reported) | `02.27.40` | ✅ | ❓ | ❓ | ❓ | [#248](https://github.com/Python-roborock/local_roborock_server/issues/248) | -| QX Revo Ultra 2 (a298) | `02.15.44` | ❓ | ✅ | ❓ | ❓ | [#193](https://github.com/Python-roborock/local_roborock_server/issues/193) | Setup notes: @@ -181,7 +181,7 @@ Setup notes: - QRevo S5V `02.33.88`: maps were not saved because `lab_status` was off and the LocalRock toggle was greyed out. Sending `set_lab_status` with `[{"lab_status": 1}]` from Home Assistant's `vacuum.send_command` enabled it. - QRevo Slim: the certificate was issued through Pangolin (Traefik) and reported as ZeroSSL. - QRevo Master: the SSL.com result used a Sectigo Public Server Authentication CA DV R36 chain and a workaround for the proxy MQTT onboarding issue in [#83](https://github.com/Python-roborock/local_roborock_server/issues/83). -- QX Revo Ultra 2: shares its model code and firmware with the QRevo Edge 2 Set. Public key recovery used header samples while query samples stayed at 0, which is expected. +- QX Revo Ultra 2 (a298): shares its model code and firmware (`02.15.44`) with the QRevo Edge 2 Set row. Onboarded with the project CLI after LocalRock's v5 auth flow returned `401 missing_authorization`. Public key recovery used `header_samples` rather than `query_samples`. Cloud-free operation was verified under a full router outbound block, and the `/f/c` rrcheck was accepted on 6 daily requests over 5 days. Live video works with the provided TURN relay and a video-only WebRTC offer; remote viewing needs the local two-key activation in [camera.md](camera.md), which `camera-activate` performs. The [report details](compatibility_reports.md) retain the newer setup profiles, camera qualifications, and unresolved requests behind these results. diff --git a/src/roborock_local_server/__main__.py b/src/roborock_local_server/__main__.py index a865107a..349042b4 100644 --- a/src/roborock_local_server/__main__.py +++ b/src/roborock_local_server/__main__.py @@ -10,7 +10,12 @@ from .configure import run_configure from .security import hash_password -from .server import build_arg_parser, repair_runtime_identities, run_server +from .server import ( + activate_camera_command, + build_arg_parser, + repair_runtime_identities, + run_server, +) def main() -> int: @@ -58,6 +63,13 @@ def main() -> int: if args.command == "repair-identities": return repair_runtime_identities(config_file=Path(args.config), links=list(args.link)) + if args.command == "camera-activate": + return activate_camera_command( + config_file=Path(args.config), + duid=str(args.duid), + timeout=float(args.timeout), + ) + parser.error(f"Unhandled command: {args.command}") return 2 diff --git a/src/roborock_local_server/bundled_backend/shared/native_schedule_sync.py b/src/roborock_local_server/bundled_backend/shared/native_schedule_sync.py index 84a7ff48..472d9011 100644 --- a/src/roborock_local_server/bundled_backend/shared/native_schedule_sync.py +++ b/src/roborock_local_server/bundled_backend/shared/native_schedule_sync.py @@ -46,7 +46,7 @@ async def sync_timer( context: Any, duid: str, name: str, enabled: bool, *, check_current: Callable[[], None], ) -> str: """Update only the named timer; a fresh read is the success criterion, and a lost ack is read back, not resent.""" - from shared.routine_runner import _RoutineMqttClient + from shared.routine_runner import RoutineMqttClient device = context.runtime_credentials.resolve_device(duid=duid) if device is None or not device.get("localkey"): @@ -56,7 +56,7 @@ async def sync_timer( write_attempted = False try: async with asyncio.timeout(45): - client = _RoutineMqttClient(context, device, logging.getLogger(__name__)) + client = RoutineMqttClient(context, device, logging.getLogger(__name__)) await client.connect() timer = _timer_entry(await client.send_command(TimerCommand.GET, []), name) current = "on" if timer.enabled else "off" @@ -184,14 +184,14 @@ def observe_request(self, duid: str, payload: bytes) -> None: return async def _client(self, duid: str, device: dict[str, Any]) -> Any: - from .routine_runner import _RoutineMqttClient + from .routine_runner import RoutineMqttClient localkey = str(device.get("localkey") or "") cached = self._clients.get(duid) if cached is not None and cached[0] == localkey: return cached[1] await self._drop_client(duid) - client = _RoutineMqttClient(self.context, device, _LOGGER) + client = RoutineMqttClient(self.context, device, _LOGGER) await client.connect() self._clients[duid] = (localkey, client) return client diff --git a/src/roborock_local_server/bundled_backend/shared/routine_runner.py b/src/roborock_local_server/bundled_backend/shared/routine_runner.py index 39bc7190..f88edba9 100644 --- a/src/roborock_local_server/bundled_backend/shared/routine_runner.py +++ b/src/roborock_local_server/bundled_backend/shared/routine_runner.py @@ -41,6 +41,7 @@ def _ensure_local_python_roborock_on_path() -> None: __all__ = [ "RoutineCommand", "RoutineExecutionError", + "RoutineMqttClient", "RoutineRunner", "RoutineStep", "commands_for_step", @@ -497,7 +498,7 @@ def _enum_or_int_value(value: Any) -> int: return int(getattr(value, "value", value)) -class _RoutineMqttClient: +class RoutineMqttClient: def __init__( self, context: ServerContext, @@ -983,7 +984,7 @@ def add_scene(candidate: dict[str, Any]) -> None: async def _sync_scene_tids( self, *, - client: _RoutineMqttClient, + client: RoutineMqttClient, scene: dict[str, Any], device_id: str, logger: logging.LoggerAdapter, @@ -1008,7 +1009,7 @@ async def _stop_scene(self, *, device_id: str, scene_id: int, scene_name: str) - }, ) logger.info("Stopping routine scene=%s device=%s", scene_name, device_id) - client = _RoutineMqttClient(self._context, device, logger) + client = RoutineMqttClient(self._context, device, logger) await client.connect() try: await client.send_command(RoborockCommand.APP_STOP, []) @@ -1018,7 +1019,7 @@ async def _stop_scene(self, *, device_id: str, scene_id: int, scene_name: str) - async def _send_step_command( self, *, - client: _RoutineMqttClient, + client: RoutineMqttClient, logger: logging.LoggerAdapter, step: RoutineStep, routine_command: RoutineCommand, @@ -1066,7 +1067,7 @@ async def _send_step_command( async def _send_step_commands( self, *, - client: _RoutineMqttClient, + client: RoutineMqttClient, logger: logging.LoggerAdapter, step: RoutineStep, commands: list[RoutineCommand], @@ -1116,7 +1117,7 @@ async def _run_steps( device_id, ) - client = _RoutineMqttClient(self._context, device, logger) + client = RoutineMqttClient(self._context, device, logger) await client.connect() try: if sync_scene_tids: diff --git a/src/roborock_local_server/camera.py b/src/roborock_local_server/camera.py new file mode 100644 index 00000000..fc5d64ce --- /dev/null +++ b/src/roborock_local_server/camera.py @@ -0,0 +1,89 @@ +"""Local two-key camera activation. + +Some models (Saros 10R, QX Revo Ultra 2) do not enable live view from +``set_homesec_password`` alone. The firmware expects the remote-view app to write +``set_camera_status`` twice — first with the request bit 5, then with bit 12 — and +then a physical Power press on the robot within about a minute. The firmware +clears bit 12 and sets the read-only monitor bit 2, which authorizes +``start_camera_preview``. + +Only bits 5 and 12 are added; the firmware truncates/validates anything else, and +writing bit 2 or bit 13 directly is rejected. +""" + +from __future__ import annotations + +import asyncio +from dataclasses import dataclass +import time +from typing import Any + +from roborock.roborock_typing import RoborockCommand + +#: Read-only "view authorized" bit the firmware sets after a successful press. +MONITOR_BIT = 0x4 +#: First and second request bits, in the order the app writes them. +REQUEST_BITS = (0x20, 0x1000) + + +@dataclass(frozen=True) +class ActivationResult: + initial_status: int + final_status: int + activated: bool + + +def activation_writes(current_status: int) -> list[int]: + """Return the ``set_camera_status`` values that arm the two-key request. + + Each write carries the previous one forward: the firmware sees bit 5 on the + first write and bit 5 plus bit 12 on the second. + """ + + status = current_status + writes: list[int] = [] + for bit in REQUEST_BITS: + status |= bit + writes.append(status) + return writes + + +def monitor_enabled(status: int) -> bool: + """True once the firmware has granted view authorization.""" + + return bool(status & MONITOR_BIT) + + +async def _read_camera_status(client: Any) -> int: + result = await client.send_command(RoborockCommand.GET_CAMERA_STATUS) + value = result[0] if isinstance(result, list) and result else result + return int(value) + + +async def activate_camera( + client: Any, + *, + timeout_seconds: float = 90.0, + poll_interval_seconds: float = 1.0, +) -> ActivationResult: + """Arm the two-key request and wait for the monitor bit. + + The caller must press Power on the robot while this is polling. Returns once + the robot reports the monitor bit or the timeout expires. + """ + + initial = await _read_camera_status(client) + if monitor_enabled(initial): + return ActivationResult(initial_status=initial, final_status=initial, activated=True) + + for value in activation_writes(initial): + await client.send_command(RoborockCommand.SET_CAMERA_STATUS, [value]) + + deadline = time.monotonic() + timeout_seconds + while True: + status = await _read_camera_status(client) + if monitor_enabled(status): + return ActivationResult(initial_status=initial, final_status=status, activated=True) + if time.monotonic() >= deadline: + return ActivationResult(initial_status=initial, final_status=status, activated=False) + await asyncio.sleep(poll_interval_seconds) diff --git a/src/roborock_local_server/server.py b/src/roborock_local_server/server.py index 157e3bea..54fdf915 100644 --- a/src/roborock_local_server/server.py +++ b/src/roborock_local_server/server.py @@ -56,6 +56,9 @@ from shared.http_helpers import with_route_headers from shared.inventory_io import atomic_write_inventory, inventory_transaction from shared.protocol_auth import ProtocolAuthStore +from shared.routine_runner import RoutineMqttClient +from roborock.roborock_typing import RoborockCommand +from .camera import activate_camera from shared.schedule_runner import ScheduleRunner from shared.native_schedule_sync import NativeScheduleSync from shared.timer_rpc import TimerRpcInterceptor @@ -2227,6 +2230,104 @@ async def run_server(*, config_file: Path, enable_standalone_admin: bool = True) return await supervisor.serve_forever() +def _build_runtime_context( + config: AppConfig, + paths: AppPaths, + runtime_credentials: RuntimeCredentialsStore, +) -> ServerContext: + """Build the minimal context the MQTT command client needs outside ``serve``.""" + + return ServerContext( + api_host=config.network.stack_fqdn, + mqtt_host=config.network.stack_fqdn, + wood_host=config.network.stack_fqdn, + region=config.network.region, + protocol_login_email=config.admin.protocol_login_email, + localkey=str(runtime_credentials.bootstrap_value("localkey", "") or ""), + duid=str(runtime_credentials.bootstrap_value("duid", "") or ""), + mqtt_usr=str(runtime_credentials.bootstrap_value("mqtt_usr", "") or ""), + mqtt_passwd=str(runtime_credentials.bootstrap_value("mqtt_passwd", "") or ""), + mqtt_clientid=str(runtime_credentials.bootstrap_value("mqtt_clientid", "") or ""), + https_port=config.network.advertised_https_port, + mqtt_tls_port=config.network.advertised_mqtt_tls_port, + http_jsonl=paths.http_jsonl_path, + mqtt_jsonl=paths.mqtt_jsonl_path, + loggers={}, + key_state_file=paths.device_key_state_path, + bootstrap_encryption_enabled=False, + runtime_state=None, + runtime_credentials=runtime_credentials, + timezone=config.network.timezone or None, + ) + + +def _single_onboarded_duid(runtime_credentials: RuntimeCredentialsStore) -> str: + duids = sorted( + {str(device.get("duid") or "").strip() for device in runtime_credentials.devices()} - {""} + ) + if not duids: + raise SystemExit("No onboarded vacuum found in runtime credentials; onboard first or pass --duid.") + if len(duids) > 1: + raise SystemExit("Multiple vacuums are onboarded; pass --duid with one of: " + ", ".join(duids)) + return duids[0] + + +async def _run_camera_activation( + client: RoutineMqttClient, + device: dict[str, str], + *, + timeout: float, +) -> int: + name = str(device.get("name") or device.get("duid") or "vacuum") + await client.connect() + try: + raw_status = await client.send_command(RoborockCommand.GET_STATUS) + status = raw_status[0] if isinstance(raw_status, list) and raw_status else raw_status + if isinstance(status, dict): + error_code = int(status.get("error_code") or 0) + if error_code: + raise SystemExit( + f"{name} reports error_code {error_code}; clear the robot error before activating." + ) + print(f"Arming the two-key camera request on {name}.") + print("Press the Power button once on the robot now.") + result = await activate_camera(client, timeout_seconds=timeout) + finally: + await client.close() + + if result.activated: + print( + f"Camera view authorized: camera_status={result.final_status} " + f"(was {result.initial_status})." + ) + print("This stays enabled until the robot is re-onboarded or its camera PIN changes.") + return 0 + + print(f"Timed out after {timeout:.0f}s: camera_status={result.final_status}.") + print("Dock the robot, clear any error, rerun this command, then press Power within 60s.") + return 1 + + +def activate_camera_command(*, config_file: Path, duid: str = "", timeout: float = 90.0) -> int: + config = load_config(config_file) + paths = resolve_paths(config_file, config) + runtime_credentials = RuntimeCredentialsStore( + paths.runtime_credentials_path, + inventory_path=paths.inventory_path, + key_state_file=paths.device_key_state_path, + ) + runtime_credentials.sync_inventory() + + selector = duid.strip() or _single_onboarded_duid(runtime_credentials) + device = runtime_credentials.device_for_selector(selector) + if device is None: + raise SystemExit(f"Vacuum '{selector}' was not found in {paths.runtime_credentials_path}") + + context = _build_runtime_context(config, paths, runtime_credentials) + client = RoutineMqttClient(context, device, logging.getLogger("roborock_local_server.camera_activate")) + return asyncio.run(_run_camera_activation(client, device, timeout=timeout)) + + def repair_runtime_identities(*, config_file: Path, links: list[str]) -> int: config = load_config(config_file) paths = resolve_paths(config_file, config) @@ -2239,28 +2340,7 @@ def repair_runtime_identities(*, config_file: Path, links: list[str]) -> int: inventory = _load_inventory(paths.inventory_path) inventory_vacuums = _extract_inventory_vacuums( - ServerContext( - api_host=config.network.stack_fqdn, - mqtt_host=config.network.stack_fqdn, - wood_host=config.network.stack_fqdn, - region=config.network.region, - protocol_login_email=config.admin.protocol_login_email, - localkey=str(runtime_credentials.bootstrap_value("localkey", "") or ""), - duid=str(runtime_credentials.bootstrap_value("duid", "") or ""), - mqtt_usr=str(runtime_credentials.bootstrap_value("mqtt_usr", "") or ""), - mqtt_passwd=str(runtime_credentials.bootstrap_value("mqtt_passwd", "") or ""), - mqtt_clientid=str(runtime_credentials.bootstrap_value("mqtt_clientid", "") or ""), - https_port=config.network.advertised_https_port, - mqtt_tls_port=config.network.advertised_mqtt_tls_port, - http_jsonl=paths.http_jsonl_path, - mqtt_jsonl=paths.mqtt_jsonl_path, - loggers={}, - key_state_file=paths.device_key_state_path, - bootstrap_encryption_enabled=False, - runtime_state=None, - runtime_credentials=runtime_credentials, - timezone=config.network.timezone or None, - ), + _build_runtime_context(config, paths, runtime_credentials), inventory, ) inventory_by_duid = {str(item.get("duid") or "").strip(): item for item in inventory_vacuums} @@ -2352,4 +2432,17 @@ def build_arg_parser() -> argparse.ArgumentParser: default=[], help="Explicit DID=DUID mapping to repair existing state; can be supplied multiple times", ) + + camera_activate = subparsers.add_parser( + "camera-activate", + help="Arm the local two-key camera activation and wait for the Power press", + ) + camera_activate.add_argument("--config", default="config.toml") + camera_activate.add_argument("--duid", default="", help="Vacuum to activate; defaults to the only onboarded one") + camera_activate.add_argument( + "--timeout", + type=float, + default=90.0, + help="Seconds to wait for the Power press after arming", + ) return parser diff --git a/tests/test_camera_activation.py b/tests/test_camera_activation.py new file mode 100644 index 00000000..c8a18554 --- /dev/null +++ b/tests/test_camera_activation.py @@ -0,0 +1,95 @@ +"""Tests for the local two-key camera activation helper. + +Models such as the Saros 10R and QX Revo Ultra 2 only enable remote viewing after +``set_camera_status`` is written with the two request bits (bit 5, then bit 12) and +the Power button is pressed on the robot. These tests pin the bit arithmetic and +the "did the monitor bit appear" poll loop without touching MQTT. +""" + +from __future__ import annotations + +import asyncio + +from roborock.roborock_typing import RoborockCommand + +from roborock_local_server.camera import ( + activate_camera, + activation_writes, + monitor_enabled, +) + + +class _FakeCameraClient: + """Records ``set_camera_status`` writes and replays ``get_camera_status`` reads.""" + + def __init__(self, statuses: list[int]) -> None: + self._statuses = list(statuses) + self.writes: list[object] = [] + + async def send_command(self, command: RoborockCommand, params: object = None) -> list[object]: + if command == RoborockCommand.GET_CAMERA_STATUS: + value = self._statuses.pop(0) if len(self._statuses) > 1 else self._statuses[0] + return [value] + self.writes.append(params) + return ["ok"] + + +def test_activation_writes_arm_the_request_bits_in_order() -> None: + assert activation_writes(385) == [417, 4513] + + +def test_activation_writes_keep_bits_that_are_already_set() -> None: + assert activation_writes(419) == [419, 4515] + + +def test_monitor_enabled_reads_the_view_authorization_bit() -> None: + assert monitor_enabled(8613) + assert not monitor_enabled(4513) + assert not monitor_enabled(417) + + +def test_already_activated_robot_is_not_rewritten() -> None: + client = _FakeCameraClient([8613]) + + result = asyncio.run(activate_camera(client, timeout_seconds=0.05)) + + assert result.activated + assert result.initial_status == 8613 + assert client.writes == [] + + +def test_activation_succeeds_when_the_robot_sets_the_monitor_bit() -> None: + client = _FakeCameraClient([417, 4513, 8613]) + + result = asyncio.run(activate_camera(client, timeout_seconds=1.0, poll_interval_seconds=0.01)) + + assert result.activated + assert result.initial_status == 417 + assert result.final_status == 8613 + assert client.writes == [[417], [4513]] + + +def test_activation_reports_timeout_when_power_is_not_pressed() -> None: + client = _FakeCameraClient([417]) + + result = asyncio.run(activate_camera(client, timeout_seconds=0.05, poll_interval_seconds=0.01)) + + assert not result.activated + assert result.initial_status == 417 + assert result.final_status == 417 + assert client.writes == [[417], [4513]] + + +def test_cli_exposes_camera_activate() -> None: + # Importing the backend bridge puts the bundled_backend dir on sys.path. + import roborock_local_server.backend as backend # noqa: F401 + + from roborock_local_server.server import build_arg_parser + + args = build_arg_parser().parse_args( + ["camera-activate", "--config", "config.toml", "--duid", "1103842126955", "--timeout", "30"] + ) + + assert args.command == "camera-activate" + assert args.duid == "1103842126955" + assert args.timeout == 30 diff --git a/tests/test_native_schedule_sync.py b/tests/test_native_schedule_sync.py index 00a0f78e..28fa794f 100644 --- a/tests/test_native_schedule_sync.py +++ b/tests/test_native_schedule_sync.py @@ -159,7 +159,7 @@ async def send_command(self, command, params): async def close(self): robot.calls.append("close") - self.network = patch.dict("sys.modules", {"shared.routine_runner": SimpleNamespace(_RoutineMqttClient=Client)}) + self.network = patch.dict("sys.modules", {"shared.routine_runner": SimpleNamespace(RoutineMqttClient=Client)}) self.network.start() self.addCleanup(self.network.stop) diff --git a/tests/test_routine_runner.py b/tests/test_routine_runner.py index 894c35d9..208c5ea5 100644 --- a/tests/test_routine_runner.py +++ b/tests/test_routine_runner.py @@ -252,7 +252,7 @@ async def send_command(self, command, params=None): async def wait_for_step_complete(self) -> None: return None - monkeypatch.setattr(routine_runner_module, "_RoutineMqttClient", FakeRoutineClient) + monkeypatch.setattr(routine_runner_module, "RoutineMqttClient", FakeRoutineClient) runner = RoutineRunner(_test_context(tmp_path)) await runner._run_scene(scene=current_scene, steps=parse_scene_steps(current_scene)) @@ -302,7 +302,7 @@ async def send_command(self, command, params=None): async def wait_for_step_complete(self) -> None: return None - monkeypatch.setattr(routine_runner_module, "_RoutineMqttClient", FakeRoutineClient) + monkeypatch.setattr(routine_runner_module, "RoutineMqttClient", FakeRoutineClient) runner = RoutineRunner(_test_context(tmp_path)) await runner._run_scene(scene=scene, steps=parse_scene_steps(scene)) @@ -425,7 +425,7 @@ async def wait_for_step_complete(self) -> None: async def wait_for_dock_settle(self, *, initial_delay_seconds=15.0) -> None: settle_calls.append(float(initial_delay_seconds)) - monkeypatch.setattr(routine_runner_module, "_RoutineMqttClient", FakeRoutineClient) + monkeypatch.setattr(routine_runner_module, "RoutineMqttClient", FakeRoutineClient) runner = RoutineRunner(_test_context(tmp_path)) await runner._run_scene(scene=scene, steps=parse_scene_steps(scene)) @@ -452,7 +452,7 @@ async def wait_for_dock_settle(self, *, initial_delay_seconds=15.0) -> None: class _ScriptedStatusClient: - """Minimal stand-in for _RoutineMqttClient that replays a status sequence.""" + """Minimal stand-in for RoutineMqttClient that replays a status sequence.""" def __init__(self, status_sequence: list[dict]) -> None: self._statuses = [StatusV2.from_dict(s) for s in status_sequence] @@ -472,10 +472,10 @@ async def send_command(self, command: RoborockCommand, params=None) -> None: _ScriptedStatusClient.wait_for_step_complete = ( - routine_runner_module._RoutineMqttClient.wait_for_step_complete + routine_runner_module.RoutineMqttClient.wait_for_step_complete ) _ScriptedStatusClient.wait_for_dock_settle = ( - routine_runner_module._RoutineMqttClient.wait_for_dock_settle + routine_runner_module.RoutineMqttClient.wait_for_dock_settle ) @@ -795,7 +795,7 @@ async def send_command(self, command, params=None): async def wait_for_step_complete(self) -> None: return None - monkeypatch.setattr(routine_runner_module, "_RoutineMqttClient", FakeRoutineClient) + monkeypatch.setattr(routine_runner_module, "RoutineMqttClient", FakeRoutineClient) runner = RoutineRunner(_test_context(tmp_path)) await runner._run_scene(scene=scene, steps=parse_scene_steps(scene)) @@ -844,7 +844,7 @@ async def send_command(self, command, params=None): async def wait_for_step_complete(self) -> None: return None - monkeypatch.setattr(routine_runner_module, "_RoutineMqttClient", FakeRoutineClient) + monkeypatch.setattr(routine_runner_module, "RoutineMqttClient", FakeRoutineClient) runner = RoutineRunner(_test_context(tmp_path)) await runner._run_scene(scene=scene, steps=parse_scene_steps(scene)) @@ -877,7 +877,7 @@ async def send_command(self, command, params=None): async def wait_for_step_complete(self) -> None: return None - monkeypatch.setattr(routine_runner_module, "_RoutineMqttClient", FakeRoutineClient) + monkeypatch.setattr(routine_runner_module, "RoutineMqttClient", FakeRoutineClient) runner = RoutineRunner(_test_context(tmp_path)) with pytest.raises(RoborockUnsupportedFeature): @@ -915,7 +915,7 @@ async def send_command(self, command, params=None): async def wait_for_step_complete(self) -> None: return None - monkeypatch.setattr(routine_runner_module, "_RoutineMqttClient", FakeRoutineClient) + monkeypatch.setattr(routine_runner_module, "RoutineMqttClient", FakeRoutineClient) scene = _scene(scene_id=1, device_id="6HL2zfniaoYYV01CkVuhkO", name="Schedule 1") runner = RoutineRunner(_test_context(tmp_path)) return sent_commands, asyncio.run(runner._run_steps(scene=scene, steps=[step], sync_scene_tids=False)) @@ -992,7 +992,7 @@ async def send_command(self, command, params=None): async def wait_for_step_complete(self) -> None: return None - monkeypatch.setattr(routine_runner_module, "_RoutineMqttClient", FakeRoutineClient) + monkeypatch.setattr(routine_runner_module, "RoutineMqttClient", FakeRoutineClient) scene = _scene(scene_id=1, device_id="6HL2zfniaoYYV01CkVuhkO", name="Schedule 1") runner = RoutineRunner(_test_context(tmp_path)) with pytest.raises(RoborockException): @@ -1051,7 +1051,7 @@ async def close(self): pass async def send_command(self, command, params=None): sent.append(command) return timers - monkeypatch.setattr(routine_runner_module, "_RoutineMqttClient", Client) + monkeypatch.setattr(routine_runner_module, "RoutineMqttClient", Client) runner = RoutineRunner(_test_context(tmp_path)) scene = _scene(scene_id=1, device_id="6HL2zfniaoYYV01CkVuhkO", name="Schedule 1") asyncio.run(runner._run_steps(scene=scene, steps=[_server_start_step(name="timer")], sync_scene_tids=False)) @@ -1068,7 +1068,7 @@ async def close(self): closed.append(True) async def send_command(self, command, params=None): sent.append(command) raise RoutineExecutionError("timed out") - monkeypatch.setattr(routine_runner_module, "_RoutineMqttClient", Client) + monkeypatch.setattr(routine_runner_module, "RoutineMqttClient", Client) runner = RoutineRunner(_test_context(tmp_path)) scene = _scene(scene_id=1, device_id="6HL2zfniaoYYV01CkVuhkO", name="Schedule 1") with pytest.raises(RoutineExecutionError, match="timed out"): @@ -1099,7 +1099,7 @@ async def send_command(self, command, params=None): elif change == "delete": schedule_store.delete_job(ctx, duid, 1) return [["timer", "on", 1]] - monkeypatch.setattr(routine_runner_module, "_RoutineMqttClient", Client) + monkeypatch.setattr(routine_runner_module, "RoutineMqttClient", Client) deadline = datetime.now(timezone.utc) + timedelta(seconds=-1 if change == "expire" else 60) runner = RoutineRunner(ctx) asyncio.run(runner._run_steps(scene=_scene(scene_id=1, device_id=duid, name="Schedule 1"), @@ -1127,7 +1127,7 @@ async def send_command(self, command, params=None): return timers return ["ok"] - monkeypatch.setattr(routine_runner_module, "_RoutineMqttClient", Client) + monkeypatch.setattr(routine_runner_module, "RoutineMqttClient", Client) runner = RoutineRunner(_test_context(tmp_path)) scene = _scene(scene_id=1, device_id="6HL2zfniaoYYV01CkVuhkO", name="Schedule 1") asyncio.run(runner._run_steps(scene=scene, steps=[_server_start_step(name="1765735413736")], sync_scene_tids=False)) diff --git a/tests/test_schedules.py b/tests/test_schedules.py index 9a5a168e..f5a5b2c1 100644 --- a/tests/test_schedules.py +++ b/tests/test_schedules.py @@ -312,7 +312,7 @@ async def send_command(self, command, params): async def close(self): pass - monkeypatch.setattr(routine_runner, "_RoutineMqttClient", Client) + monkeypatch.setattr(routine_runner, "RoutineMqttClient", Client) return robot