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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Xiaomi Purifier 4 Lite #75949

Closed

Conversation

borky
Copy link
Contributor

@borky borky commented Jul 29, 2022

Proposed change

Add support for the Xiaomi Mi Air Purifier 4 Lite.

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)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

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.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 馃 Silver
  • 馃 Gold
  • 馃弳 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

This pull request needs to be manually signed off by @home-assistant/core before it can get merged.
(message by ReviewEnforcer)

@probot-home-assistant
Copy link

Hey there @rytilahti, @syssi, @starkillerOG, @bieniu, mind taking a look at this pull request as it has been labeled with an integration (xiaomi_miio) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@project-bot project-bot bot added this to Needs review in Dev Jul 29, 2022
@borky
Copy link
Contributor Author

borky commented Jul 29, 2022

Please do not merge till is it confirmed working with the actual device by Theliel or alexdrl .

@MartinHjelmare MartinHjelmare changed the title Added support for Xiaomi Purifier 4 Lite Add support for Xiaomi Purifier 4 Lite Jul 29, 2022
@Theliel
Copy link

Theliel commented Jul 31, 2022

OK, tested again Dev Build

-Device its correctly Detected

-Sensors
Seem to work perfectly: humidity, temperature, PM2.5, motor_speed, filter (remain, used, left).
"Use_time" is not available, and its not present on specs

-Switch
Buzzer and Child work fine
Display Brightness disabled and low work fine, max dont work, set brightness to disabled instead.
Mode is not present: Mode = 0 is auto, Mode = 1 Silent and Mode = 2 is Manual/Favorite.
Favorite Level dont work. Favorite Level its custom fan speed/power, and dont work with Mode 0 (automatic). In Mode 2 (Favorite/Manual) Favorite Level is used to control fan speed. But even with Mode 2, code dont work and Favorite Level is not able to set the Fan Speed.

@borky
Copy link
Contributor Author

borky commented Jul 31, 2022

OK, tested again Dev Build

-Device its correctly Detected

-Sensors Seem to work perfectly: humidity, temperature, PM2.5, motor_speed, filter (remain, used, left). "Use_time" is not available, and its not present on specs

-Switch Buzzer and Child work fine Display Brightness disabled and low work fine, max dont work, set brightness to disabled instead. Mode is not present: Mode = 0 is auto, Mode = 1 Silent and Mode = 2 is Manual/Favorite. Favorite Level dont work. Favorite Level its custom fan speed/power, and dont work with Mode 0 (automatic). In Mode 2 (Favorite/Manual) Favorite Level is used to control fan speed. But even with Mode 2, code dont work and Favorite Level is not able to set the Fan Speed.

Display brightness Max is not working due to a bug in xiaomi-miio library(rytilahti/python-miio#1477), it was fixed and should work once a new release is made and integrated in HA.

With Mode is not present you mean that it is not present on the fan entity? You can't change modes? Also Favorite level works only if the Favorite Mode is active.

@Theliel
Copy link

Theliel commented Jul 31, 2022

About Max brightness, perfect.

About Mode, entity is not available/exposed to HA, so cannot be changed. The fan.turn_on/off only poweroff/on the device. And even when mode is changed by app (for example), Fan control still dont work, a short error about: "Favorite Level no longer available" after any change try.

@borky
Copy link
Contributor Author

borky commented Jul 31, 2022

could you try directly with python-miio(v0.5.12) library via the command: miiocli airpurifiermiot --ip "x.x.x.x" --token "xxxxx" set_mode favorite ? Please try to change between the modes to make sure that the library is working ok and that the problem comes from the configuration in HA. Also is there any error related to the purifier in the HA log?

@Theliel
Copy link

Theliel commented Jul 31, 2022

-Yes, miiocli can change perfectly between all modes, this work fine, but again, property is not exposed to HA... I will try again from scratch all integration with miio, just in case

-miiocli is not working fine at least to fan control. A simple status check dont retrieve any value, never, even after changing mode to favorite.

Power: on
Anion: None
AQI: 2 渭g/m鲁
TVOC: None
Average AQI: None 渭g/m鲁
Humidity: 42 %
Temperature: 29 掳C
PM10 Density: None 渭g/m鲁
Fan Level: None
Mode: OperationMode.Favorite
LED: None
LED brightness: LedBrightness.Dim
LED brightness level: None
Gestures: None
Buzzer: False
Buzzer vol.: None
Child lock: False
Favorite level: None

Trying to set manually Level favorite, bring back a error status code:

Setting favorite level to 10
[{'did': 'favorite_level', 'siid': 9, 'piid': 5, 'code': -4003}]

If I monitor the value of the parameter with miio_raw, the value (favorite_level) varies over time without even modifying the fan with the application, It seems to be a counter, which goes from 300 to zero (about 5-6 min), which is reset if the value of the fan is modified from the application and the counter had already reached zero. If the counter has not reached zero, modifying the fan in the application does not reset it.

Which makes me think that the specification that we currently have is wrong, and there is some other parameter that is controlling it via another property. If I have time I will intercept the traffic to really see what is going in and out of the application/device

@borky
Copy link
Contributor Author

borky commented Jul 31, 2022

so you have the zhimi.airp.rmb1. I think the mapping of the favorite level is wrong in the python-miio, in the spec linked to in the code it is siid=9 and piid=11, but in the miio it is siid=9 and piid=5. You could try to clone the repo and try to see if doing this change makes it work(siid=9 and piid=11).

@Theliel
Copy link

Theliel commented Aug 1, 2022

Right, its "{'did': 'favorite_level', 'piid': 11, 'siid': 9}" <- Work fine.

my original code in miio_raw was inverted.

@borky
Copy link
Contributor Author

borky commented Aug 1, 2022

then please create a bug issue on the https://github.com/rytilahti/python-miio/issues repo if you did not already or a pull request with the fix because you have the device to proper test.

@alexdrl
Copy link
Contributor

alexdrl commented Aug 1, 2022

hey guys, sorry but had a really really busy weekend, do you need help with additional testing?

@borky
Copy link
Contributor Author

borky commented Aug 2, 2022

@alexdrl i guess from what i understood there seems to be a wrong mapping of the favorite level in the python-miio library. You could double check it by updating the mapping for it and see if it works after. If this is the case then we need an update in that library first(create an issue or PR to fix it) and wait for a new version to be released.

@alexdrl
Copy link
Contributor

alexdrl commented Aug 5, 2022

@Theliel so basically changing that mapping will just work?

@borky and probably maintainers, could we just merge this even the favorite setting is not working 100%? Want that device support and we may need to wait for a new python-miio version.

@bieniu
Copy link
Member

bieniu commented Aug 10, 2022

IMO it's a very bad idea to merge something if it doesn't work. Favorite level should be removed or this PR should wait for a new version of python-miio.

@alexdrl
Copy link
Contributor

alexdrl commented Aug 10, 2022

IMO it's a very bad idea to merge something if it doesn't work. Favorite level should be removed or this PR should wait for a new version of python-miio.

Agree with that, favorite mode could be set aside for that, just removing the feature.

And waiting for the new version with that fixed... @borky did you test the favorite level on this PR? Not have that device to test, but tested with the same results as @Theliel there.

@borky
Copy link
Contributor Author

borky commented Aug 11, 2022

@alexdrl yes i tested both devices for that PR as i have those, the favorite level is working ok. So should i remove the favorite level from here and continue with the merge? i saw that there is no issue or pull request made for this on the https://github.com/rytilahti/python-miio repository, i think someone that has this device should do that otherwise this feature might be missing for some time.

@alexdrl
Copy link
Contributor

alexdrl commented Aug 11, 2022

@borky I have no background on Python development but I can give it a try, anyways there is no harm on removing the favorite level feature if I can't make it in a reasonable time

@alexdrl
Copy link
Contributor

alexdrl commented Aug 11, 2022

@borky trying that and using python-miio locally was a lot easier than expected. I have created a PR for that rytilahti/python-miio#1486

Tested locally and that works for me :D

@borky
Copy link
Contributor Author

borky commented Aug 11, 2022

@alexdrl great:)! then should i remove for the moment the favorite level from this device and continue with the merge?

@alexdrl
Copy link
Contributor

alexdrl commented Sep 21, 2022

@borky can you remove the favorite level so this get merged? python-miio release process is slower than i expected and would be nice to have this on home-assistant 2022.10

@rytilahti
Copy link
Member

rytilahti commented Sep 21, 2022

Yeah, sorry for the slow release cycle (of python-miio), I'd also suggest not wait for a quick upstream release at the moment.. I'm currently working on refactoring the library to make it the only source of truth when it comes to which devices are supported and what functionality is offered by them.

It would be great if someone could take a look at rytilahti/python-miio#1495 (esp. "Call for help") and create a PR to add the decorators to python-miio. This way the future homeassistant integration will expose the available sensors & settings automatically without changes at homeassistant's end :-)

@aherbjornsen
Copy link

What happened here? I would really like to see this merged so it at least could be available in Home Assistant 2022.11

@alexdrl
Copy link
Contributor

alexdrl commented Oct 5, 2022

What happened here? I would really like to see this merged so it at least could be available in Home Assistant 2022.11

Didn't have time to give a try the dev env for this, but this could be merged removing the favourite level feature from the purifier 4 lite on this PR

@aherbjornsen
Copy link

this could be merged removing the favourite level feature from the purifier 4 lite on this PR

Yes, I have been using it, patching the files in core manually. It is working fine, but it's a pain to do this every time I upgrade HA.

@alexdrl
Copy link
Contributor

alexdrl commented Oct 6, 2022

@bieniu @rytilahti Can I create a copy of this PR without the favorite level so we can merge it?
Don't want to take credit for something I have not done (just tested the python-miio fix that has not been released yet), but @borky seems to be not available for this.

@rytilahti
Copy link
Member

Hey, you could fork the branch of this PR, add your changes on top your fork, and create a new PR based on your branch, while still keeping the initial commits (and thus the credit) intact :)

@alexdrl
Copy link
Contributor

alexdrl commented Oct 6, 2022

@rytilahti completely makes sense, created this one #79758

@rytilahti
Copy link
Member

Let's close this as superseded then, thanks @borky and @alexdrl!

@rytilahti rytilahti closed this Oct 7, 2022
Dev automation moved this from Needs review to Cancelled Oct 7, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Cancelled
Development

Successfully merging this pull request may close these issues.

None yet

8 participants