Skip to content

Commit 7fd5daa

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`
1 parent 1cbc8ed commit 7fd5daa

File tree

7 files changed

+134
-0
lines changed

7 files changed

+134
-0
lines changed

deebot_client/capabilities.py

Lines changed: 5 additions & 0 deletions
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: CapabilitySetTypes[MopAutoWashFrequencyEvent, MopAutoWashFrequency] | None = (
198+
None
199+
)
195200
moveup_warning: CapabilitySetEnable[MoveUpWarningEvent] | None = None
196201
cross_map_border_warning: CapabilitySetEnable[CrossMapBorderWarningEvent] | None = (
197202
None

deebot_client/commands/json/__init__.py

Lines changed: 6 additions & 0 deletions
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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
:return: A message response
30+
"""
31+
event_bus.notify(MopAutoWashFrequencyEvent(MopAutoWashFrequency(int(data["interval"]))))
32+
return HandlingResult.success()
33+
34+
35+
class SetMopAutoWashFrequency(JsonSetCommand):
36+
"""Set Mop Auto-Wash Frequency command."""
37+
38+
name = "setWashInfo"
39+
get_command = GetMopAutoWashFrequency
40+
_mqtt_params = MappingProxyType({"interval": InitParam(MopAutoWashFrequency)})
41+
42+
def __init__(self, interval: MopAutoWashFrequency | int) -> None:
43+
if isinstance(interval, int):
44+
interval = get_enum(MopAutoWashFrequency, interval)
45+
super().__init__({"interval": interval.value})

deebot_client/events/__init__.py

Lines changed: 3 additions & 0 deletions
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
@@ -40,6 +41,8 @@
4041
"Event",
4142
"FanSpeedEvent",
4243
"FanSpeedLevel",
44+
"MopAutoWashFrequency",
45+
"MopAutoWashFrequencyEvent",
4346
"MajorMapEvent",
4447
"MapChangedEvent",
4548
"MapSetEvent",
Lines changed: 24 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
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 GetMopAutoWashFrequency, SetMopAutoWashFrequency
4546
from deebot_client.commands.json.multimap_state import (
4647
GetMultimapState,
4748
SetMultimapState,
@@ -75,6 +76,8 @@
7576
MajorMapEvent,
7677
MapChangedEvent,
7778
MapTraceEvent,
79+
MopAutoWashFrequency,
80+
MopAutoWashFrequencyEvent,
7881
MultimapStateEvent,
7982
NetworkInfoEvent,
8083
PositionsEvent,
@@ -172,6 +175,16 @@
172175
[GetCarpetAutoFanBoost()],
173176
SetCarpetAutoFanBoost,
174177
),
178+
mop_auto_wash_frequency=CapabilitySetTypes(
179+
event=MopAutoWashFrequencyEvent,
180+
get=[GetMopAutoWashFrequency()],
181+
set=SetMopAutoWashFrequency,
182+
types=(
183+
MopAutoWashFrequency.TEN_MINUTES,
184+
MopAutoWashFrequency.FIFTEEN_MINUTES,
185+
MopAutoWashFrequency.TWENTY_FIVE_MINUTES,
186+
),
187+
),
175188
true_detect=CapabilitySetEnable(
176189
TrueDetectEvent, [GetTrueDetect()], SetTrueDetect
177190
),
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
({"interval": 15}, MopAutoWashFrequencyEvent(MopAutoWashFrequency.FIFTEEN_MINUTES)),
22+
({"interval": 25}, MopAutoWashFrequencyEvent(MopAutoWashFrequency.TWENTY_FIVE_MINUTES)),
23+
],
24+
)
25+
async def test_GetMopAutoWashFrequency(
26+
json: dict[str, Any], expected: MopAutoWashFrequencyEvent
27+
) -> None:
28+
json = get_request_json(get_success_body(json))
29+
await assert_command(GetMopAutoWashFrequency(), json, expected)
30+
31+
32+
@pytest.mark.parametrize(("value"), [MopAutoWashFrequency.TEN_MINUTES, 10])
33+
async def test_SetMopAutoWashFrequency(value: MopAutoWashFrequency | int) -> None:
34+
command = SetMopAutoWashFrequency(value)
35+
args = {"interval": 10}
36+
await assert_set_command(
37+
command, args, MopAutoWashFrequencyEvent(MopAutoWashFrequency.TEN_MINUTES)
38+
)

0 commit comments

Comments
 (0)