Skip to content

Commit

Permalink
Refactoring reset consumable
Browse files Browse the repository at this point in the history
  • Loading branch information
mrin committed Nov 7, 2017
1 parent aa3338c commit 1ce83c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
11 changes: 8 additions & 3 deletions miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class TimerState(enum.Enum):
On = "on"
Off = "off"

class Consumable(enum.Enum):
MainBrush = "main_brush_work_time"
SideBrush = "side_brush_work_time"
Filter = "filter_work_time"
SensorDirty = "sensor_dirty_time"

class Vacuum(Device):
"""Main class representing the vacuum."""

Expand Down Expand Up @@ -110,10 +116,9 @@ def consumable_status(self) -> ConsumableStatus:
"""Return information about consumables."""
return ConsumableStatus(self.send("get_consumable")[0])

def consumable_reset(self, name):
def consumable_reset(self, consumable: Consumable):
"""Reset consumable information."""
# name = ["main_brush_work_time", "side_brush_work_time", "sensor_dirty_time" or "filter_work_time"]
return self.send("reset_consumable", [name])
return self.send("reset_consumable", [consumable.value])

def map(self):
"""Return map token."""
Expand Down
19 changes: 15 additions & 4 deletions miio/vacuum_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,20 @@ def consumables(vac: miio.Vacuum):
@click.argument('name', type=str, required=True)
@pass_dev
def reset_consumable(vac: miio.Vacuum, name):
"""Query and reset consumable."""
click.echo("Reset consumable %s" % name)
vac.consumable_reset(name)
"""Reset consumable."""
from miio.vacuum import Consumable
if name == 'main_brush':
consumable = Consumable.MainBrush
elif name == 'side_brush':
consumable = Consumable.SideBrush
elif name == 'filter':
consumable = Consumable.Filter
elif name == 'sensor_dirty':
consumable = Consumable.SensorDirty
else:
return

click.echo("Resetting consumable '%s': %s" % (name, vac.consumable_reset(consumable)))


@cli.command()
Expand Down Expand Up @@ -454,6 +465,6 @@ def raw_command(vac: miio.Vacuum, cmd, parameters):
click.echo("Sending cmd %s with params %s" % (cmd, params))
click.echo(vac.raw_command(cmd, params))


cli()
if __name__ == "__main__":
cli()

0 comments on commit 1ce83c2

Please sign in to comment.