forked from DeebotUniverse/client.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`
- Loading branch information
1 parent
1cbc8ed
commit 7fd5daa
Showing
7 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
) |