Skip to content

Commit 5baf707

Browse files
flubshipentesttkr
authored andcommitted
XML add ExecuteCommand
1 parent 911d851 commit 5baf707

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

deebot_client/commands/xml/common.py

+32-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
from defusedxml import ElementTree # type: ignore[import-untyped]
1010

11-
from deebot_client.command import Command, CommandWithMessageHandling
11+
from deebot_client.command import Command, CommandWithMessageHandling, SetCommand
1212
from deebot_client.const import DataType
1313
from deebot_client.logging_filter import get_logger
14-
from deebot_client.message import HandlingResult, MessageStr
14+
from deebot_client.message import HandlingResult, MessageStr, HandlingState
1515

1616
if TYPE_CHECKING:
1717
from deebot_client.event_bus import EventBus
@@ -46,11 +46,16 @@ class XmlCommandWithMessageHandling(
4646

4747
@classmethod
4848
@abstractmethod
49-
def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
49+
def _handle_xml(cls, _: EventBus, xml: Element) -> HandlingResult:
5050
"""Handle xml message and notify the correct event subscribers.
5151
5252
:return: A message response
5353
"""
54+
if xml.attrib.get("ret") == "ok":
55+
return HandlingResult.success()
56+
57+
_LOGGER.warning('Command "%s" was not successfully. xml response: %s', cls.NAME, xml)
58+
return HandlingResult(HandlingState.FAILED)
5459

5560
@classmethod
5661
def _handle_str(cls, event_bus: EventBus, message: str) -> HandlingResult:
@@ -60,3 +65,27 @@ def _handle_str(cls, event_bus: EventBus, message: str) -> HandlingResult:
6065
"""
6166
xml = ElementTree.fromstring(message)
6267
return cls._handle_xml(event_bus, xml)
68+
69+
70+
class ExecuteCommand(XmlCommandWithMessageHandling, ABC):
71+
"""Command, which is executing something (ex. Charge)."""
72+
73+
@classmethod
74+
def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
75+
"""Handle message->xml and notify the correct event subscribers.
76+
77+
:return: A message response
78+
"""
79+
# Success event looks like <ctl ret='ok'/>
80+
if xml.attrib.get("ret") == "ok":
81+
return HandlingResult.success()
82+
83+
_LOGGER.warning('Command "%s" was not successful. XML response: %s', cls.NAME, xml)
84+
return HandlingResult(HandlingState.FAILED)
85+
86+
87+
class XmlSetCommand(ExecuteCommand, SetCommand, ABC):
88+
"""Xml base set command.
89+
90+
Command needs to be linked to the "get" command, for handling (updating) the sensors.
91+
"""

0 commit comments

Comments
 (0)