Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wash interval commands #376

Open
wants to merge 21 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3534d34
Update capabilities.py - WashInterval
NEVdataDyne Dec 18, 2023
23fe3b8
Update __init__.py - Wash interval
NEVdataDyne Dec 18, 2023
de0f4d4
Create wash_interval.py - Wash interval
NEVdataDyne Dec 18, 2023
0c1b727
Update wash_interval.py - Wash interval
NEVdataDyne Dec 18, 2023
45bd31b
Update __init__.py - Wash interval
NEVdataDyne Dec 18, 2023
c377052
Create wash_interval.py - Wash interval
NEVdataDyne Dec 18, 2023
cf4ff86
Update wash_interval.py - Wash interval
NEVdataDyne Dec 18, 2023
78ce0c2
Update p1jij8.py - Wash interval
NEVdataDyne Dec 18, 2023
aa3d91e
Create test_wash_interval.py - Wash interval
NEVdataDyne Dec 18, 2023
4ed8e2b
Update test_wash_interval.py - Wash interval
NEVdataDyne Dec 18, 2023
c82254c
Update wash_interval.py - Wash interval correction
NEVdataDyne Dec 18, 2023
e855c24
Update wash_interval.py - Was interval correction
NEVdataDyne Dec 18, 2023
1785238
Update tests/commands/json/test_wash_interval.py
NEVdataDyne Dec 18, 2023
8550419
Update deebot_client/commands/json/wash_interval.py
NEVdataDyne Dec 18, 2023
70938eb
Update deebot_client/commands/json/wash_interval.py
NEVdataDyne Dec 18, 2023
e21b21e
Update deebot_client/commands/json/wash_interval.py
NEVdataDyne Dec 18, 2023
8b948e9
Update deebot_client/commands/json/wash_interval.py
NEVdataDyne Dec 18, 2023
c94193c
Update deebot_client/commands/json/wash_interval.py
NEVdataDyne Dec 29, 2023
98392b1
Update deebot_client/commands/json/wash_interval.py
NEVdataDyne Dec 29, 2023
64d553e
Update deebot_client/events/wash_interval.py
NEVdataDyne Dec 29, 2023
a2fab23
Merge branch 'dev' into dev
NEVdataDyne Feb 1, 2024
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
2 changes: 2 additions & 0 deletions deebot_client/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
TrueDetectEvent,
VoiceAssistantStateEvent,
VolumeEvent,
WashIntervalEvent,
WaterAmount,
WaterInfoEvent,
WorkMode,
Expand Down Expand Up @@ -129,6 +130,7 @@ class CapabilityClean:
count: CapabilitySet[CleanCountEvent, int] | None = None
log: CapabilityEvent[CleanLogEvent] | None = None
preference: CapabilitySetEnable[CleanPreferenceEvent] | None = None
wash_interval: CapabilitySet[WashIntervalEvent, int] | None = None
work_mode: CapabilitySetTypes[WorkModeEvent, WorkMode] | None = None


Expand Down
6 changes: 6 additions & 0 deletions deebot_client/commands/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from .true_detect import GetTrueDetect, SetTrueDetect
from .voice_assistant_state import GetVoiceAssistantState, SetVoiceAssistantState
from .volume import GetVolume, SetVolume
from .wash_interval import GetWashInterval, SetWashInterval
from .water_info import GetWaterInfo, SetWaterInfo
from .work_mode import GetWorkMode, SetWorkMode

Expand Down Expand Up @@ -90,6 +91,8 @@
"SetVoiceAssistantState",
"GetVolume",
"SetVolume",
"GetWashInterval",
"SetWashInterval",
"GetWaterInfo",
"SetWaterInfo",
"GetWorkMode",
Expand Down Expand Up @@ -170,6 +173,9 @@
GetVolume,
SetVolume,

GetWashInterval,
SetWashInterval,

GetWaterInfo,
SetWaterInfo,

Expand Down
40 changes: 40 additions & 0 deletions deebot_client/commands/json/wash_interval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Pads cleaning interval commands."""
from types import MappingProxyType
from typing import Any
NEVdataDyne marked this conversation as resolved.
Show resolved Hide resolved

from deebot_client.command import InitParam
from deebot_client.event_bus import EventBus
from deebot_client.events.wash_interval import WashIntervalEvent
from deebot_client.message import HandlingResult

from .common import JsonGetCommand, JsonSetCommand


class GetWashInterval(JsonGetCommand):
"""Get wash interval command."""

name = "getWashInterval"

@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(WashIntervalEvent(int(data["interval"])))
return HandlingResult.success()


class SetWashInterval(JsonSetCommand):
"""Set wash interval command."""

name = "setWashInterval"
get_command = GetWashInterval
_mqtt_params = MappingProxyType({"interval": InitParam(int)})

def __init__(self, interval: int) -> None:
if interval <= 0:
raise ValueError("'interval' must be positive")
super().__init__({"interval": interval})
2 changes: 2 additions & 0 deletions deebot_client/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
PositionType,
)
from .network import NetworkInfoEvent
from .wash_interval import WashIntervalEvent
from .water_info import WaterAmount, WaterInfoEvent
from .work_mode import WorkMode, WorkModeEvent

Expand Down Expand Up @@ -51,6 +52,7 @@
"Position",
"PositionType",
"PositionsEvent",
"WashIntervalEvent",
"SweepModeEvent",
"WaterAmount",
"WaterInfoEvent",
Expand Down
11 changes: 11 additions & 0 deletions deebot_client/events/wash_interval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Cleaning pads interval event module."""
from dataclasses import dataclass

from .base import Event


@dataclass(frozen=True)
class WashIntervalEvent(Event):
"""Wash interval event representation."""

interval: int
10 changes: 10 additions & 0 deletions deebot_client/hardware/deebot/p1jij8.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
from deebot_client.commands.json.stats import GetStats, GetTotalStats
from deebot_client.commands.json.true_detect import GetTrueDetect, SetTrueDetect
from deebot_client.commands.json.volume import GetVolume, SetVolume
from deebot_client.commands.json.wash_interval import (
GetWashInterval,
SetWashInterval,
)
from deebot_client.commands.json.water_info import GetWaterInfo, SetWaterInfo
from deebot_client.commands.json.work_mode import GetWorkMode, SetWorkMode
from deebot_client.const import DataType
Expand Down Expand Up @@ -83,6 +87,7 @@
TotalStatsEvent,
TrueDetectEvent,
VolumeEvent,
WashIntervalEvent,
WaterAmount,
WaterInfoEvent,
WorkMode,
Expand Down Expand Up @@ -113,6 +118,11 @@
preference=CapabilitySetEnable(
CleanPreferenceEvent, [GetCleanPreference()], SetCleanPreference
),
wash_interval=CapabilitySet(
event=WashIntervalEvent,
get=[GetWashInterval()],
set=SetWashInterval,
),
work_mode=CapabilitySetTypes(
event=WorkModeEvent,
get=[GetWorkMode()],
Expand Down
37 changes: 37 additions & 0 deletions tests/commands/json/test_wash_interval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from typing import Any

import pytest

from deebot_client.commands.json import GetWashInterval, SetWashInterval
from deebot_client.events import WashIntervalEvent
from tests.helpers import (
get_request_json,
get_success_body,
)

from . import assert_command, assert_set_command


@pytest.mark.parametrize(
("json", "expected"),
[
({"interval": 6}, WashIntervalEvent(6)),
({"interval": 10}, WashIntervalEvent(10)),
],
)
async def test_GetPadsCleaningInterval(
json: dict[str, Any], expected: WashIntervalEvent
) -> None:
json = get_request_json(get_success_body(json))
await assert_command(GetWashInterval(), json, expected)


async def test_SetWashInterval() -> None:
command = SetWashInterval(60)
args = {"interval": 60}
await assert_set_command(command, args, WashIntervalEvent(60))


def test_SetWashInterval_invalid_value() -> None:
with pytest.raises(ValueError, match="'interval' must be positive"):
SetWashInterval(0)
Loading