88
99from 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
1212from deebot_client .const import DataType
1313from 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
1616if TYPE_CHECKING :
1717 from deebot_client .event_bus import EventBus
@@ -34,7 +34,8 @@ def _get_payload(self) -> str:
3434 element = ctl_element = Element ("ctl" )
3535
3636 if len (self ._args ) > 0 :
37- if self .has_sub_element :
37+ # FIXME TypeError: 'classmethod' object is not callable
38+ if False and self .has_sub_element :
3839 element = SubElement (element , self .name .lower ())
3940
4041 if isinstance (self ._args , dict ):
@@ -65,3 +66,27 @@ def _handle_str(cls, event_bus: EventBus, message: str) -> HandlingResult:
6566 """
6667 xml = ElementTree .fromstring (message )
6768 return cls ._handle_xml (event_bus , xml )
69+
70+
71+ class ExecuteCommand (XmlCommandWithMessageHandling , ABC ):
72+ """Command, which is executing something (ex. Charge)."""
73+
74+ @classmethod
75+ def _handle_xml (cls , event_bus : EventBus , xml : Element ) -> HandlingResult :
76+ """Handle message->xml and notify the correct event subscribers.
77+
78+ :return: A message response
79+ """
80+ # Success event looks like <ctl ret='ok'/>
81+ if xml .attrib .get ("ret" ) == "ok" :
82+ return HandlingResult .success ()
83+
84+ _LOGGER .warning ('Command "%s" was not successful. XML response: %s' , cls .name , xml )
85+ return HandlingResult (HandlingState .FAILED )
86+
87+
88+ class XmlSetCommand (ExecuteCommand , SetCommand , ABC ):
89+ """Xml base set command.
90+
91+ Command needs to be linked to the "get" command, for handling (updating) the sensors.
92+ """
0 commit comments