xiaomi_airpurifier: Cannot import name 'AirHumidifierMiot' from 'miio'" - workaround

Get error, when check config: Platform error fan.xiaomi_miio_airpurifier - cannot import name 'AirHumidifierMiot' from 'miio' (/usr/local/lib/python3.8/site-packages/miio/__init__.py)

Error appears, when adding to configuration.yaml:

fan:
  - platform: xiaomi_miio_airpurifier
    name: mi_humidifier_child
    host: 192.168.x.xx
    token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    model: deerma.humidifier.mjjsq

HA supervised. Xiaomi Mi Air Purifier, Air Humidifier, Air Fresh and Pedestal Fan Integration installed via HACS. System info:

arch | x86_64
-- | --
chassis | vm
dev | false
docker | true
docker_version | 19.03.11
hassio | true
host_os | HassOS 4.15
installation_type | Home Assistant OS
os_name | Linux
os_version | 5.4.72
python_version | 3.8.6
supervisor | 2020.11.0
timezone | Europe/Moscow
version | 0.117.4
virtualenv | false

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 28 (11 by maintainers)

Most upvoted comments

I got the error Platform error fan.xiaomi_miio_airpurifier - cannot import name 'FanMiot' from 'miio' today with HA 0.118.0 after upgrading xiaomi_airpurifier from 0.6.1 to 0.6.2 I tried HACS and manual install from downloaded xiaomi_airpurifier-develop.zip Downgraded back to 0.6.1

I have another error with this model. Errors starts with last version, before works fine

Platform error fan.xiaomi_miio_airpurifier - cannot import name 'FanMiot' from 'miio' (/usr/local/lib/python3.8/site-packages/miio/__init__.py)

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config.py", line 823, in async_process_component_config
    platform = p_integration.get_platform(domain)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 422, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 427, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_components/xiaomi_miio_airpurifier/fan.py", line 7, in <module>
    from miio import (  # pylint: disable=import-error
ImportError: cannot import name 'FanMiot' from 'miio' (/usr/local/lib/python3.8/site-packages/miio/__init__.py)

I use homeassistant/qemux86-64-homeassistant:0.117.5 container, it has 0.5.4 python-miio

bash-4.3# docker exec -it 64114 bash
bash-5.0# pip3 list | grep miio
python-miio                      0.5.4
bash-5.0# python3
Python 3.8.6 (default, Oct 14 2020, 15:45:05)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from miio import AirHumidifierMiot
>>> from miio import FanMiot
>>>

I found a workaround which works for me. Copy the official xiaomi_miio component to your custom_components folder and edit the manifest.json. The updated dependencies must be used here:

{
  "domain": "xiaomi_miio",
  "name": "Xiaomi Miio",
  "config_flow": true,
  "documentation": "https://www.home-assistant.io/integrations/xiaomi_miio",
  "requirements": ["construct==2.10.56", "python-miio==0.5.4"],
  "codeowners": ["@rytilahti", "@syssi", "@starkillerOG"],
  "zeroconf": ["_miio._udp.local."]
}

Reboot HA. This solves the issue of different required python-miio and construct versions. All manifest.json’s of python-miio dependend custom components requires the same version/line at the manifest:

  "requirements": ["construct==2.10.56", "python-miio==0.5.4"],

If this is fulfilled the errors are gone. As soon HA 0.119 is reased the xiaomi_miio folder can be removed again.

I hit the same issue today:

2020-11-18 15:15:20 ERROR (MainThread) [homeassistant.config] Platform error: fan
Traceback (most recent call last):
  File "/srv/homeassistant-sebastian/lib/python3.7/site-packages/homeassistant/config.py", line 823, in async_process_component_config
    platform = p_integration.get_platform(domain)
  File "/srv/homeassistant-sebastian/lib/python3.7/site-packages/homeassistant/loader.py", line 422, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/srv/homeassistant-sebastian/lib/python3.7/site-packages/homeassistant/loader.py", line 427, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/var/homeassistant-sebastian/config/custom_components/xiaomi_miio_airpurifier/fan.py", line 7, in <module>
    from miio import (  # pylint: disable=import-error

If I check the age of the __init__.py we can see the pip package is installed on every reboot:

$ ls -l lib/python3.7/site-packages/miio/__init__.py         
-rw-r--r-- 1 homeassistant homeassistant 2483 Nov 18 15:15 lib/python3.7/site-packages/miio/__init__.py

As soon as HA and the custom component uses the same python-miio version the issue will be gone.

@syssi That’s what I did 😉 Guten Rutsch ins neue Jahr. Greetings from Shanghai

@neo799 just update the manifest.json of the heater to:

"construct==2.10.56",
"python-miio>=0.5.4"