Skip to content

Commit aa14cca

Browse files
committed
Integrate PR feedback
1 parent cdda9e3 commit aa14cca

2 files changed

Lines changed: 19 additions & 23 deletions

File tree

deebot_client/commands/xml/pos.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from typing import TYPE_CHECKING
66

7-
from deebot_client.events import Position, PositionsEvent
87
from deebot_client.message import HandlingResult
8+
from deebot_client.messages.xml import Pos
99
from deebot_client.rs.map import PositionType
1010

1111
from .common import XmlCommandWithMessageHandling
@@ -16,25 +16,7 @@
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"

deebot_client/messages/xml/pos.py

Lines changed: 16 additions & 2 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.commands.xml.pos import PosParser
7+
from deebot_client.events import Position, PositionsEvent
88
from deebot_client.message import HandlingResult
99
from deebot_client.messages.xml.common import XmlMessage
1010
from deebot_client.rs.map import PositionType
@@ -15,7 +15,7 @@
1515
from deebot_client.event_bus import EventBus
1616

1717

18-
class Pos(XmlMessage, PosParser):
18+
class Pos(XmlMessage):
1919
"""Pos message."""
2020

2121
NAME = "Pos"
@@ -26,3 +26,17 @@ def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
2626
return HandlingResult.analyse()
2727

2828
return cls._parse_xml(PositionType.DEEBOT, event_bus, xml)
29+
30+
@classmethod
31+
def _parse_xml(
32+
cls, position_type: PositionType, event_bus: EventBus, xml: Element
33+
) -> HandlingResult:
34+
"""Handle xml message and notify the correct event subscribers."""
35+
if (p := xml.attrib.get("p")) and (xml.attrib.get("valid", "1")) == "1":
36+
p_x, p_y = p.split(",", 2)
37+
p_a = xml.attrib.get("a", 0)
38+
position = Position(type=position_type, x=int(p_x), y=int(p_y), a=int(p_a))
39+
event_bus.notify(PositionsEvent(positions=[position]))
40+
return HandlingResult.success()
41+
42+
return HandlingResult.analyse()

0 commit comments

Comments
 (0)