rytilahti / python-miio

Python library & console tool for controlling Xiaomi smart appliances
https://python-miio.readthedocs.io
GNU General Public License v3.0
3.52k stars 542 forks source link

Unable to find mapping for zhimi.airp.mb3a, falling back to zhimi.airpurifier.ma4 #1907

Open netizeni opened 4 months ago

netizeni commented 4 months ago

I'm aware of this closed issue which is basically identical and opened almost 2 years ago and these two merged PRs, but this message is showing on the current latest version of HA and spamming logs constantly with:

[miio.device] Found an unsupported model 'zhimi.airp.mb3a' for class 'AirPurifierMiot'. If this is working for you, please open an issue at https://github.com/rytilahti/python-miio/
[miio.miot_device] Unable to find mapping for zhimi.airp.mb3a, falling back to zhimi.airpurifier.ma4

Describe the bug

When adding Mi 3H air purifier (the latest firmware version available) to the latest version of HA, logs gets flooded with above entries.

Version information (please complete the following information):

Device information: Mi 3H air purifier

To Reproduce As the standard login/password routine didn't work, I used token extractor to get API token and add the device manually. First warning after adding IP and token: The device model is not known, not able to set up the device using config flow. There's a dropdown below it to select a device model, and I selected zhimi.airpurifier.mb3. Next dialog shows:

Created configuration for zhimi.airp.mb3a.
We found the following devices:
zhimi.airp.mb3a
zhimi.airpurifier.mb3 (Xiaomi)

Once added, it appears in Devices as:

zhimi.airpurifier.mb3
by Xiaomi 

and it starts spamming the logs with those two entries. From the moment of adding the device yesterday until now, there are 5672 occurrences.

Expected behavior Clean log without warnings.

netizeni commented 4 months ago

One more bug I noticed, which is related to this issue, is that the air purifier updates PM2.5 level every 30 mins. I assume this can solved by adding OR with zhimi.airp.mb3a to this line: https://github.com/rytilahti/python-miio/blob/3e94c6d9889e72cad98a4671828339a9563e8998/miio/airpurifier_miot.py#L408

but it might be easier to see how to change zhimi.airp.mb3a to zhimi.airpurifier.mb3 which will automatically solve this issue.

netizeni commented 3 months ago

@rytilahti is it possible to do something about adding this integration? It's crashing HA with a ton of logs.

I see the model name exists here: https://github.com/rytilahti/python-miio/blob/35a8773f8cfdcb36e148b1944dff93726888cfe2/miio/integrations/zhimi/airpurifier/airpurifier_miot.py#L242

but it doesn't exist in supported models in this class: https://github.com/rytilahti/python-miio/blob/3e94c6d9889e72cad98a4671828339a9563e8998/miio/airpurifier_miot.py#L12-L17

Is it possible this is the reason it's falling back to the first one in the array?

rytilahti commented 3 months ago

I replied to you here https://github.com/home-assistant/core/issues/112509#issuecomment-2000732641 but this should already be fixed for your device (in git master and 0.6.0.dev0) as the model is already there as you pointed out.

Now, looking at the code, it should not spam that message in the first place so I'm going to fix that.

netizeni commented 3 months ago

@rytilahti thank you! Is it also possible to add a model name to if check I mentioned above, as the current implementation only updates PM2.5 every 30 mins?

Basically, the same thing which was addressed here, but for this specific name.

Now, looking at the code, it should not spam that message in the first place so I'm going to fix that.

I'm not familiar with Python, so was just checking "on the fly", and now I'm curious, which mappings it gets here? Those from airpurifier_miot.py file which is in airpurifier folder or the one in miio?

https://github.com/rytilahti/python-miio/blob/35a8773f8cfdcb36e148b1944dff93726888cfe2/miio/miot_device.py#L193-L204