mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Hue device capabilities. Color temperature support for light component and hue platform
This commit is contained in:
parent
18747f8ae1
commit
e25503bc4a
@ -43,6 +43,9 @@ Supports following parameters:
|
||||
A list containing three integers representing the xy color you want the
|
||||
light to be.
|
||||
|
||||
- ct_color
|
||||
An INT in mireds represending the color temperature you want the light to be
|
||||
|
||||
- brightness
|
||||
Integer between 0 and 255 representing how bright you want the light to be.
|
||||
|
||||
@ -77,6 +80,7 @@ ATTR_TRANSITION = "transition"
|
||||
# lists holding color values
|
||||
ATTR_RGB_COLOR = "rgb_color"
|
||||
ATTR_XY_COLOR = "xy_color"
|
||||
ATTR_CT_COLOR = "ct_color"
|
||||
|
||||
# int with value 0 .. 255 representing brightness of the light
|
||||
ATTR_BRIGHTNESS = "brightness"
|
||||
@ -105,6 +109,7 @@ DISCOVERY_PLATFORMS = {
|
||||
PROP_TO_ATTR = {
|
||||
'brightness': ATTR_BRIGHTNESS,
|
||||
'color_xy': ATTR_XY_COLOR,
|
||||
'color_ct': ATTR_CT_COLOR,
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -119,8 +124,8 @@ def is_on(hass, entity_id=None):
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
def turn_on(hass, entity_id=None, transition=None, brightness=None,
|
||||
rgb_color=None, xy_color=None, profile=None, flash=None,
|
||||
effect=None):
|
||||
rgb_color=None, xy_color=None, ct_color=None, profile=None,
|
||||
flash=None, effect=None):
|
||||
""" Turns all or specified light on. """
|
||||
data = {
|
||||
key: value for key, value in [
|
||||
@ -130,6 +135,7 @@ def turn_on(hass, entity_id=None, transition=None, brightness=None,
|
||||
(ATTR_BRIGHTNESS, brightness),
|
||||
(ATTR_RGB_COLOR, rgb_color),
|
||||
(ATTR_XY_COLOR, xy_color),
|
||||
(ATTR_CT_COLOR, ct_color),
|
||||
(ATTR_FLASH, flash),
|
||||
(ATTR_EFFECT, effect),
|
||||
] if value is not None
|
||||
@ -240,6 +246,16 @@ def setup(hass, config):
|
||||
# ValueError if value could not be converted to float
|
||||
pass
|
||||
|
||||
if ATTR_CT_COLOR in dat:
|
||||
# ct_color should be an int of mirads value
|
||||
ctcolor = dat.get(ATTR_CT_COLOR)
|
||||
|
||||
# Without this check, a ctcolor with value '99' would work
|
||||
# These values are based on Philips Hue, may need ajustment later
|
||||
if isinstance(ctcolor, int):
|
||||
if 154 <= ctcolor <= 500:
|
||||
params[ATTR_CT_COLOR] = ctcolor
|
||||
|
||||
if ATTR_RGB_COLOR in dat:
|
||||
try:
|
||||
# rgb_color should be a list containing 3 ints
|
||||
@ -301,6 +317,11 @@ class Light(ToggleEntity):
|
||||
""" XY color value [float, float]. """
|
||||
return None
|
||||
|
||||
@property
|
||||
def color_ct(self):
|
||||
""" CT color value in mirads. """
|
||||
return None
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
""" Returns device specific state attributes. """
|
||||
|
@ -14,9 +14,9 @@ from homeassistant.loader import get_component
|
||||
import homeassistant.util as util
|
||||
from homeassistant.const import CONF_HOST, DEVICE_DEFAULT_NAME
|
||||
from homeassistant.components.light import (
|
||||
Light, ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_TRANSITION,
|
||||
ATTR_FLASH, FLASH_LONG, FLASH_SHORT, ATTR_EFFECT,
|
||||
EFFECT_COLORLOOP)
|
||||
Light, ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_CT_COLOR,
|
||||
ATTR_TRANSITION, ATTR_FLASH, FLASH_LONG, FLASH_SHORT,
|
||||
ATTR_EFFECT, EFFECT_COLORLOOP)
|
||||
|
||||
REQUIREMENTS = ['phue==0.8']
|
||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||
@ -147,6 +147,16 @@ class HueLight(Light):
|
||||
self.bridge = bridge
|
||||
self.update_lights = update_lights
|
||||
|
||||
# Hue can control multiple type of lights
|
||||
capability_map = {
|
||||
'Dimmable light': ['bri'],
|
||||
'Dimmable plug-in unit': ['bri'],
|
||||
'Color light': ['bri', 'xy'],
|
||||
'Extended color light': ['bri', 'xy', 'ct'],
|
||||
'unknown': []}
|
||||
self.capabilities = capability_map.get(
|
||||
self.info['type'], 'unknown')
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
""" Returns the id of this Hue light """
|
||||
@ -161,12 +171,26 @@ class HueLight(Light):
|
||||
@property
|
||||
def brightness(self):
|
||||
""" Brightness of this light between 0..255. """
|
||||
return self.info['state']['bri']
|
||||
if 'bri' in self.capabilities:
|
||||
return self.info['state']['bri']
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def color_xy(self):
|
||||
""" XY color value. """
|
||||
return self.info['state'].get('xy')
|
||||
if 'xy' in self.capabilities:
|
||||
return self.info['state'].get('xy')
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def color_ct(self):
|
||||
""" CT color value. """
|
||||
if 'ct' in self.capabilities:
|
||||
return self.info['state'].get('ct')
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
@ -190,6 +214,9 @@ class HueLight(Light):
|
||||
if ATTR_XY_COLOR in kwargs:
|
||||
command['xy'] = kwargs[ATTR_XY_COLOR]
|
||||
|
||||
if ATTR_CT_COLOR in kwargs:
|
||||
command['ct'] = kwargs[ATTR_CT_COLOR]
|
||||
|
||||
flash = kwargs.get(ATTR_FLASH)
|
||||
|
||||
if flash == FLASH_LONG:
|
||||
|
@ -20,6 +20,10 @@ turn_on:
|
||||
description: Color for the light in XY-format
|
||||
example: '[0.52, 0.43]'
|
||||
|
||||
ct_color:
|
||||
description: Color temperature for the light in mireds (154-500)
|
||||
example: '250'
|
||||
|
||||
brightness:
|
||||
description: Number between 0..255 indicating brightness
|
||||
example: 120
|
||||
|
Loading…
x
Reference in New Issue
Block a user