mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Merge pull request #559 from balloob/light_ct_color
Color temperature support for light component and hue platform
This commit is contained in:
commit
288db9a57f
@ -43,6 +43,9 @@ Supports following parameters:
|
|||||||
A list containing three integers representing the xy color you want the
|
A list containing three integers representing the xy color you want the
|
||||||
light to be.
|
light to be.
|
||||||
|
|
||||||
|
- color_temp
|
||||||
|
An INT in mireds represending the color temperature you want the light to be
|
||||||
|
|
||||||
- brightness
|
- brightness
|
||||||
Integer between 0 and 255 representing how bright you want the light to be.
|
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
|
# lists holding color values
|
||||||
ATTR_RGB_COLOR = "rgb_color"
|
ATTR_RGB_COLOR = "rgb_color"
|
||||||
ATTR_XY_COLOR = "xy_color"
|
ATTR_XY_COLOR = "xy_color"
|
||||||
|
ATTR_COLOR_TEMP = "color_temp"
|
||||||
|
|
||||||
# int with value 0 .. 255 representing brightness of the light
|
# int with value 0 .. 255 representing brightness of the light
|
||||||
ATTR_BRIGHTNESS = "brightness"
|
ATTR_BRIGHTNESS = "brightness"
|
||||||
@ -105,6 +109,7 @@ DISCOVERY_PLATFORMS = {
|
|||||||
PROP_TO_ATTR = {
|
PROP_TO_ATTR = {
|
||||||
'brightness': ATTR_BRIGHTNESS,
|
'brightness': ATTR_BRIGHTNESS,
|
||||||
'color_xy': ATTR_XY_COLOR,
|
'color_xy': ATTR_XY_COLOR,
|
||||||
|
'color_temp': ATTR_COLOR_TEMP,
|
||||||
}
|
}
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -119,8 +124,8 @@ def is_on(hass, entity_id=None):
|
|||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
def turn_on(hass, entity_id=None, transition=None, brightness=None,
|
def turn_on(hass, entity_id=None, transition=None, brightness=None,
|
||||||
rgb_color=None, xy_color=None, profile=None, flash=None,
|
rgb_color=None, xy_color=None, color_temp=None, profile=None,
|
||||||
effect=None):
|
flash=None, effect=None):
|
||||||
""" Turns all or specified light on. """
|
""" Turns all or specified light on. """
|
||||||
data = {
|
data = {
|
||||||
key: value for key, value in [
|
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_BRIGHTNESS, brightness),
|
||||||
(ATTR_RGB_COLOR, rgb_color),
|
(ATTR_RGB_COLOR, rgb_color),
|
||||||
(ATTR_XY_COLOR, xy_color),
|
(ATTR_XY_COLOR, xy_color),
|
||||||
|
(ATTR_COLOR_TEMP, color_temp),
|
||||||
(ATTR_FLASH, flash),
|
(ATTR_FLASH, flash),
|
||||||
(ATTR_EFFECT, effect),
|
(ATTR_EFFECT, effect),
|
||||||
] if value is not None
|
] if value is not None
|
||||||
@ -240,6 +246,15 @@ def setup(hass, config):
|
|||||||
# ValueError if value could not be converted to float
|
# ValueError if value could not be converted to float
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if ATTR_COLOR_TEMP in dat:
|
||||||
|
# color_temp should be an int of mirads value
|
||||||
|
colortemp = dat.get(ATTR_COLOR_TEMP)
|
||||||
|
|
||||||
|
# Without this check, a ctcolor with value '99' would work
|
||||||
|
# These values are based on Philips Hue, may need ajustment later
|
||||||
|
if isinstance(colortemp, int) and 154 <= colortemp <= 500:
|
||||||
|
params[ATTR_COLOR_TEMP] = colortemp
|
||||||
|
|
||||||
if ATTR_RGB_COLOR in dat:
|
if ATTR_RGB_COLOR in dat:
|
||||||
try:
|
try:
|
||||||
# rgb_color should be a list containing 3 ints
|
# rgb_color should be a list containing 3 ints
|
||||||
@ -301,6 +316,11 @@ class Light(ToggleEntity):
|
|||||||
""" XY color value [float, float]. """
|
""" XY color value [float, float]. """
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def color_temp(self):
|
||||||
|
""" CT color value in mirads. """
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
""" Returns device specific state attributes. """
|
""" Returns device specific state attributes. """
|
||||||
|
@ -8,7 +8,7 @@ Demo platform that implements lights.
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
Light, ATTR_BRIGHTNESS, ATTR_XY_COLOR)
|
Light, ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_COLOR_TEMP)
|
||||||
|
|
||||||
|
|
||||||
LIGHT_COLORS = [
|
LIGHT_COLORS = [
|
||||||
@ -16,22 +16,26 @@ LIGHT_COLORS = [
|
|||||||
[0.460, 0.470],
|
[0.460, 0.470],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
LIGHT_TEMPS = [160, 500]
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
""" Find and return demo lights. """
|
""" Find and return demo lights. """
|
||||||
add_devices_callback([
|
add_devices_callback([
|
||||||
DemoLight("Bed Light", False),
|
DemoLight("Bed Light", False),
|
||||||
DemoLight("Ceiling Lights", True, LIGHT_COLORS[0]),
|
DemoLight("Ceiling Lights", True, LIGHT_TEMPS[1], LIGHT_COLORS[0]),
|
||||||
DemoLight("Kitchen Lights", True, LIGHT_COLORS[1])
|
DemoLight("Kitchen Lights", True, LIGHT_TEMPS[0], LIGHT_COLORS[1])
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
class DemoLight(Light):
|
class DemoLight(Light):
|
||||||
""" Provides a demo switch. """
|
""" Provides a demo switch. """
|
||||||
def __init__(self, name, state, xy=None, brightness=180):
|
# pylint: disable=too-many-arguments
|
||||||
|
def __init__(self, name, state, xy=None, ct=None, brightness=180):
|
||||||
self._name = name
|
self._name = name
|
||||||
self._state = state
|
self._state = state
|
||||||
self._xy = xy or random.choice(LIGHT_COLORS)
|
self._xy = xy or random.choice(LIGHT_COLORS)
|
||||||
|
self._ct = ct or random.choice(LIGHT_TEMPS)
|
||||||
self._brightness = brightness
|
self._brightness = brightness
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -54,6 +58,11 @@ class DemoLight(Light):
|
|||||||
""" XY color value. """
|
""" XY color value. """
|
||||||
return self._xy
|
return self._xy
|
||||||
|
|
||||||
|
@property
|
||||||
|
def color_temp(self):
|
||||||
|
""" CT color temperature. """
|
||||||
|
return self._ct
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
""" True if device is on. """
|
""" True if device is on. """
|
||||||
@ -66,6 +75,9 @@ class DemoLight(Light):
|
|||||||
if ATTR_XY_COLOR in kwargs:
|
if ATTR_XY_COLOR in kwargs:
|
||||||
self._xy = kwargs[ATTR_XY_COLOR]
|
self._xy = kwargs[ATTR_XY_COLOR]
|
||||||
|
|
||||||
|
if ATTR_COLOR_TEMP in kwargs:
|
||||||
|
self._ct = kwargs[ATTR_COLOR_TEMP]
|
||||||
|
|
||||||
if ATTR_BRIGHTNESS in kwargs:
|
if ATTR_BRIGHTNESS in kwargs:
|
||||||
self._brightness = kwargs[ATTR_BRIGHTNESS]
|
self._brightness = kwargs[ATTR_BRIGHTNESS]
|
||||||
|
|
||||||
|
@ -14,9 +14,9 @@ from homeassistant.loader import get_component
|
|||||||
import homeassistant.util as util
|
import homeassistant.util as util
|
||||||
from homeassistant.const import CONF_HOST, DEVICE_DEFAULT_NAME
|
from homeassistant.const import CONF_HOST, DEVICE_DEFAULT_NAME
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
Light, ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_TRANSITION,
|
Light, ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_COLOR_TEMP,
|
||||||
ATTR_FLASH, FLASH_LONG, FLASH_SHORT, ATTR_EFFECT,
|
ATTR_TRANSITION, ATTR_FLASH, FLASH_LONG, FLASH_SHORT,
|
||||||
EFFECT_COLORLOOP)
|
ATTR_EFFECT, EFFECT_COLORLOOP)
|
||||||
|
|
||||||
REQUIREMENTS = ['phue==0.8']
|
REQUIREMENTS = ['phue==0.8']
|
||||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||||
@ -125,6 +125,7 @@ def request_configuration(host, hass, add_devices_callback):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# pylint: disable=unused-argument
|
||||||
def hue_configuration_callback(data):
|
def hue_configuration_callback(data):
|
||||||
""" Actions to do when our configuration callback is called. """
|
""" Actions to do when our configuration callback is called. """
|
||||||
setup_bridge(host, hass, add_devices_callback)
|
setup_bridge(host, hass, add_devices_callback)
|
||||||
@ -168,6 +169,11 @@ class HueLight(Light):
|
|||||||
""" XY color value. """
|
""" XY color value. """
|
||||||
return self.info['state'].get('xy')
|
return self.info['state'].get('xy')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def color_temp(self):
|
||||||
|
""" CT color value. """
|
||||||
|
return self.info['state'].get('ct')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
""" True if device is on. """
|
""" True if device is on. """
|
||||||
@ -190,6 +196,9 @@ class HueLight(Light):
|
|||||||
if ATTR_XY_COLOR in kwargs:
|
if ATTR_XY_COLOR in kwargs:
|
||||||
command['xy'] = kwargs[ATTR_XY_COLOR]
|
command['xy'] = kwargs[ATTR_XY_COLOR]
|
||||||
|
|
||||||
|
if ATTR_COLOR_TEMP in kwargs:
|
||||||
|
command['ct'] = kwargs[ATTR_COLOR_TEMP]
|
||||||
|
|
||||||
flash = kwargs.get(ATTR_FLASH)
|
flash = kwargs.get(ATTR_FLASH)
|
||||||
|
|
||||||
if flash == FLASH_LONG:
|
if flash == FLASH_LONG:
|
||||||
|
@ -20,6 +20,10 @@ turn_on:
|
|||||||
description: Color for the light in XY-format
|
description: Color for the light in XY-format
|
||||||
example: '[0.52, 0.43]'
|
example: '[0.52, 0.43]'
|
||||||
|
|
||||||
|
color_temp:
|
||||||
|
description: Color temperature for the light in mireds (154-500)
|
||||||
|
example: '250'
|
||||||
|
|
||||||
brightness:
|
brightness:
|
||||||
description: Number between 0..255 indicating brightness
|
description: Number between 0..255 indicating brightness
|
||||||
example: 120
|
example: 120
|
||||||
|
Loading…
x
Reference in New Issue
Block a user