mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Merge pull request #1552 from balloob/hue-allow-unreachable
Hue Lights - Allow Unreachable Lights
This commit is contained in:
commit
ba0cbab6cb
@ -53,6 +53,8 @@ def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE):
|
||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
"""Setup the Hue lights."""
|
||||
filename = config.get(CONF_FILENAME, PHUE_CONFIG_FILE)
|
||||
allow_unreachable = config.get('allow_unreachable', False)
|
||||
|
||||
if discovery_info is not None:
|
||||
host = urlparse(discovery_info[1]).hostname
|
||||
else:
|
||||
@ -69,10 +71,11 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
if host in _CONFIGURING:
|
||||
return
|
||||
|
||||
setup_bridge(host, hass, add_devices_callback, filename)
|
||||
setup_bridge(host, hass, add_devices_callback, filename, allow_unreachable)
|
||||
|
||||
|
||||
def setup_bridge(host, hass, add_devices_callback, filename):
|
||||
def setup_bridge(host, hass, add_devices_callback, filename,
|
||||
allow_unreachable):
|
||||
"""Setup a phue bridge based on host parameter."""
|
||||
import phue
|
||||
|
||||
@ -88,7 +91,8 @@ def setup_bridge(host, hass, add_devices_callback, filename):
|
||||
except phue.PhueRegistrationException:
|
||||
_LOGGER.warning("Connected to Hue at %s but not registered.", host)
|
||||
|
||||
request_configuration(host, hass, add_devices_callback, filename)
|
||||
request_configuration(host, hass, add_devices_callback, filename,
|
||||
allow_unreachable)
|
||||
|
||||
return
|
||||
|
||||
@ -130,7 +134,7 @@ def setup_bridge(host, hass, add_devices_callback, filename):
|
||||
if light_id not in lights:
|
||||
lights[light_id] = HueLight(int(light_id), info,
|
||||
bridge, update_lights,
|
||||
bridge_type=bridge_type)
|
||||
bridge_type, allow_unreachable)
|
||||
new_lights.append(lights[light_id])
|
||||
else:
|
||||
lights[light_id].info = info
|
||||
@ -141,7 +145,8 @@ def setup_bridge(host, hass, add_devices_callback, filename):
|
||||
update_lights()
|
||||
|
||||
|
||||
def request_configuration(host, hass, add_devices_callback, filename):
|
||||
def request_configuration(host, hass, add_devices_callback, filename,
|
||||
allow_unreachable):
|
||||
"""Request configuration steps from the user."""
|
||||
configurator = get_component('configurator')
|
||||
|
||||
@ -155,7 +160,8 @@ def request_configuration(host, hass, add_devices_callback, filename):
|
||||
# pylint: disable=unused-argument
|
||||
def hue_configuration_callback(data):
|
||||
"""The actions to do when our configuration callback is called."""
|
||||
setup_bridge(host, hass, add_devices_callback, filename)
|
||||
setup_bridge(host, hass, add_devices_callback, filename,
|
||||
allow_unreachable)
|
||||
|
||||
_CONFIGURING[host] = configurator.request_config(
|
||||
hass, "Philips Hue", hue_configuration_callback,
|
||||
@ -171,7 +177,7 @@ class HueLight(Light):
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
def __init__(self, light_id, info, bridge, update_lights,
|
||||
bridge_type='hue'):
|
||||
bridge_type, allow_unreachable):
|
||||
"""Initialize the light."""
|
||||
self.light_id = light_id
|
||||
self.info = info
|
||||
@ -179,6 +185,8 @@ class HueLight(Light):
|
||||
self.update_lights = update_lights
|
||||
self.bridge_type = bridge_type
|
||||
|
||||
self.allow_unreachable = allow_unreachable
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the ID of this Hue light."""
|
||||
@ -209,7 +217,11 @@ class HueLight(Light):
|
||||
def is_on(self):
|
||||
"""Return true if device is on."""
|
||||
self.update_lights()
|
||||
return self.info['state']['reachable'] and self.info['state']['on']
|
||||
|
||||
if self.allow_unreachable:
|
||||
return self.info['state']['on']
|
||||
else:
|
||||
return self.info['state']['reachable'] and self.info['state']['on']
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the specified or all lights on."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user