8
8
9
9
from defusedxml import ElementTree # type: ignore[import-untyped]
10
10
11
- from deebot_client .command import Command , CommandWithMessageHandling
11
+ from deebot_client .command import Command , CommandWithMessageHandling , SetCommand
12
12
from deebot_client .const import DataType
13
13
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
15
15
16
16
if TYPE_CHECKING :
17
17
from deebot_client .event_bus import EventBus
@@ -60,3 +60,27 @@ def _handle_str(cls, event_bus: EventBus, message: str) -> HandlingResult:
60
60
"""
61
61
xml = ElementTree .fromstring (message )
62
62
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