Miio platform broken after upgrade 0.62

Yeah I figured. I’m getting good at the ‘fix’ now. Thanks for tracking it down. I was on my way to bed last night when I got your second request and it was solved this morning.

Thanks again.

What about those not using hassio? Was working on 0.61. Skipped 0.62 due to z-wave problems.
Today upgrade to 0.63 and all i get in the logs

[miio.device] Unable to discover a device at address xxx.xiaomi_vacuum_ip
[miio.device] Unable to discover a device at address xxx.philips_light_ip

Running manually gives me this

/srv/homeassistant/bin/mirobo --ip xxx --token xxx
WARNING:miio.device:error while reading discover results: _decode() takes 3 positional arguments but 4 were given
ERROR:miio.device:Unable to discover a device at address xxx
Error: Unable to discover the device xxx

Update:

Ok got a solution. Construct library once again. 0.63.1 installed construct library of .30 version.
Downgrading contruct to .28 fixed it…
So maybe put a dependency in the miio component?

Done by https://github.com/rytilahti/python-miio/pull/220.

1 Like

The bunch of fixes isn’t part of HA 0.63.2 unfortunately. :cry: The dev branch of homeassistant provides stable miio components already. They will be part of HA 0.64.

1 Like

Hi @syssi, can you please provide a step by step guide, with links to the code needed, to fix this on 63.2.

I have tried updating construct to 2.9.30, 2.9.28, 2.9.23 and a few other lower versions, still no luck. Vacuum and Plugs all not showing with the following error/s

error while reading discover results: _decode() takes 3 positional arguments but 4 were given

mirobo discover shows all the devices, but is showing some weird tokens for a few items;

INFO:miio.discovery:Discovering devices with mDNS, press any key to quit...
INFO:miio.discovery:Found a supported 'Vacuum' at 192.168.1.107 - token: ffffffffffffffffffffffffffffffff
/usr/local/lib/python3.4/dist-packages/miio/discovery.py:65: UserWarning: Please consider using python-yeelight for more complete support.
  dev = device_cls(ip=addr)
INFO:miio.discovery:Found a supported 'Yeelight' at 192.168.1.133 - token: 00000000000000000000000000000000
INFO:miio.discovery:Found a supported 'Yeelight' at 192.168.1.132 - token: 83727099ae234a364256a57dd773f621
INFO:miio.discovery:Found a supported 'Yeelight' at 192.168.1.136 - token: 24d96634882a4ea7d8b799f04216bae9
INFO:miio.discovery:Found a supported 'Plug' at 192.168.1.131 - token: ecfab41498ca766b4d418e9d08a1d656
INFO:miio.discovery:Found a supported 'Yeelight' at 192.168.1.134 - token: 00000000000000000000000000000000
INFO:miio.discovery:Found a supported 'Plug' at 192.168.1.125 - token: dda3be600510c17061a050b178d7c7a7
INFO:miio.discovery:lumi-gateway-v3_miio56299938._miio._udp.local. @ 192.168.1.106, check https://github.com/Danielhiversen/PyXiaomiGateway: token: 73e5027d43a15563f77bf21a448a5fc0
INFO:miio.discovery:Found a supported 'Plug' at 192.168.1.135 - token: 2eb11ad5ffd935e3ce3b0cec5ee3cd0e

Other info;

# flake8: noqa
__version__ = "0.3.6"

Construct;

version = (2,9,30)
version_string = "2.9.30"
release_date = "2018.02.13"

Help would be much appreciated.

I think I have it sorted finally. I copy/pasted all the code from; https://github.com/rytilahti/python-miio/tree/master/miio

version.py, protocol.py & device.py to the respective files in srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/miio/ and then pip3 install construct==2.9.28, and everything came back up.

What a process! Can’t wait for this to finally be fixed in 64.0

@kanga_who Yeah! I need your support (or somebody else with a Xiaomi Vacuum).

Please install the current master of python-miio

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

and provide the output of

mirobo --ip <ip> --token <token> -d info
mirobo --ip <ip> --token <token> consumables
mirobo --ip <ip> --token <token> discover
mirobo --ip <ip> --token <token> 

Thanks in advance!

Sure @syssi

mirobo --ip 192.168.1.107 --token 6c6c726f7047393061526873706d7a30 -d info

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 664, in _build_master
    ws.require(__requires__)
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 981, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 872, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (construct 2.9.31 (/usr/local/lib/python3.4/dist-packages), Requirement.parse('construct<=2.9.30,>=2.9.23'), {'python-miio'})

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/mirobo", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 3138, in <module>
    @_call_aside
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 3122, in _call_aside
    f(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 3151, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 666, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 679, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 867, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'construct<=2.9.30,>=2.9.23' distribution was not found and is required by python-miio

All produce the same errors

Hmm… please try again:

pip3 install -U https://github.com/syssi/python-miio/archive/feature/release-v0.3.7.zip
mirobo --ip <ip> --token <token> -d info
mirobo --ip <ip> --token <token> consumables
mirobo --ip <ip> --token <token> discover
mirobo --ip <ip> --token <token> 

Thanks!

I have just upgraded to 0.63.3 and now it is working!

1 Like

Have just reinstalled HA fresh with 0.63.3 with the latest MIIO version from masterzip. Which includes construct 2.9.31.
Still no luck with the Philips Bulb. I’ll be patiently waiting for 0.64. (well, I’ll try :slight_smile: )

What does your setup now look like @DDK ?

I only have the mi vacuum, no lights.
I just upgraded to the new version and followed the instructions to install the vacuum component, like getting the token etc.
After that the vacuum appeared. I bought it recently, while the Mi issues were going on, so I never had it working before.
I did not do any of the hot fixes like downgrading component.
Note that when I connected the vacuum to my phone I used the mainland server, not sure if that makes any difference.

@syssi

mirobo --ip 192.168.1.107 --token 6c6c726f7047393061526873706d7a30 -d info

INFO:miio.vacuum_cli:Debug mode active
DEBUG:miio.vacuum_cli:Connecting to 192.168.1.107 with token 6c6c726f7047393061526873706d7a30
DEBUG:miio.protocol:Unable to decrypt, returning raw bytes: b''
DEBUG:miio.device:Got a response: Container:
data = Container:
    length = 0
    data =  (total 0)
    offset1 = 32
    offset2 = 32
    value =  (total 0)
header = Container:
    length = 16
    data = !1\x00 \x00\x00\x00\x00\x03\xd9\x93\x01Z\x8a-} (total 16)
    offset1 = 0
    offset2 = 16
    value = Container:
        length = 32
        unknown = 0
        device_id = \x03\xd9\x93\x01 (total 4)
        ts = 2018-02-19 01:50:53
checksum = \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff (total 16)
DEBUG:miio.device:Discovered b'03d99301' with ts: 2018-02-19 01:50:53, token: b'ffffffffffffffffffffffffffffffff'
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 2330, in _build
return self.subcon._build(obj, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 587, in _build
return self.subcon._build(self._encode(obj, context, path), stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 757, in _build
_write_stream(stream, data, length)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 97, in _write_stream
raise StreamError("could not write bytes, expected %d, found %d" % (length, len(data)))
construct.core.StreamError: could not write bytes, expected 4, found 8

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/mirobo", line 11, in <module>
sys.exit(cli())
  File "/usr/local/lib/python3.4/dist-packages/miio/click_common.py", line 47, in __call__
return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/miio/vacuum_cli.py", line 380, in info
res = vac.info()
  File "/usr/local/lib/python3.4/dist-packages/miio/device.py", line 290, in info
return DeviceInfo(self.send("miIO.info", []))
  File "/usr/local/lib/python3.4/dist-packages/miio/device.py", line 227, in send
m = Message.build(msg, token=self.token)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 285, in build
self.build_stream(obj, stream, **kw)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 301, in build_stream
self._build(obj, stream, context, "(building)")
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 1890, in _build
buildret = sc._build(subobj, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 2330, in _build
return self.subcon._build(obj, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 4057, in _build
ret = self.subcon._build(value, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 1890, in _build
buildret = sc._build(subobj, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 2334, in _build
raise e.__class__("%s\n    %s" % (e, path))
construct.core.StreamError: could not write bytes, expected 4, found 8
(building) -> header -> device_id

mirobo --ip 192.168.1.107 --token 6c6c726f7047393061526873706d7a30 consumables

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 2330, in _build
    return self.subcon._build(obj, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 587, in _build
    return self.subcon._build(self._encode(obj, context, path), stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 757, in _build
    _write_stream(stream, data, length)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 97, in _write_stream
    raise StreamError("could not write bytes, expected %d, found %d" % (length, len(data)))
construct.core.StreamError: could not write bytes, expected 4, found 8

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/mirobo", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.4/dist-packages/miio/click_common.py", line 47, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/miio/vacuum_cli.py", line 121, in consumables
    res = vac.consumable_status()
  File "/usr/local/lib/python3.4/dist-packages/miio/vacuum.py", line 120, in consumable_status
    return ConsumableStatus(self.send("get_consumable")[0])
  File "/usr/local/lib/python3.4/dist-packages/miio/device.py", line 227, in send
    m = Message.build(msg, token=self.token)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 285, in build
    self.build_stream(obj, stream, **kw)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 301, in build_stream
    self._build(obj, stream, context, "(building)")
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 1890, in _build
    buildret = sc._build(subobj, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 2330, in _build
    return self.subcon._build(obj, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 4057, in _build
    ret = self.subcon._build(value, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 1890, in _build
    buildret = sc._build(subobj, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 2334, in _build
    raise e.__class__("%s\n    %s" % (e, path))
construct.core.StreamError: could not write bytes, expected 4, found 8
    (building) -> header -> device_id

mirobo --ip 192.168.1.107 --token 6c6c726f7047393061526873706d7a30 discover

INFO:miio.discovery:Discovering devices with mDNS, press any key to quit...
INFO:miio.discovery:Found a supported 'Plug' at 192.168.1.131 - token: ecfab41498ca766b4d418e9d08a1d656
/usr/local/lib/python3.4/dist-packages/miio/discovery.py:65: UserWarning: Please consider using python-yeelight for more complete support.
  dev = device_cls(ip=addr)
INFO:miio.discovery:Found a supported 'Yeelight' at 192.168.1.136 - token: 24d96634882a4ea7d8b799f04216bae9
INFO:miio.discovery:Found a supported 'Yeelight' at 192.168.1.133 - token: 00000000000000000000000000000000
INFO:miio.discovery:Found a supported 'Yeelight' at 192.168.1.134 - token: 00000000000000000000000000000000
INFO:miio.discovery:Found a supported 'Yeelight' at 192.168.1.132 - token: 83727099ae234a364256a57dd773f621
INFO:miio.discovery:lumi-gateway-v3_miio56299938._miio._udp.local. @ 192.168.1.106, check https://github.com/Danielhiversen/PyXiaomiGateway: token: 73e5027d43a15563f77bf21a448a5fc0
INFO:miio.discovery:Found a supported 'Plug' at 192.168.1.125 - token: dda3be600510c17061a050b178d7c7a7
INFO:miio.discovery:Found a supported 'Plug' at 192.168.1.135 - token: 2eb11ad5ffd935e3ce3b0cec5ee3cd0e
INFO:miio.discovery:Found a supported 'Vacuum' at 192.168.1.107 - token: ffffffffffffffffffffffffffffffff

mirobo --ip 192.168.1.107 --token 6c6c726f7047393061526873706d7a30

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 2330, in _build
    return self.subcon._build(obj, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 587, in _build
    return self.subcon._build(self._encode(obj, context, path), stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 757, in _build
    _write_stream(stream, data, length)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 97, in _write_stream
    raise StreamError("could not write bytes, expected %d, found %d" % (length, len(data)))
construct.core.StreamError: could not write bytes, expected 4, found 8

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/mirobo", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.4/dist-packages/miio/click_common.py", line 47, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 1043, in invoke
    return Command.invoke(self, ctx)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/miio/vacuum_cli.py", line 64, in cli
    ctx.invoke(status)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/miio/vacuum_cli.py", line 100, in status
    res = vac.status()
  File "/usr/local/lib/python3.4/dist-packages/miio/vacuum.py", line 108, in status
    return VacuumStatus(self.send("get_status")[0])
  File "/usr/local/lib/python3.4/dist-packages/miio/device.py", line 227, in send
    m = Message.build(msg, token=self.token)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 285, in build
    self.build_stream(obj, stream, **kw)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 301, in build_stream
    self._build(obj, stream, context, "(building)")
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 1890, in _build
    buildret = sc._build(subobj, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 2330, in _build
    return self.subcon._build(obj, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 4057, in _build
    ret = self.subcon._build(value, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 1890, in _build
    buildret = sc._build(subobj, stream, context, path)
  File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 2334, in _build
    raise e.__class__("%s\n    %s" % (e, path))
construct.core.StreamError: could not write bytes, expected 4, found 8
    (building) -> header -> device_id

Thanks for your help! We released python-miio 0.3.7 last night.

1 Like

You should just block internet access from all xiaomi devices to the internet. U don’T need it at all. As soon as u got the token u can block their internet access. As long as there’s no significant updates just let them out of the chinese cloud… that’S the purpose of using home assistant :slight_smile:

1 Like

HA 0.63.3 was released a few days ago: https://home-assistant.io/blog/2018/02/10/release-63/#release-0633---february-17

The xiaomi_miio stack is back alive! :sparkler:

3 Likes

After updating to 0.63.3 seems everything it’s working fine again,
Thanks!!!

After updating to 0.63.3 Xiaomi Philips bulb works fine, but I always get errors on log:

2018-02-23 14:02:24 ERROR (SyncWorker_8) [miio.device] Unable to discover a device at address 10.0.0.50
2018-02-23 14:02:24 ERROR (MainThread) [homeassistant.components.light.xiaomi_miio] Got exception while fetching the state: Unable to discover the device 10.0.0.50

This is fine. The bulb doesn’t respond to the first request sometimes.

Fresh install of Hass 0.64 on my Pine64 running Python 3.5. No luck with miio (remote and lights)

2018-02-26 20:22:57 ERROR (Thread-21) [homeassistant.util.package] Unable to install package python-miio==0.3.7: Exception:
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/pip/basecommand.py”, line 215, in main
status = self.run(options, args)
File “/srv/homeassistant/lib/python3.5/site-packages/pip/commands/install.py”, line 353, in run
wb.build(autobuilding=True)
File “/srv/homeassistant/lib/python3.5/site-packages/pip/wheel.py”, line 749, in build
self.requirement_set.prepare_files(self.finder)
File “/srv/homeassistant/lib/python3.5/site-packages/pip/req/req_set.py”, line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File “/srv/homeassistant/lib/python3.5/site-packages/pip/req/req_set.py”, line 620, in _prepare_file
session=self.session, hashes=hashes)
File “/srv/homeassistant/lib/python3.5/site-packages/pip/download.py”, line 809, in unpack_url
unpack_file_url(link, location, download_dir, hashes=hashes)
File “/srv/homeassistant/lib/python3.5/site-packages/pip/download.py”, line 715, in unpack_file_url
unpack_file(from_path, location, content_type, link)
File “/srv/homeassistant/lib/python3.5/site-packages/pip/utils/init.py”, line 617, in unpack_file
flatten=not filename.endswith(‘.whl’)
File “/srv/homeassistant/lib/python3.5/site-packages/pip/utils/init.py”, line 502, in unzip_file
zip = zipfile.ZipFile(zipfp, allowZip64=True)
File “/usr/lib/python3.5/zipfile.py”, line 1026, in init
self._RealGetContents()
File “/usr/lib/python3.5/zipfile.py”, line 1094, in _RealGetContents
raise BadZipFile(“File is not a zip file”)
zipfile.BadZipFile: File is not a zip file
2018-02-26 20:22:57 ERROR (MainThread) [homeassistant.requirements] Not initializing light.xiaomi_miio because could not install requirement python-miio==0.3.7
2018-02-26 20:22:57 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform light.xiaomi_miio: Could not install all requirements.

Update :
Manually installed miio 0.37 from Master.zip , not there yet. Now I only get :

2018-02-26 20:41:25 WARNING (MainThread) [homeassistant.components.light] Platform xiaomi_miio not ready yet. Retrying in 60 seconds.
2018-02-26 20:42:26 WARNING (MainThread) [homeassistant.components.light] Platform xiaomi_miio not ready yet. Retrying in 90 seconds.