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
@@ -46,11 +46,16 @@ class XmlCommandWithMessageHandling(
46
46
47
47
@classmethod
48
48
@abstractmethod
49
- def _handle_xml (cls , event_bus : EventBus , xml : Element ) -> HandlingResult :
49
+ def _handle_xml (cls , _ : EventBus , xml : Element ) -> HandlingResult :
50
50
"""Handle xml message and notify the correct event subscribers.
51
51
52
52
:return: A message response
53
53
"""
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 )
54
59
55
60
@classmethod
56
61
def _handle_str (cls , event_bus : EventBus , message : str ) -> HandlingResult :
@@ -60,3 +65,27 @@ def _handle_str(cls, event_bus: EventBus, message: str) -> HandlingResult:
60
65
"""
61
66
xml = ElementTree .fromstring (message )
62
67
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