diff --git a/miio/vacuum.py b/miio/vacuum.py index 7742b453e..16aa475e9 100644 --- a/miio/vacuum.py +++ b/miio/vacuum.py @@ -21,6 +21,14 @@ 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.""" @@ -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.""" diff --git a/miio/vacuum_cli.py b/miio/vacuum_cli.py index 5f0966d52..618cd42e2 100644 --- a/miio/vacuum_cli.py +++ b/miio/vacuum_cli.py @@ -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("Unexpected state name: %s" % name) + return + + click.echo("Resetting consumable '%s': %s" % ( + name, + vac.consumable_reset(consumable) + )) + + @cli.command() @pass_dev def start(vac: miio.Vacuum):