From 7fd5daa85cd39e1422316d6a56aabf439ba15dfd Mon Sep 17 00:00:00 2001 From: XxInvictus <3955293+XxInvictus@users.noreply.github.com> Date: Fri, 13 Dec 2024 08:55:28 +1030 Subject: [PATCH] Add Support for Mop Auto-Wash Frequency Ref #555 - Add support for Mop Auto-Wash Frequency - Add Capability to T20/T30 Omni/X5 Pro Omni via `p1jij8.py` --- deebot_client/capabilities.py | 5 +++ deebot_client/commands/json/__init__.py | 6 +++ .../commands/json/mop_auto_wash_frequency.py | 45 +++++++++++++++++++ deebot_client/events/__init__.py | 3 ++ .../events/mop_auto_wash_frequency.py | 24 ++++++++++ deebot_client/hardware/deebot/p1jij8.py | 13 ++++++ .../json/test_mop_auto_wash_frequency.py | 38 ++++++++++++++++ 7 files changed, 134 insertions(+) create mode 100644 deebot_client/commands/json/mop_auto_wash_frequency.py create mode 100644 deebot_client/events/mop_auto_wash_frequency.py create mode 100644 tests/commands/json/test_mop_auto_wash_frequency.py diff --git a/deebot_client/capabilities.py b/deebot_client/capabilities.py index 40bfa2ec..8e7dd886 100644 --- a/deebot_client/capabilities.py +++ b/deebot_client/capabilities.py @@ -32,6 +32,8 @@ MajorMapEvent, MapChangedEvent, MapTraceEvent, + MopAutoWashFrequency, + MopAutoWashFrequencyEvent, MoveUpWarningEvent, MultimapStateEvent, NetworkInfoEvent, @@ -192,6 +194,9 @@ class CapabilitySettings: border_switch: CapabilitySetEnable[BorderSwitchEvent] | None = None child_lock: CapabilitySetEnable[ChildLockEvent] | None = None cut_direction: CapabilitySet[CutDirectionEvent, int] | None = None + mop_auto_wash_frequency: CapabilitySetTypes[MopAutoWashFrequencyEvent, MopAutoWashFrequency] | None = ( + None + ) moveup_warning: CapabilitySetEnable[MoveUpWarningEvent] | None = None cross_map_border_warning: CapabilitySetEnable[CrossMapBorderWarningEvent] | None = ( None diff --git a/deebot_client/commands/json/__init__.py b/deebot_client/commands/json/__init__.py index 384e2697..16e14509 100644 --- a/deebot_client/commands/json/__init__.py +++ b/deebot_client/commands/json/__init__.py @@ -34,6 +34,7 @@ GetMapTrace, GetMinorMap, ) +from .mop_auto_wash_frequency import GetMopAutoWashFrequency, SetMopAutoWashFrequency from .moveup_warning import GetMoveUpWarning, SetMoveUpWarning from .multimap_state import GetMultimapState, SetMultimapState from .network import GetNetInfo @@ -84,6 +85,7 @@ "GetMapSubSet", "GetMapTrace", "GetMinorMap", + "GetMopAutoWashFrequency" "GetMoveUpWarning", "GetMultimapState", "GetNetInfo", @@ -111,6 +113,7 @@ "SetCutDirection", "SetEfficiencyMode", "SetFanSpeed", + "SetMopAutoWashFrequency", "SetMoveUpWarning", "SetMultimapState", "SetOta", @@ -187,6 +190,9 @@ GetMapTrace, GetMinorMap, + GetMopAutoWashFrequency, + SetMopAutoWashFrequency, + GetMoveUpWarning, SetMoveUpWarning, diff --git a/deebot_client/commands/json/mop_auto_wash_frequency.py b/deebot_client/commands/json/mop_auto_wash_frequency.py new file mode 100644 index 00000000..242737f8 --- /dev/null +++ b/deebot_client/commands/json/mop_auto_wash_frequency.py @@ -0,0 +1,45 @@ +"""Mop Auto-Wash Frequency command module.""" + +from __future__ import annotations + +from types import MappingProxyType +from typing import TYPE_CHECKING, Any + +from deebot_client.command import InitParam +from deebot_client.events import MopAutoWashFrequency, MopAutoWashFrequencyEvent +from deebot_client.message import HandlingResult +from deebot_client.util import get_enum + +from .common import JsonGetCommand, JsonSetCommand + +if TYPE_CHECKING: + from deebot_client.event_bus import EventBus + + +class GetMopAutoWashFrequency(JsonGetCommand): + """Get Mop Auto-Wash Frequency command.""" + + name = "getWashInfo" + + @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(MopAutoWashFrequencyEvent(MopAutoWashFrequency(int(data["interval"])))) + return HandlingResult.success() + + +class SetMopAutoWashFrequency(JsonSetCommand): + """Set Mop Auto-Wash Frequency command.""" + + name = "setWashInfo" + get_command = GetMopAutoWashFrequency + _mqtt_params = MappingProxyType({"interval": InitParam(MopAutoWashFrequency)}) + + def __init__(self, interval: MopAutoWashFrequency | int) -> None: + if isinstance(interval, int): + interval = get_enum(MopAutoWashFrequency, interval) + super().__init__({"interval": interval.value}) \ No newline at end of file diff --git a/deebot_client/events/__init__.py b/deebot_client/events/__init__.py index 12a03b95..bca69faf 100644 --- a/deebot_client/events/__init__.py +++ b/deebot_client/events/__init__.py @@ -23,6 +23,7 @@ PositionsEvent, PositionType, ) +from .mop_auto_wash_frequency import MopAutoWashFrequency, MopAutoWashFrequencyEvent from .network import NetworkInfoEvent from .water_info import SweepType, WaterAmount, WaterInfoEvent from .work_mode import WorkMode, WorkModeEvent @@ -40,6 +41,8 @@ "Event", "FanSpeedEvent", "FanSpeedLevel", + "MopAutoWashFrequency", + "MopAutoWashFrequencyEvent", "MajorMapEvent", "MapChangedEvent", "MapSetEvent", diff --git a/deebot_client/events/mop_auto_wash_frequency.py b/deebot_client/events/mop_auto_wash_frequency.py new file mode 100644 index 00000000..5c64f4fe --- /dev/null +++ b/deebot_client/events/mop_auto_wash_frequency.py @@ -0,0 +1,24 @@ +"""Mop Auto-Wash Frequency event module.""" + +from __future__ import annotations + +from dataclasses import dataclass +from enum import IntEnum, unique + +from .base import Event + + +@unique +class MopAutoWashFrequency(IntEnum): + """Enum class for all possible mop auto-wash frequencies.""" + + TEN_MINUTES = 10 + FIFTEEN_MINUTES = 15 + TWENTY_FIVE_MINUTES = 25 + + +@dataclass(frozen=True) +class MopAutoWashFrequencyEvent(Event): + """Mop Auto-Wash Frequency event representation.""" + + interval: MopAutoWashFrequency \ No newline at end of file diff --git a/deebot_client/hardware/deebot/p1jij8.py b/deebot_client/hardware/deebot/p1jij8.py index a9c2094e..85f96090 100644 --- a/deebot_client/hardware/deebot/p1jij8.py +++ b/deebot_client/hardware/deebot/p1jij8.py @@ -42,6 +42,7 @@ from deebot_client.commands.json.fan_speed import GetFanSpeed, SetFanSpeed from deebot_client.commands.json.life_span import GetLifeSpan, ResetLifeSpan from deebot_client.commands.json.map import GetCachedMapInfo, GetMajorMap, GetMapTrace +from deebot_client.commands.json.mop_auto_wash_frequency import GetMopAutoWashFrequency, SetMopAutoWashFrequency from deebot_client.commands.json.multimap_state import ( GetMultimapState, SetMultimapState, @@ -75,6 +76,8 @@ MajorMapEvent, MapChangedEvent, MapTraceEvent, + MopAutoWashFrequency, + MopAutoWashFrequencyEvent, MultimapStateEvent, NetworkInfoEvent, PositionsEvent, @@ -172,6 +175,16 @@ [GetCarpetAutoFanBoost()], SetCarpetAutoFanBoost, ), + mop_auto_wash_frequency=CapabilitySetTypes( + event=MopAutoWashFrequencyEvent, + get=[GetMopAutoWashFrequency()], + set=SetMopAutoWashFrequency, + types=( + MopAutoWashFrequency.TEN_MINUTES, + MopAutoWashFrequency.FIFTEEN_MINUTES, + MopAutoWashFrequency.TWENTY_FIVE_MINUTES, + ), + ), true_detect=CapabilitySetEnable( TrueDetectEvent, [GetTrueDetect()], SetTrueDetect ), diff --git a/tests/commands/json/test_mop_auto_wash_frequency.py b/tests/commands/json/test_mop_auto_wash_frequency.py new file mode 100644 index 00000000..7c9607d4 --- /dev/null +++ b/tests/commands/json/test_mop_auto_wash_frequency.py @@ -0,0 +1,38 @@ +from __future__ import annotations + +from typing import Any + +import pytest + +from deebot_client.commands.json import GetMopAutoWashFrequency, SetMopAutoWashFrequency +from deebot_client.events import MopAutoWashFrequency, MopAutoWashFrequencyEvent +from tests.helpers import ( + get_request_json, + get_success_body, +) + +from . import assert_command, assert_set_command + + +@pytest.mark.parametrize( + ("json", "expected"), + [ + ({"interval": 10}, MopAutoWashFrequencyEvent(MopAutoWashFrequency.TEN_MINUTES)), + ({"interval": 15}, MopAutoWashFrequencyEvent(MopAutoWashFrequency.FIFTEEN_MINUTES)), + ({"interval": 25}, MopAutoWashFrequencyEvent(MopAutoWashFrequency.TWENTY_FIVE_MINUTES)), + ], +) +async def test_GetMopAutoWashFrequency( + json: dict[str, Any], expected: MopAutoWashFrequencyEvent +) -> None: + json = get_request_json(get_success_body(json)) + await assert_command(GetMopAutoWashFrequency(), json, expected) + + +@pytest.mark.parametrize(("value"), [MopAutoWashFrequency.TEN_MINUTES, 10]) +async def test_SetMopAutoWashFrequency(value: MopAutoWashFrequency | int) -> None: + command = SetMopAutoWashFrequency(value) + args = {"interval": 10} + await assert_set_command( + command, args, MopAutoWashFrequencyEvent(MopAutoWashFrequency.TEN_MINUTES) + ) \ No newline at end of file