44
55from typing import TYPE_CHECKING
66
7- from deebot_client .events import Position , PositionsEvent
87from deebot_client .message import HandlingResult
8+ from deebot_client .messages .xml import Pos
99from deebot_client .rs .map import PositionType
1010
1111from .common import XmlCommandWithMessageHandling
1616 from deebot_client .event_bus import EventBus
1717
1818
19- class PosParser :
20- """Support class for producing Pos events."""
21-
22- @classmethod
23- def _parse_xml (
24- cls , position_type : PositionType , event_bus : EventBus , xml : Element
25- ) -> HandlingResult :
26- """Handle xml message and notify the correct event subscribers."""
27- if (p := xml .attrib .get ("p" )) and (xml .attrib .get ("valid" , "1" )) == "1" :
28- p_x , p_y = p .split ("," , 2 )
29- p_a = xml .attrib .get ("a" , 0 )
30- position = Position (type = position_type , x = int (p_x ), y = int (p_y ), a = int (p_a ))
31- event_bus .notify (PositionsEvent (positions = [position ]))
32- return HandlingResult .success ()
33-
34- return HandlingResult .analyse ()
35-
36-
37- class GetPos (XmlCommandWithMessageHandling , PosParser ):
19+ class GetPos (XmlCommandWithMessageHandling , Pos ):
3820 """GetPos command."""
3921
4022 NAME = "GetPos"
@@ -51,7 +33,7 @@ def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
5133 return cls ._parse_xml (PositionType .DEEBOT , event_bus , xml )
5234
5335
54- class GetChargerPos (XmlCommandWithMessageHandling , PosParser ):
36+ class GetChargerPos (XmlCommandWithMessageHandling , Pos ):
5537 """GetChargerPos command."""
5638
5739 NAME = "GetChargerPos"
0 commit comments