Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion deebot_client/messages/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
from .battery import OnBattery
from .map import OnMapSetV2
from .station_state import OnStationState
from .stats import ReportStats
from .stats import OnStats, ReportStats

if TYPE_CHECKING:
from deebot_client.message import Message

__all__ = [
"OnBattery",
"OnMapSetV2",
"OnStats",
Comment thread
edenhaus marked this conversation as resolved.
"ReportStats",
]

Expand All @@ -30,6 +31,7 @@

OnStationState,

OnStats,
ReportStats,
]
# fmt: on
Expand Down
21 changes: 20 additions & 1 deletion deebot_client/messages/json/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from typing import TYPE_CHECKING, Any

from deebot_client.events import CleanJobStatus, ReportStatsEvent
from deebot_client.events import CleanJobStatus, ReportStatsEvent, StatsEvent
from deebot_client.message import HandlingResult, MessageBodyDataDict

if TYPE_CHECKING:
Expand Down Expand Up @@ -40,3 +40,22 @@ def _handle_body_data_dict(
)
event_bus.notify(stats_event)
return HandlingResult.success()


class OnStats(MessageBodyDataDict):
"""Get stats command."""

NAME = "onStats"

@classmethod
def _handle_body_data_dict(
cls, event_bus: EventBus, data: dict[str, Any]
) -> HandlingResult:
"""Handle message->body->data and notify the correct event subscribers.

:return: A message response
"""
event_bus.notify(
StatsEvent(area=data["area"], time=data["time"], type=data["type"])
)
return HandlingResult.success()
68 changes: 66 additions & 2 deletions tests/messages/json/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

import pytest

from deebot_client.events import CleanJobStatus, FirmwareEvent, ReportStatsEvent
from deebot_client.messages.json import ReportStats
from deebot_client.events import (
CleanJobStatus,
FirmwareEvent,
ReportStatsEvent,
StatsEvent,
)
from deebot_client.messages.json import OnStats, ReportStats
from tests.messages import assert_message


Expand Down Expand Up @@ -61,3 +66,62 @@ def test_ReportStats(data: dict[str, Any], expected: ReportStatsEvent) -> None:
}

assert_message(ReportStats, data, (FirmwareEvent("1.8.2"), expected))


@pytest.mark.parametrize(
("data", "expected"),
[
(
{
"area": 2,
"time": 89,
"cid": "2002066096",
"start": "1744009746",
"type": "auto",
"enablePowerMop": 1,
"powerMopType": 2,
"aiopen": 1,
"aitypes": [9],
"avoidCount": 1,
},
StatsEvent(
area=2,
time=89,
type="auto",
),
),
(
{
"area": 50,
"time": 56289,
"cid": "2002066096",
"start": "1744009746",
"type": "auto",
"enablePowerMop": 1,
"powerMopType": 2,
"aiopen": 1,
"aitypes": [9],
"avoidCount": 1,
},
StatsEvent(
area=50,
time=56289,
type="auto",
),
),
],
)
def test_onStats(data: dict[str, Any], expected: StatsEvent) -> None:
data = {
"header": {
"pri": 1,
"tzm": 480,
"ts": "1662017348913",
"ver": "0.0.1",
"fwVer": "1.8.2",
"hwVer": "0.1.1",
},
"body": {"data": data},
}

assert_message(OnStats, data, (FirmwareEvent("1.8.2"), expected))
2 changes: 2 additions & 0 deletions tests/messages/test_get_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from deebot_client.const import DataType
from deebot_client.messages import get_message
from deebot_client.messages.json.battery import OnBattery
from deebot_client.messages.json.stats import OnStats

if TYPE_CHECKING:
from deebot_client.message import Message
Expand All @@ -19,6 +20,7 @@
("onBattery", DataType.JSON, OnBattery),
("onBattery_V2", DataType.JSON, OnBattery),
("onError", DataType.JSON, GetError),
("onStats", DataType.JSON, OnStats),
("GetCleanLogs", DataType.JSON, None),
("unknown", DataType.JSON, None),
("unknown", DataType.XML, None),
Expand Down