home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.06k stars 31.08k forks source link

Python Error in miio - Xiaomi Smartmi Fresh Air (like Purifier 2/Pro) #17689

Closed alxnovo closed 6 years ago

alxnovo commented 6 years ago

Home Assistant release with the issue: 0.80.3 Last working Home Assistant release (if known): 0.79 Operating environment (Hass.io/Docker/Windows/etc.): Raspbian on Raspberry Pi 3+ Component/platform: zhimi.airpurifier.v6 (real zhimi.airfresh.va2) Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

- platform: xiaomi_miio
    host: <ip adress>
    token: <token>
    name: Air Fresh Xiaomi
    model: zhimi.airpurifier.v6
    # model: zhimi.airfresh.va2

Description of problem:

On Home Assistant 0.79, I normally worked (on / off) xiaomi smartmi fresh air, which was registered in the config as zhimi.airpurifier.v6 (miiocli defines it as zhimi.airfresh.va2) After upgrading to 0.80, one day worked fine, but today when you restart, the Home Assistant shows an error like in https://github.com/home-assistant/home-assistant/issues/12031

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 251, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 347, in async_device_update
    await self.async_update()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/fan/xiaomi_miio.py", line 569, in async_update
    key, value in self._available_attributes.items()})
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/fan/xiaomi_miio.py", line 569, in <dictcomp>
    key, value in self._available_attributes.items()})
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/fan/xiaomi_miio.py", line 447, in _extract_value_from_attribute
    value = getattr(state, attribute)
  File "/srv/homeassistant/lib/python3.5/site-packages/miio/airpurifier.py", line 142, in mode
    return OperationMode(self.data["mode"])
  File "/usr/lib/python3.5/enum.py", line 241, in __call__
    return cls.__new__(cls, value)
  File "/usr/lib/python3.5/enum.py", line 476, in __new__
    raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 'middle' is not a valid OperationMode

I tried to update python-miio to the current master, but this did not fix the problem :(

sudo -u homeassistant -H -s
source /srv/homeassistant/bin/activate
pip3 install -U https://github.com/rytilahti/python-miio/archive/master.zip
rytilahti commented 6 years ago

Please open an issue in python-miio repository, as that's where this should be fixed (the problem is a non-mapped OperationMode, odd that it used to work, but maybe you never had that mode active before), thanks!