From 7aef39dbd133b7479a5fc60fa2ce9fdd60116ba6 Mon Sep 17 00:00:00 2001
From: flubshi <4031504+flubshi@users.noreply.github.com>
Date: Wed, 11 Sep 2024 22:15:04 +0200
Subject: [PATCH 1/6] Add XML command "PlaySound"
---
deebot_client/commands/xml/__init__.py | 3 +++
deebot_client/commands/xml/play_sound.py | 14 ++++++++++++++
2 files changed, 17 insertions(+)
create mode 100644 deebot_client/commands/xml/play_sound.py
diff --git a/deebot_client/commands/xml/__init__.py b/deebot_client/commands/xml/__init__.py
index d16c8c576..73064e85f 100644
--- a/deebot_client/commands/xml/__init__.py
+++ b/deebot_client/commands/xml/__init__.py
@@ -9,6 +9,7 @@
from .charge_state import GetChargeState
from .error import GetError
from .fan_speed import GetFanSpeed
+from .play_sound import PlaySound
from .pos import GetPos
from .stats import GetCleanSum
@@ -21,12 +22,14 @@
"GetError",
"GetFanSpeed",
"GetPos",
+ "PlaySound",
]
# fmt: off
# ordered by file asc
_COMMANDS: list[type[XmlCommand]] = [
GetError,
+ PlaySound,
]
# fmt: on
diff --git a/deebot_client/commands/xml/play_sound.py b/deebot_client/commands/xml/play_sound.py
new file mode 100644
index 000000000..19eff15d1
--- /dev/null
+++ b/deebot_client/commands/xml/play_sound.py
@@ -0,0 +1,14 @@
+"""Play sound commands."""
+
+from __future__ import annotations
+
+from .common import ExecuteCommand
+
+
+class PlaySound(ExecuteCommand):
+ """Play sound command."""
+
+ name = "PlaySound"
+
+ def __init__(self) -> None:
+ super().__init__({"sid": "30"})
From 911d851736071d7d0fcd0ec250f5b89a2885ee91 Mon Sep 17 00:00:00 2001
From: flubshi <4031504+flubshi@users.noreply.github.com>
Date: Sun, 5 Jan 2025 11:55:49 +0100
Subject: [PATCH 2/6] XML Command PlaySound: Fix name field
---
deebot_client/commands/xml/play_sound.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/deebot_client/commands/xml/play_sound.py b/deebot_client/commands/xml/play_sound.py
index 19eff15d1..31eaf6be9 100644
--- a/deebot_client/commands/xml/play_sound.py
+++ b/deebot_client/commands/xml/play_sound.py
@@ -8,7 +8,7 @@
class PlaySound(ExecuteCommand):
"""Play sound command."""
- name = "PlaySound"
+ NAME = "PlaySound"
def __init__(self) -> None:
super().__init__({"sid": "30"})
From e46f8e553b671b749224cd41341c55cc0d9b82ec Mon Sep 17 00:00:00 2001
From: flubshi <4031504+flubshi@users.noreply.github.com>
Date: Sun, 5 Jan 2025 11:56:48 +0100
Subject: [PATCH 3/6] XML add ExecuteCommand
---
deebot_client/commands/xml/common.py | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/deebot_client/commands/xml/common.py b/deebot_client/commands/xml/common.py
index bc04d3d9c..74f3a9218 100644
--- a/deebot_client/commands/xml/common.py
+++ b/deebot_client/commands/xml/common.py
@@ -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
@@ -60,3 +60,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, _: EventBus, xml: Element) -> HandlingResult:
+ """Handle message->xml and notify the correct event subscribers.
+
+ :return: A message response
+ """
+ # Success event looks like
+ if xml.attrib.get("ret") == "ok":
+ return HandlingResult.success()
+
+ _LOGGER.warning('Command "%s" was not successful. XML response: %s', cls.NAME, xml)
+ return HandlingResult(HandlingState.FAILED)
+
+
+class XmlSetCommand(ExecuteCommand, SetCommand, ABC):
+ """Xml base set command.
+
+ Command needs to be linked to the "get" command, for handling (updating) the sensors.
+ """
\ No newline at end of file
From 210b2567284adfd551c3c07b6e948364865c1896 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Sun, 5 Jan 2025 11:22:17 +0000
Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---
deebot_client/commands/xml/common.py | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/deebot_client/commands/xml/common.py b/deebot_client/commands/xml/common.py
index 74f3a9218..ac026df71 100644
--- a/deebot_client/commands/xml/common.py
+++ b/deebot_client/commands/xml/common.py
@@ -11,7 +11,7 @@
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, HandlingState
+from deebot_client.message import HandlingResult, HandlingState, MessageStr
if TYPE_CHECKING:
from deebot_client.event_bus import EventBus
@@ -75,7 +75,9 @@ def _handle_xml(cls, _: EventBus, xml: Element) -> HandlingResult:
if xml.attrib.get("ret") == "ok":
return HandlingResult.success()
- _LOGGER.warning('Command "%s" was not successful. XML response: %s', cls.NAME, xml)
+ _LOGGER.warning(
+ 'Command "%s" was not successful. XML response: %s', cls.NAME, xml
+ )
return HandlingResult(HandlingState.FAILED)
@@ -83,4 +85,4 @@ class XmlSetCommand(ExecuteCommand, SetCommand, ABC):
"""Xml base set command.
Command needs to be linked to the "get" command, for handling (updating) the sensors.
- """
\ No newline at end of file
+ """
From d039abb0a587e2679ca96ed5f6b15c1573ef9df1 Mon Sep 17 00:00:00 2001
From: flubshi <4031504+flubshi@users.noreply.github.com>
Date: Sun, 19 Jan 2025 19:47:35 +0100
Subject: [PATCH 5/6] Add tests for xml command 'play_sound'
---
tests/commands/xml/test_play_sound.py | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
create mode 100644 tests/commands/xml/test_play_sound.py
diff --git a/tests/commands/xml/test_play_sound.py b/tests/commands/xml/test_play_sound.py
new file mode 100644
index 000000000..6161ce85d
--- /dev/null
+++ b/tests/commands/xml/test_play_sound.py
@@ -0,0 +1,26 @@
+from __future__ import annotations
+
+import pytest
+
+from deebot_client.command import CommandResult
+from deebot_client.commands.xml import PlaySound
+from deebot_client.message import HandlingState
+from tests.commands import assert_command
+
+from . import get_request_xml
+
+@pytest.mark.parametrize(
+ ("xml_response", "command_result"),
+ [
+ ("", HandlingState.SUCCESS),
+ ("", HandlingState.FAILED),
+ ],
+)
+async def test_play_sound(xml_response: str, command_result: HandlingState) -> None:
+ json = get_request_xml(xml_response)
+ await assert_command(
+ PlaySound(),
+ json,
+ None,
+ command_result=CommandResult(command_result)
+ )
From f89d2beff689d8d5c7a4555b6bd335c0334266ce Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
<66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Sun, 19 Jan 2025 18:51:18 +0000
Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---
tests/commands/xml/test_play_sound.py | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/tests/commands/xml/test_play_sound.py b/tests/commands/xml/test_play_sound.py
index 6161ce85d..f3b158da4 100644
--- a/tests/commands/xml/test_play_sound.py
+++ b/tests/commands/xml/test_play_sound.py
@@ -9,6 +9,7 @@
from . import get_request_xml
+
@pytest.mark.parametrize(
("xml_response", "command_result"),
[
@@ -19,8 +20,5 @@
async def test_play_sound(xml_response: str, command_result: HandlingState) -> None:
json = get_request_xml(xml_response)
await assert_command(
- PlaySound(),
- json,
- None,
- command_result=CommandResult(command_result)
+ PlaySound(), json, None, command_result=CommandResult(command_result)
)