|
5 | 5 | from typing import TYPE_CHECKING |
6 | 6 |
|
7 | 7 | from deebot_client.events import ( |
| 8 | + CleanJobStatus, |
8 | 9 | FanSpeedEvent, |
9 | 10 | FanSpeedLevel, |
10 | 11 | Position, |
11 | 12 | PositionsEvent, |
| 13 | + ReportStatsEvent, |
12 | 14 | StateEvent, |
| 15 | + StatsEvent, |
13 | 16 | ) |
14 | 17 | from deebot_client.logging_filter import get_logger |
15 | 18 | from deebot_client.message import HandlingResult |
@@ -81,14 +84,46 @@ class CleanReportServer(XmlMessage): |
81 | 84 | NAME = "CleanReportServer" |
82 | 85 |
|
83 | 86 | @classmethod |
84 | | - def _handle_xml(cls, _event_bus: EventBus, _xml: Element) -> HandlingResult: |
| 87 | + def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult: |
85 | 88 | """Handle xml message and notify the correct event subscribers. |
86 | 89 |
|
87 | 90 | b"<ctl ts='1744467262312' td='CleanReportServer' act='s' type='auto' cs='1134230540'/>" |
88 | 91 | b"<ctl ts='1744467393682' td='CleanReportServer' act='h' type='auto' sts='1744467262' cs='1134230540' area='1' last='76' mapCount='6'/>" |
89 | 92 |
|
90 | 93 | :return: A message response |
91 | 94 | """ |
| 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() |
92 | 127 | return HandlingResult.analyse() |
93 | 128 |
|
94 | 129 |
|
|
0 commit comments