Skip to content

Commit 6398796

Browse files
committed
handle commentary from the pr
1 parent 52c0c58 commit 6398796

2 files changed

Lines changed: 25 additions & 20 deletions

File tree

mirobo/vacuum.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import math
33
import time
44
from typing import List
5+
import enum
56

67
from .vacuumcontainers import (VacuumStatus, ConsumableStatus,
78
CleaningSummary, CleaningDetails, Timer)
@@ -14,6 +15,10 @@ class VacuumException(DeviceException):
1415
pass
1516

1617

18+
class TimerState(enum.Enum):
19+
On = "on"
20+
Off = "off"
21+
1722
class Vacuum(Device):
1823
"""Main class representing the vacuum."""
1924

@@ -139,20 +144,22 @@ def timer(self) -> List[Timer]:
139144

140145
return timers
141146

142-
def add_timer(self, cron, command, parameters):
147+
def add_timer(self, cron: str, command: str, parameters: str):
148+
"""Add a timer."""
143149
import time
144150
ts = int(round(time.time() * 1000))
145151
return self.send("set_timer", [
146152
[str(ts), [cron, [command, parameters]]]
147153
])
148154

149155
def delete_timer(self, timer_id: int):
156+
"""Delete a timer."""
150157
return self.send("del_timer", [str(timer_id)])
151158

152-
def update_timer(self, timer_id: int, mode):
153-
if mode != "on" and mode != "off":
154-
raise DeviceException("'on' or 'off are only allowed")
155-
return self.send("upd_timer", [str(timer_id), mode])
159+
def update_timer(self, timer_id: int, mode: TimerState):
160+
if mode != TimerState.On and mode != TimerState.Off:
161+
raise DeviceException("Only 'On' or 'Off' are allowed")
162+
return self.send("upd_timer", [str(timer_id), mode.value])
156163

157164
def dnd_status(self):
158165
"""Returns do-not-disturb status."""

mirobo/vacuum_cli.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,13 @@ def timer(ctx, vac: mirobo.Vacuum):
302302
if ctx.invoked_subcommand is not None:
303303
return
304304
timers = vac.timer()
305+
click.echo("Timezone: %s\n" % vac.timezone())
305306
for idx, timer in enumerate(timers):
306307
color = "green" if timer.enabled else "yellow"
307-
# Note ts == ID for changes
308308
click.echo(click.style("Timer #%s, id %s (ts: %s)" % (
309309
idx, timer.id, timer.ts), bold=True, fg=color))
310-
print(" %s" % timer.cron)
310+
click.echo(" %s" % timer.cron)
311311
min, hr, x, y, days = timer.cron.split(' ')
312-
# hr is in gmt+8 (chinese time), TODO convert to local
313-
if hr != '*':
314-
hr = (int(hr) - 8) % 24
315312
cron = "%s %s %s %s %s" % (min, hr, x, y, days)
316313
click.echo(" %s" % pretty_cron.prettify_cron(cron))
317314

@@ -322,29 +319,30 @@ def timer(ctx, vac: mirobo.Vacuum):
322319
@click.option('--params', default='', required=False)
323320
@pass_dev
324321
def add(vac: mirobo.Vacuum, cron, command, params):
325-
"""Schedule vacuuming.."""
322+
"""Add a timer."""
326323
click.echo(vac.add_timer(cron, command, params))
327324

328325

329326
@timer.command()
330327
@click.argument('timer_id', type=int, required=True)
331328
@pass_dev
332329
def delete(vac: mirobo.Vacuum, timer_id):
333-
"""Delete existing schedule."""
330+
"""Delete a timer."""
334331
click.echo(vac.delete_timer(timer_id))
335332

336333

337334
@timer.command()
338335
@click.argument('timer_id', type=int, required=True)
339-
@click.option('--on', is_flag=True)
340-
@click.option('--off', is_flag=True)
336+
@click.option('--enable', is_flag=True)
337+
@click.option('--disable', is_flag=True)
341338
@pass_dev
342-
def update(vac: mirobo.Vacuum, timer_id, on, off):
343-
"""Update (on or off) an existing scheduled."""
344-
if on and not off:
345-
vac.update_timer(timer_id, "on")
346-
elif off and not on:
347-
vac.update_timer(timer_id, "off")
339+
def update(vac: mirobo.Vacuum, timer_id, enable, disable):
340+
"""Enable/disable a timer."""
341+
from mirobo.vacuum import TimerState
342+
if enable and not disable:
343+
vac.update_timer(timer_id, TimerState.On)
344+
elif disable and not enable:
345+
vac.update_timer(timer_id, TimerState.Off)
348346
else:
349347
click.echo("Only 'on' and 'off' are valid for timer")
350348

0 commit comments

Comments
 (0)