home-assistant-libs / netdisco

:mag_right: Python library to scan local network for services and devices.
Other
268 stars 147 forks source link

Address already in use if home assistant is launched via docker in a NAS #216

Closed ultratoto14 closed 6 years ago

ultratoto14 commented 6 years ago

Launched home assistant in docker from QNAP NAS. The NAS already have internal UDP discovery and when the daikin.py is used, i have this error

Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/discovery.py", line 168, in scan_devices
    results = await hass.async_add_job(_discover, netdisco)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/discovery.py", line 194, in _discover
    netdisco.scan()
  File "/usr/local/lib/python3.6/site-packages/netdisco/discovery.py", line 69, in scan
    self.daikin.scan()
  File "/usr/local/lib/python3.6/site-packages/netdisco/daikin.py", line 25, in scan
    self.update()
  File "/usr/local/lib/python3.6/site-packages/netdisco/daikin.py", line 39, in update
    sock.bind(("", UDP_SRC_PORT))
OSError: [Errno 98] Address already in use

Adding sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) just below sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) fixed the problem.

balloob commented 6 years ago

A PR is welcome 👍