-
-
Notifications
You must be signed in to change notification settings - Fork 563
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
Conversation
… sensor_dirty_time, filter_work_time
miio/vacuum.py
Outdated
"""Reset consumable information.""" | ||
raise NotImplementedError("unknown parameters") | ||
# self.send("reset_consumable", ["unknown"]) | ||
# name = ["main_brush_work_time", "side_brush_work_time", "sensor_dirty_time" or "filter_work_time"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (108 > 79 characters)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you create a Consumable
enum, and use it instead of passing strings around. See https://github.com/rytilahti/python-miio/blob/master/miio/vacuum.py#L20 (and its use in https://github.com/rytilahti/python-miio/blob/master/miio/vacuum.py#L164) for example.
We do not need to follow their naming scheme either, I think it makes sense here to go for the same naming as in ConsumableStatus
(https://github.com/rytilahti/python-miio/blob/master/miio/vacuumcontainers.py#L284).
miio/vacuum.py
Outdated
"""Reset consumable information.""" | ||
raise NotImplementedError("unknown parameters") | ||
# self.send("reset_consumable", ["unknown"]) | ||
# name = ["main_brush_work_time", "side_brush_work_time", "sensor_dirty_time" or "filter_work_time"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (108 > 79 characters)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! This will be good to have around when it's time for a filter change. I added some slight commentary which should be done before getting this merged.
miio/vacuum_cli.py
Outdated
@pass_dev | ||
def reset_consumable(vac: miio.Vacuum, name): | ||
"""Query and reset consumable.""" | ||
click.echo("Reset consumable %s" % name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Reseting consumable '%s'" would look here nicer.
miio/vacuum.py
Outdated
raise NotImplementedError("unknown parameters") | ||
# self.send("reset_consumable", ["unknown"]) | ||
# name = ["main_brush_work_time", "side_brush_work_time", "sensor_dirty_time" or "filter_work_time"] | ||
return self.send("reset_consumable", [name]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you happen to know if multiple consumables can be reseted at once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I not tried this case on my robo.
miio/vacuum.py
Outdated
"""Reset consumable information.""" | ||
raise NotImplementedError("unknown parameters") | ||
# self.send("reset_consumable", ["unknown"]) | ||
# name = ["main_brush_work_time", "side_brush_work_time", "sensor_dirty_time" or "filter_work_time"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you create a Consumable
enum, and use it instead of passing strings around. See https://github.com/rytilahti/python-miio/blob/master/miio/vacuum.py#L20 (and its use in https://github.com/rytilahti/python-miio/blob/master/miio/vacuum.py#L164) for example.
We do not need to follow their naming scheme either, I think it makes sense here to go for the same naming as in ConsumableStatus
(https://github.com/rytilahti/python-miio/blob/master/miio/vacuumcontainers.py#L284).
miio/vacuum_cli.py
Outdated
@@ -445,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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 2 blank lines after class or function definition, found 1
miio/vacuum_cli.py
Outdated
else: | ||
return | ||
|
||
click.echo("Resetting consumable '%s': %s" % (name, vac.consumable_reset(consumable))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (90 > 79 characters)
miio/vacuum.py
Outdated
@@ -21,6 +21,12 @@ class TimerState(enum.Enum): | |||
On = "on" | |||
Off = "off" | |||
|
|||
class Consumable(enum.Enum): |
There was a problem hiding this comment.
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
miio/vacuum_cli.py
Outdated
return | ||
|
||
click.echo("Resetting consumable '%s': %s" % (name, | ||
vac.consumable_reset(consumable))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (84 > 79 characters)
miio/vacuum_cli.py
Outdated
elif name == 'sensor_dirty': | ||
consumable = Consumable.SensorDirty | ||
else: | ||
return |
There was a problem hiding this comment.
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.
miio/vacuum_cli.py
Outdated
@click.argument('name', type=str, required=True) | ||
@pass_dev | ||
def reset_consumable(vac: miio.Vacuum, name): | ||
"""Reset consumable.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a list information about the available values? Adding an empty line after the "title line" will make it only visible when help on the specific command is requested, IIRC, so I suppose something like this would work:
"""Reset consumable state.
Allowed values:
main_brush - explanation
another one - x
"""
miio/vacuum_cli.py
Outdated
elif name == 'sensor_dirty': | ||
consumable = Consumable.SensorDirty | ||
else: | ||
click.echo("Allowed values: main_brush, side_brush, filter, sensor_dirty") |
There was a problem hiding this comment.
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)
Thanks a lot! I adjusted the help text a bit. |
Available consumable names:
CLI example:
miio reset_consumable sensor_dirty_time
Tested with my robot.