-
-
Notifications
You must be signed in to change notification settings - Fork 97
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 XML command "CleanArea" #817
Open
flubshi
wants to merge
3
commits into
DeebotUniverse:dev
Choose a base branch
from
flubshi:xml_clean_area
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Clean commands.""" | ||
|
||
from __future__ import annotations | ||
|
||
from deebot_client.models import CleanAction, CleanMode | ||
|
||
from .common import ExecuteCommand | ||
|
||
|
||
class CleanArea(ExecuteCommand): | ||
"""Clean area command.""" | ||
|
||
NAME = "Clean" | ||
HAS_SUB_ELEMENT = True | ||
|
||
def __init__(self, mode: CleanMode, area: str, cleanings: int = 1) -> None: | ||
# <ctl><clean type='SpotArea' act='s' speed='standard' deep='1' mid='4,5'/></ctl> | ||
|
||
super().__init__( | ||
{ | ||
"type": mode.xml_value, | ||
"act": CleanAction.START.xml_value, | ||
"speed": "standard", # TODO: FanSpeedLevel.NORMAL.xml_value, after #560 is merged | ||
"deep": str(cleanings), | ||
"mid": area, | ||
} | ||
) |
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,29 @@ | ||
"""Enum util.""" | ||
|
||
from __future__ import annotations | ||
|
||
from enum import StrEnum | ||
from typing import Self | ||
|
||
|
||
class StrEnumWithXml(StrEnum): | ||
"""String enum with xml value.""" | ||
|
||
xml_value: str | ||
|
||
def __new__(cls, value: str, xml_value: str = "") -> Self: | ||
"""Create new StrEnumWithXml.""" | ||
obj = str.__new__(cls, value) | ||
obj._value_ = value | ||
obj.xml_value = xml_value | ||
return obj | ||
|
||
@classmethod | ||
def from_xml(cls, value: str) -> Self: | ||
flubshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Get CleanAction from xml value.""" | ||
for member in cls: | ||
if member.xml_value == value: | ||
return member | ||
|
||
msg = f"{value} is not a valid {cls.__name__}" | ||
raise ValueError(msg) |
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 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from deebot_client.command import CommandResult | ||
from deebot_client.commands.xml.clean import CleanArea | ||
from deebot_client.message import HandlingState | ||
from deebot_client.models import CleanMode | ||
from tests.commands import assert_command | ||
|
||
from . import get_request_xml | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("command", "command_result"), | ||
[ | ||
(CleanArea(CleanMode.SPOT_AREA, "4", 1), HandlingState.SUCCESS), | ||
], | ||
) | ||
async def test_CleanArea(command: CleanArea, command_result: HandlingState) -> None: | ||
json = get_request_xml("<ctl ret='ok'/>") | ||
await assert_command( | ||
command, json, None, command_result=CommandResult(command_result) | ||
) |
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,35 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from deebot_client.util.enum import StrEnumWithXml | ||
|
||
|
||
class TestStrEnumWithXml(StrEnumWithXml): | ||
"""Simple Enum for testing.""" | ||
|
||
ENUM1 = "value1", "xmlvalue1" | ||
ENUM2 = "value2", "xmlvalue2" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("test_enum", "test_value", "test_xml_value"), | ||
[ | ||
(TestStrEnumWithXml.ENUM1, "value1", "xmlvalue1"), | ||
(TestStrEnumWithXml.ENUM2, "value2", "xmlvalue2"), | ||
], | ||
) | ||
def test_StrEnumWithXml_values( | ||
test_enum: TestStrEnumWithXml, test_value: str, test_xml_value: str | ||
) -> None: | ||
assert test_enum.value == test_value | ||
assert test_enum.xml_value == test_xml_value | ||
assert test_value == TestStrEnumWithXml.from_xml(test_xml_value).value | ||
assert test_xml_value == TestStrEnumWithXml(test_value).xml_value | ||
|
||
# test ENUM from invalid xml | ||
try: | ||
TestStrEnumWithXml.from_xml("this_is_invalid") | ||
raise AssertionError | ||
except ValueError: | ||
assert True |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this mean that the bot will always start with the fan level at
standard
and not the one defined in the fan speed entity?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to pass it as parameter. But we have to wait for #560 for the new FanSpeedLevel Enum.
We can either merge it like it is and address this in another PR, or we wait for #560