|
| 1 | +"""RTK status command (mowers only).""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import TYPE_CHECKING, Any |
| 6 | + |
| 7 | +from deebot_client.events.rtk import RtkBaseStation, RtkEvent |
| 8 | +from deebot_client.message import HandlingResult, MessageBodyDataDict |
| 9 | + |
| 10 | +from .common import JsonCommandWithMessageHandling |
| 11 | + |
| 12 | +if TYPE_CHECKING: |
| 13 | + from deebot_client.event_bus import EventBus |
| 14 | + |
| 15 | + |
| 16 | +def _coerce_base_station(raw: dict[str, Any]) -> RtkBaseStation: |
| 17 | + return RtkBaseStation( |
| 18 | + serial_number=str(raw.get("sn", "")), |
| 19 | + satellites_visible=int(raw.get("star", 0) or 0), |
| 20 | + firmware=raw.get("version"), |
| 21 | + state=raw.get("state"), |
| 22 | + mode=raw.get("mode"), |
| 23 | + ) |
| 24 | + |
| 25 | + |
| 26 | +class GetRtk(JsonCommandWithMessageHandling, MessageBodyDataDict): |
| 27 | + r"""Get RTK status command for mower devices. |
| 28 | +
|
| 29 | + Sends ``getRTK`` to the device and notifies a :class:`RtkEvent` with |
| 30 | + the parsed response. The cloud payload is shaped like this (sample |
| 31 | + captured from a GOAT A1600 RTK on firmware 1.15.13):: |
| 32 | +
|
| 33 | + { |
| 34 | + "result": 0, |
| 35 | + "rtks": [ |
| 36 | + {"sn": "908276", "star": 30, "state": 0, "mode": 0, |
| 37 | + "version": "...,QD302 1.3.8,...,QD302 1.3.1"} |
| 38 | + ], |
| 39 | + "observations": { |
| 40 | + "solStat": 0, "poseType": 50, |
| 41 | + "roverId": "908336", "roverSvs": 35, "roverSolnSvs": 30, |
| 42 | + "roverSignalRate": 44, "roverSignalScore": 90, |
| 43 | + "roverOcclusionRate": 8, |
| 44 | + "baseStnId": "\\"1544\\"", "baseSolnSvs": 29, |
| 45 | + "baseSignalRate": 45, "baseSignalScore": 94, |
| 46 | + "baseOcclusionRate": 24 |
| 47 | + } |
| 48 | + } |
| 49 | + """ |
| 50 | + |
| 51 | + NAME = "getRTK" |
| 52 | + |
| 53 | + @classmethod |
| 54 | + def _handle_body_data_dict( |
| 55 | + cls, event_bus: EventBus, data: dict[str, Any] |
| 56 | + ) -> HandlingResult: |
| 57 | + observations = data.get("observations") or {} |
| 58 | + if not observations: |
| 59 | + return HandlingResult.analyse() |
| 60 | + |
| 61 | + rtks_raw = data.get("rtks") or [] |
| 62 | + base_stations = [ |
| 63 | + _coerce_base_station(r) for r in rtks_raw if isinstance(r, dict) |
| 64 | + ] |
| 65 | + |
| 66 | + event_bus.notify( |
| 67 | + RtkEvent( |
| 68 | + rover_serial_number=str(observations.get("roverId", "")), |
| 69 | + rover_satellites_visible=int(observations.get("roverSvs", 0) or 0), |
| 70 | + rover_satellites_used=int(observations.get("roverSolnSvs", 0) or 0), |
| 71 | + base_satellites_used=int(observations.get("baseSolnSvs", 0) or 0), |
| 72 | + rover_signal_score=int(observations.get("roverSignalScore", 0) or 0), |
| 73 | + base_signal_score=int(observations.get("baseSignalScore", 0) or 0), |
| 74 | + rover_occlusion_rate=int( |
| 75 | + observations.get("roverOcclusionRate", 0) or 0 |
| 76 | + ), |
| 77 | + base_occlusion_rate=int(observations.get("baseOcclusionRate", 0) or 0), |
| 78 | + base_stations=base_stations, |
| 79 | + base_station_id=observations.get("baseStnId"), |
| 80 | + solution_status=observations.get("solStat"), |
| 81 | + pose_type=observations.get("poseType"), |
| 82 | + ) |
| 83 | + ) |
| 84 | + return HandlingResult.success() |
0 commit comments