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

My shot at 'Vacuum: Provide human readable fan speeds (rytilahti#468)' #523

Closed
wants to merge 2 commits into from

Conversation

bugficks
Copy link

Since #468 seems to be stalled for some time I took the freedom to give it a try.

It supports both enums and integer levels.
The issue with V2 levels is that those 100 > levels < 105 get converted to percentage level on device so when queried later they return a different value.

# mirobo fanspeed
Current fan speed: FanSpeed.Max

# mirobo fanspeed 10
Setting fan speed to 10

# mirobo fanspeed
Current fan speed: FanSpeed.Level_10

# mirobo fanspeed 60
Setting fan speed to 60

# mirobo fanspeed
Current fan speed: FanSpeed.Balanced

# mirobo fanspeed mop
Setting fan speed to mop

# mirobo fanspeed
Current fan speed: FanSpeed.Mop

# mirobo fanspeed 105
Setting fan speed to 105

# mirobo fanspeed
Current fan speed: FanSpeed.Mop

vac.set_fan_speed(speed)
else:
click.echo("Current fan speed: %s" % vac.fan_speed())

@cli.command()

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.py Outdated
)
def set_fan_speed(self, speed: int):
def set_fan_speed(self, speed: [int,FanSpeed]):

Choose a reason for hiding this comment

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

missing whitespace after ','

Turbo = 77
Max = 90

@enum.unique

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.py Outdated


FanSpeed = enum.Enum('FanSpeed',
[

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent

@coveralls
Copy link

coveralls commented Jun 25, 2019

Coverage Status

Coverage decreased (-0.8%) to 71.149% when pulling 38aa5a9 on bugficks:vacuum-fan-speeds into cc1a559 on rytilahti:master.

@bugficks
Copy link
Author

bugficks commented Jul 3, 2019

seems there is no interest...

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.

Every PR is very much appreciated and I'm sorry that it took so long time to answer to you. As explained elsewhere, I do not currently have access to my test device, so I'm hesitant to merge things that can break something for existing users.

If you are still willing to work on this, I'm sure it'd be greatly appreciated by those who are having a problem with the current implementation, so I left some commentary behind..

('Mop', 'mop'),
]
# comment if only levels above are wanted...
+ [("Level_%d" % x, x) for x in range(0, 101)]
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure sure if there should be specific values for separate levels, I'd prefer to have just a "Custom" or "Other" and let the user of the library to handle the case however it wants to.

@@ -46,6 +79,32 @@ def __init__(self, ip: str, token: str = None, start_id: int = 0,
debug: int = 0) -> None:
super().__init__(ip, token, start_id, debug)
self.manual_seqnum = -1
self._model = self.info().model
self._init_fan_speeds()
Copy link
Owner

Choose a reason for hiding this comment

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

Until now the library does not do any I/O operations in constructors, so I think this should be deferred until it's really necessary. One way would be to have an internal _fanspeedMap function/property, which queries and stores the data during the first fetch for later uses.

)
def set_fan_speed(self, speed: int):
def set_fan_speed(self, speed: [int, FanSpeed]):
Copy link
Owner

Choose a reason for hiding this comment

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

This could be an Union, but I think it is better to keep it as integer; or is there some specific need why both should be accepted?

return self.send("get_custom_mode")[0]
speed = self.send("get_custom_mode")[0]
try:
if hasattr(self, '_fanspeedMap'):
Copy link
Owner

Choose a reason for hiding this comment

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

This should be already defined when it gets this far, so no need for checking, right?

return speed

@command()
def fan_speed_list(self):
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe fan_speed_presets?

if speed:
click.echo("Setting fan speed to %s" % speed)
try:
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 first to check for the preset name, and then fall back to int conversion. Furthermore, if the conversion is not possible, and the exception should be captured and reported back.

rytilahti added a commit that referenced this pull request Mar 15, 2020
This returns a dictionary {name, value} of the available fan speeds,
the main driver being the need to simplify homeassistant integrations for different devices.

For viomi vacuums this is currently straightforward and hard-coded, but we do special handling
for rockrobo devices (based on info() responses):

* If the query succeeds, newer firmware versions (3.5.7+) of v1 are handled as a special case,
  otherwise the new-style [100-105] mapping is returned.

* If the query fails, we fall back to rockrobo v1's percentage-based mapping.
  This happens, e.g., when the vacuum has no cloud connectivity.

Related to #523

Related downstream issues
home-assistant/core#32821
home-assistant/core#31268
home-assistant/core#27268
rytilahti added a commit that referenced this pull request Mar 27, 2020
* Add fan_speed_presets() for querying available fan speeds

This returns a dictionary {name, value} of the available fan speeds,
the main driver being the need to simplify homeassistant integrations for different devices.

For viomi vacuums this is currently straightforward and hard-coded, but we do special handling
for rockrobo devices (based on info() responses):

* If the query succeeds, newer firmware versions (3.5.7+) of v1 are handled as a special case,
  otherwise the new-style [100-105] mapping is returned.

* If the query fails, we fall back to rockrobo v1's percentage-based mapping.
  This happens, e.g., when the vacuum has no cloud connectivity.

Related to #523

Related downstream issues
home-assistant/core#32821
home-assistant/core#31268
home-assistant/core#27268

* Fix method naming..

* small pre-merge cleanups
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.

None yet

4 participants