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

Unexpected response for get_device_list on Xiaomi Miio gateway #51294

Closed
frabar55 opened this issue May 31, 2021 · 18 comments · Fixed by #54601
Closed

Unexpected response for get_device_list on Xiaomi Miio gateway #51294

frabar55 opened this issue May 31, 2021 · 18 comments · Fixed by #54601

Comments

@frabar55
Copy link

The problem

error in integrating lumi.gateway3 in home assistant

What is version of Home Assistant Core has the issue?

2021.5.05

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Core

Integration causing the issue

Xiaomi Miio

Link to integration documentation on our website

No response

Example YAML snippet

when i try to integrate the lumi.gateway3 I always receive the error (see below)

Anything in the logs that might be useful for us?

Logger: homeassistant.config_entries
Source: components/xiaomi_miio/gateway.py:43
First occurred: 15:28:48 (1 occurrences)
Last logged: 15:28:48

Error setting up entry Xiaomi Gateway for xiaomi_miio
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/config_entries.py", line 269, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/xiaomi_miio/__init__.py", line 45, in async_setup_entry
    ] == CONF_GATEWAY and not await async_setup_gateway_entry(hass, entry):
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/xiaomi_miio/__init__.py", line 69, in async_setup_gateway_entry
    if not await gateway.async_connect_gateway(host, token):
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/xiaomi_miio/gateway.py", line 43, in async_connect_gateway
    await self._hass.async_add_executor_job(
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.8/site-packages/miio/gateway/gateway.py", line 172, in discover_devices
    model_info = self.match_zigbee_model(device["model"], device["did"])
TypeError: string indices must be integers

Additional information

No response

@probot-home-assistant
Copy link

Hey there @rytilahti, @syssi, @starkillerOG, mind taking a look at this issue as its been labeled with an integration (xiaomi_miio) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@starkillerOG
Copy link
Contributor

@frabar55 what kind of gateway are u using (see https://www.home-assistant.io/integrations/xiaomi_miio/#supported-xiaomi-gateway-models)?
You say "lumi.gateway3" but if you mean "lumi.gateway.v3" model "DGNWG02LM" something really weard is going on because the error indicates it is using the code for the "lumi.gateway.mgl03" gateway model "ZNDMWG03LM"

In any case, it seems like the response you get from the gateway is not a dictionary but some string, it might just be a case of using json.loads().

Could you run the following python script and post the output?

from miio import Gateway
gateway = Gateway("192.168.1.IP", "TokenTokenToken")
print(gateway.send("get_device_list"))

@frabar55
Copy link
Author

frabar55 commented Jun 3, 2021

I'm using the ZNDMWG03LM. I'l send you the output of the script soon

@frabar55
Copy link
Author

frabar55 commented Jun 3, 2021

I apologize, but Iìm not able to riun the script yoiu suggested. The following is the error I received just at th first row

Traceback (most recent call last):
File "/home/pi/Desktop/gw3.py", line 1, in
from miio import Gateway
ModuleNotFoundError: No module named 'miio'

@starkillerOG
Copy link
Contributor

@frabar55 that error just means python-miio is not installed in the location you are running the python script.
Use "pip install --upgrade python-miio" to install python-miio (in the command line)

@frabar55
Copy link
Author

frabar55 commented Jun 3, 2021

that is the output of the script:

Traceback (most recent call last):
File "/home/pi/Desktop/gw3.py", line 2, in
gateway = Gateway("192.168.178.49", "TokenTokenToken")
File "/home/pi/.local/lib/python3.8/site-packages/miio/gateway/gateway.py", line 83, in init
super().init(ip, token, start_id, debug, lazy_discover)
File "/home/pi/.local/lib/python3.8/site-packages/miio/device.py", line 151, in init
self._protocol = MiIOProtocol(
File "/home/pi/.local/lib/python3.8/site-packages/miio/miioprotocol.py", line 43, in init
self.token = bytes.fromhex(token)
ValueError: non-hexadecimal number found in fromhex() arg at position 0

@frabar55
Copy link
Author

frabar55 commented Jun 3, 2021

I'm sorry, this is the real result:

{'code': 0, 'id': 1, 'exe_time': 110}

@starkillerOG
Copy link
Contributor

That is pretty weird, are you on the latest firmware version of the gateway? (you can update in the Mii home app)

@starkillerOG
Copy link
Contributor

@rytilahti do you know why the gateway.send("get_device_list") function does not just return the contents of the replay of the gateway but this message indication some response code or something.

@frabar55
Copy link
Author

frabar55 commented Jun 3, 2021

  1. the firmware rel is 1.5.0_0026
  2. I'm not able to answer to the second question

@frabar55
Copy link
Author

frabar55 commented Jun 3, 2021

Hi everybody, passing to the new HA rel (2021.6.00), the error has changed:

Logger: homeassistant.components.xiaomi_miio.gateway
Source: components/xiaomi_miio/gateway.py:47
Integration: Xiaomi Miio (documentation, issues)
First occurred: 17:33:33 (1 occurrences)
Last logged: 17:33:33

DeviceException during setup of xiaomi gateway with host 192.168.178.49

@frabar55
Copy link
Author

frabar55 commented Jun 3, 2021

Sorry, reset!
The error is the same (I've re-installed the integration)!

Logger: homeassistant.config_entries
Source: components/xiaomi_miio/gateway.py:43
First occurred: 17:47:29 (1 occurrences)
Last logged: 17:47:29

Error setting up entry Xiaomi Gateway for xiaomi_miio
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/config_entries.py", line 293, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/xiaomi_miio/init.py", line 45, in async_setup_entry
] == CONF_GATEWAY and not await async_setup_gateway_entry(hass, entry):
File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/xiaomi_miio/init.py", line 69, in async_setup_gateway_entry
if not await gateway.async_connect_gateway(host, token):
File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/xiaomi_miio/gateway.py", line 43, in async_connect_gateway
await self._hass.async_add_executor_job(
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/srv/homeassistant/lib/python3.8/site-packages/miio/gateway/gateway.py", line 172, in discover_devices
model_info = self.match_zigbee_model(device["model"], device["did"])
TypeError: string indices must be integers

@rytilahti
Copy link
Member

@rytilahti do you know why the gateway.send("get_device_list") function does not just return the contents of the replay of the gateway but this message indication some response code or something.

Unfortunately no, my guess would be that the device/firmware doesn't support the command (or that there are no devices bound to it?). python-miio should check if the response is in expected format and raise an exception when not (like in this case).

@rytilahti rytilahti changed the title Xiaomi Miio integratiom problem Unexpected response for get_device_list on Xiaomi Miio gateway Jun 3, 2021
@starkillerOG
Copy link
Contributor

@frabar55 Thas is a good question: Are there any subdevices connected to this gateway and if so: how many?

@frabar55
Copy link
Author

frabar55 commented Jun 3, 2021

There are three BLE devices (miaomiaoce.sensor_ht.t2) and none Zigbee because the gateway are not able to pair any (i have either Lumi and Aqarq devices but conneccted to Zigbee2mqtt)

@starkillerOG
Copy link
Contributor

@frabar55 alright, that explains it.
The "get_device_list" command only gets the zigbee devices as far as I am aware.
I never tested what happes if there are no zigbee devices, apperently you get the message as you displayed.

I will make a PR in python-miio that will catch this case and not return an error if there are no zigbee devices connected.
The gateway will then setup fine and you can control the alarm and the light of the gateway.

I don't know how BLE devices work and how they are connected (and if) to the gateway.
Not sure if they can even be controlled through the gateway.
In any case BLE devices will not show up with the current code, maybe there is a possibility to add support for them, but since I don't have any it will be hard to program that.

@starkillerOG
Copy link
Contributor

This PR schould fix your issue: rytilahti/python-miio#1065

@frabar55
Copy link
Author

frabar55 commented Jun 4, 2021

Thanks to everybody. Please tell me haw I can check on my own.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants