Skip to content

Commit e6e6534

Browse files
committed
Handle MapTrace events
1 parent d0e3129 commit e6e6534

5 files changed

Lines changed: 50 additions & 16 deletions

File tree

deebot_client/messages/xml/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
CleanReportServer,
1313
CleanSt,
1414
)
15-
from deebot_client.messages.xml.map import MapP
15+
from deebot_client.messages.xml.map import MapP, Trace
1616
from deebot_client.messages.xml.pos import Pos
1717
from deebot_client.messages.xml.sleep import SleepStatus
1818
from deebot_client.messages.xml.water_info import WaterBoxInfo
@@ -30,6 +30,7 @@
3030
"MapP",
3131
"Pos",
3232
"SleepStatus",
33+
"Trace",
3334
"WaterBoxInfo",
3435
]
3536
# fmt: off
@@ -44,6 +45,7 @@
4445
MapP,
4546
Pos,
4647
SleepStatus,
48+
Trace,
4749
WaterBoxInfo,
4850
]
4951
# fmt: on

deebot_client/messages/xml/clean.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ def _handle_xml(cls, _event_bus: EventBus, _xml: Element) -> HandlingResult:
3939
4040
b"<ctl td='CleanSt' a='21' s='1743945874' l='1595' t='' type='auto'/>"
4141
42+
We currently ignore this message as we prefer to use CleanReport
4243
:return: A message response
4344
"""
44-
return HandlingResult.analyse()
45+
return HandlingResult.success()
4546

4647

4748
class CleanReport(XmlMessage):
@@ -93,29 +94,34 @@ def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
9394
:return: A message response
9495
"""
9596
event_reported = False
96-
if act := xml.attrib.get("act"):
97+
if (
98+
(act := xml.attrib.get("act")) is not None
99+
and (last := xml.attrib.get("last")) is not None
100+
and (area := xml.attrib.get("area")) is not None
101+
):
97102
clean_session = xml.attrib.get("cs")
98-
last = xml.attrib.get("last")
99-
area = xml.attrib.get("area")
100-
type = xml.attrib.get("type")
103+
clean_type = xml.attrib.get("type")
104+
101105
clean_action = CleanAction.from_xml(act)
102106
if clean_action == CleanAction.STOP:
103-
event_bus.notify(StatsEvent(area=area, time=last, type=type))
107+
event_bus.notify(
108+
StatsEvent(area=int(area), time=int(last), type=clean_type)
109+
)
104110
event_reported = True
105111
if clean_session:
106112
if clean_action == CleanAction.STOP:
107113
job_status = CleanJobStatus.FINISHED
108114
elif clean_action == CleanAction.START:
109115
job_status = CleanJobStatus.CLEANING
110116
elif clean_action == CleanAction.PAUSE:
111-
job_status = CleanJobStatus.PAUSED
117+
job_status = CleanJobStatus.MANUALLY_STOPPED
112118
else:
113119
job_status = CleanJobStatus.NO_STATUS
114120
event_bus.notify(
115121
ReportStatsEvent(
116-
area=area,
117-
time=last,
118-
type=type,
122+
area=int(area),
123+
time=int(last),
124+
type=clean_type,
119125
cleaning_id=clean_session,
120126
status=job_status,
121127
content=[],

deebot_client/messages/xml/map.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from typing import TYPE_CHECKING
66

7+
from deebot_client.events.map import MapTraceEvent
78
from deebot_client.message import HandlingResult
89
from deebot_client.messages.xml.common import XmlMessage
910

@@ -27,6 +28,31 @@ def _handle_xml(cls, _event_bus: EventBus, _xml: Element) -> HandlingResult:
2728
2829
b"<ctl td='MapP' i='1245233875' pid='27' p='XQAABAAQJwAAAABv/f//o7f/Rz5IFXI5YVG4kYRDU5g6Z4W8UflplyVyfWyHmYdt2YVgA/k3ENxVye1lEM...fqEp3pept9Re5qT0lZFDWpoFg4D51VXQopPSDLSo2ZpM/zQ4IAhvgWIKnp7zlwcd6Ekj7U2FnOTTAQeWq3DPT+MTrAVO2wL/6mmGODzk4hBtA/wjZzOujPgEA=='/>"
2930
31+
This is currently ignored as we prefer to pull map pieces
3032
:return: A message response
3133
"""
34+
return HandlingResult.success()
35+
36+
37+
class Trace(XmlMessage):
38+
"""Trace message."""
39+
40+
NAME = "trace"
41+
42+
@classmethod
43+
def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
44+
"""Handle xml message and notify the correct event subscribers.
45+
46+
Sample message:
47+
<ctl td='trace' trid='631369' tf='16' tt='17' tr='XQAABAAKAAAAAG0/wEAAA2cAS5AAAA=='/>
48+
49+
:return: A message response
50+
"""
51+
if (
52+
(tf := xml.attrib.get("tf"))
53+
and (tt := xml.attrib.get("tt"))
54+
and (tr := xml.attrib.get("tr"))
55+
):
56+
event_bus.notify(MapTraceEvent(start=int(tf), total=int(tt), data=tr))
57+
return HandlingResult.success()
3258
return HandlingResult.analyse()

deebot_client/messages/xml/sleep.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def _handle_xml(cls, _event_bus: EventBus, _xml: Element) -> HandlingResult:
2424
2525
b"<ctl ts='1744467249545' td='SleepStatus' st='0'/>"
2626
27+
We currently ignore this message
28+
2729
:return: A message response
2830
"""
29-
return HandlingResult.analyse()
31+
return HandlingResult.success()

deebot_client/messages/xml/water_info.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from typing import TYPE_CHECKING
66

7-
from deebot_client.events import WaterAmount, WaterInfoEvent
7+
from deebot_client.events import WaterInfoEvent
88
from deebot_client.message import HandlingResult
99
from deebot_client.messages.xml.common import XmlMessage
1010

@@ -28,7 +28,5 @@ def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
2828
if (on := xml.attrib.get("on")) is None:
2929
return HandlingResult.analyse()
3030

31-
event_bus.notify(
32-
WaterInfoEvent(amount=WaterAmount.HIGH, mop_attached=on != "0")
33-
)
31+
event_bus.notify(WaterInfoEvent(mop_attached=on != "0"))
3432
return HandlingResult.success()

0 commit comments

Comments
 (0)