-
-
Notifications
You must be signed in to change notification settings - Fork 534
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
Implement adding, deleting and updating the timer #78
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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 |
---|---|---|
|
@@ -294,27 +294,57 @@ def fanspeed(vac: mirobo.Vacuum, speed): | |
click.echo("Current fan speed: %s" % vac.fan_speed()) | ||
|
||
|
||
@cli.command() | ||
@click.argument('timer', required=False, default=None) | ||
@cli.group(invoke_without_command=True) | ||
@pass_dev | ||
@click.pass_context | ||
def timer(ctx, vac: mirobo.Vacuum): | ||
"""List and modify existing timers.""" | ||
if ctx.invoked_subcommand is not None: | ||
return | ||
timers = vac.timer() | ||
click.echo("Timezone: %s\n" % vac.timezone()) | ||
for idx, timer in enumerate(timers): | ||
color = "green" if timer.enabled else "yellow" | ||
click.echo(click.style("Timer #%s, id %s (ts: %s)" % ( | ||
idx, timer.id, timer.ts), bold=True, fg=color)) | ||
click.echo(" %s" % timer.cron) | ||
min, hr, x, y, days = timer.cron.split(' ') | ||
cron = "%s %s %s %s %s" % (min, hr, x, y, days) | ||
click.echo(" %s" % pretty_cron.prettify_cron(cron)) | ||
|
||
|
||
@timer.command() | ||
@click.option('--cron') | ||
@click.option('--command', default='', required=False) | ||
@click.option('--params', default='', required=False) | ||
@pass_dev | ||
def add(vac: mirobo.Vacuum, cron, command, params): | ||
"""Add a timer.""" | ||
click.echo(vac.add_timer(cron, command, params)) | ||
|
||
|
||
@timer.command() | ||
@click.argument('timer_id', type=int, required=True) | ||
@pass_dev | ||
def delete(vac: mirobo.Vacuum, timer_id): | ||
"""Delete a timer.""" | ||
click.echo(vac.delete_timer(timer_id)) | ||
|
||
|
||
@timer.command() | ||
@click.argument('timer_id', type=int, required=True) | ||
@click.option('--enable', is_flag=True) | ||
@click.option('--disable', is_flag=True) | ||
@pass_dev | ||
def timer(vac: mirobo.Vacuum, timer): | ||
"""Schedule vacuuming, times in GMT.""" | ||
if timer: | ||
raise NotImplementedError() | ||
# vac.set_timer(x) | ||
def update(vac: mirobo.Vacuum, timer_id, enable, disable): | ||
"""Enable/disable a timer.""" | ||
from mirobo.vacuum import TimerState | ||
if enable and not disable: | ||
vac.update_timer(timer_id, TimerState.On) | ||
elif disable and not enable: | ||
vac.update_timer(timer_id, TimerState.Off) | ||
else: | ||
timers = vac.timer() | ||
for idx, timer in enumerate(timers): | ||
color = "green" if timer.enabled else "yellow" | ||
# Note ts == ID for changes | ||
click.echo(click.style("Timer #%s, id %s (ts: %s)" % ( | ||
idx, timer.id, timer.ts), bold=True, fg=color)) | ||
print(" %s" % timer.cron) | ||
min, hr, x, y, days = timer.cron.split(' ') | ||
# hr is in gmt+8 (chinese time), TODO convert to local | ||
hr = (int(hr) - 8) % 24 | ||
cron = "%s %s %s %s %s" % (min, hr, x, y, days) | ||
click.echo(" %s" % pretty_cron.prettify_cron(cron)) | ||
click.echo("Only 'on' and 'off' are valid for timer") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this one. |
||
|
||
|
||
@cli.command() | ||
|
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.
You missed to update this line.
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.
Both are fixed now, thanks!