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

Use backend-provided fan speed presets for Xiaomi vacuums, bump python-miio #32850

Merged
merged 7 commits into from
Apr 2, 2020

Conversation

rytilahti
Copy link
Member

@rytilahti rytilahti commented Mar 15, 2020

This needs input from Xiaomi vacuum owners to verify that it does not break anything.
I have personally tested this on rockrobo v1 (old mapping).

Devices tested (thanks!):

  • rockrobo v1 (old fw, by me)
  • rockrobo v1 (new fw, testers wanted!)
  • Xiaomi Vacuum 1S (by @pplucky)
  • Roborock S4 (by @DeadEnded)
  • Roborock S5 (by @markrennie71)
  • Roborock S55 v2 (by @Blackpander)

Related issues/PRs:
#32821 (replaces)
#31268
#27268

Breaking change

Proposed change

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

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

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

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

This needs input from Xiaomi vacuum owners to verify that it does not break anything.
I have personally tested this on rockrobo v1 (old mapping).

Related issues/PRs:
home-assistant#32821
home-assistant#31268
home-assistant#27268

This is a WIP as it requires a new upstream release.
The PR is rytilahti/python-miio#643
@probot-home-assistant
Copy link

Hey there @syssi, mind taking a look at this pull request as its been labeled with a integration (xiaomi_miio) you are listed as a codeowner for? Thanks!

@cyborghound
Copy link

I can test this for you with Roborock S55 V2. How can I do this, just importing the xiaomi_miio as custom component?

@rytilahti
Copy link
Member Author

rytilahti commented Mar 15, 2020

Thanks for the offer! So testing this requires manually installing the linked python-miio PR (pip install -e git+https://github.com/rytilahti/python-miio.git@fanspeed_reporting#egg=python-miio) and then this PR (which can be added as a custom_component for testing).

My hope is that I can get at least some feedback from non-v1 (old) users before I prepare a new python-miio release, after which this PR needs to be updated to bump the version.

edit: You can also check out if the library part is working before going to test whether it works with homeassistant:

$ miiocli vacuum --ip 192.168.xx.xx --token <token> fan_speed_presets

Running command fan_speed_presets
ERROR:miio.protocol:unable to parse json '': Expecting value: line 1 column 1 (char 0)
{'Silent': 38, 'Standard': 60, 'Medium': 77, 'Turbo': 90}

@cyborghound
Copy link

cyborghound commented Mar 15, 2020

@rytilahti I installed a new instance of Home Assistant 106.6 on my Macbook and installed the library you named, and connected my vacuum. Also picked the whole xiaomi_miio integration and placed it in custom_components with your PR. I got the following error in the log:

Log Details (ERROR)
Logger: homeassistant.components.vacuum
Integration: Vacuum (documentation, issues)
First occured: 11:20:56 PM (1 occurences)
Last logged: 11:20:56 PM

xiaomi_miio: Error on device update!
Traceback (most recent call last):
File "/Users/---------/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 312, in _async_add_entity
await entity.async_device_update(warning=False)
File "/Users/---------/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 476, in async_device_update
await self.hass.async_add_executor_job(self.update)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/Users/---------/.homeassistant/custom_components/xiaomi_miio/vacuum.py", line 455, in update
self._fan_speeds = self._vacuum.fan_speed_presets()
AttributeError: 'Vacuum' object has no attribute 'fan_speed_presets'

@rytilahti
Copy link
Member Author

Hmm, looks like the PR is not there, maybe homeassistant re-installed the released version during the startup and overwrote the PR version.. If that is the case, please re-install the PR (and verify that the above miiocli command is working), and then launch homeassistant with hass --skip-pip :-)

@cyborghound
Copy link

@rytilahti You're correct, I installed the PR again and started home assistant with skip-pip. Everything works as expected, names of the fan speeds are correct, and I tried every speed while checking the Xiaomi Home-app for changes. Tested with de Roborock S55 v2.

@frenck
Copy link
Member

frenck commented Mar 16, 2020

We should see if we can fix up this PR to be mergeable and try to include it into the beta IMHO.

@rytilahti
Copy link
Member Author

This depends on a new upstream release, but I'll try to push that out as soon as possible. I'm currently waiting for feedback before merging two pending PRs (one of which is the one in question here) and making a new release.

@DeadEnded
Copy link
Contributor

DeadEnded commented Mar 17, 2020

@rytilahti
Just wanting to help out... I have a roborock s4 - I updated the python-miio:

pip3 install -e git+https://github.com/rytilahti/python-miio.git@fanspeed_reporting#egg=python-miio

And then ran the command, here is my output:
image

I'll try setting up the custom component in HA to test that part next, and update this comment if I succeed 😕.

... Okay ... I don't know how I managed it.. but I did!
Success! Setup the PR as a custom component (copied from core component, and then replaced vacuum.py). updated the python-miio@fanspeed_reporting branch... and after a restart of HA, the speeds are now appearing as text instead of numeric values!

Apologies for the small exuberance - this was my first time doing any type of testing like this... so I was excited to succeed. 😄. Anyway - confirmed to fix on Roborock s4 (Gen3 I believe).

DeadEnd

@rytilahti
Copy link
Member Author

Great, thanks for testing @DeadEnded! The only missing one is gen1 new firmware (as that's the one with a special handling in the code).

@markrennie71
Copy link

I just tested this on mine and here is the output..

Running command fan_speed_presets
INFO:miio.vacuum:model: roborock.vacuum.s5
{'Silent': 101, 'Standard': 102, 'Medium': 103, 'Turbo': 104, 'Gentle': 105}

@pplucky
Copy link

pplucky commented Mar 28, 2020

Just tested it via miiocli on a Xiaomi Vacuum 1S and it looks good:

Running command fan_speed_presets
INFO:miio.vacuum:model: roborock.vacuum.m1s
{'Silent': 101, 'Standard': 102, 'Medium': 103, 'Turbo': 104, 'Gentle': 105}

The only odd thing is that I can only 4 speeds on Mi Home app:
Quiet = 101
Balanced = 102
Turbo = 103
MAX = 104

What is this 105?

@rytilahti
Copy link
Member Author

The mode gentle is used for mopping (it disables the vacuum), I'm not sure if this works on non-mop models, so maybe it needs to be removed for versions without mopping?

@pplucky
Copy link

pplucky commented Mar 28, 2020

The mode gentle is used for mopping (it disables the vacuum), I'm not sure if this works on non-mop models, so maybe it needs to be removed for versions without mopping?

Yes, maybe it makes more sense, to avoid people using it inadvertedtly

@pplucky
Copy link

pplucky commented Mar 28, 2020

Got a friend to do it for me on a Xiaomi Vacuum 1st gen

Running command fan_speed_presets
Traceback (most recent call last):
  File "/home/pi/temp_venv/bin/miiocli", line 11, in <module>
    load_entry_point('python-miio', 'console_scripts', 'miiocli')()
  File "/home/pi/temp_venv/src/python-miio/miio/cli.py", line 44, in create_cli
    return cli(auto_envvar_prefix="MIIO")
  File "/home/pi/temp_venv/src/python-miio/miio/click_common.py", line 59, in _call_
    return self.main(*args, **kwargs)
  File "/home/pi/temp_venv/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/pi/temp_venv/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/pi/temp_venv/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/pi/temp_venv/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/pi/temp_venv/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/pi/temp_venv/src/python-miio/miio/click_common.py", line 280, in wrap
    kwargs["result"] = func(*args, **kwargs)
  File "/home/pi/temp_venv/lib/python3.7/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/pi/temp_venv/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/pi/temp_venv/src/python-miio/miio/click_common.py", line 245, in command_callback
    return miio_command.call(miio_device, *args, **kwargs)
  File "/home/pi/temp_venv/src/python-miio/miio/click_common.py", line 193, in call
    return method(*args, **kwargs)
  File "/home/pi/temp_venv/src/python-miio/miio/vacuum.py", line 476, in fan_speed_presets
    self._autodetect_model()
  File "/home/pi/temp_venv/src/python-miio/miio/vacuum.py", line 445, in _autodetect_model
    info = self.info()
  File "/home/pi/temp_venv/src/python-miio/miio/device.py", line 156, in info
    return DeviceInfo(self._protocol.send("miIO.info"))
  File "/home/pi/temp_venv/src/python-miio/miio/miioprotocol.py", line 158, in send
    m = Message.build(msg, token=self.token)
  File "/home/pi/temp_venv/lib/python3.7/site-packages/construct/core.py", line 336, in build
    self.build_stream(obj, stream, **contextkw)
  File "/home/pi/temp_venv/lib/python3.7/site-packages/construct/core.py", line 348, in build_stream
    self._build(obj, stream, context, "(building)")
  File "/home/pi/temp_venv/lib/python3.7/site-packages/construct/core.py", line 2005, in _build
    buildret = sc._build(subobj, stream, context, path)
  File "/home/pi/temp_venv/lib/python3.7/site-packages/construct/core.py", line 2443, in _build
    return self.subcon._build(obj, stream, context, path)
  File "/home/pi/temp_venv/lib/python3.7/site-packages/construct/core.py", line 3996, in _build
    buildret = self.subcon._build(obj, stream, context, path)
  File "/home/pi/temp_venv/lib/python3.7/site-packages/construct/core.py", line 4283, in _build
    buildret = self.subcon._build(value, stream, context, path)
  File "/home/pi/temp_venv/lib/python3.7/site-packages/construct/core.py", line 701, in _build
    obj2 = self._encode(obj, context, path)
  File "/home/pi/temp_venv/src/python-miio/miio/protocol.py", line 157, in _encode
    json.dumps(obj).encode("utf-8") + b"\x00", context["_"]["token"]
  File "/home/pi/temp_venv/src/python-miio/miio/protocol.py", line 83, in encrypt
    cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
  File "/home/pi/temp_venv/lib/python3.7/site-packages/cryptography/hazmat/backends/_init_.py", line 15, in default_backend
    from cryptography.hazmat.backends.openssl.backend import backend
  File "/home/pi/temp_venv/lib/python3.7/site-packages/cryptography/hazmat/backends/openssl/_init_.py", line 7, in <module>
    from cryptography.hazmat.backends.openssl.backend import backend
  File "/home/pi/temp_venv/lib/python3.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 75, in <module>
    from cryptography.hazmat.bindings.openssl import binding
  File "/home/pi/temp_venv/lib/python3.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 15, in <module>
    from cryptography.hazmat.bindings._openssl import ffi, lib
ImportError: /usr/lib/arm-linux-gnueabihf/libssl.so.1.1: version `OPENSSL_1_1_1' not found (required by /home/pi/temp_venv/lib/python3.7/site-packages/cryptography/hazmat/bindings/_openssl.abi3.so)

Didn't go that well..

@rytilahti
Copy link
Member Author

About the "gentle" mode: I think it'll stay like that as I don't know which exact model numbers have it and which do not. I'll happily accept PRs to fix that though.

About the error, that sounds like a problem in the environment (libssl, ..), unfortunately I cannot help with that :/

@rytilahti rytilahti changed the title WIP: Use backend-provided fan speed presets for Xiaomi vacuums Use backend-provided fan speed presets for Xiaomi vacuums, bump version Mar 29, 2020
@rytilahti rytilahti changed the title Use backend-provided fan speed presets for Xiaomi vacuums, bump version Use backend-provided fan speed presets for Xiaomi vacuums, bump python-miio Mar 29, 2020
@rytilahti rytilahti force-pushed the xiaomi_dynamic_fanspeeds branch from 5825271 to 44f6a45 Compare March 29, 2020 16:38
@balloob balloob merged commit e641043 into home-assistant:dev Apr 2, 2020
@rytilahti rytilahti deleted the xiaomi_dynamic_fanspeeds branch April 3, 2020 12:25
@lock lock bot locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

xiaomi_miio: vacuum.set_fan_speed not working on fw: 3.5.7_002008+
9 participants