Python Error in miio - Xiaomi Air Purifier 2

Hi,
I had set up a Xiaomi Air Purifier as a fan on xiaomi_miio according to instructions at: https://home-assistant.io/components/fan.xiaomi_miio/ set the token up too…

Getting the error xiaomi_miio: Error on device update!

More Info:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 397, in _async_add_entity
    yield from entity.async_device_update(warning=False)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 306, in async_device_update
    yield from self.async_update()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/fan/xiaomi_miio.py", line 240, in async_update
    self._air_purifier.status)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/miio/airpurifier.py", line 215, in status
    properties[0:13]
  File "/srv/homeassistant/lib/python3.5/site-packages/miio/device.py", line 216, in send
    m = Message.build(msg, ctx)
TypeError: build() takes 2 positional arguments but 3 were given

Running HASS ver. 0.62.0

Any help appreciated

if you suspect its the latest hass version, then simply downgrade and see if it works for you :wink:

HASS 62.1 has the same problem. worked fine with 61.1 (just updated) Almost same error for vacuum.

This has only been fixed for now in the git version of python-miio (https://github.com/rytilahti/python-miio/pull/192), for the time being you can manually downgrade construct package to version 2.9.22 (pip install construct==2.9.22) or wait until a fixed version gets released later on.

Solution given by syssi at GitHub in response to the issue I filed

Please update python-miio to the current master:

su - homeassistant
source /srv/homeassistant/bin/activate
pip3 install -U https://github.com/rytilahti/python-miio/archive/master.zip
1 Like

I tried both installing construct in v2.8.22 (2.9.22 not found), and installing python-miio from master, but still get the same error.

2018-02-04 14:47:55 ERROR (MainThread) [homeassistant.components.vacuum] xiaomi_miio: Error on device update!
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 397, in _async_add_entity
    yield from entity.async_device_update(warning=False)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 308, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 331, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 244, in _wakeup
    future.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 244, in result
    raise self._exception
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/vacuum/xiaomi_miio.py", line 368, in update
    state = self._vacuum.status()
  File "/config/deps/lib/python3.6/site-packages/miio/vacuum.py", line 108, in status
    return VacuumStatus(self.send("get_status")[0])
  File "/config/deps/lib/python3.6/site-packages/miio/device.py", line 216, in send
    m = Message.build(msg, ctx)
TypeError: build() takes 2 positional arguments but 3 were given

.

root@blop:/# pip show construct
Name: construct
Version: 2.8.22

What other solution can I try?

After installing python-mioo from master, it still shows version 0.3.4, is that the expected result?

root@blop:/# pip3 show python-miio
Name: python-miio
Version: 0.3.4
1 Like

The version information is correct as there has been no 0.3.5 yet, you will require a newer (>2.9.23) version of construct to use with the master branch.

I also tried with construct 2.9.27 and python-miio 0.3.5, still getting the same error.

I also manually applied the change from https://github.com/home-assistant/home-assistant/commit/137933a774625ef901904f14335dca6eb957915d, didn’t help.

Same problem here, 2.9.27 and installed the linked master.zip without error, still have this error for fan and vacuum:

xiaomi_miio: Error on device update!

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 397, in _async_add_entity
    yield from entity.async_device_update(warning=False)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 308, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/vacuum/xiaomi_miio.py", line 368, in update
    state = self._vacuum.status()
  File "/srv/homeassistant/lib/python3.5/site-packages/miio/vacuum.py", line 108, in status
    return VacuumStatus(self.send("get_status")[0])
  File "/srv/homeassistant/lib/python3.5/site-packages/miio/device.py", line 216, in send
    m = Message.build(msg, ctx)
TypeError: build() takes 2 positional arguments but 3 were given

You will also need version 0.3.5 of python-miio, as you can see there’s no such line anymore: https://github.com/rytilahti/python-miio/blob/0.3.5/miio/device.py#L221 for that release (nor for master anymore, for 9 days now).

Looks like home assistant is downgrading python-miio to 0.3.4 on start.

Updating homeassistant to current dev version works 0.63.0.dev0 because it uses python-miio 0.3.5.

Also, there was a problem with Xiaomi smartmi fresh air (similar to Purifier 2 / Pro) after upgrading to 0.80

At 0.79 it worked like zhimi.airpurifier.v6, now it gives an error:

2018-10-22 18:16:07 ERROR (MainThread) [homeassistant.components.fan] xiaomi_miio: Error on device update!
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

update python-mio to the current master did not help: (

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

How to overcome the error and restore functionality?