From b7341b07359c7e778465676a43d67f0cd5741dd4 Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Wed, 20 Feb 2019 10:45:24 -0500 Subject: [PATCH] Update SpotArea Update SpotArea and CLI command to more closely reflect the app Library: SpotArea namedarea -> area SpotArea customarea -> map_position CLI Commands: spotclean -> area Ex: sucks area 0,1 - will clean areas 0 and 1 / A and B area options: --map-postion|-p - will clean a specified map coordinate Ex: sucks area -p "-602,1812,800,723" - will clean the specified custom map coordinates --- sucks/__init__.py | 12 ++++++------ sucks/cli.py | 13 +++++++++---- tests/test_commands.py | 22 +++++++++++----------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/sucks/__init__.py b/sucks/__init__.py index 711d156..f8b7c4e 100644 --- a/sucks/__init__.py +++ b/sucks/__init__.py @@ -1020,14 +1020,14 @@ class Stop(Clean): super().__init__('stop', 'normal') class SpotArea(Clean): - def __init__(self, action='start', namedarea='', customarea='', cleanings='1'): - if namedarea != '': #For cleaning specified map area - super().__init__('spot_area', 'normal', act=CLEAN_ACTION_TO_ECOVACS[action], mid=namedarea) - elif customarea != '': #For cleaning custom map area, and specify deep amount 1x/2x - super().__init__('spot_area' ,'normal',act=CLEAN_ACTION_TO_ECOVACS[action], p=customarea, deep=cleanings) + def __init__(self, action='start', area='', map_position='', cleanings='1'): + if area != '': #For cleaning specified area + super().__init__('spot_area', 'normal', act=CLEAN_ACTION_TO_ECOVACS[action], mid=area) + elif map_position != '': #For cleaning custom map area, and specify deep amount 1x/2x + super().__init__('spot_area' ,'normal',act=CLEAN_ACTION_TO_ECOVACS[action], p=map_position, deep=cleanings) else: #no valid entries - raise ValueError("must provide namedarea or customarea for spotarea clean") + raise ValueError("must provide area or map_position for spotarea clean") class Charge(VacBotCommand): def __init__(self): diff --git a/sucks/cli.py b/sucks/cli.py index a241ddf..042d5bb 100644 --- a/sucks/cli.py +++ b/sucks/cli.py @@ -179,10 +179,15 @@ def edge(frequency, minutes): return CliAction(Edge(), wait=TimeWait(minutes * 60)) -@cli.command(help='spotcleans provided room(s)') -@click.argument('room', type=click.STRING) -def spotclean(room): - return CliAction(SpotArea('start', room), wait=StatusWait('charge_status', 'returning')) +@cli.command(help='cleans provided area(s), ex: "0,1"',context_settings={"ignore_unknown_options": True}) #ignore_unknown for map coordinates with negatives +@click.option("--map-position","-p", is_flag=True, help='clean provided map position instead of area, ex: "-602,1812,800,723"') +@click.argument('area', type=click.STRING, required=True) +def area(area, map_position): + if map_position: + return CliAction(SpotArea('start', map_position=area), wait=StatusWait('charge_status', 'returning')) + else: + return CliAction(SpotArea('start', area=area), wait=StatusWait('charge_status', 'returning')) + @cli.command(help='returns to charger') def charge(): diff --git a/tests/test_commands.py b/tests/test_commands.py index 7afa2f5..bbdd4a9 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -61,31 +61,31 @@ def test_spotarea_command(): assert_equals(ElementTree.tostring(c.to_xml()), b'') #Test namedarea clean - c = SpotArea('start', namedarea='0') + c = SpotArea('start', area='0') assert_equals(ElementTree.tostring(c.to_xml()), b'') #Test namedarea keyword clean - c = SpotArea('start', '', '01234,56789') + c = SpotArea('start', '', '-602,1812,800,723') assert_equals(ElementTree.tostring(c.to_xml()), - b'') #Test customarea clean + b'') #Test customarea clean - c = SpotArea('start', '', '01234,56789', '2') + c = SpotArea('start', '', '-602,1812,800,723', '2') assert_equals(ElementTree.tostring(c.to_xml()), - b'') #Test customarea clean with deep 2 + b'') #Test customarea clean with deep 2 - c = SpotArea('start', '', customarea='01234,56789') + c = SpotArea('start', '', map_position='-602,1812,800,723') assert_equals(ElementTree.tostring(c.to_xml()), - b'') #Test customarea keyword clean with deep default + b'') #Test customarea keyword clean with deep default - c = SpotArea('start', customarea='01234,56789', cleanings='2') + c = SpotArea('start', map_position='-602,1812,800,723', cleanings='2') assert_equals(ElementTree.tostring(c.to_xml()), - b'') #Test customarea keyword and cleanings keyword clean with deep default + b'') #Test customarea keyword and cleanings keyword clean with deep default - c = SpotArea('start', namedarea='0', customarea='01234,56789', cleanings='2') + c = SpotArea('start', area='0', map_position='-602,1812,800,723', cleanings='2') assert_equals(ElementTree.tostring(c.to_xml()), b'') #Test all keywords specified, should default to only mid - c = SpotArea('start', '0', '01234,56789','2') + c = SpotArea('start', '0', '-602,1812,800,723','2') assert_equals(ElementTree.tostring(c.to_xml()), b'') #Test all keywords specified, should default to only mid