Danielhiversen / PyXiaomiGateway

PyXiaomiGateway
MIT License
152 stars 55 forks source link

FreeBSD: Can't assign requested address #137

Closed xiwenc closed 5 years ago

xiwenc commented 5 years ago

Home Assistant release with the issue (if applicable):

Last working Home Assistant release (if known): unknown

PyXiaomiGateway library version (if known): 0.11.1

Operating environment (Hass.io/Docker/Windows/etc.): FreeBSD 11.2-RELEASE-p7 (freenas)

Traceback (if applicable):

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/setup.py", line 148, in _async_setup_component
    component.setup, hass, processed_config)  # type: ignore
  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/homeassistant/components/xiaomi_aqara.py", line 137, in setup
    xiaomi.listen()
  File "/root/.homeassistant/deps/lib/python3.7/site-packages/xiaomi_gateway/__init__.py", line 138, in listen
    self._mcastsocket = self._create_mcast_socket()
  File "/root/.homeassistant/deps/lib/python3.7/site-packages/xiaomi_gateway/__init__.py", line 119, in _create_mcast_socket
    sock.bind((self.MULTICAST_ADDRESS, self.MULTICAST_PORT))
OSError: [Errno 49] Can't assign requested address

The module tries to bind to multicast when it's not Windows:

         if self._interface != 'any':
             if platform.system() != "Windows":
                 sock.bind((self.MULTICAST_ADDRESS, self.MULTICAST_PORT))
             else:
                 sock.bind((self._interface, self.MULTICAST_PORT))

It seems this breaks (is not available?) on FreeBSD.

xiwenc commented 5 years ago

To run in Freebsd jail it's also required to turn on vnet with option allow_raw_sockets=1 if not sensors and the gateway itself are not fully working.

xiwenc commented 5 years ago

After more intensive testing it's best to revert https://github.com/Danielhiversen/PyXiaomiGateway/pull/138 because that was not the core issue. It could be breaking something else I'm not aware of instead.

So to summarize the working setup is:

related links:

Sorry for the confusion! Hope this helps others in the future when attempting to run in jails.