mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Hue improvements (#5474)
* Allow automatic removal of all Hue entities from emulated_hue * Allow disabling of Hue groups * Only add device state attributes if they need to be there
This commit is contained in:
parent
14309401d0
commit
2efd7d4e4a
@ -25,6 +25,7 @@ from homeassistant.components.light import (
|
|||||||
from homeassistant.config import load_yaml_config_file
|
from homeassistant.config import load_yaml_config_file
|
||||||
from homeassistant.const import (CONF_FILENAME, CONF_HOST, DEVICE_DEFAULT_NAME)
|
from homeassistant.const import (CONF_FILENAME, CONF_HOST, DEVICE_DEFAULT_NAME)
|
||||||
from homeassistant.loader import get_component
|
from homeassistant.loader import get_component
|
||||||
|
from homeassistant.components.emulated_hue import ATTR_EMULATED_HUE
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['phue==0.9']
|
REQUIREMENTS = ['phue==0.9']
|
||||||
@ -50,10 +51,21 @@ SUPPORT_HUE = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_EFFECT |
|
|||||||
SUPPORT_FLASH | SUPPORT_RGB_COLOR | SUPPORT_TRANSITION |
|
SUPPORT_FLASH | SUPPORT_RGB_COLOR | SUPPORT_TRANSITION |
|
||||||
SUPPORT_XY_COLOR)
|
SUPPORT_XY_COLOR)
|
||||||
|
|
||||||
|
CONF_ALLOW_IN_EMULATED_HUE = "allow_in_emulated_hue"
|
||||||
|
DEFAULT_ALLOW_IN_EMULATED_HUE = True
|
||||||
|
|
||||||
|
CONF_ALLOW_HUE_GROUPS = "allow_hue_groups"
|
||||||
|
DEFAULT_ALLOW_HUE_GROUPS = True
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_HOST): cv.string,
|
vol.Optional(CONF_HOST): cv.string,
|
||||||
vol.Optional(CONF_ALLOW_UNREACHABLE): cv.boolean,
|
vol.Optional(CONF_ALLOW_UNREACHABLE,
|
||||||
vol.Optional(CONF_FILENAME): cv.string,
|
default=DEFAULT_ALLOW_UNREACHABLE): cv.boolean,
|
||||||
|
vol.Optional(CONF_FILENAME, default=PHUE_CONFIG_FILE): cv.string,
|
||||||
|
vol.Optional(CONF_ALLOW_IN_EMULATED_HUE,
|
||||||
|
default=DEFAULT_ALLOW_IN_EMULATED_HUE): cv.boolean,
|
||||||
|
vol.Optional(CONF_ALLOW_HUE_GROUPS,
|
||||||
|
default=DEFAULT_ALLOW_HUE_GROUPS): cv.boolean,
|
||||||
})
|
})
|
||||||
|
|
||||||
ATTR_GROUP_NAME = "group_name"
|
ATTR_GROUP_NAME = "group_name"
|
||||||
@ -63,6 +75,8 @@ SCENE_SCHEMA = vol.Schema({
|
|||||||
vol.Required(ATTR_SCENE_NAME): cv.string,
|
vol.Required(ATTR_SCENE_NAME): cv.string,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ATTR_IS_HUE_GROUP = "is_hue_group"
|
||||||
|
|
||||||
|
|
||||||
def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE):
|
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."""
|
||||||
@ -84,9 +98,10 @@ def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE):
|
|||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Hue lights."""
|
"""Setup the Hue lights."""
|
||||||
# Default needed in case of discovery
|
# Default needed in case of discovery
|
||||||
filename = config.get(CONF_FILENAME, PHUE_CONFIG_FILE)
|
filename = config.get(CONF_FILENAME)
|
||||||
allow_unreachable = config.get(CONF_ALLOW_UNREACHABLE,
|
allow_unreachable = config.get(CONF_ALLOW_UNREACHABLE)
|
||||||
DEFAULT_ALLOW_UNREACHABLE)
|
allow_in_emulated_hue = config.get(CONF_ALLOW_IN_EMULATED_HUE)
|
||||||
|
allow_hue_groups = config.get(CONF_ALLOW_HUE_GROUPS)
|
||||||
|
|
||||||
if discovery_info is not None:
|
if discovery_info is not None:
|
||||||
host = urlparse(discovery_info[1]).hostname
|
host = urlparse(discovery_info[1]).hostname
|
||||||
@ -109,10 +124,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
socket.gethostbyname(host) in _CONFIGURED_BRIDGES:
|
socket.gethostbyname(host) in _CONFIGURED_BRIDGES:
|
||||||
return
|
return
|
||||||
|
|
||||||
setup_bridge(host, hass, add_devices, filename, allow_unreachable)
|
setup_bridge(host, hass, add_devices, filename, allow_unreachable,
|
||||||
|
allow_in_emulated_hue, allow_hue_groups)
|
||||||
|
|
||||||
|
|
||||||
def setup_bridge(host, hass, add_devices, filename, allow_unreachable):
|
def setup_bridge(host, hass, add_devices, filename, allow_unreachable,
|
||||||
|
allow_in_emulated_hue, allow_hue_groups):
|
||||||
"""Setup a phue bridge based on host parameter."""
|
"""Setup a phue bridge based on host parameter."""
|
||||||
import phue
|
import phue
|
||||||
|
|
||||||
@ -129,7 +146,8 @@ def setup_bridge(host, hass, add_devices, filename, allow_unreachable):
|
|||||||
_LOGGER.warning("Connected to Hue at %s but not registered.", host)
|
_LOGGER.warning("Connected to Hue at %s but not registered.", host)
|
||||||
|
|
||||||
request_configuration(host, hass, add_devices, filename,
|
request_configuration(host, hass, add_devices, filename,
|
||||||
allow_unreachable)
|
allow_unreachable, allow_in_emulated_hue,
|
||||||
|
allow_hue_groups)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -143,7 +161,7 @@ def setup_bridge(host, hass, add_devices, filename, allow_unreachable):
|
|||||||
|
|
||||||
lights = {}
|
lights = {}
|
||||||
lightgroups = {}
|
lightgroups = {}
|
||||||
skip_groups = False
|
skip_groups = not allow_hue_groups
|
||||||
|
|
||||||
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
|
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
|
||||||
def update_lights():
|
def update_lights():
|
||||||
@ -184,7 +202,8 @@ def setup_bridge(host, hass, add_devices, filename, allow_unreachable):
|
|||||||
if light_id not in lights:
|
if light_id not in lights:
|
||||||
lights[light_id] = HueLight(int(light_id), info,
|
lights[light_id] = HueLight(int(light_id), info,
|
||||||
bridge, update_lights,
|
bridge, update_lights,
|
||||||
bridge_type, allow_unreachable)
|
bridge_type, allow_unreachable,
|
||||||
|
allow_in_emulated_hue)
|
||||||
new_lights.append(lights[light_id])
|
new_lights.append(lights[light_id])
|
||||||
else:
|
else:
|
||||||
lights[light_id].info = info
|
lights[light_id].info = info
|
||||||
@ -200,7 +219,8 @@ def setup_bridge(host, hass, add_devices, filename, allow_unreachable):
|
|||||||
if lightgroup_id not in lightgroups:
|
if lightgroup_id not in lightgroups:
|
||||||
lightgroups[lightgroup_id] = HueLight(
|
lightgroups[lightgroup_id] = HueLight(
|
||||||
int(lightgroup_id), info, bridge, update_lights,
|
int(lightgroup_id), info, bridge, update_lights,
|
||||||
bridge_type, allow_unreachable, True)
|
bridge_type, allow_unreachable, allow_in_emulated_hue,
|
||||||
|
True)
|
||||||
new_lights.append(lightgroups[lightgroup_id])
|
new_lights.append(lightgroups[lightgroup_id])
|
||||||
else:
|
else:
|
||||||
lightgroups[lightgroup_id].info = info
|
lightgroups[lightgroup_id].info = info
|
||||||
@ -229,7 +249,8 @@ def setup_bridge(host, hass, add_devices, filename, allow_unreachable):
|
|||||||
|
|
||||||
|
|
||||||
def request_configuration(host, hass, add_devices, filename,
|
def request_configuration(host, hass, add_devices, filename,
|
||||||
allow_unreachable):
|
allow_unreachable, allow_in_emulated_hue,
|
||||||
|
allow_hue_groups):
|
||||||
"""Request configuration steps from the user."""
|
"""Request configuration steps from the user."""
|
||||||
configurator = get_component('configurator')
|
configurator = get_component('configurator')
|
||||||
|
|
||||||
@ -243,7 +264,8 @@ def request_configuration(host, hass, add_devices, filename,
|
|||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def hue_configuration_callback(data):
|
def hue_configuration_callback(data):
|
||||||
"""The actions to do when our configuration callback is called."""
|
"""The actions to do when our configuration callback is called."""
|
||||||
setup_bridge(host, hass, add_devices, filename, allow_unreachable)
|
setup_bridge(host, hass, add_devices, filename, allow_unreachable,
|
||||||
|
allow_in_emulated_hue, allow_hue_groups)
|
||||||
|
|
||||||
_CONFIGURING[host] = configurator.request_config(
|
_CONFIGURING[host] = configurator.request_config(
|
||||||
hass, "Philips Hue", hue_configuration_callback,
|
hass, "Philips Hue", hue_configuration_callback,
|
||||||
@ -259,7 +281,8 @@ class HueLight(Light):
|
|||||||
"""Representation of a Hue light."""
|
"""Representation of a Hue light."""
|
||||||
|
|
||||||
def __init__(self, light_id, info, bridge, update_lights,
|
def __init__(self, light_id, info, bridge, update_lights,
|
||||||
bridge_type, allow_unreachable, is_group=False):
|
bridge_type, allow_unreachable, allow_in_emulated_hue,
|
||||||
|
is_group=False):
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
self.light_id = light_id
|
self.light_id = light_id
|
||||||
self.info = info
|
self.info = info
|
||||||
@ -268,6 +291,7 @@ class HueLight(Light):
|
|||||||
self.bridge_type = bridge_type
|
self.bridge_type = bridge_type
|
||||||
self.allow_unreachable = allow_unreachable
|
self.allow_unreachable = allow_unreachable
|
||||||
self.is_group = is_group
|
self.is_group = is_group
|
||||||
|
self.allow_in_emulated_hue = allow_in_emulated_hue
|
||||||
|
|
||||||
if is_group:
|
if is_group:
|
||||||
self._command_func = self.bridge.set_group
|
self._command_func = self.bridge.set_group
|
||||||
@ -395,3 +419,13 @@ class HueLight(Light):
|
|||||||
def update(self):
|
def update(self):
|
||||||
"""Synchronize state with bridge."""
|
"""Synchronize state with bridge."""
|
||||||
self.update_lights(no_throttle=True)
|
self.update_lights(no_throttle=True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self):
|
||||||
|
"""Return the device state attributes."""
|
||||||
|
attributes = {}
|
||||||
|
if not self.allow_in_emulated_hue:
|
||||||
|
attributes[ATTR_EMULATED_HUE] = self.allow_in_emulated_hue
|
||||||
|
if self.is_group:
|
||||||
|
attributes[ATTR_IS_HUE_GROUP] = self.is_group
|
||||||
|
return attributes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user