Accept human readable color names to change light colors (#2075)
* Add support for providing color_name which accepts a CSS3 valid, human readable string such as red or blue * Forgot the schema validation! * ugh farcy * use html5_parse_legacy_color for more input options * Add webcolors==1.5 to setup.py * Block pylint no-member errors on tuple * add color_name_to_rgb test * whoops * revert changes to individual platforms * If color_name is set, pop it off params and set rgb_color with it * Forgot to reset wink.py * Import the legacy function as color_name_to_rgb directly * reset test_color.py * Improve light services.yaml
This commit is contained in:
parent
7208ff515e
commit
a431277de1
5 changed files with 17 additions and 1 deletions
|
@ -39,6 +39,7 @@ ATTR_TRANSITION = "transition"
|
|||
ATTR_RGB_COLOR = "rgb_color"
|
||||
ATTR_XY_COLOR = "xy_color"
|
||||
ATTR_COLOR_TEMP = "color_temp"
|
||||
ATTR_COLOR_NAME = "color_name"
|
||||
|
||||
# int with value 0 .. 255 representing brightness of the light.
|
||||
ATTR_BRIGHTNESS = "brightness"
|
||||
|
@ -87,6 +88,7 @@ LIGHT_TURN_ON_SCHEMA = vol.Schema({
|
|||
ATTR_PROFILE: str,
|
||||
ATTR_TRANSITION: VALID_TRANSITION,
|
||||
ATTR_BRIGHTNESS: cv.byte,
|
||||
ATTR_COLOR_NAME: str,
|
||||
ATTR_RGB_COLOR: vol.All(vol.ExactSequence((cv.byte, cv.byte, cv.byte)),
|
||||
vol.Coerce(tuple)),
|
||||
ATTR_XY_COLOR: vol.All(vol.ExactSequence((cv.small_float, cv.small_float)),
|
||||
|
@ -122,7 +124,7 @@ 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, color_temp=None, profile=None,
|
||||
flash=None, effect=None):
|
||||
flash=None, effect=None, color_name=None):
|
||||
"""Turn all or specified light on."""
|
||||
data = {
|
||||
key: value for key, value in [
|
||||
|
@ -135,6 +137,7 @@ def turn_on(hass, entity_id=None, transition=None, brightness=None,
|
|||
(ATTR_COLOR_TEMP, color_temp),
|
||||
(ATTR_FLASH, flash),
|
||||
(ATTR_EFFECT, effect),
|
||||
(ATTR_COLOR_NAME, color_name),
|
||||
] if value is not None
|
||||
}
|
||||
|
||||
|
@ -228,6 +231,11 @@ def setup(hass, config):
|
|||
params.setdefault(ATTR_XY_COLOR, profile[:2])
|
||||
params.setdefault(ATTR_BRIGHTNESS, profile[2])
|
||||
|
||||
color_name = params.pop(ATTR_COLOR_NAME, None)
|
||||
|
||||
if color_name is not None:
|
||||
params[ATTR_RGB_COLOR] = color_util.color_name_to_rgb(color_name)
|
||||
|
||||
for light in target_lights:
|
||||
light.turn_on(**params)
|
||||
|
||||
|
|
|
@ -16,6 +16,10 @@ turn_on:
|
|||
description: Color for the light in RGB-format
|
||||
example: '[255, 100, 100]'
|
||||
|
||||
color_name:
|
||||
description: A human readable color name
|
||||
example: 'red'
|
||||
|
||||
xy_color:
|
||||
description: Color for the light in XY-format
|
||||
example: '[0.52, 0.43]'
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
"""Color util methods."""
|
||||
import math
|
||||
# pylint: disable=unused-import
|
||||
from webcolors import html5_parse_legacy_color as color_name_to_rgb # noqa
|
||||
|
||||
HASS_COLOR_MAX = 500 # mireds (inverted)
|
||||
HASS_COLOR_MIN = 154
|
||||
|
|
|
@ -6,6 +6,7 @@ pip>=7.0.0
|
|||
vincenty==0.1.4
|
||||
jinja2>=2.8
|
||||
voluptuous==0.8.9
|
||||
webcolors==1.5
|
||||
|
||||
# homeassistant.components.isy994
|
||||
PyISY==1.0.5
|
||||
|
|
1
setup.py
1
setup.py
|
@ -18,6 +18,7 @@ REQUIRES = [
|
|||
'vincenty==0.1.4',
|
||||
'jinja2>=2.8',
|
||||
'voluptuous==0.8.9',
|
||||
'webcolors==1.5',
|
||||
]
|
||||
|
||||
setup(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue