Skip to content

Commit 65dd4d9

Browse files
committed
Add decoding for ReportStatsEvent
1 parent 6192e02 commit 65dd4d9

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

deebot_client/hardware/deebot/2pv572.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
play_sound=CapabilityExecute(PlaySound),
9393
state=CapabilityEvent(StateEvent, [GetChargeState(), GetCleanState()]),
9494
stats=CapabilityStats(
95-
clean=CapabilityEvent(StatsEvent, [GetCleanSum()]),
95+
clean=CapabilityEvent(StatsEvent, []),
9696
report=CapabilityEvent(ReportStatsEvent, []),
9797
total=CapabilityEvent(TotalStatsEvent, [GetCleanSum()]),
9898
),

deebot_client/messages/xml/clean.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
from typing import TYPE_CHECKING
66

77
from deebot_client.events import (
8+
CleanJobStatus,
89
FanSpeedEvent,
910
FanSpeedLevel,
1011
Position,
1112
PositionsEvent,
13+
ReportStatsEvent,
1214
StateEvent,
15+
StatsEvent,
1316
)
1417
from deebot_client.logging_filter import get_logger
1518
from deebot_client.message import HandlingResult
@@ -81,14 +84,46 @@ class CleanReportServer(XmlMessage):
8184
NAME = "CleanReportServer"
8285

8386
@classmethod
84-
def _handle_xml(cls, _event_bus: EventBus, _xml: Element) -> HandlingResult:
87+
def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
8588
"""Handle xml message and notify the correct event subscribers.
8689
8790
b"<ctl ts='1744467262312' td='CleanReportServer' act='s' type='auto' cs='1134230540'/>"
8891
b"<ctl ts='1744467393682' td='CleanReportServer' act='h' type='auto' sts='1744467262' cs='1134230540' area='1' last='76' mapCount='6'/>"
8992
9093
:return: A message response
9194
"""
95+
event_reported = False
96+
if act := xml.attrib.get("act"):
97+
clean_session = xml.attrib.get("cs")
98+
last = xml.attrib.get("last")
99+
area = xml.attrib.get("area")
100+
type = xml.attrib.get("type")
101+
clean_action = CleanAction.from_xml(act)
102+
if clean_action == CleanAction.STOP:
103+
event_bus.notify(StatsEvent(area=area, time=last, type=type))
104+
event_reported = True
105+
if clean_session:
106+
if clean_action == CleanAction.STOP:
107+
job_status = CleanJobStatus.FINISHED
108+
elif clean_action == CleanAction.START:
109+
job_status = CleanJobStatus.CLEANING
110+
elif clean_action == CleanAction.PAUSE:
111+
job_status = CleanJobStatus.PAUSED
112+
else:
113+
job_status = CleanJobStatus.NO_STATUS
114+
event_bus.notify(
115+
ReportStatsEvent(
116+
area=area,
117+
time=last,
118+
type=type,
119+
cleaning_id=clean_session,
120+
status=job_status,
121+
content=[],
122+
)
123+
)
124+
event_reported = True
125+
if event_reported:
126+
return HandlingResult.success()
92127
return HandlingResult.analyse()
93128

94129

0 commit comments

Comments
 (0)