Skip to content

Commit

Permalink
Add CleanAreaV2 (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Aug 6, 2024
1 parent 7dc623c commit c7b8386
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
35 changes: 26 additions & 9 deletions deebot_client/commands/json/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ async def _execute(

return await super()._execute(authenticator, device_info, event_bus)

@staticmethod
def _get_args(action: CleanAction) -> dict[str, Any]:
def _get_args(self, action: CleanAction) -> dict[str, Any]:
args = {"act": action.value}
if action == CleanAction.START:
args["type"] = CleanMode.AUTO.value
Expand All @@ -61,22 +60,26 @@ class CleanArea(Clean):
"""Clean area command."""

def __init__(self, mode: CleanMode, area: str, cleanings: int = 1) -> None:
self._additional_args = {
"type": mode.value,
"content": area,
"count": cleanings,
}
super().__init__(CleanAction.START)
if not isinstance(self._args, dict):
raise TypeError("args must be a dict!")

self._args["type"] = mode.value
self._args["content"] = str(area)
self._args["count"] = cleanings
def _get_args(self, action: CleanAction) -> dict[str, Any]:
args = super()._get_args(action)
if action == CleanAction.START:
args.update(self._additional_args)
return args


class CleanV2(Clean):
"""Clean V2 command."""

name = "clean_V2"

@staticmethod
def _get_args(action: CleanAction) -> dict[str, Any]:
def _get_args(self, action: CleanAction) -> dict[str, Any]:
content: dict[str, str] = {}
args = {"act": action.value, "content": content}
match action:
Expand All @@ -87,6 +90,20 @@ def _get_args(action: CleanAction) -> dict[str, Any]:
return args


class CleanAreaV2(CleanV2):
"""Clean area command."""

def __init__(self, mode: CleanMode, area: str, _: int = 1) -> None:
self._additional_content = {"type": mode.value, "value": area}
super().__init__(CleanAction.START)

def _get_args(self, action: CleanAction) -> dict[str, Any]:
args = super()._get_args(action)
if action == CleanAction.START:
args["content"].update(self._additional_content)
return args


class GetCleanInfo(JsonCommandWithMessageHandling, MessageBodyDataDict):
"""Get clean info command."""

Expand Down
4 changes: 2 additions & 2 deletions deebot_client/hardware/deebot/kr0277.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from deebot_client.commands.json.charge import Charge
from deebot_client.commands.json.charge_state import GetChargeState
from deebot_client.commands.json.child_lock import GetChildLock, SetChildLock
from deebot_client.commands.json.clean import CleanArea, CleanV2, GetCleanInfoV2
from deebot_client.commands.json.clean import CleanAreaV2, CleanV2, GetCleanInfoV2
from deebot_client.commands.json.clean_count import GetCleanCount, SetCleanCount
from deebot_client.commands.json.clean_logs import GetCleanLogs
from deebot_client.commands.json.continuous_cleaning import (
Expand Down Expand Up @@ -95,7 +95,7 @@
battery=CapabilityEvent(BatteryEvent, [GetBattery()]),
charge=CapabilityExecute(Charge),
clean=CapabilityClean(
action=CapabilityCleanAction(command=CleanV2, area=CleanArea),
action=CapabilityCleanAction(command=CleanV2, area=CleanAreaV2),
continuous=CapabilitySetEnable(
ContinuousCleaningEvent,
[GetContinuousCleaning()],
Expand Down
32 changes: 29 additions & 3 deletions tests/commands/json/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
import pytest

from deebot_client.commands.json import GetCleanInfo
from deebot_client.commands.json.clean import Clean, CleanV2, GetCleanInfoV2
from deebot_client.commands.json.clean import (
Clean,
CleanArea,
CleanAreaV2,
CleanV2,
GetCleanInfoV2,
)
from deebot_client.event_bus import EventBus
from deebot_client.events import StateEvent
from deebot_client.models import ApiDeviceInfo, CleanAction, State
from deebot_client.models import ApiDeviceInfo, CleanAction, CleanMode, State
from tests.helpers import get_request_json, get_success_body

from . import assert_command
from . import assert_command, assert_execute_command

if TYPE_CHECKING:
from deebot_client.authentication import Authenticator
Expand Down Expand Up @@ -71,3 +77,23 @@ async def test_Clean_act(

if command_type is CleanV2:
assert isinstance(command._args["content"], dict)


@pytest.mark.parametrize(
("command", "args"),
[
(
CleanArea(CleanMode.SPOT_AREA, "5,8"),
{"act": "start", "type": "spotArea", "content": "5,8", "count": 1},
),
(
CleanAreaV2(CleanMode.SPOT_AREA, "5,8"),
{"act": "start", "content": {"type": "spotArea", "value": "5,8"}},
),
],
ids=["CleanArea", "CleanAreaV2"],
)
async def test_CleanArea(
command: CleanArea | CleanAreaV2, args: dict[str, str]
) -> None:
await assert_execute_command(command, args)

0 comments on commit c7b8386

Please sign in to comment.