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 pause, resume, fixed stop #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added dist/sucks-0.9.3-py3.7.egg
Binary file not shown.
24 changes: 19 additions & 5 deletions sucks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
CLEAN_MODE_SPOT_AREA = 'spot_area'
CLEAN_MODE_SINGLE_ROOM = 'single_room'
CLEAN_MODE_STOP = 'stop'
CLEAN_MODE_PAUSE = 'pause'

CLEAN_ACTION_START = 'start'
CLEAN_ACTION_PAUSE = 'pause'
Expand Down Expand Up @@ -61,7 +62,8 @@
CLEAN_MODE_SPOT: 'spot',
CLEAN_MODE_SPOT_AREA: 'SpotArea',
CLEAN_MODE_SINGLE_ROOM: 'singleroom',
CLEAN_MODE_STOP: 'stop'
CLEAN_MODE_STOP: 'stop',
CLEAN_MODE_PAUSE: 'pause',
}

CLEAN_ACTION_TO_ECOVACS = {
Expand All @@ -85,7 +87,8 @@
'spot_area': CLEAN_MODE_SPOT_AREA,
'singleroom': CLEAN_MODE_SINGLE_ROOM,
'stop': CLEAN_MODE_STOP,
'going': CHARGE_MODE_RETURNING
'going': CHARGE_MODE_RETURNING,
'pause': CLEAN_MODE_PAUSE,
}

FAN_SPEED_TO_ECOVACS = {
Expand Down Expand Up @@ -727,8 +730,9 @@ def send_ping(self):
return False

def send_command(self, action, recipient):
if action.name == "Clean": #For handling Clean when action not specified (i.e. CLI)
action.args['clean']['act'] = CLEAN_ACTION_TO_ECOVACS['start'] #Inject a start action
# these lines cause pause commands to not work, so it is disabled
# if action.name == "Clean": #For handling Clean when action not specified (i.e. CLI)
# action.args['clean']['act'] = CLEAN_ACTION_TO_ECOVACS['start'] #Inject a start action
c = self._wrap_command(action, recipient)
_LOGGER.debug('Sending command {0}'.format(c))
self._handle_ctl_api(action,
Expand Down Expand Up @@ -1044,7 +1048,17 @@ def __init__(self):

class Stop(Clean):
def __init__(self):
super().__init__('stop', 'normal')
super().__init__(mode='stop', action="stop")

class Pause(Clean):
def __init__(self):
super().__init__(mode="pause",action='pause')


class Resume(Clean):
def __init__(self):
super().__init__(mode="auto",action='resume')


class SpotArea(Clean):
def __init__(self, action='start', area='', map_position='', cleanings='1'):
Expand Down
50 changes: 37 additions & 13 deletions sucks/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import click
from pycountry_convert import country_alpha2_to_continent_code

import sucks
from sucks import *

print(sucks.__file__)

Choose a reason for hiding this comment

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

Is this needed or just a forgotten print ?

Copy link
Author

Choose a reason for hiding this comment

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

Just forgotten, can be omitted!

_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -67,12 +68,15 @@ def __init__(self, wait_on, wait_for):

def wait(self, bot):
if not hasattr(bot, self.wait_on):
raise ValueError("object " + bot + " does not have method " + self.wait_on)
_LOGGER.debug("waiting on " + self.wait_on + " for value " + self.wait_for)
raise ValueError("object " + bot +
" does not have method " + self.wait_on)
_LOGGER.debug("waiting on " + self.wait_on +
" for value " + self.wait_for)

while getattr(bot, self.wait_on) != self.wait_for:
time.sleep(0.5)
_LOGGER.debug("wait complete; " + self.wait_on + " is now " + self.wait_for)
_LOGGER.debug("wait complete; " + self.wait_on +
" is now " + self.wait_for)


class CliAction:
Expand All @@ -96,7 +100,8 @@ def config_file_exists():
def read_config():
parser = configparser.ConfigParser()
with open(config_file()) as fp:
parser.read_file(itertools.chain(['[global]'], fp), source=config_file())
parser.read_file(itertools.chain(
['[global]'], fp), source=config_file())
return parser['global']


Expand Down Expand Up @@ -124,7 +129,8 @@ def should_run(frequency):
return True
n = random.random()
result = n <= frequency
_LOGGER.debug("tossing coin: {:0.3f} <= {:0.3f}: {}".format(n, frequency, result))
_LOGGER.debug("tossing coin: {:0.3f} <= {:0.3f}: {}".format(
n, frequency, result))
return result


Expand All @@ -150,7 +156,8 @@ def login(email, password, country_code, continent_code, verify_ssl):
password_hash = EcoVacsAPI.md5(password)
device_id = EcoVacsAPI.md5(str(time.time()))
try:
EcoVacsAPI(device_id, email, password_hash, country_code, continent_code, verify_ssl)
EcoVacsAPI(device_id, email, password_hash,
country_code, continent_code, verify_ssl)
except ValueError as e:
click.echo(e.args[0])
exit(1)
Expand All @@ -169,7 +176,7 @@ def login(email, password, country_code, continent_code, verify_ssl):
@click.option('--frequency', '-f', type=FREQUENCY, help='frequency with which to run; e.g. 0.5 or 3/7')
@click.argument('minutes', type=click.FLOAT)
def clean(frequency, minutes):
waiter = StatusWait('charge_status', 'charging')
waiter = StatusWait('charge_status', 'charging')
if minutes > 0:
waiter = TimeWait(minutes * 60)

Expand All @@ -185,15 +192,16 @@ def edge(frequency, minutes):
return CliAction(Edge(), wait=TimeWait(minutes * 60))


@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"')
# ignore_unknown for map coordinates with negatives
@cli.command(help='cleans provided area(s), ex: "0,1"', context_settings={"ignore_unknown_options": True})
@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'))
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():
Expand All @@ -209,6 +217,21 @@ def stop():
return CliAction(Stop(), terminal=True, wait=StatusWait('clean_status', 'stop'))


@cli.command(help='pause the robot in its current position')
def pause():
return CliAction(Pause(), terminal=True, wait=StatusWait('clean_status', 'pause'))


@cli.command(help='Resume job')
def resume():
return CliAction(Resume(), terminal=True, wait=StatusWait('charge_status', 'charging'))


@cli.command(help='get the current state of the robot')
def state():
return CliAction(GetCleanState(), terminal=True, wait=TimeWait(10))


@cli.resultcallback()
def run(actions, debug):
actions = list(filter(None.__ne__, actions))
Expand All @@ -227,7 +250,8 @@ def run(actions, debug):
api = EcoVacsAPI(config['device_id'], config['email'], config['password_hash'],
config['country'], config['continent'], verify_ssl=config['verify_ssl'])
vacuum = api.devices()[0]
vacbot = VacBot(api.uid, api.REALM, api.resource, api.user_access_token, vacuum, config['continent'], verify_ssl=config['verify_ssl'])
vacbot = VacBot(api.uid, api.REALM, api.resource, api.user_access_token,
vacuum, config['continent'], verify_ssl=config['verify_ssl'])
vacbot.connect_and_wait_until_ready()

for action in actions:
Expand Down