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

Air purifier 3/3H support (remastered) #634

Merged
merged 14 commits into from
Mar 15, 2020

Conversation

foxel
Copy link
Contributor

@foxel foxel commented Feb 20, 2020

Rebased copy of #585 - original description below:

Add support for basic operations for new Xiaomi Air Purifier 3/3H (zhimi-airpurifier-mb3 and zhimi-airpurifier-ma4 (#577)).

In order to support that, also implement MiotDevice class with basic support for MIoT protocol which the AirPurifierMiot extends to retrieve & set properties.

Mapping is based on #543 (comment) - thanks, it helped a lot!

Note

  • I have not added any tests yet. I'd appreciate first round of a review before I do so.
  • I have not tried the template/generative approach. Thought it would be better just to get it working. I can attempt to do that separately later.

Disclaimer: this is my first contribution to this project & I don't have Python experience.

ToDo:

  • extract Filter Type detection to a separate class
  • add test coverage

Manually tested operations:

  • info (see output below)
  • status (see output below)
  • off
  • on
  • set_buzzer <true|false>
  • set_child_lock <true|false>
  • set_fan_level <1-3>
  • set_favorite_level <0-14>
  • set_led <true|false>
  • set_led_brightness <off|dim|bright>
  • set_mode <auto|fan|favorite|silent>

Example output of info:

$ python miio/cli.py airpurifiermiot --ip $AIR_IP --token $TOKEN info
Model: zhimi.airpurifier.mb3
Hardware version: esp32
Firmware version: 2.0.5
Network: {'localIp': '192.168.0.22', 'mask': '255.255.255.0', 'gw': '192.168.0.1'}
AP: {'ssid': 'coolwifi', 'bssid': '20:E5:2A:3C:BC:82', 'rssi': -59, 'primary': 8}

Example output of status:

$ python miio/cli.py airpurifiermiot --ip $AIR_IP --token $TOKEN status
Power: on
AQI: 3 μg/m³
Average AQI: 6 μg/m³
Humidity: 58 %
Temperature: 25.799999 °C
Mode: OperationMode.Favorite
LED: True
LED brightness: LedBrightness.Dim
Buzzer: False
Child lock: False
Favorite level: 14
Filter life remaining: 98 %
Filter hours used: 59
Use time: 212700 s
Purify volume: 8606 m³
Motor speed: 2148 rpm
Filter RFID product id: 0:0:31:31
Filter RFID tag: 80:66:6a:da:38:bd:4
Filter type: FilterType.Regular

Closes #577

Petr Kotek and others added 8 commits February 20, 2020 13:45
…t that, also implement MiotDevice class with basic support for MIoT protocol.
# Conflicts:
#	miio/ceil_cli.py
#	miio/device.py
#	miio/philips_eyecare_cli.py
#	miio/plug_cli.py
#	miio/tests/dummies.py
#	miio/tests/test_airconditioningcompanion.py
#	miio/tests/test_wifirepeater.py
#	miio/vacuum.py
#	miio/vacuum_cli.py
… out if no button was pressed since purifier started up
@coveralls
Copy link

coveralls commented Feb 20, 2020

Coverage Status

Coverage increased (+0.2%) to 74.225% when pulling a400d56 on foxel:air-purifier-3h-support into efd4370 on rytilahti:master.

@foxel foxel force-pushed the air-purifier-3h-support branch from a0ea50a to 6feed42 Compare February 20, 2020 07:51
@foxel foxel marked this pull request as ready for review February 20, 2020 09:42
@lucidyan
Copy link

@foxel Do you experience same behavior with 3/3H?
#585 (comment)

@foxel
Copy link
Contributor Author

foxel commented Feb 24, 2020

@lucidyan with Purifier 3 I got it working with no issues. I have it running with my HA installation for more than a week now.
I didn't try set_favorite_rpm though, will check

@lucidyan
Copy link

@foxel I edit comment a little, because figured out how to make alarm works. I think it's interesting and will be very glad if you try it with 3* model.

Also is it a good idea to add a handler in get_params method to ignore records with such nonzero error codes to avoid such errors in the future?

I see already hardcoded solutions for similar problems:

if "code" in error and error["code"] == -30001:

@pmasknguyen
Copy link

after upgrade to new version Home Assistant 0.106.1 the air purify 3h not recognize like before, thank for help

@foxel
Copy link
Contributor Author

foxel commented Feb 29, 2020

@pmasknguyen mine works well. I've checked 106. there were no changes in xiami-miio fan

@pmasknguyen
Copy link

thank you I double checked and it works

@foxel
Copy link
Contributor Author

foxel commented Feb 29, 2020

@lucidyan I've looked more closely thru the code and that miot specs and added some handling of possibly unavailable features, plus added buzzer volume.

Please make some tests on your rare device

@foxel foxel force-pushed the air-purifier-3h-support branch from b9eb3ea to 31b0248 Compare February 29, 2020 18:34
@foxel
Copy link
Contributor Author

foxel commented Mar 1, 2020

Hi, @rytilahti

What's the plan for this one?

@lucidyan
Copy link

lucidyan commented Mar 1, 2020

@foxel Thanks a lot!

I watch through your code and find one inaccuracy:
31b0248#diff-7f2ec049fa93db605930bf4492455753R347-R348

Also in my zhimi.airpurifier.va1 device API motor-favorite is not writeable (WTF xiaomi), so method won't work. And number of favorite levels is 9 instead of 14. So the question: how we will handle such API differences for all zoo of purifiers in the future?

Copy link
Collaborator

@syssi syssi left a comment

Choose a reason for hiding this comment

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

Good job!

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.

Sorry, I have been busy and that's why it has taken so long to do a review. Generally speaking it looks good to me, I just left a couple of comments behind.

miio/version.py Outdated
@@ -1,2 +1,2 @@
# flake8: noqa
__version__ = "0.4.8"
__version__ = "0.5.0"
Copy link
Owner

Choose a reason for hiding this comment

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

Please do not bump the version in feature PRs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will keep in mind. I need this to make HA install this fork correctly

Copy link
Owner

Choose a reason for hiding this comment

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

Ok, could you please remove this and update the README to contain information about miot support & the new devices? I think we can merge and prepare a new release then 🎉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

miio/miot_device.py Show resolved Hide resolved
miio/airpurifier_miot.py Show resolved Hide resolved
miio/airpurifier_miot.py Outdated Show resolved Hide resolved
miio/airpurifier_miot.py Outdated Show resolved Hide resolved
miio/miot_device.py Show resolved Hide resolved
miio/miot_device.py Show resolved Hide resolved
@foxel
Copy link
Contributor Author

foxel commented Mar 11, 2020

@rytilahti please take another look

@foxel foxel force-pushed the air-purifier-3h-support branch from a400d56 to becd8a0 Compare March 11, 2020 17:16
@foxel
Copy link
Contributor Author

foxel commented Mar 14, 2020

@rytilahti anything else? Can we proceed with this PR?

@rytilahti
Copy link
Owner

Oh, sorry, I was waiting for updating the README file to contain the newly supported devices. If you could do that, I will do the merge and start preparations for a new release.

@foxel
Copy link
Contributor Author

foxel commented Mar 14, 2020

@rytilahti I don't see a place for it in README, it's pretty general and states support for purifiers in common...

@rytilahti
Copy link
Owner

Ah, okay, I suppose that's fine as it is then. Let's get this merged now! Thanks @petrkotek and @foxel! 🎉

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.

Support for Xiaomi Air Purifier 3 (zhimi.airpurifier.ma4)
6 participants