syssi / xiaomi_fan

Xiaomi Mi Smart Fan integration for Home Assistant
Apache License 2.0
428 stars 118 forks source link

Add support for Smart Standing Fan 2 Pro #195

Closed AlexKalopsia closed 2 years ago

AlexKalopsia commented 2 years ago

Hi there, today I got myself a Smart Standing Fan 2 Pro, so I spent some time adding support to it. I have tested all the supported functions and they all work correctly.

Model: dmaker.fan.p33
Hardware version: esp8266
Firmware version: 2.1.3

https://www.mi.com/global/product/xiaomi-smart-standing-fan-2-pro/

AlexKalopsia commented 2 years ago

I have committed some changes, and I came to the conclusion that - as you suggested - it made more sense to inherit from XiaomiFanMiot

I initially thought that the attr names needed to be in line with what miot-spec would report in the JSON file, but that doesn't seem to be the case, so I aligned the names with the rest of the codebase. This potentially means that I can perhaps just use AVAILABLE_ATTRIBUTES_FAN_P5.

I have left some TODOs for which I might appreciate some help:

1 - The child lock command works correctly from HA, but the entity status keeps showing child_lock as null. I have honestly tried everything (making a specific async function for the P33, using the JSON variable name, but HA is set on it being null. Any idea what could be causing this?

2 - I noticed that fan.turn_on() doesn't manage to set the percentage. The set_percentage() function works fine though, so I am not sure if this is something that the component is unable to overwrite (ie the Fan just alweays reloads the latest speed, at least that's what the manual says)

I hope I am not giving you too many headaches with this, I appreciate the help

syssi commented 2 years ago
  1. Do you know how to send raw commands to your device using miiocli from python-miio? This could help to get a better understanding of the different requests and responses. I assume you don't monitor/track the right property to update the child lock on every update.
  2. Could you try turn off your fan and set the percentage without turning the fan on? I assume the firmware of your device requires two commands (turn_on + set_percentage) to act properly.

Please add miio: debug to the logger to enable the debug output of the underlying library. So you can see all raw requests and responses: https://github.com/syssi/xiaomi_raw#debugging

syssi commented 2 years ago

PS. You can ignore/change the attribute names of the miot specs. The IDs are the important keys.

syssi commented 2 years ago

Did you fix the temperature=KeyError?

AlexKalopsia commented 2 years ago

Do you know how to send raw commands to your device using miiocli from python-miio? This could help to get a better understanding of the different requests and responses. I assume you don't monitor/track the right property to update the child lock on every update.

Yes, that's how I am currently testing everything. I am 100% sure the child lock property is correct. It's (7, 1), and when I activate it, I can manually see that it is correctly acrivated/deactivated, and miiocli returns the correct bool. The weird thing is that now I added the lovelave-fan-card (https://github.com/ikaruswill/lovelace-fan-xiaomi) and by clicking on the button, the child_lock got finally correctly set. Now it works correctly, I am wondering if it's a matter of it not having been correctly initialized somehow.

Could you try turn off your fan and set the percentage without turning the fan on? I assume the firmware of your device requires two commands (turn_on + set_percentage) to act properly.

I can confirm that from off state, fan.set_percentage works correctly. Seems like on just overwrites it then, if that's how it is then I guess I'll leave a comment.

Please add miio: debug to the logger

Thank you!

Did you fix the temperature=KeyError?

Yes, it was one of those leftover properties that I didn't even need

AlexKalopsia commented 2 years ago

Did some more testing and I noticed that I had an issue with the delay timer (ZA5 was doing some minutes -> seconds conversion), so I took the time to test and fix it. It works correctly now.

AlexKalopsia commented 2 years ago

All changes done. So much of it is a reminder to not code the entire day, I dunno what the hell I was thinking with all those enum conversions lol

Thanks for the help improving this PR

syssi commented 2 years ago

Please ping me if you are ready with testing and sure everything is working as expected. I would like to prepare a new release this evening.

AlexKalopsia commented 2 years ago

If with testing you mean "manually testing the device", I have tested it extensively since the last PR and it works correctly 👍

syssi commented 2 years ago

Thanks for your contribution! Feel free to prepare additional pull requests if you see room for improvements!