Skip to content

Commit e46f8e5

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

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

deebot_client/commands/xml/common.py

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

0 commit comments

Comments
 (0)