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

Added new commands app_goto_target and app_zoned_clean #310

Merged
merged 11 commits into from
Apr 18, 2018
22 changes: 21 additions & 1 deletion miio/tests/test_vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
class DummyVacuum(DummyDevice, Vacuum):
STATE_CHARGING = 8
STATE_CLEANING = 5
STATE_ZONED_CLEAN = 9
STATE_IDLE = 3
STATE_HOME = 6
STATE_SPOT = 11
STATE_GOTO = 4
STATE_ERROR = 12
STATE_PAUSED = 10
STATE_MANUAL = 7
Expand All @@ -28,7 +30,7 @@ def __init__(self, *args, **kwargs):
'clean_area': 0,
'battery': 100,
'fan_power': 20,
'msg_seq': 320
'msg_seq': 320,
}

self.return_values = {
Expand All @@ -37,6 +39,8 @@ def __init__(self, *args, **kwargs):
'app_stop': lambda x: self.change_mode("stop"),
'app_pause': lambda x: self.change_mode("pause"),
'app_spot': lambda x: self.change_mode("spot"),
'app_goto_target': lambda x: self.change_mode("goto"),
'app_zoned_clean': lambda x: self.change_mode("zoned clean"),
'app_charge': lambda x: self.change_mode("charge")
}

Expand All @@ -53,6 +57,10 @@ def change_mode(self, new_mode):
self.state["state"] = DummyVacuum.STATE_CLEANING
elif new_mode == "stop":
self.state["state"] = DummyVacuum.STATE_IDLE
elif new_mode == "goto":
self.state["state"] = DummyVacuum.STATE_GOTO
elif new_mode == "zoned cleaning":
self.state["state"] = DummyVacuum.STATE_ZONED_CLEAN
elif new_mode == "charge":
self.state["state"] = DummyVacuum.STATE_CHARGING

Expand Down Expand Up @@ -128,6 +136,18 @@ def test_home(self):
# Another option is to mock that app_stop mode is entered before
# the charging is activated.

def test_goto(self):
self.device.start()
assert self.status().is_on is True
self.device.goto(24000,24000)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace after ','

assert self.status().state_code == self.device.STATE_GOTO

def test_zoned_clean(self):
self.device.start()
assert self.status().is_on is True
self.device.zoned_clean(25000,25000,25500,25500,3)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing whitespace after ','

assert self.status().state_code == self.device.STATE_ZONED_CLEAN

@pytest.mark.xfail
def test_manual_control(self):
self.fail()
Expand Down
29 changes: 29 additions & 0 deletions miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,35 @@ def home(self):
self.send("app_stop")
return self.send("app_charge")

@command(
click.argument("x_coord", type=int),
click.argument("y_coord", type=int),
)
def goto(self, x_coord: int, y_coord: int):
"""Go to specific target.
:param int x_coord: x coordinate
:param int y_coord: y coordinate"""
return self.send("app_goto_target",
[x_coord, y_coord])

@command(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 1 blank line, found 0

click.argument("x1_coord", type=int),
click.argument("y1_coord", type=int),
click.argument("x2_coord", type=int),
click.argument("y2_coord", type=int),
click.argument("iterations", type=int),
)
def zoned_clean(self, x1_coord: int, y1_coord: int,
x2_coord: int, y2_coord: int, iterations: int):
"""Clean a zoned area.
:param int x1_coord: x1 coordinate bottom left corner
:param int y1_coord: y1 coordinate bottom left corner
:param int x2_coord: x2 coordinate top right corner
:param int y2_coord: y2 coordinate top right corner
:param int iterations: How many times the zone should be cleaned"""
return self.send("app_zoned_clean",
[x1_coord, y1_coord, x2_coord, y2_coord, iterations])

@command()
def manual_start(self):
"""Start manual control mode."""
Expand Down