Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to discover a device #217

Closed
ljw092 opened this issue Feb 13, 2018 · 10 comments
Closed

Unable to discover a device #217

ljw092 opened this issue Feb 13, 2018 · 10 comments

Comments

@ljw092
Copy link

ljw092 commented Feb 13, 2018

I have Xiaomi Mi Smart Socket Plug (1 Socket, 1 USB Port) . this is homeassistant.log:
2018-02-13 10:29:21 ERROR (Thread-17) [miio.device] Got error when receiving: timed out
2018-02-13 10:29:21 WARNING (Thread-17) [miio.device] Retrying with incremented id, retries left: 3
2018-02-13 10:29:57 ERROR (Thread-11) [miio.device] Unable to discover a device at address 192.168.0.100
2018-02-13 10:29:57 ERROR (Thread-13) [miio.device] Unable to discover a device at address 192.168.0.100
2018-02-13 10:29:57 ERROR (MainThread) [homeassistant.components.switch.xiaomi_miio] Got exception while fetching the state: Unable to discover the device 192.168.0.100
2018-02-13 10:29:57 ERROR (MainThread) [homeassistant.components.switch.xiaomi_miio] Got exception while fetching the state: Unable to discover the device 192.168.0.100

And I try command mirobo --ip 192.168.0.100 --token xxxxxxxxx -d status

INFO:miio.vacuum_cli:Debug mode active
DEBUG:miio.vacuum_cli:Connecting to 192.168.0.100 with token xxxxxxxxxx
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 192.168.0.100
DEBUG:miio.click_common:Exception: Unable to discover the device 192.168.0.100

Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/miio/click_common.py ", line 47, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py ", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py ", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py ", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py ", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/decorators.py ", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py ", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/miio/vacuum_cli.py ", line 100, in status
res = vac.status()
File "/usr/local/lib/python3.5/dist-packages/miio/vacuum.py ", line 108, in status
return VacuumStatus(self.send("get_status")[0])
File "/usr/local/lib/python3.5/dist-packages/miio/device.py ", line 204, in send
self.do_discover()
File "/usr/local/lib/python3.5/dist-packages/miio/device.py ", line 144, in do_discover
raise DeviceException("Unable to discover the device %s" % self.ip)
miio.device.DeviceException: Unable to discover the device 192.168.0.100

Error: Unable to discover the device 192.168.0.100

miio version==0.3.5, ha version=0.63.1, how can I do?

@moskovskiy82
Copy link

I have an exactly the same issue.

Since HA 0.63 i get 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

@DJLemkes
Copy link

Think I found what's wrong. My Traceback points to the construct package that seems to have made a pretty big API change:

Feb 13 09:37:28 hassbian hass[7688]: 2018-02-13 09:37:28 INFO (MainThread) [homeassistant.components.light.xiaomi_miio] Initializing with host 192.168.x.y
Feb 13 09:37:29 hassbian hass[7688]: Traceback (most recent call last):
Feb 13 09:37:29 hassbian hass[7688]:   File "/srv/homeassistant/lib/python3.5/site-packages/miio/device.py", line 177, in discover
Feb 13 09:37:29 hassbian hass[7688]:     m = Message.parse(data)  # type: Message
Feb 13 09:37:29 hassbian hass[7688]:   File "/srv/homeassistant/lib/python3.5/site-packages/construct/core.py", line 241, in parse
Feb 13 09:37:29 hassbian hass[7688]:     return self.parse_stream(io.BytesIO(data), **kw)
Feb 13 09:37:29 hassbian hass[7688]:   File "/srv/homeassistant/lib/python3.5/site-packages/construct/core.py", line 258, in parse_stream
Feb 13 09:37:29 hassbian hass[7688]:     return self._parse(stream, context, "(parsing)")
Feb 13 09:37:29 hassbian hass[7688]:   File "/srv/homeassistant/lib/python3.5/site-packages/construct/core.py", line 1928, in _parse
Feb 13 09:37:29 hassbian hass[7688]:     subobj = sc._parse(stream, context, path)
Feb 13 09:37:29 hassbian hass[7688]:   File "/srv/homeassistant/lib/python3.5/site-packages/construct/core.py", line 2379, in _parse
Feb 13 09:37:29 hassbian hass[7688]:     return self.subcon._parse(stream, context, path)
Feb 13 09:37:29 hassbian hass[7688]:   File "/srv/homeassistant/lib/python3.5/site-packages/construct/core.py", line 3802, in _parse
Feb 13 09:37:29 hassbian hass[7688]:     obj = self.subcon._parse(stream, context, path)
Feb 13 09:37:29 hassbian hass[7688]:   File "/srv/homeassistant/lib/python3.5/site-packages/construct/core.py", line 4165, in _parse
Feb 13 09:37:29 hassbian hass[7688]:     obj = self.subcon._parse(stream, context, path)
Feb 13 09:37:29 hassbian hass[7688]:   File "/srv/homeassistant/lib/python3.5/site-packages/construct/core.py", line 581, in _parse
Feb 13 09:37:29 hassbian hass[7688]:     return self._decode(self.subcon._parse(stream, context, path), context, path)
Feb 13 09:37:29 hassbian hass[7688]: TypeError: _decode() takes 3 positional arguments but 4 were given
Feb 13 09:37:29 hassbian hass[7688]: 2018-02-13 09:37:29 WARNING (MainThread) [miio.device] error while reading discover results: _decode() takes 3 positional arguments but 4 were given
Feb 13 09:37:29 hassbian hass[7688]: 2018-02-13 09:37:29 ERROR (MainThread) [miio.device] Unable to discover a device at address 192.168.x.y

pyhton-miio depends on construct>=2.9.23 which as of yesterday resolves to version 2.9.30 in which the callers of _decode have changed the arguments being passed.

Quick n dirty solution: manually uninstall construct and re-install it at a specific version (pip3 install construct==2.9.23)

Better solution: explicitly require a specific version in requirements.txt to protect against unexpected API changes in dependencies.

@syssi
Copy link
Collaborator

syssi commented Feb 13, 2018

@DJLemkes You are right. construct==2.9.30 broke the library again. :-(

DJLemkes added a commit to DJLemkes/python-miio that referenced this issue Feb 13, 2018
This protects against breaking changes in construct API as
encountered in rytilahti#217.
@ljw092
Copy link
Author

ljw092 commented Feb 13, 2018

@syssi @DJLemkes
I install the construct==2.9.23,miio==0.3.5,ha==0.63.1 but still get error

root@raspberrypi:~# mirobo --ip 192.168.0.100 --token xxxxxxxxxxxxx -d status
INFO:miio.vacuum_cli:Debug mode active
DEBUG:miio.vacuum_cli:Connecting to 192.168.0.100 with token xxxxxxxxxxxxx
ERROR:miio.device:Unable to discover a device at address 192.168.0.100
DEBUG:miio.click_common:Exception: Unable to discover the device 192.168.0.100
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/miio/click_common.py", line 47, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/miio/vacuum_cli.py", line 100, in status
res = vac.status()
File "/usr/local/lib/python3.5/dist-packages/miio/vacuum.py", line 108, in status
return VacuumStatus(self.send("get_status")[0])
File "/usr/local/lib/python3.5/dist-packages/miio/device.py", line 204, in send
self.do_discover()
File "/usr/local/lib/python3.5/dist-packages/miio/device.py", line 144, in do_discover
raise DeviceException("Unable to discover the device %s" % self.ip)
miio.device.DeviceException: Unable to discover the device 192.168.0.100
Error: Unable to discover the device 192.168.0.100

root@raspberrypi:~# mirobo discover
INFO:miio.discovery:Discovering devices with mDNS, press any key to quit...
ERROR:miio.device:Unable to discover a device at address 192.168.0.100
Exception in thread zeroconf-ServiceBrowser__miio._udp.local.:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.5/dist-packages/zeroconf.py", line 1334, in run
handler(self.zc)
File "/usr/local/lib/python3.5/dist-packages/zeroconf.py", line 1282, in
state_change=state_change,
File "/usr/local/lib/python3.5/dist-packages/zeroconf.py", line 1197, in fire
h(**kwargs)
File "/usr/local/lib/python3.5/dist-packages/zeroconf.py", line 1255, in on_change
listener.add_service(*args)
File "/usr/local/lib/python3.5/dist-packages/miio/discovery.py", line 104, in add_service
dev = self.check_and_create_device(info, addr)
File "/usr/local/lib/python3.5/dist-packages/miio/discovery.py", line 89, in check_and_create_device
return create_device(addr, v)
File "/usr/local/lib/python3.5/dist-packages/miio/discovery.py", line 66, in create_device
m = dev.do_discover()
File "/usr/local/lib/python3.5/dist-packages/miio/device.py", line 144, in do_discover
raise DeviceException("Unable to discover the device %s" % self.ip)
miio.device.DeviceException: Unable to discover the device 192.168.0.100

@syssi
Copy link
Collaborator

syssi commented Feb 13, 2018

Are you able to ping the device (192.168.0.100)? Are you sure about the used token?

@ljw092
Copy link
Author

ljw092 commented Feb 13, 2018

@syssi I can ping the device. I sure the token is right.

@syssi
Copy link
Collaborator

syssi commented Feb 13, 2018

What kind of device it is?

@ljw092
Copy link
Author

ljw092 commented Feb 14, 2018

@syssi My device is chuangmi plug v1 (1 Socket, 1 USB Port).
I reinstall the ha==0.63.1, python-miio==0.3.5, construct==2.9.23, then

root@raspberrypi:~# mirobo discover
INFO:miio.discovery:Discovering devices with mDNS, press any key to quit...
INFO:miio.discovery:Found a supported 'PlugV1' at 192.168.0.100  - token: xxxxxxx

I can discover the device, but I command

root@raspberrypi:~# mirobo --ip 192.168.0.100  --token xxxxxxxx -d status
INFO:miio.vacuum_cli:Debug mode active
DEBUG:miio.vacuum_cli:Connecting to 192.168.0.100 with token xxxxxxxx
DEBUG:miio.protocol:Unable to decrypt, returning raw bytes: b''
DEBUG:miio.device:Got a response: Container: 
    data = Container: 
        offset2 = 32
        length = 0
        value =  (total 0)
        data =  (total 0)
        offset1 = 32
    header = Container: 
        offset2 = 16
        length = 16
        value = Container: 
            length = 32
            unknown = 0
            device_id = 0005ff7d (total 8)
            ts = 1970-01-02 02:14:46
        data = !1\x00 \x00\x00\x00\x00\x00\x05\xff}\x00\x01q\x16 (total 16)
        offset1 = 0
    checksum = \xc2\x01\xd9&\x1b\xc0T\xedw!>\x98\x7f\x95\xb7\xbd (total 16)
DEBUG:miio.device:Discovered b'0005ff7d' with ts: 1970-01-02 02:14:46, token: b'xxxxxxxxxxxx'
DEBUG:miio.device:192.168.0.100:54321 

 >>: {'method': 'get_status', 'id': 1}
DEBUG:miio.device:192.168.0.100:54321 

 (ts: 1970-01-02 02:14:47, id: 1) << {'id': 1, 'error': {'message': 'Req object invalid.', 'code': -32600}}
DEBUG:miio.click_common:Exception: {'message': 'Req object invalid.', 'code': -32600}
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/miio/click_common.py 

", line 47, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py 

", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py 

", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.5/dist-packages/click/core.py 

", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py 

", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/decorators.py 

", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py 

", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/miio/vacuum_cli.py 

", line 100, in status
    res = vac.status()
  File "/usr/local/lib/python3.5/dist-packages/miio/vacuum.py 

", line 108, in status
    return VacuumStatus(self.send("get_status")[0])
  File "/usr/local/lib/python3.5/dist-packages/miio/device.py 

", line 251, in send
    raise DeviceError(m.data.value["error"])
miio.device.DeviceError: {'message': 'Req object invalid.', 'code': -32600}
Error: {'message': 'Req object invalid.', 'code': -32600}

And in ha, I still get error:

WARNING (MainThread) [miio.device] error while reading discover results: _decode() takes 3 positional arguments but 4 were given
ERROR (MainThread) [miio.device] Unable to discover a device at address 192.168.0.100 

This is my pip3 list, python version is 3.5.3

aiohttp (2.3.10)
android-backup (0.1.0)
appdirs (1.4.3)
asn1crypto (0.24.0)
astral (1.5)
async-timeout (2.0.0)
attrs (17.4.0)
automationhat (0.0.4)
blinker (1.3)
blinkt (0.1.0)
broadlink (0.6)
Cap1xxx (0.1.3)
certifi (2018.1.18)
cffi (1.11.4)
chardet (3.0.4)
click (6.7)
colorama (0.3.7)
construct (2.9.23)
cryptography (2.1.4)
drumhat (0.0.5)
enum-compat (0.0.2)
envirophat (0.0.6)
ExplorerHAT (0.4.2)
Flask (0.12.1)
fourletterphat (0.0.2)
gpiozero (1.4.0)
homeassistant (0.63.1)
idna (2.6)
idna-ssl (1.0.0)
itsdangerous (0.24)
jedi (0.10.2)
Jinja2 (2.10)
keyrings.alt (1.3)
MarkupSafe (1.0)
microdotphat (0.1.3)
mote (0.0.3)
motephat (0.0.2)
multidict (4.1.0)
netifaces (0.10.6)
numpy (1.12.1)
oauthlib (2.0.1)
phatbeat (0.0.2)
pianohat (0.0.5)
picamera (1.13)
picraft (1.0)
piglow (1.2.4)
pigpio (1.38)
Pillow (4.0.0)
pip (9.0.1)
pretty-cron (1.0.2)
psutil (5.4.3)
pyasn1 (0.1.9)
pycparser (2.18)
pycrypto (2.6.1)
pygobject (3.22.0)
pyinotify (0.9.6)
PyJWT (1.4.2)
pyOpenSSL (16.2.0)
pyserial (3.2.1)
python-apt (1.1.0b5)
python-miio (0.3.5)
pytz (2018.3)
pyxdg (0.25)
PyYAML (3.12)
rainbowhat (0.0.2)
requests (2.18.4)
requests-oauthlib (0.7.0)
RPi.GPIO (0.6.3)
RTIMULib (7.2.1)
scrollphat (0.0.7)
scrollphathd (1.1.1)
sense-emu (1.0)
sense-hat (2.2.0)
setuptools (33.1.1)
simplejson (3.10.0)
six (1.11.0)
skywriter (0.0.7)
sn3218 (1.2.7)
spidev (3.3)
SQLAlchemy (1.2.2)
thonny (2.1.10)
touchphat (0.0.1)
twython (3.4.0)
typing (3.6.4)
urllib3 (1.22)
voluptuous (0.10.5)
Werkzeug (0.11.15)
wheel (0.29.0)
yarl (1.1.0)
zeroconf (0.19.1)

What's the problem, please?

@syssi
Copy link
Collaborator

syssi commented Feb 14, 2018

  1. mirobo discover looks good!
  2. mirobo --ip 192.168.0.100 --token xxxxxxxx -d status send the command "get_status" to the device. This command isn't supported by the Chuangmi plug. Supported commands are:
mirobo --ip 192.168.0.100  --token xxxxxxxx raw_command get_prop "['on', 'usb_on', 'temperature']"
mirobo --ip 192.168.0.100  --token xxxxxxxx raw_command set_on "[]"
mirobo --ip 192.168.0.100  --token xxxxxxxx raw_command set_off "[]"
mirobo --ip 192.168.0.100  --token xxxxxxxx raw_command get_usb_on "[]"
mirobo --ip 192.168.0.100  --token xxxxxxxx raw_command get_usb_of "[]"
  1. If you enable the debug output of the component at homeassistant you will see some more details (paths) about the problem:
logger:                                                                                                                                                                                                                                        
  default: debug                                                                                                                                                                                                                               
  logs:                                                                                                                                                                                                                                        
    homeassistant.components.switch.xiaomi_miio: debug                                                                                                                                                                                                     
    miio: debug 

I assume you have installed "python-miio" and "construct" multiple times. There will be a system install under /usr/local/lib/python3.5/dist-packages/ and another one in a subfolder of homeassistant. If you compare the versions they won't be compatible. This error

WARNING (MainThread) [miio.device] error while reading discover results: _decode() takes 3 positional arguments but 4 were given

is an error of construct 2.9.30.

@ljw092
Copy link
Author

ljw092 commented Feb 14, 2018

@syssi You are right. It works now. Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants