Skip to content

Commit

Permalink
XML add ExecuteCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
flubshi authored and pentesttkr committed Jan 5, 2025
1 parent 911d851 commit 5baf707
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions deebot_client/commands/xml/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

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

from deebot_client.command import Command, CommandWithMessageHandling
from deebot_client.command import Command, CommandWithMessageHandling, SetCommand
from deebot_client.const import DataType
from deebot_client.logging_filter import get_logger
from deebot_client.message import HandlingResult, MessageStr
from deebot_client.message import HandlingResult, MessageStr, HandlingState

if TYPE_CHECKING:
from deebot_client.event_bus import EventBus
Expand Down Expand Up @@ -46,11 +46,16 @@ class XmlCommandWithMessageHandling(

@classmethod
@abstractmethod
def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
def _handle_xml(cls, _: EventBus, xml: Element) -> HandlingResult:
"""Handle xml message and notify the correct event subscribers.
:return: A message response
"""
if xml.attrib.get("ret") == "ok":
return HandlingResult.success()

Check warning on line 55 in deebot_client/commands/xml/common.py

View check run for this annotation

Codecov / codecov/patch

deebot_client/commands/xml/common.py#L55

Added line #L55 was not covered by tests

_LOGGER.warning('Command "%s" was not successfully. xml response: %s', cls.NAME, xml)
return HandlingResult(HandlingState.FAILED)

Check warning on line 58 in deebot_client/commands/xml/common.py

View check run for this annotation

Codecov / codecov/patch

deebot_client/commands/xml/common.py#L57-L58

Added lines #L57 - L58 were not covered by tests

@classmethod
def _handle_str(cls, event_bus: EventBus, message: str) -> HandlingResult:
Expand All @@ -60,3 +65,27 @@ def _handle_str(cls, event_bus: EventBus, message: str) -> HandlingResult:
"""
xml = ElementTree.fromstring(message)
return cls._handle_xml(event_bus, xml)


class ExecuteCommand(XmlCommandWithMessageHandling, ABC):
"""Command, which is executing something (ex. Charge)."""

@classmethod
def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
"""Handle message->xml and notify the correct event subscribers.
:return: A message response
"""
# Success event looks like <ctl ret='ok'/>
if xml.attrib.get("ret") == "ok":
return HandlingResult.success()

Check warning on line 81 in deebot_client/commands/xml/common.py

View check run for this annotation

Codecov / codecov/patch

deebot_client/commands/xml/common.py#L81

Added line #L81 was not covered by tests

_LOGGER.warning('Command "%s" was not successful. XML response: %s', cls.NAME, xml)
return HandlingResult(HandlingState.FAILED)

Check warning on line 84 in deebot_client/commands/xml/common.py

View check run for this annotation

Codecov / codecov/patch

deebot_client/commands/xml/common.py#L83-L84

Added lines #L83 - L84 were not covered by tests


class XmlSetCommand(ExecuteCommand, SetCommand, ABC):
"""Xml base set command.
Command needs to be linked to the "get" command, for handling (updating) the sensors.
"""

0 comments on commit 5baf707

Please sign in to comment.