Danielhiversen / PyXiaomiGateway

PyXiaomiGateway
MIT License
152 stars 55 forks source link

Multicast socket error on WSL system #171

Open dshokouhi opened 4 years ago

dshokouhi commented 4 years ago

Home Assistant release with the issue (if applicable):

i was testing 0.112b0 on my WSL dev environment Last working Home Assistant release (if known): none

PyXiaomiGateway library version (if known): 0.12.4

Operating environment (Hass.io/Docker/Windows/etc.): windows subsystem for linux

Traceback (if applicable):

2020-06-25 07:52:15 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 146, 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 127, in _create_mcast_socket
    sock.bind((self.MULTICAST_ADDRESS, self.MULTICAST_PORT))
OSError: [Errno 99] Cannot assign requested address

Description of the bug:

This is an odd issue that I was able to resolve on my own. I noticed that the code looks for the windows platform and it seems in this case it is not identifying it properly. If I modify line 127 to be identical to line 136 the error disappears and I am able to use the integration successfully.

sock.bind(('', self.MULTICAST_PORT))

More details can be found in this closed HA bug: https://github.com/home-assistant/core/issues/37073

I have tried the above with network interface set to any and also the IP address of the HA installation but the error still persists.

starkillerOG commented 4 years ago

@Danielhiversen could you look at this, since a lot of users are experiancing problems with this in HomeAssistant in the latest release.

Maybe just put a try except block around it and on the OSError just use sock.bind(('', self.MULTICAST_PORT))

starkillerOG commented 3 years ago

This can be closed, since the PR to fix this issue is merged. It will be in the upcomming release of HomeAssistant 0.113.4 that will be released on August 12 2020 (I think)