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

Reset consumable by name #115

Merged
merged 7 commits into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from 6 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
13 changes: 10 additions & 3 deletions miio/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class TimerState(enum.Enum):
On = "on"
Off = "off"


class Consumable(enum.Enum):

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

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 +118,9 @@ def consumable_status(self) -> ConsumableStatus:
"""Return information about consumables."""
return ConsumableStatus(self.send("get_consumable")[0])

def consumable_reset(self):
def consumable_reset(self, consumable: Consumable):
"""Reset consumable information."""
raise NotImplementedError("unknown parameters")
# self.send("reset_consumable", ["unknown"])
return self.send("reset_consumable", [consumable.value])

def map(self):
"""Return map token."""
Expand Down
27 changes: 27 additions & 0 deletions miio/vacuum_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,33 @@ def consumables(vac: miio.Vacuum):
click.echo("Sensor dirty: %s" % res.sensor_dirty)


@cli.command()
@click.argument('name', type=str, required=True)
@pass_dev
def reset_consumable(vac: miio.Vacuum, name):
"""Reset consumable state

Allowed values: main_brush, side_brush, filter, sensor_dirty
"""
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:
click.echo("Allowed values: main_brush, side_brush, filter, sensor_dirty")

Choose a reason for hiding this comment

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

line too long (82 > 79 characters)

return
Copy link
Owner

Choose a reason for hiding this comment

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

I think it makes sense to error out here before returning, if not just to avoid bug reports caused by potential misspellings / name changes.


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


@cli.command()
@pass_dev
def start(vac: miio.Vacuum):
Expand Down