|
| 1 | +"""Map messages.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import TYPE_CHECKING |
| 6 | + |
| 7 | +from deebot_client.events.map import MapTraceEvent, MinorMapEvent |
| 8 | +from deebot_client.message import HandlingResult |
| 9 | +from deebot_client.messages.xml.common import XmlMessage |
| 10 | + |
| 11 | +if TYPE_CHECKING: |
| 12 | + from xml.etree.ElementTree import Element |
| 13 | + |
| 14 | + from deebot_client.event_bus import EventBus |
| 15 | + |
| 16 | + |
| 17 | +class MapP(XmlMessage): |
| 18 | + """MapP message.""" |
| 19 | + |
| 20 | + NAME = "MapP" |
| 21 | + |
| 22 | + @classmethod |
| 23 | + def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult: |
| 24 | + """Handle xml message and notify the correct event subscribers. |
| 25 | +
|
| 26 | + Sample message: |
| 27 | + b"<ctl td='MapP' i='1245233875' pid='27' p='XQAABAAQJwAAAABv/f//o7f/Rz5IFXI5YVG4kYRDU5g6Z4W8UflplyVyfWyHmYdt2YVgA/k3ENxVye1lEM...fqEp3pept9Re5qT0lZFDWpoFg4D51VXQopPSDLSo2ZpM/zQ4IAhvgWIKnp7zlwcd6Ekj7U2FnOTTAQeWq3DPT+MTrAVO2wL/6mmGODzk4hBtA/wjZzOujPgEA=='/>" |
| 28 | + :return: A message response |
| 29 | + """ |
| 30 | + if ( |
| 31 | + (pid := xml.attrib.get("pid")) |
| 32 | + and (piece := xml.attrib.get("p")) |
| 33 | + and pid.isdecimal() |
| 34 | + ): |
| 35 | + event_bus.notify(MinorMapEvent(index=int(pid), value=piece)) |
| 36 | + return HandlingResult.success() |
| 37 | + |
| 38 | + return HandlingResult.analyse() |
| 39 | + |
| 40 | + |
| 41 | +class Trace(XmlMessage): |
| 42 | + """Trace message.""" |
| 43 | + |
| 44 | + NAME = "trace" |
| 45 | + |
| 46 | + @classmethod |
| 47 | + def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult: |
| 48 | + """Handle xml message and notify the correct event subscribers. |
| 49 | +
|
| 50 | + Sample message: |
| 51 | + <ctl td='trace' trid='631369' tf='16' tt='17' tr='XQAABAAKAAAAAG0/wEAAA2cAS5AAAA=='/> |
| 52 | + :return: A message response |
| 53 | + """ |
| 54 | + if ( |
| 55 | + (tf := xml.attrib.get("tf")) |
| 56 | + and tf.isdecimal() |
| 57 | + and (tt := xml.attrib.get("tt")) |
| 58 | + and tt.isdecimal() |
| 59 | + and (tr := xml.attrib.get("tr")) |
| 60 | + ): |
| 61 | + event_bus.notify(MapTraceEvent(start=int(tf), total=int(tt), data=tr)) |
| 62 | + return HandlingResult.success() |
| 63 | + return HandlingResult.analyse() |
0 commit comments