61.1 seems to have broken xiaomi_miio

I have just updated to 61.1 and both my Xiaomi Vacuum and WiFi plugs are not being recognized and are producing the following errors (which I can not understand :frowning: )

 Error while setting up platform xiaomi_miio
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 171, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib/python3.4/asyncio/tasks.py", line 372, in wait_for
    return fut.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/usr/lib/python3.4/asyncio/coroutines.py", line 141, in coro
    res = func(*args, **kw)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/switch/xiaomi_miio.py", line 41, in async_setup_platform
    from miio import Device, DeviceException
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/miio/__init__.py", line 2, in <module>
    from miio.protocol import Message, Utils
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/miio/protocol.py", line 179, in <module>
    Const(Int16ub, 0x2131),
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/construct/core.py", line 1277, in __init__
    super(Const, self).__init__(subcon)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/construct/core.py", line 287, in __init__
    raise TypeError("subcon should be a Construct field")
TypeError: subcon should be a Construct field

Any help would be appreciated.

It looks like the package “construct” is broken somehow. I will check it tonight.

1 Like

I have the same error here as well

Yep. I’m able to reproduce the issue, too.

Okay. I know what’s going on:

If you edit

File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/miio/protocol.py", line 179, in <module>

and interchange the order of

-        Const(Int16ub, 0x2131),
+        Const(0x2131, Int16ub),

it will work again. I will provide a patch.

2 Likes

Working; I’m am little confused, becasue i started with hass, and this is used, ~.homeassistant\dep not srv ; But if use as service used from /srv.

The location depends on your setup. I’m using hassbian.

1 Like

That did the trick, thanks so much @syssi.

GREAT! Works! Thanks so much… also for each time those hot fixes. Just great!

Thanks for the fix :slight_smile:

Strange.after restarting hass miio is also reinstalled with wrong protocol.py

This is normal. The issue is fixed in homeassistant’s dev branch:

https://github.com/home-assistant/home-assistant/pull/11837

is it possible to fix this in hassio?.. actually I’m on 0.62.0 not 0.61.1

Hi, I am on 0.62.0 too and I have now a different error:

2018-01-29 13:19:44 ERROR (MainThread) [homeassistant.components.switch] Error while setting up platform xiaomi_miio
Traceback (most recent call last):
  File "/home/hcooh/hass/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 189, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib64/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/lib64/python3.6/asyncio/futures.py", line 243, in result
    raise self._exception
  File "/usr/lib64/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/lib64/python3.6/asyncio/coroutines.py", line 212, in coro
    res = func(*args, **kw)
  File "/home/hcooh/hass/lib/python3.6/site-packages/homeassistant/components/switch/xiaomi_miio.py", line 52, in async_setup_platform
    device_info = plug.info()
  File "/home/hcooh/hass/lib/python3.6/site-packages/miio/device.py", line 271, in info
    return DeviceInfo(self.send("miIO.info", []))
  File "/home/hcooh/hass/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

It seems the build function does not like those parameters anymore…

replacing ctx by token=self.token in the device.py seems to fix the issue (as fixed in github already)

1 Like

The same question here

Please install python-miio master and construct==2.9.23.

pip3 install https://github.com/rytilahti/python-miio/archive/master.zip
pip3 install construct==2.9.23

Hi,

I am running 0.62 on hassio 1.1 and seem to have the same problem as above, though my errors differs a bit (the first lines are the same but not the end) :

Error while setting up platform xiaomi_miio
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py", line 189, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/lib/python3.6/asyncio/coroutines.py", line 210, in coro
    res = func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/vacuum/xiaomi_miio.py", line 90, in async_setup_platform
    from miio import Vacuum
  File "/usr/lib/python3.6/site-packages/miio/__init__.py", line 2, in <module>
    from miio.protocol import Message, Utils
  File "/usr/lib/python3.6/site-packages/miio/protocol.py", line 179, in <module>
    Const(0x2131, Int16ub),
  File "/usr/lib/python3.6/site-packages/construct/core.py", line 1894, in __init__
    super(Const, self).__init__(subcon)
  File "/usr/lib/python3.6/site-packages/construct/core.py", line 291, in __init__
    raise TypeError("subcon should be a Construct field")
TypeError: subcon should be a Construct field

pip3 is not possible to run as I am on hassio and I do not find a device.py anywhere.

Could you help me with that ? :slight_smile:

Please ask a docker/hassio guru how to persistent update pip packages.

Thanks, and where could I find such a guru ? :slight_smile:

At the hassio channel of discord!