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

Implement adding, deleting and updating the timer #78

Merged
merged 4 commits into from Sep 16, 2017
Merged

Conversation

rytilahti
Copy link
Owner

New commands are:

  • mirobo timer add --cron --command --params
  • mirobo timer delete
  • mirobo timer update [--on|--off]

Although the vacuum accepts command and params, the added cron entry will be just 'start_clean'

New commands are:
  * mirobo timer add --cron <cron string> --command <command> --params <params>
  * mirobo timer delete <id>
  * mirobo timer update [--on|--off] <id>

Although the vacuum accepts command and params, the added cron entry will be just 'start_clean'
mirobo/vacuum.py Outdated

def update_timer(self, timer_id: int, mode):
if mode != "on" and mode != "off":
raise DeviceException("update_timer needs to be either 'on' or 'off")

Choose a reason for hiding this comment

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

line too long (81 > 79 characters)

mirobo/vacuum.py Outdated
def add_timer(self, cron, command, parameters):
import time
ts = int(round(time.time() * 1000))
return self.send("set_timer", [[str(ts), [cron, [command, parameters]]]])

Choose a reason for hiding this comment

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

line too long (81 > 79 characters)

@coveralls
Copy link

coveralls commented Sep 15, 2017

Coverage Status

Coverage decreased (-0.4%) to 32.645% when pulling f3d5e43 on vacuum_timer into 69ae780 on master.

@coveralls
Copy link

coveralls commented Sep 15, 2017

Coverage Status

Coverage decreased (-0.4%) to 32.645% when pulling 52c0c58 on vacuum_timer into 69ae780 on master.

@rytilahti
Copy link
Owner Author

@syssi please check and feel free to merge as you see fit. Same applies for the readme update in #79!

# 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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you use print here instead of click.echo?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Fixed.

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Be careful here. I assume the issue will be fixed in future. Users of the mi home app are affected, too.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Since the vacuum supports timezones nowadays, those should be times in active timezone. Removed the conversion and added a print-out for the timezone.

@click.option('--off', is_flag=True)
@pass_dev
def update(vac: mirobo.Vacuum, timer_id, on, off):
"""Update (on or off) an existing scheduled."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Enable/Disable a stored timer. I would prefer "--enable" and "--disable" as well.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Changed to --enable and --disable, """Enable/disable a timer.""" as help message to be consistent with other commands.

mirobo/vacuum.py Outdated
return self.send("del_timer", [str(timer_id)])

def update_timer(self, timer_id: int, mode):
if mode != "on" and mode != "off":
Copy link
Collaborator

Choose a reason for hiding this comment

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

You would suggest a "enum class" here. ;-)

Copy link
Owner Author

Choose a reason for hiding this comment

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

I would indeed, was thinking about whether to have it for a boolean here. I changed it by adding Vacuum.TimerState {On, Off} ;-)

@coveralls
Copy link

coveralls commented Sep 16, 2017

Coverage Status

Coverage decreased (-0.3%) to 32.784% when pulling 6398796 on vacuum_timer into 69ae780 on master.

README.md Outdated
Activating/deactivating an existing timer,
use `mirobo timer` to get the required id.
```
$ mirobo timer update <id> [--off|--on]
Copy link
Collaborator

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.

Copy link
Owner Author

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!

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")
Copy link
Collaborator

Choose a reason for hiding this comment

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

And this one.

@coveralls
Copy link

coveralls commented Sep 16, 2017

Coverage Status

Coverage decreased (-0.3%) to 32.784% when pulling b63b5d6 on vacuum_timer into 69ae780 on master.

@syssi syssi merged commit e3f6389 into master Sep 16, 2017
@syssi syssi deleted the vacuum_timer branch September 16, 2017 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants