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

Add new fan speed mapping for V2 Roborock Vacuum #20286

Closed
wants to merge 2 commits into from

Conversation

poma
Copy link

@poma poma commented Jan 21, 2019

Description:

Update fan speeds to reflect values that Mi Home app is sending to the vacuum. Tested on Roborock S50, this version correctly reflects values set by the app, and the app correctly highlights speeds set by this component.

To keep backwards compatibility, added a new boolean setting to yaml config - new_fan_speeds which defaults to the old fan speed mapping. Maybe someone can suggest shorter and more clear name for new variables.

Related issue (if applicable): fixes #17695
Link to an earlier attempt to fix this: #17090

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#8233

Example entry for configuration.yaml (if applicable):

vacuum:
- platform: xiaomi_miio
  host: <...>
  token: <...>
  new_fan_speeds: true

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

if value == speed][0]
return speed

@property
def fan_speed_list(self):
"""Get the list of available fan speed steps of the vacuum cleaner."""
return list(sorted(FAN_SPEEDS.keys(), key=lambda s: FAN_SPEEDS[s]))
return list(sorted(self._speed_map.keys(), key=lambda s: self._speed_map[s]))

Choose a reason for hiding this comment

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

line too long (85 > 79 characters)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_TOKEN): vol.All(str, vol.Length(min=32, max=32)),
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_NEW_FAN_SPEEDS, default=DEFAULT_NEW_FAN_SPEEDS): cv.boolean,

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)

@frenck
Copy link
Member

frenck commented Jan 21, 2019

⚠️ I was unable to find a documentation PR (matching this code change) in our documentation repository.

📚Please, update the documentation and open a PR for it (be sure to create a documentation PR against the next branch) and link 🔗 this PR and the new documentation PR by mentioning the link to the PR's in both openings posts/descriptions.

🏷 I am adding the docs-missing label until this has been resolved.

👍 Thanks (times a million!)

@poma
Copy link
Author

poma commented Jan 21, 2019

@frenck fixed, home-assistant/home-assistant.io#8233

@MartinHjelmare
Copy link
Member

Comment on the previous PR attempt:

These values are only valid to the 2nd generation model, the proper way to fix this is to change python-miio to report back the available fan speeds per model and use that information inside home-assistant.

@poma
Copy link
Author

poma commented Jan 23, 2019

Relevant comment from the linked issue

But it is not an issue for the underlying library because it doesn't know about the speeds and it doesn't enumerate them, it just set them by integer value. HA is enumerating the speeds and using library to set them to certain integer value. That would be brand new feature for underlying library to know which type of vacuum it is communicating with and the PR would also need to change the API because now the underyling library would be doing the enumeration of speeds. And then we would also need to change HA.

So if we want to request to push functionality from HA to the underlying library it can take a really long time. The better approach is to solve this within HA. Auto detecting the vacuum version instead of setting it in config would be good though but I don't know a way to do that.

@MartinHjelmare
Copy link
Member

Time isn't an argument for moving logic into home assistant. The library should preferably tell us, somehow, how many speed settings there are per device.

@poma
Copy link
Author

poma commented Jan 23, 2019

But the logic is already in home assistant and it works incorrectly. By that logic we should remove the speed dropdown from home assistant and let user enter integer numbers until this is implemented in miio lib.

@MartinHjelmare
Copy link
Member

No. The library should give us enough information, eg a version or a list of possible speeds, to know the correct interface to use.

@poma
Copy link
Author

poma commented Jan 23, 2019

Maybe. But what currently happens is home assistant tries to guess the list of possible speeds and does this wrong. The existing functionality should be either fixed or removed. The current PR will at least allow user to choose the version to fix their UI.

@MartinHjelmare
Copy link
Member

We should not add a config option for this.

@poma
Copy link
Author

poma commented Jan 23, 2019

Well then, leaving this for someone with more spare time to fix

@syssi
Copy link
Member

syssi commented Jan 23, 2019

@poma I'm planning a python-miio release this weekend. Let's move your code there! :-) I will provide some support.

@poma
Copy link
Author

poma commented Jan 23, 2019

First we will need some way to automatically figure out which mapping to use for a given vacuum. It could depend on vacuum model, firmware version, or even version of the Mi Home app that user installed on their phone, I don't know.

@syssi
Copy link
Member

syssi commented Jan 23, 2019

Got it. Let's start with your device. ;-) Which model and firmware version do you use?

@poma
Copy link
Author

poma commented Jan 23, 2019

Roborock S50, firmware 3.3.9_001710

upd: AFAIK the new mappings should apply to gen 2 vacuum models. Also I've notice that sometimes fan speeds can still use older speed mappings, so when mapping from int to string it should check all mapping versions.

@syssi
Copy link
Member

syssi commented Jan 23, 2019

This is a first draft: rytilahti/python-miio#468

@robbiet480
Copy link
Member

@syssi @poma Checking in on this + Can you fix the merge conflict?

@andrewsayre
Copy link
Member

This PR has gone stale. Please update the code and open a new PR if you wish to continue with this contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Xiaomi vacuum V2 fan speed is not mapped correctly
8 participants