Skip to content

Commit 93ee9b0

Browse files
committed
Add Support for Mop Auto-Wash Frequency
Ref DeebotUniverse#555 - Add support for Mop Auto-Wash Frequency - Add Capability to T20/T30 Omni/X5 Pro Omni via `p1jij8.py` Fix missing list seperator Make pre-commit happy Fix error in SetAutoMopWashFrequency test case Small fix to resolve Mop Auto Wash and checkers not agreeing with int Ruff lint/format Ruff Linting/Fixes
1 parent c7a9b2f commit 93ee9b0

File tree

7 files changed

+146
-0
lines changed

7 files changed

+146
-0
lines changed

deebot_client/capabilities.py

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
MajorMapEvent,
3333
MapChangedEvent,
3434
MapTraceEvent,
35+
MopAutoWashFrequency,
36+
MopAutoWashFrequencyEvent,
3537
MoveUpWarningEvent,
3638
MultimapStateEvent,
3739
NetworkInfoEvent,
@@ -192,6 +194,9 @@ class CapabilitySettings:
192194
border_switch: CapabilitySetEnable[BorderSwitchEvent] | None = None
193195
child_lock: CapabilitySetEnable[ChildLockEvent] | None = None
194196
cut_direction: CapabilitySet[CutDirectionEvent, int] | None = None
197+
mop_auto_wash_frequency: (
198+
CapabilitySetTypes[MopAutoWashFrequencyEvent, MopAutoWashFrequency] | None
199+
) = None
195200
moveup_warning: CapabilitySetEnable[MoveUpWarningEvent] | None = None
196201
cross_map_border_warning: CapabilitySetEnable[CrossMapBorderWarningEvent] | None = (
197202
None

deebot_client/commands/json/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
GetMapTrace,
3535
GetMinorMap,
3636
)
37+
from .mop_auto_wash_frequency import GetMopAutoWashFrequency, SetMopAutoWashFrequency
3738
from .moveup_warning import GetMoveUpWarning, SetMoveUpWarning
3839
from .multimap_state import GetMultimapState, SetMultimapState
3940
from .network import GetNetInfo
@@ -84,6 +85,7 @@
8485
"GetMapSubSet",
8586
"GetMapTrace",
8687
"GetMinorMap",
88+
"GetMopAutoWashFrequency",
8789
"GetMoveUpWarning",
8890
"GetMultimapState",
8991
"GetNetInfo",
@@ -111,6 +113,7 @@
111113
"SetCutDirection",
112114
"SetEfficiencyMode",
113115
"SetFanSpeed",
116+
"SetMopAutoWashFrequency",
114117
"SetMoveUpWarning",
115118
"SetMultimapState",
116119
"SetOta",
@@ -187,6 +190,9 @@
187190
GetMapTrace,
188191
GetMinorMap,
189192

193+
GetMopAutoWashFrequency,
194+
SetMopAutoWashFrequency,
195+
190196
GetMoveUpWarning,
191197
SetMoveUpWarning,
192198

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""Mop Auto-Wash Frequency command module."""
2+
3+
from __future__ import annotations
4+
5+
from types import MappingProxyType
6+
from typing import TYPE_CHECKING, Any
7+
8+
from deebot_client.command import InitParam
9+
from deebot_client.events import MopAutoWashFrequency, MopAutoWashFrequencyEvent
10+
from deebot_client.message import HandlingResult
11+
from deebot_client.util import get_enum
12+
13+
from .common import JsonGetCommand, JsonSetCommand
14+
15+
if TYPE_CHECKING:
16+
from deebot_client.event_bus import EventBus
17+
18+
19+
class GetMopAutoWashFrequency(JsonGetCommand):
20+
"""Get Mop Auto-Wash Frequency command."""
21+
22+
name = "getWashInfo"
23+
24+
@classmethod
25+
def _handle_body_data_dict(
26+
cls, event_bus: EventBus, data: dict[str, Any]
27+
) -> HandlingResult:
28+
"""Handle message->body->data and notify the correct event subscribers.
29+
30+
:return: A message response
31+
"""
32+
event_bus.notify(
33+
MopAutoWashFrequencyEvent(MopAutoWashFrequency(int(data["interval"])))
34+
)
35+
return HandlingResult.success()
36+
37+
38+
class SetMopAutoWashFrequency(JsonSetCommand):
39+
"""Set Mop Auto-Wash Frequency command."""
40+
41+
name = "setWashInfo"
42+
get_command = GetMopAutoWashFrequency
43+
_mqtt_params = MappingProxyType({"interval": InitParam(MopAutoWashFrequency)})
44+
45+
def __init__(self, interval: MopAutoWashFrequency | str) -> None:
46+
if isinstance(interval, str):
47+
interval = get_enum(MopAutoWashFrequency, interval)
48+
super().__init__({"interval": interval.value})

deebot_client/events/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
PositionsEvent,
2424
PositionType,
2525
)
26+
from .mop_auto_wash_frequency import MopAutoWashFrequency, MopAutoWashFrequencyEvent
2627
from .network import NetworkInfoEvent
2728
from .water_info import SweepType, WaterAmount, WaterInfoEvent
2829
from .work_mode import WorkMode, WorkModeEvent
@@ -47,6 +48,8 @@
4748
"MapSubsetEvent",
4849
"MapTraceEvent",
4950
"MinorMapEvent",
51+
"MopAutoWashFrequency",
52+
"MopAutoWashFrequencyEvent",
5053
"NetworkInfoEvent",
5154
"Position",
5255
"PositionType",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Mop Auto-Wash Frequency event module."""
2+
3+
from __future__ import annotations
4+
5+
from dataclasses import dataclass
6+
from enum import IntEnum, unique
7+
8+
from .base import Event
9+
10+
11+
@unique
12+
class MopAutoWashFrequency(IntEnum):
13+
"""Enum class for all possible mop auto-wash frequencies."""
14+
15+
TEN_MINUTES = 10
16+
FIFTEEN_MINUTES = 15
17+
TWENTY_FIVE_MINUTES = 25
18+
19+
20+
@dataclass(frozen=True)
21+
class MopAutoWashFrequencyEvent(Event):
22+
"""Mop Auto-Wash Frequency event representation."""
23+
24+
interval: MopAutoWashFrequency

deebot_client/hardware/deebot/p1jij8.py

+16
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
from deebot_client.commands.json.fan_speed import GetFanSpeed, SetFanSpeed
4343
from deebot_client.commands.json.life_span import GetLifeSpan, ResetLifeSpan
4444
from deebot_client.commands.json.map import GetCachedMapInfo, GetMajorMap, GetMapTrace
45+
from deebot_client.commands.json.mop_auto_wash_frequency import (
46+
GetMopAutoWashFrequency,
47+
SetMopAutoWashFrequency,
48+
)
4549
from deebot_client.commands.json.multimap_state import (
4650
GetMultimapState,
4751
SetMultimapState,
@@ -75,6 +79,8 @@
7579
MajorMapEvent,
7680
MapChangedEvent,
7781
MapTraceEvent,
82+
MopAutoWashFrequency,
83+
MopAutoWashFrequencyEvent,
7884
MultimapStateEvent,
7985
NetworkInfoEvent,
8086
PositionsEvent,
@@ -172,6 +178,16 @@
172178
[GetCarpetAutoFanBoost()],
173179
SetCarpetAutoFanBoost,
174180
),
181+
mop_auto_wash_frequency=CapabilitySetTypes(
182+
event=MopAutoWashFrequencyEvent,
183+
get=[GetMopAutoWashFrequency()],
184+
set=SetMopAutoWashFrequency,
185+
types=(
186+
MopAutoWashFrequency.TEN_MINUTES,
187+
MopAutoWashFrequency.FIFTEEN_MINUTES,
188+
MopAutoWashFrequency.TWENTY_FIVE_MINUTES,
189+
),
190+
),
175191
true_detect=CapabilitySetEnable(
176192
TrueDetectEvent, [GetTrueDetect()], SetTrueDetect
177193
),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
5+
import pytest
6+
7+
from deebot_client.commands.json import GetMopAutoWashFrequency, SetMopAutoWashFrequency
8+
from deebot_client.events import MopAutoWashFrequency, MopAutoWashFrequencyEvent
9+
from tests.helpers import (
10+
get_request_json,
11+
get_success_body,
12+
)
13+
14+
from . import assert_command, assert_set_command
15+
16+
17+
@pytest.mark.parametrize(
18+
("json", "expected"),
19+
[
20+
({"interval": 10}, MopAutoWashFrequencyEvent(MopAutoWashFrequency.TEN_MINUTES)),
21+
(
22+
{"interval": 15},
23+
MopAutoWashFrequencyEvent(MopAutoWashFrequency.FIFTEEN_MINUTES),
24+
),
25+
(
26+
{"interval": 25},
27+
MopAutoWashFrequencyEvent(MopAutoWashFrequency.TWENTY_FIVE_MINUTES),
28+
),
29+
],
30+
)
31+
async def test_GetMopAutoWashFrequency(
32+
json: dict[str, Any], expected: MopAutoWashFrequencyEvent
33+
) -> None:
34+
json = get_request_json(get_success_body(json))
35+
await assert_command(GetMopAutoWashFrequency(), json, expected)
36+
37+
38+
@pytest.mark.parametrize(("value"), [MopAutoWashFrequency.TEN_MINUTES, "ten_minutes"])
39+
async def test_SetMopAutoWashFrequency(value: MopAutoWashFrequency | str) -> None:
40+
command = SetMopAutoWashFrequency(value)
41+
args = {"interval": 10}
42+
await assert_set_command(
43+
command, args, MopAutoWashFrequencyEvent(MopAutoWashFrequency.TEN_MINUTES)
44+
)

0 commit comments

Comments
 (0)