mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Support multiple hue hubs using a filename parameter.
This commit is contained in:
parent
622a6deb04
commit
0361f37178
@ -17,7 +17,7 @@ from urllib.parse import urlparse
|
|||||||
from homeassistant.loader import get_component
|
from homeassistant.loader import get_component
|
||||||
import homeassistant.util as util
|
import homeassistant.util as util
|
||||||
import homeassistant.util.color as color_util
|
import homeassistant.util.color as color_util
|
||||||
from homeassistant.const import CONF_HOST, DEVICE_DEFAULT_NAME
|
from homeassistant.const import CONF_HOST, CONF_FILENAME, DEVICE_DEFAULT_NAME
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
Light, ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_COLOR_TEMP,
|
Light, ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_COLOR_TEMP,
|
||||||
ATTR_TRANSITION, ATTR_FLASH, FLASH_LONG, FLASH_SHORT,
|
ATTR_TRANSITION, ATTR_FLASH, FLASH_LONG, FLASH_SHORT,
|
||||||
@ -35,9 +35,9 @@ _CONFIGURING = {}
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _find_host_from_config(hass):
|
def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE):
|
||||||
""" Attempt to detect host based on existing configuration. """
|
""" Attempt to detect host based on existing configuration. """
|
||||||
path = hass.config.path(PHUE_CONFIG_FILE)
|
path = hass.config.path(filename)
|
||||||
|
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
return None
|
return None
|
||||||
@ -54,13 +54,14 @@ def _find_host_from_config(hass):
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
""" Gets the Hue lights. """
|
""" Gets the Hue lights. """
|
||||||
|
filename = config.get(CONF_FILENAME, PHUE_CONFIG_FILE)
|
||||||
if discovery_info is not None:
|
if discovery_info is not None:
|
||||||
host = urlparse(discovery_info[1]).hostname
|
host = urlparse(discovery_info[1]).hostname
|
||||||
else:
|
else:
|
||||||
host = config.get(CONF_HOST, None)
|
host = config.get(CONF_HOST, None)
|
||||||
|
|
||||||
if host is None:
|
if host is None:
|
||||||
host = _find_host_from_config(hass)
|
host = _find_host_from_config(hass, filename)
|
||||||
|
|
||||||
if host is None:
|
if host is None:
|
||||||
_LOGGER.error('No host found in configuration')
|
_LOGGER.error('No host found in configuration')
|
||||||
@ -70,17 +71,17 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
if host in _CONFIGURING:
|
if host in _CONFIGURING:
|
||||||
return
|
return
|
||||||
|
|
||||||
setup_bridge(host, hass, add_devices_callback)
|
setup_bridge(host, hass, add_devices_callback, filename)
|
||||||
|
|
||||||
|
|
||||||
def setup_bridge(host, hass, add_devices_callback):
|
def setup_bridge(host, hass, add_devices_callback, filename):
|
||||||
""" Setup a phue bridge based on host parameter. """
|
""" Setup a phue bridge based on host parameter. """
|
||||||
import phue
|
import phue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bridge = phue.Bridge(
|
bridge = phue.Bridge(
|
||||||
host,
|
host,
|
||||||
config_file_path=hass.config.path(PHUE_CONFIG_FILE))
|
config_file_path=hass.config.path(filename))
|
||||||
except ConnectionRefusedError: # Wrong host was given
|
except ConnectionRefusedError: # Wrong host was given
|
||||||
_LOGGER.exception("Error connecting to the Hue bridge at %s", host)
|
_LOGGER.exception("Error connecting to the Hue bridge at %s", host)
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ CONF_USERNAME = "username"
|
|||||||
CONF_PASSWORD = "password"
|
CONF_PASSWORD = "password"
|
||||||
CONF_API_KEY = "api_key"
|
CONF_API_KEY = "api_key"
|
||||||
CONF_ACCESS_TOKEN = "access_token"
|
CONF_ACCESS_TOKEN = "access_token"
|
||||||
|
CONF_FILENAME = "filename"
|
||||||
|
|
||||||
CONF_VALUE_TEMPLATE = "value_template"
|
CONF_VALUE_TEMPLATE = "value_template"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user