Skip to content

Commit b7aba52

Browse files
jeremydkballoob
authored andcommitted
Emulated Hue "host-ip" fails to bind when running in docker without --net=host (home-assistant#5550)
* UPNP changes to allow a separate advertised IP and Port. * Fixing lint. * UPNP changes to allow a separate advertised IP and Port. * Fixing lint. * Update __init__.py * Moved logic for advertised ip and port into config class. * Commenting change for clarity. * Spacing changes for PEP8 * Spacing Changes for PEP8 * Style Changes
1 parent 6ede1c0 commit b7aba52

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

homeassistant/components/emulated_hue/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
CONF_HOST_IP = 'host_ip'
3232
CONF_LISTEN_PORT = 'listen_port'
33+
CONF_ADVERTISE_IP = 'advertise_ip'
34+
CONF_ADVERTISE_PORT = 'advertise_port'
3335
CONF_UPNP_BIND_MULTICAST = 'upnp_bind_multicast'
3436
CONF_OFF_MAPS_TO_ON_DOMAINS = 'off_maps_to_on_domains'
3537
CONF_EXPOSE_BY_DEFAULT = 'expose_by_default'
@@ -53,6 +55,9 @@
5355
vol.Optional(CONF_HOST_IP): cv.string,
5456
vol.Optional(CONF_LISTEN_PORT, default=DEFAULT_LISTEN_PORT):
5557
vol.All(vol.Coerce(int), vol.Range(min=1, max=65535)),
58+
vol.Optional(CONF_ADVERTISE_IP): cv.string,
59+
vol.Optional(CONF_ADVERTISE_PORT):
60+
vol.All(vol.Coerce(int), vol.Range(min=1, max=65535)),
5661
vol.Optional(CONF_UPNP_BIND_MULTICAST): cv.boolean,
5762
vol.Optional(CONF_OFF_MAPS_TO_ON_DOMAINS): cv.ensure_list,
5863
vol.Optional(CONF_EXPOSE_BY_DEFAULT): cv.boolean,
@@ -92,7 +97,8 @@ def setup(hass, yaml_config):
9297

9398
upnp_listener = UPNPResponderThread(
9499
config.host_ip_addr, config.listen_port,
95-
config.upnp_bind_multicast)
100+
config.upnp_bind_multicast, config.advertise_ip,
101+
config.advertise_port)
96102

97103
@asyncio.coroutine
98104
def stop_emulated_hue_bridge(event):
@@ -169,6 +175,13 @@ def __init__(self, hass, conf):
169175
self.exposed_domains = conf.get(
170176
CONF_EXPOSED_DOMAINS, DEFAULT_EXPOSED_DOMAINS)
171177

178+
# Calculated effective advertised IP and port for network isolation
179+
self.advertise_ip = conf.get(
180+
CONF_ADVERTISE_IP) or self.host_ip_addr
181+
182+
self.advertise_port = conf.get(
183+
CONF_ADVERTISE_PORT) or self.listen_port
184+
172185
def entity_id_to_number(self, entity_id):
173186
"""Get a unique number for the entity id."""
174187
if self.type == TYPE_ALEXA:

homeassistant/components/emulated_hue/upnp.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def get(self, request):
5050
"""
5151

5252
resp_text = xml_template.format(
53-
self.config.host_ip_addr, self.config.listen_port)
53+
self.config.advertise_ip, self.config.advertise_port)
5454

5555
return web.Response(text=resp_text, content_type='text/xml')
5656

@@ -60,7 +60,8 @@ class UPNPResponderThread(threading.Thread):
6060

6161
_interrupted = False
6262

63-
def __init__(self, host_ip_addr, listen_port, upnp_bind_multicast):
63+
def __init__(self, host_ip_addr, listen_port, upnp_bind_multicast,
64+
advertise_ip, advertise_port):
6465
"""Initialize the class."""
6566
threading.Thread.__init__(self)
6667

@@ -81,9 +82,9 @@ def __init__(self, host_ip_addr, listen_port, upnp_bind_multicast):
8182
8283
"""
8384

84-
self.upnp_response = resp_template.format(host_ip_addr, listen_port) \
85-
.replace("\n", "\r\n") \
86-
.encode('utf-8')
85+
self.upnp_response = resp_template.format(
86+
advertise_ip, advertise_port).replace("\n", "\r\n") \
87+
.encode('utf-8')
8788

8889
# Set up a pipe for signaling to the receiver that it's time to
8990
# shutdown. Essentially, we place the SSDP socket into nonblocking

0 commit comments

Comments
 (0)