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

Conversation

mrin
Copy link
Contributor

@mrin mrin commented Nov 6, 2017

Available consumable names:

  • main_brush_work_time
  • side_brush_work_time
  • sensor_dirty_time
  • filter_work_time

CLI example:
miio reset_consumable sensor_dirty_time

Tested with my robot.

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"]

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)

Copy link
Owner

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"]

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)

@coveralls
Copy link

coveralls commented Nov 6, 2017

Coverage Status

Coverage decreased (-0.1%) to 45.071% when pulling aa3338c on mrin:reset_consumable into 23a6aae on rytilahti:master.

Copy link
Owner

@rytilahti rytilahti left a 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.

@pass_dev
def reset_consumable(vac: miio.Vacuum, name):
"""Query and reset consumable."""
click.echo("Reset consumable %s" % name)
Copy link
Owner

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])
Copy link
Owner

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?

Copy link
Contributor Author

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"]
Copy link
Owner

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).

@@ -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()

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

else:
return

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

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):

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

@coveralls
Copy link

coveralls commented Nov 7, 2017

Coverage Status

Coverage decreased (-0.2%) to 45.0% when pulling 1ce83c2 on mrin:reset_consumable into 23a6aae on rytilahti:master.

@coveralls
Copy link

coveralls commented Nov 7, 2017

Coverage Status

Coverage decreased (-0.2%) to 45.018% when pulling de89ac1 on mrin:reset_consumable into 23a6aae on rytilahti:master.

return

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

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)

@coveralls
Copy link

coveralls commented Nov 7, 2017

Coverage Status

Coverage decreased (-0.2%) to 45.018% when pulling d6557ee on mrin:reset_consumable into 23a6aae on rytilahti:master.

@coveralls
Copy link

coveralls commented Nov 7, 2017

Coverage Status

Coverage decreased (-0.2%) to 45.018% when pulling 3d1b833 on mrin:reset_consumable into 23a6aae on rytilahti:master.

elif name == 'sensor_dirty':
consumable = Consumable.SensorDirty
else:
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.argument('name', type=str, required=True)
@pass_dev
def reset_consumable(vac: miio.Vacuum, name):
"""Reset consumable."""
Copy link
Owner

@rytilahti rytilahti Nov 7, 2017

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
"""

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)

@coveralls
Copy link

coveralls commented Nov 8, 2017

Coverage Status

Coverage decreased (-0.2%) to 45.0% when pulling 120de89 on mrin:reset_consumable into 23a6aae on rytilahti:master.

@rytilahti
Copy link
Owner

Thanks a lot! I adjusted the help text a bit.

@coveralls
Copy link

coveralls commented Nov 9, 2017

Coverage Status

Coverage decreased (-0.2%) to 45.0% when pulling 2bbb532 on mrin:reset_consumable into 23a6aae on rytilahti:master.

@rytilahti rytilahti merged commit ed01fd8 into rytilahti:master Nov 9, 2017
@mrin mrin deleted the reset_consumable branch November 9, 2017 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants