From 4d7606cd8986cd18f237507d273078c913c36123 Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Mon, 19 May 2025 22:05:28 +0000 Subject: [PATCH] Fix xml custom coordinates cleaning --- deebot_client/commands/xml/clean.py | 31 +++++++++++++++-------------- tests/commands/json/test_clean.py | 21 ++++++++++++++++++- tests/commands/xml/test_clean.py | 1 + 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/deebot_client/commands/xml/clean.py b/deebot_client/commands/xml/clean.py index ef22d5386..6419fd7de 100644 --- a/deebot_client/commands/xml/clean.py +++ b/deebot_client/commands/xml/clean.py @@ -24,38 +24,39 @@ class Clean(ExecuteCommand): HAS_SUB_ELEMENT = True def __init__( - self, action: CleanAction, speed: FanSpeedLevel = FanSpeedLevel.NORMAL + self, + action: CleanAction, + speed: FanSpeedLevel = FanSpeedLevel.NORMAL, + mode: CleanMode = CleanMode.AUTO, + additional_args: dict[str, str] | None = None, ) -> None: + """Initialize the command.""" + if additional_args is None: + additional_args = {} super().__init__( { - "type": CleanMode.AUTO.xml_value, + "type": mode.xml_value, "act": action.xml_value, "speed": speed.xml_value, + **additional_args, } ) -class CleanArea(ExecuteCommand): +class CleanArea(Clean): """Clean area command.""" - NAME = "Clean" - HAS_SUB_ELEMENT = True - def __init__( self, mode: CleanMode, - area: str, + area_or_coordinates: str, cleanings: int = 1, - speed: FanSpeedLevel = FanSpeedLevel.NORMAL, ) -> None: + key = "area" if mode == CleanMode.SPOT_AREA else "p" super().__init__( - { - "type": mode.xml_value, - "act": CleanAction.START.xml_value, - "speed": speed.xml_value, - "deep": str(cleanings), - "mid": area, - } + CleanAction.START, + mode=mode, + additional_args={"deep": str(cleanings), key: area_or_coordinates}, ) diff --git a/tests/commands/json/test_clean.py b/tests/commands/json/test_clean.py index 7955a049b..4d7a7aee0 100644 --- a/tests/commands/json/test_clean.py +++ b/tests/commands/json/test_clean.py @@ -93,8 +93,27 @@ async def test_Clean_act( CleanAreaV2(CleanMode.SPOT_AREA, "5,8"), {"act": "start", "content": {"type": "spotArea", "value": "5,8"}}, ), + ( + CleanArea(CleanMode.CUSTOM_AREA, "1580.0,-4087.0,3833.0,-7525.0"), + { + "act": "start", + "type": "customArea", + "content": "1580.0,-4087.0,3833.0,-7525.0", + "count": 1, + }, + ), + ( + CleanAreaV2(CleanMode.CUSTOM_AREA, "1580.0,-4087.0,3833.0,-7525.0"), + { + "act": "start", + "content": { + "type": "customArea", + "value": "1580.0,-4087.0,3833.0,-7525.0", + }, + }, + ), ], - ids=["CleanArea", "CleanAreaV2"], + ids=["Rooms", "Rooms V2", "Coordinates", "Coordinates V2"], ) async def test_CleanArea( command: CleanArea | CleanAreaV2, args: dict[str, str] diff --git a/tests/commands/xml/test_clean.py b/tests/commands/xml/test_clean.py index 38caf74e8..ab9be79fe 100644 --- a/tests/commands/xml/test_clean.py +++ b/tests/commands/xml/test_clean.py @@ -35,6 +35,7 @@ async def test_Clean(command: Clean) -> None: "command", [ CleanArea(CleanMode.SPOT_AREA, "4", 1), + CleanArea(CleanMode.CUSTOM_AREA, "1580.0,-4087.0,3833.0,-7525.0"), ], ) async def test_CleanArea(command: CleanArea) -> None: