Do not setup or configure a hue bridge twice (#1848)

Tracks previously configured bridges by IP and prevents duplicates
from being configured
This commit is contained in:
Dan 2016-04-18 01:41:31 -04:00 committed by Paulus Schoutsen
parent c89e9d87e8
commit 276c2070be

View file

@ -32,6 +32,9 @@ PHUE_CONFIG_FILE = "phue.conf"
_CONFIGURING = {}
_LOGGER = logging.getLogger(__name__)
# Track previously setup bridges
_CONFIGURED_BRIDGES = {}
def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE):
"""Attempt to detect host based on existing configuration."""
@ -68,7 +71,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
return False
# Only act if we are not already configuring this host
if host in _CONFIGURING:
if host in _CONFIGURING or \
socket.gethostbyname(host) in _CONFIGURED_BRIDGES:
return
setup_bridge(host, hass, add_devices_callback, filename, allow_unreachable)
@ -142,6 +146,7 @@ def setup_bridge(host, hass, add_devices_callback, filename,
if new_lights:
add_devices_callback(new_lights)
_CONFIGURED_BRIDGES[socket.gethostbyname(host)] = True
update_lights()