diff --git a/deebot_client/commands/json/clean.py b/deebot_client/commands/json/clean.py index 469ac3fe..68f32464 100644 --- a/deebot_client/commands/json/clean.py +++ b/deebot_client/commands/json/clean.py @@ -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 @@ -61,13 +60,18 @@ 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): @@ -75,8 +79,7 @@ class CleanV2(Clean): 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: @@ -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.""" diff --git a/deebot_client/hardware/deebot/kr0277.py b/deebot_client/hardware/deebot/kr0277.py index 78b12eb8..44211871 100644 --- a/deebot_client/hardware/deebot/kr0277.py +++ b/deebot_client/hardware/deebot/kr0277.py @@ -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 ( @@ -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()], diff --git a/tests/commands/json/test_clean.py b/tests/commands/json/test_clean.py index 4f5110a4..571cefe0 100644 --- a/tests/commands/json/test_clean.py +++ b/tests/commands/json/test_clean.py @@ -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 @@ -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)