Skip to content

Commit 366e96a

Browse files
authored
Merge branch 'dev' into xml_set_fanspeed
2 parents 136fb4d + fafef75 commit 366e96a

File tree

7 files changed

+93
-7
lines changed

7 files changed

+93
-7
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: "actions/checkout@v4"
1919
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
2020
id: python
21-
uses: actions/setup-python@v5.1.1
21+
uses: actions/setup-python@v5.2.0
2222
with:
2323
python-version: ${{ env.DEFAULT_PYTHON }}
2424
cache: "pip"
@@ -45,7 +45,7 @@ jobs:
4545
- uses: "actions/checkout@v4"
4646
- name: Set up Python ${{ matrix.python-version }}
4747
id: python
48-
uses: actions/setup-python@v5.1.1
48+
uses: actions/setup-python@v5.2.0
4949
with:
5050
python-version: ${{ matrix.python-version }}
5151
cache: "pip"

.github/workflows/python-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: actions/checkout@v4
2424

2525
- name: Set up Python
26-
uses: actions/setup-python@v5.1.1
26+
uses: actions/setup-python@v5.2.0
2727
with:
2828
python-version: "3.12"
2929

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ default_language_version:
1111

1212
repos:
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.5.6
14+
rev: v0.6.3
1515
hooks:
1616
- id: ruff
1717
args:

deebot_client/commands/xml/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
from .error import GetError
1111
from .fan_speed import GetFanSpeed, SetFanSpeed
1212
from .pos import GetPos
13+
from .stats import GetCleanSum
1314

1415
if TYPE_CHECKING:
1516
from .common import XmlCommand
1617

1718
__all__ = [
1819
"GetChargeState",
20+
"GetCleanSum",
1921
"GetError",
2022
"GetFanSpeed",
2123
"SetFanSpeed",

deebot_client/commands/xml/stats.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""CleanSum command module."""
2+
3+
from __future__ import annotations
4+
5+
from typing import TYPE_CHECKING
6+
7+
from deebot_client.events import TotalStatsEvent
8+
from deebot_client.message import HandlingResult
9+
10+
from .common import XmlCommandWithMessageHandling
11+
12+
if TYPE_CHECKING:
13+
from xml.etree.ElementTree import Element
14+
15+
from deebot_client.event_bus import EventBus
16+
17+
18+
class GetCleanSum(XmlCommandWithMessageHandling):
19+
"""GetCleanSum command."""
20+
21+
name = "GetCleanSum"
22+
23+
@classmethod
24+
def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
25+
"""Handle xml message and notify the correct event subscribers.
26+
27+
:return: A message response
28+
"""
29+
if xml.attrib.get("ret") != "ok":
30+
return HandlingResult.analyse()
31+
32+
if (
33+
(area := xml.attrib.get("a"))
34+
and (lifetime := xml.attrib.get("l"))
35+
and (count := xml.attrib.get("c"))
36+
):
37+
event_bus.notify(TotalStatsEvent(int(area), int(lifetime), int(count)))
38+
return HandlingResult.success()
39+
40+
return HandlingResult.analyse()

requirements-test.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
mypy==1.11.1
1+
mypy==1.11.2
22
pre-commit==3.8.0
33
pycountry==24.6.1
4-
pylint==3.2.6
4+
pylint==3.2.7
55
pytest==8.3.2
6-
pytest-asyncio==0.23.8
6+
pytest-asyncio==0.24.0
77
pytest-cov==5.0.0
88
pytest-docker-fixtures==1.3.19
99
pytest-timeout==2.3.1

tests/commands/xml/test_stats.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
import pytest
6+
7+
from deebot_client.command import CommandResult
8+
from deebot_client.commands.xml import GetCleanSum
9+
from deebot_client.events import TotalStatsEvent
10+
from deebot_client.message import HandlingState
11+
from tests.commands import assert_command
12+
13+
from . import get_request_xml
14+
15+
if TYPE_CHECKING:
16+
from deebot_client.events.base import Event
17+
18+
19+
@pytest.mark.parametrize(
20+
("area", "lifetime", "count", "expected_event"),
21+
[
22+
(1000, 20, 30, TotalStatsEvent(1000, 20, 30)),
23+
],
24+
)
25+
async def test_get_clean_sum(
26+
area: int, lifetime: int, count: int, expected_event: Event
27+
) -> None:
28+
json = get_request_xml(f"<ctl ret='ok' a='{area}' l='{lifetime}' c='{count}' />")
29+
await assert_command(GetCleanSum(), json, expected_event)
30+
31+
32+
@pytest.mark.parametrize(
33+
"xml",
34+
["<ctl ret='error'/>", "<ctl ret='ok' a='34' />"],
35+
ids=["error", "error"],
36+
)
37+
async def test_get_clean_sum_error(xml: str) -> None:
38+
json = get_request_xml(xml)
39+
await assert_command(
40+
GetCleanSum(),
41+
json,
42+
None,
43+
command_result=CommandResult(HandlingState.ANALYSE_LOGGED),
44+
)

0 commit comments

Comments
 (0)