home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.81k stars 30.07k forks source link

Multiple Xiaomi Gateways via Integration page not working #37306

Closed YoinkZed closed 4 years ago

YoinkZed commented 4 years ago

The problem

Recent update to 0.112 introduced an error when setting up multiple Xiaomi Aqara Gateways. This was doable through the configuration.yaml file in 0.111.4. The error comes when trying to add the second gateway using either (any, internal ip of Home Assistant, or the gateway ip): image

... and then the error: image

Multiple reboots on both Home Assistant and the Gateway doesn't solve the issue.

Environment

arch x86_64
chassis embedded
dev false
docker true
docker_version 19.03.8
hassio true
host_os HassOS 4.10
installation_type Home Assistant OS
os_name Linux
os_version 5.4.44
python_version 3.7.7
supervisor 227
timezone Europe/Copenhagen
version 0.112.0
virtualenv false

Problem-relevant configuration.yaml

Latest working configuration.yaml code.

xiaomi_aqara:
  discovery_retry: 20
  gateways:
    - key: !secret xiaomi_key1
      host: 192.168.1.91
      mac: !secret xiaomi_mac1
    - key: !secret xiaomi_key2
      host: 192.168.1.92
      mac: !secret xiaomi_mac2

Traceback/Error logs

Additional information

Snarky73 commented 4 years ago

Single Xaomi Gateway stop working too after upgrade from 0.111.4 to 0.112

YoinkZed commented 4 years ago

Single Xaomi Gateway stop working too after upgrade from 0.111.4

Was working for me though in 0.111.4.

dshokouhi commented 4 years ago

can you guys check the logs for errors? make sure that you try to setup the config flow again because it does not get imported from YAML.

Nebr88 commented 4 years ago

I have the same error. Disabled the record in the configuration.yaml and rebooted HA

Nebr88 commented 4 years ago

can you guys check the logs for errors? make sure that you try to setup the config flow again because it does not get imported from YAML.

I have this one in log

`Уровень: ERROR Logger: aiohttp.server Source: components/xiaomi_aqara/config_flow.py:61 First occurred: 2:43:27 (4 occurrences) Last logged: 2:43:35

Error handling request Traceback (most recent call last): File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start resp = await task File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle resp = await handler(request) File "/srv/homeassistant/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl return await handler(request) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware return await handler(request) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/http/ban.py", line 73, in ban_middleware return await handler(request) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/http/auth.py", line 127, in auth_middleware return await handler(request) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/http/view.py", line 129, in handle result = await result File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/config/config_entries.py", line 145, in post return await super().post(request, flow_id) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/http/data_validator.py", line 60, in wrapper result = await method(view, request, *args, *kwargs) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/data_entry_flow.py", line 106, in post result = await self._flow_mgr.async_configure(flow_id, data) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/data_entry_flow.py", line 153, in async_configure result = await self._async_handle_step(flow, cur_step["step_id"], user_input) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/data_entry_flow.py", line 201, in _async_handle_step result: Dict = await getattr(flow, method)(user_input) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/xiaomi_aqara/config_flow.py", line 61, in async_step_user await self.hass.async_add_executor_job(xiaomi.discover_gateways) File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(self.args, **self.kwargs) File "/srv/homeassistant/lib/python3.7/site-packages/xiaomi_gateway/init.py", line 47, in discover_gateways _socket.bind((self._interface, 0)) OSError: [Errno 99] Cannot assign requested address`

Nebr88 commented 4 years ago

Also this one

`Logger: homeassistant.components.xiaomi_miio.gateway Source: components/xiaomi_miio/gateway.py:38 Integration: Xiaomi Miio (documentation, issues) First occurred: 2:37:20 (1 occurrences) Last logged: 2:37:20

DeviceException during setup of xiaomi gateway with host 192.168.0.132`

ctripodi commented 4 years ago

same issue here, Single Xaomi Gateway stop working too after upgrade from 0.111.4 to 0.112

resoai commented 4 years ago

Same here. One of the gateways was discovered but there is no way to add the second one.

3ZVK commented 4 years ago

Same here, one gateway, not working anymore. Running homeassistant core in docker

chrisrock1984 commented 4 years ago

same for me

Solved it by using the integration page and the 8Byte keys - I have 3 GW's

YoinkZed commented 4 years ago

Solved it by using the integration page and the 8Byte keys - I have 3 GW's

I'm not sure I understand - did you use the integration page and used the "any" and then with the 8Byte key? The key you get from the Hub?

maury77 commented 4 years ago

same for me

Solved it by using the integration page and the 8Byte keys - I have 3 GW's

what changes have you made? the integration page show error: Zeroconf discovered Gateway could not be located to get the necessary information, try using the IP of the device running HomeAssistant as interface

chrisrock1984 commented 4 years ago

Exactly I used the 8byte key from the app. I have a gen2 gateway. Originally I used to configure xiaomi within the yaml file. With the latest update, 0.112.0 this was broken. So I tried the Integration method. All 3 Gateways were found, they have a static IP address. I used the same keys from the yaml file and it worked again. Nothing else was done.

YoinkZed commented 4 years ago

Exactly I used the 8byte key from the app. I have a gen2 gateway. Originally I used to configure xiaomi within the yaml file. With the latest update, 0.112.0 this was broken. So I tried the Integration method. All 3 Gateways were found, they have a static IP address. I used the same keys from the yaml file and it worked again. Nothing else was done.

Impressive how differently it acts. But what "type" of Home Assistant do you run? Is it Ubuntu with docker or is it on a Pie or NUC like mine is?

artbrayko commented 4 years ago

Same. Having two gateways and not one is not added, although it is detected

chrisrock1984 commented 4 years ago

I have a Rock64 board 4gb running ubuntu. Hassio is running in a docker Container.

to4ko commented 4 years ago

working like a charm (x86 in docker as well as rpi 3b+) image

fliphess commented 4 years ago

Having the same error running core in a virtualenv as a restricted user.

if the correct network interface is given (enp1s0f0) i'm receiving an Invalid network interface error.

If interface any is given instead, an error is raised related to permissions:

2020-07-02 22:23:35 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/home/homeassistant/hass/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/home/homeassistant/hass/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/home/homeassistant/hass/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/home/homeassistant/hass/lib/python3.7/site-packages/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware
    return await handler(request)
  File "/home/homeassistant/hass/lib/python3.7/site-packages/homeassistant/components/http/ban.py", line 73, in ban_middleware
    return await handler(request)
  File "/home/homeassistant/hass/lib/python3.7/site-packages/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/home/homeassistant/hass/lib/python3.7/site-packages/homeassistant/components/http/view.py", line 129, in handle
    result = await result
  File "/home/homeassistant/hass/lib/python3.7/site-packages/homeassistant/components/config/config_entries.py", line 145, in post
    return await super().post(request, flow_id)
  File "/home/homeassistant/hass/lib/python3.7/site-packages/homeassistant/components/http/data_validator.py", line 60, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/home/homeassistant/hass/lib/python3.7/site-packages/homeassistant/helpers/data_entry_flow.py", line 106, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/home/homeassistant/hass/lib/python3.7/site-packages/homeassistant/data_entry_flow.py", line 153, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/home/homeassistant/hass/lib/python3.7/site-packages/homeassistant/data_entry_flow.py", line 201, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/home/homeassistant/hass/lib/python3.7/site-packages/homeassistant/components/xiaomi_aqara/config_flow.py", line 61, in async_step_user
    await self.hass.async_add_executor_job(xiaomi.discover_gateways)
  File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/hass/lib/python3.7/site-packages/xiaomi_gateway/__init__.py", line 77, in discover_gateways
    (self.MULTICAST_ADDRESS, self.GATEWAY_DISCOVERY_PORT))
PermissionError: [Errno 1] Operation not permitted

Setting CAP_NET_ADMIN in systemd CapabilityBoundingSet does not help (still the permissions error)

Reverting to 0.111.4 did solve the issue.

dshokouhi commented 4 years ago

@starkillerOG FYI in case you are not aware :)

guoyiang commented 4 years ago

It had the same issue in 0.113.0.dev version, then I re-do the setup following instruction in the document here: https://www.home-assistant.io/integrations/xiaomi_aqara/#setup . After that, xiaomi integration back working again. It was initially setup using configuration.yaml. Maybe that changed recently, I don't see configuration.yaml mentioned in the above document any more.

starkillerOG commented 4 years ago

@dshokouhi thanks, I was not aware of this issue.

My appologies to everyone experiencing this issue.

First of all, everyone using YAML configuration: that is not supported anymore, remove it from yaml and use config flow.

The real issue here is in the socket binding in the underlying library which gives a OSError: [Errno 99] Cannot assign requested address, basically this is because some opperating systems do not allow you to specify the interface during binding of a socket (as far as I know).

It looks very simular to this issue https://github.com/home-assistant/core/issues/37073#issuecomment-649630707 that was reported during beta release by @dshokouhi.

That issue was already reported to the underlying library here: https://github.com/Danielhiversen/PyXiaomiGateway/issues/171

The strange thing is that the underlying library did not change, so this issue schould also have been present in the previous HomeAssistant releases. So I am still not sure what is going on..... Note that this issue is specifically pops up in test enviroments where a diffrent operating system is run on top of another operating system which causes a miss identification of the operating system (Windows Subsystem for Linux, as reported by @dshokouhi).

Personally I am not that familiar with socket bindings and all the network configuration stuff that comes with it, but apperently something is wrong for some operating systems....

resoai commented 4 years ago

How about making it possible to enter IP address of the gateway as a fallback whenever discovery fails?

starkillerOG commented 4 years ago

How about making it possible to enter IP address of the gateway as a fallback whenever discovery fails?

That is not possible because you don't know the port and sid, although the port is I think always 9898. anyway you still do not know the sid.

I did just figure out that it is possible using the zeroconf data to configure the gateway withouth having to go through the discovery, although that assummes port 9898 is always used.

starkillerOG commented 4 years ago

I made a first attempt to fix this issue in this PR: https://github.com/Danielhiversen/PyXiaomiGateway/pull/172/files I have not tested it yet on my system, but it schould work I think.

Could someone experiancing problems try this fix and see if it works?

fliphess commented 4 years ago

@starkillerOG Love to test it, but how to do that? Can you supply some instructions? Afaik home assistant installs the required python dependencies itself on startup.

Is there any way to add version overrides or change a requirements file or listing with a newer version to test if it works?

dshokouhi commented 4 years ago

I made a first attempt to fix this issue in this PR: https://github.com/Danielhiversen/PyXiaomiGateway/pull/172/files I have not tested it yet on my system, but it schould work I think.

Could someone experiancing problems try this fix and see if it works?

I replaced the init.py file in my dev system and this is the error I get when I restart HA...all entities are unavailable

2020-07-03 09:40:37 ERROR (MainThread) [homeassistant.setup] Setup failed for xiaomi_aqara: unknown error
Traceback (most recent call last):
  File "/mnt/c/dev/home-assistant/homeassistant/setup.py", line 145, in _async_setup_component
    component = integration.get_component()
  File "/mnt/c/dev/home-assistant/homeassistant/loader.py", line 313, in get_component
    cache[self.domain] = importlib.import_module(self.pkg_path)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/mnt/c/dev/home-assistant/homeassistant/components/xiaomi_aqara/__init__.py", line 7, in <module>
    from xiaomi_gateway import XiaomiGateway, XiaomiGatewayDiscovery
  File "/mnt/c/dev/home-assistant/venv/lib/python3.7/site-packages/xiaomi_gateway/__init__.py", line 194
    def __init__(self, ip_adress, port=MULTICAST_PORT, sid, key, discovery_retries, interface, proto=None):
                ^
SyntaxError: non-default argument follows default argument

this error below repeats itself a few times

2020-07-03 09:40:54 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/mnt/c/dev/home-assistant/homeassistant/data_entry_flow.py", line 117, in async_init
    flow = await self.async_create_flow(handler, context=context, data=data)
  File "/mnt/c/dev/home-assistant/homeassistant/config_entries.py", line 528, in async_create_flow
    integration.get_platform("config_flow")
  File "/mnt/c/dev/home-assistant/homeassistant/loader.py", line 322, in get_platform
    f"{self.pkg_path}.{platform_name}"
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/mnt/c/dev/home-assistant/homeassistant/components/xiaomi_aqara/__init__.py", line 7, in <module>
    from xiaomi_gateway import XiaomiGateway, XiaomiGatewayDiscovery
  File "/mnt/c/dev/home-assistant/venv/lib/python3.7/site-packages/xiaomi_gateway/__init__.py", line 194
    def __init__(self, ip_adress, port=MULTICAST_PORT, sid, key, discovery_retries, interface, proto=None):
                ^
SyntaxError: non-default argument follows default argument
fliphess commented 4 years ago

Ah! you cannot place named arguments before unnamed arguments in python , so this has to be something like:

    def __init__(self, ip_adress, sid, key, discovery_retries, interface, port=MULTICAST_PORT, proto=None):

(Will add this comment on the PR as well)

starkillerOG commented 4 years ago

have fixed that issue, as I sad: I had not tested it myself....

dshokouhi commented 4 years ago

Replaced line 194 as @fliphess suggested:

new error

2020-07-03 09:48:07 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Xiaomi Aqara Gateway for xiaomi_aqara
Traceback (most recent call last):
  File "/mnt/c/dev/home-assistant/homeassistant/config_entries.py", line 220, in async_setup
    hass, self
  File "/mnt/c/dev/home-assistant/homeassistant/components/xiaomi_aqara/__init__.py", line 150, in async_setup_entry
    entry.data[CONF_PROTOCOL],
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/mnt/c/dev/home-assistant/venv/lib/python3.7/site-packages/xiaomi_gateway/__init__.py", line 197, in __init__
    self.port = int(port)
ValueError: invalid literal for int() with base 10: 'any'
starkillerOG commented 4 years ago

@dshokouhi yea now the order of the arguments has changed. I just made another commit to fix the rest of the order in the init.py file in the lib.

also line 142 to 151 in init.py of HomeAssistant needs to change from:

    xiaomi_gateway = await hass.async_add_executor_job(
        XiaomiGateway,
        entry.data[CONF_HOST],
        entry.data[CONF_PORT],
        entry.data[CONF_SID],
        entry.data[CONF_KEY],
        DEFAULT_DISCOVERY_RETRY,
        entry.data[CONF_INTERFACE],
        entry.data[CONF_PROTOCOL],
    )

to:

    xiaomi_gateway = await hass.async_add_executor_job(
        XiaomiGateway,
        entry.data[CONF_HOST],
        entry.data[CONF_SID],
        entry.data[CONF_KEY],
        DEFAULT_DISCOVERY_RETRY,
        entry.data[CONF_INTERFACE],
        entry.data[CONF_PORT],
        entry.data[CONF_PROTOCOL],
    )
starkillerOG commented 4 years ago

But maybe it is better to test it myself first.... Will not have time today, but can test tommorow.

fliphess commented 4 years ago

Take your time, there is a workaround available (temporary downgrade to 0.111.4), so no rush needed :)

Thanks for your effort so far!

dshokouhi commented 4 years ago

@starkillerOG at least in my unique dev instance im back to the same error I had before that i mentioned in the bug that you linked to:

2020-07-03 09:57:06 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Xiaomi Aqara Gateway for xiaomi_aqara
Traceback (most recent call last):
  File "/mnt/c/dev/home-assistant/homeassistant/config_entries.py", line 220, in async_setup
    hass, self
  File "/mnt/c/dev/home-assistant/homeassistant/components/xiaomi_aqara/__init__.py", line 161, in async_setup_entry
    await hass.async_add_executor_job(gateway_discovery.listen)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/mnt/c/dev/home-assistant/venv/lib/python3.7/site-packages/xiaomi_gateway/__init__.py", line 143, in listen
    self._mcastsocket = self._create_mcast_socket()
  File "/mnt/c/dev/home-assistant/venv/lib/python3.7/site-packages/xiaomi_gateway/__init__.py", line 131, in _create_mcast_socket
    sock.bind((self.MULTICAST_ADDRESS, MULTICAST_PORT))
OSError: [Errno 99] Cannot assign requested address
starkillerOG commented 4 years ago

@dshokouhi if you run this python code inside of the virtual env where your test HomeAssistant runs, what is the result?

import platform
print(platform.system())
starkillerOG commented 4 years ago

@dshokouhi latest commit schould catch that OSError, but still would like to know what system is reported in your test env.

dshokouhi commented 4 years ago

@starkillerOG

>>> import platform
>>> print(platform.system())
Linux
starkillerOG commented 4 years ago

@starkillerOG

>>> import platform
>>> print(platform.system())
Linux

yea then we can't properly handle it because it is a windows PC right? So I think this is something pretty specific to running on Windows Subsystem for Linux...

I think the try catch of my latest comment schould fix it for WSL and I think that is the best we can do.

dshokouhi commented 4 years ago

@starkillerOG latest commit seems to have fixed the issue for me :) no more errors and entities are all available! Thats with all the changes you mentioned to the component and parent library

starkillerOG commented 4 years ago

@fliphess could you also test?

Basically just replace the init.py file in your python virtuel enviroment of the xiaomi_gateway module. The path schould be something like: venv\lib\python3.7\site-packages\xiaomi_gateway\__init__.py

And also make the changes to the init.py file of HomeAssistant xiaomi_aqara component, the path to that file schould be something like: home-assistant\homeassistant\components\xiaomi_aqara\__init__.py

heculess commented 4 years ago

I have the same issue here.

Logger: aiohttp.server Source: components/xiaomi_aqara/config_flow.py:61 First occurred: 下午5:40:04 (8 occurrences) Last logged: 下午5:46:08

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start resp = await task File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle resp = await handler(request) File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 73, in ban_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle result = await result File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 145, in post return await super().post(request, flow_id) File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 60, in wrapper result = await method(view, request, *args, *kwargs) File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 106, in post result = await self._flow_mgr.async_configure(flow_id, data) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 153, in async_configure result = await self._async_handle_step(flow, cur_step["step_id"], user_input) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 201, in _async_handle_step result: Dict = await getattr(flow, method)(user_input) File "/usr/src/homeassistant/homeassistant/components/xiaomi_aqara/config_flow.py", line 61, in async_step_user await self.hass.async_add_executor_job(xiaomi.discover_gateways) File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(self.args, **self.kwargs) File "/usr/local/lib/python3.7/site-packages/xiaomi_gateway/init.py", line 47, in discover_gateways _socket.bind((self._interface, 0)) OSError: [Errno 99] Address not available

starkillerOG commented 4 years ago

@heculess please try the changes of these PRs: https://github.com/home-assistant/core/pull/37469 https://github.com/Danielhiversen/PyXiaomiGateway/pull/172

and test if that works, I do not have this issue, so I can not test if those PRs indeed solve it... If someone can confirm that those PRs work I can ask if they can get merged.

artbrayko commented 4 years ago

Please excuse me, but I don’t understand what should I do to make the new integration work. Please write instructions. In the next update to the Home Assistant, will this bug be fixed? Thanks you.

KptnKMan commented 4 years ago

Hi @starkillerOG I'm happy to test, I have a single gateway in same subnet that refuses to be found.

How do I test your PR? Per your previous comment, do I only need to edit the files: venv\lib\python3.7\site-packages\xiaomi_gateway\__init__.py home-assistant\homeassistant\components\xiaomi_aqara\__init__.py

I need to edit these with the content of your PR?

starkillerOG commented 4 years ago

Hi @starkillerOG I'm happy to test, I have a single gateway in same subnet that refuses to be found.

How do I test your PR? Per your previous comment, do I only need to edit the files: venv\lib\python3.7\site-packages\xiaomi_gateway\__init__.py home-assistant\homeassistant\components\xiaomi_aqara\__init__.py

I need to edit these with the content of your PR?

Yes that is completly right! Would be great if you could test

This PR #37469 includes the changes for home-assistant\homeassistant\components\xiaomi_aqara\__init__.py and This PR Danielhiversen/PyXiaomiGateway#172 includes the changes for venv\lib\python3.7\site-packages\xiaomi_gateway\__init__.py

starkillerOG commented 4 years ago

Please excuse me, but I don’t understand what should I do to make the new integration work. Please write instructions. In the next update to the Home Assistant, will this bug be fixed? Thanks you.

No it will not be nessesarly fixed in the next release (could be though), first someone schould test if this actally fixes the problem. If that test works than it can be merged and then it will be in the next realease comming up from that point on.

Please follow the instructions of @KptnKMan, edit those files with the chages of my 2 PR's as mentioned.

artbrayko commented 4 years ago

I do not have the /python3.7 folder, I have the /python3.8 folder, but it does not have the / xiaomi_gateway folder. Which way could be in my case? thank

starkillerOG commented 4 years ago

@artbrayko /python3.8 folder is fine, just means you have a newer python version. Are you sure you are looking at the /python3.8 in the virtuel enviroment where HomeAssistant is installed? under the /python3.8 folder there schould be a folder called site-packages and in that folder the xiaomi_gateway folder schould be pressent, if not it means PyXiaomiGateway is not installed in that python enviroment.

HomeAssistant schould have installed PyXiaomiGateway when you setup the component....

VDigitall commented 4 years ago

@starkillerOG, hi I have single gateway and tested on the current dev branch with applying proposed changes

    xiaomi_gateway = await hass.async_add_executor_job(
        XiaomiGateway,
        entry.data[CONF_HOST],
        entry.data[CONF_SID],
        entry.data[CONF_KEY],
        DEFAULT_DISCOVERY_RETRY,
        entry.data[CONF_INTERFACE],
        entry.data[CONF_PORT],
        entry.data[CONF_PROTOCOL],
    )

and install PyXiaomiGateway from the branch with your patch, and receive in logs:

2020-07-09 19:10:37 ERROR (SyncWorker_4) [xiaomi_gateway] Response does not match return cmd

when I print resp it was heartbeat message

{'cmd': 'heartbeat', 'model': 'gateway', 'sid': '******', 'short_id': '0', 'token': '*********', 'data': '{"ip":"192.*.*.*"}'}
artbrayko commented 4 years ago

Everything worked for me before. If it worked for me according to the old method, have I not installed PyXiaomiGateway?

ekt- commented 4 years ago

@starkillerOG the problem is that the discovery via multicast does not always work hence, previously, it was possible to directly specify the gateway ip with the 'host' entry in the configuration. So it is not something new or a change in PyXiaomiGateway.

See #37661

Can you please rollback the change until you get it working as before? thanks