From 49d7bbe55d7ac4a7b20ac3cb26e84a7fba259ea9 Mon Sep 17 00:00:00 2001 From: Nicklas Johnson Date: Sun, 5 Feb 2023 12:57:22 -0800 Subject: [PATCH] Fix emulated hue SO_REUSEPORT when creating the upnp socket for proper sharing (#86916) Co-authored-by: J. Nick Koston fixes undefined --- homeassistant/components/emulated_hue/upnp.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/homeassistant/components/emulated_hue/upnp.py b/homeassistant/components/emulated_hue/upnp.py index ca8c0a45281..9f5ca312343 100644 --- a/homeassistant/components/emulated_hue/upnp.py +++ b/homeassistant/components/emulated_hue/upnp.py @@ -2,6 +2,7 @@ from __future__ import annotations import asyncio +from contextlib import suppress import logging import socket from typing import cast @@ -150,7 +151,12 @@ async def async_create_upnp_datagram_endpoint( ssdp_socket.setblocking(False) # Required for receiving multicast + # Note: some code duplication from async_upnp_client/ssdp.py here. ssdp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + with suppress(AttributeError): + ssdp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) + + ssdp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) ssdp_socket.setsockopt( socket.SOL_IP, socket.IP_MULTICAST_IF, socket.inet_aton(host_ip_addr)