Use hue/sat as internal light color interface (#11288)
* Accept and report both xy and RGB color for lights * Fix demo light supported_features * Add new XY color util functions * Always make color changes available as xy and RGB * Always expose color as RGB and XY * Consolidate color supported_features * Test fixes * Additional test fix * Use hue/sat as the hass core color interface * Tests updates * Assume MQTT RGB devices need full RGB brightness * Convert new platforms * More migration * Use float for HS API * Fix backwards conversion for KNX lights * Adjust limitless min saturation for new scale
This commit is contained in:
parent
6b059489a6
commit
89c7c80e42
57 changed files with 898 additions and 965 deletions
|
@ -9,9 +9,11 @@ import logging
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_RGB_COLOR, SUPPORT_RGB_COLOR, Light, PLATFORM_SCHEMA)
|
||||
ATTR_BRIGHTNESS, ATTR_HS_COLOR, SUPPORT_BRIGHTNESS, SUPPORT_COLOR, Light,
|
||||
PLATFORM_SCHEMA)
|
||||
from homeassistant.const import CONF_NAME
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import homeassistant.util.color as color_util
|
||||
|
||||
REQUIREMENTS = ['blinkstick==1.1.8']
|
||||
|
||||
|
@ -21,7 +23,7 @@ CONF_SERIAL = 'serial'
|
|||
|
||||
DEFAULT_NAME = 'Blinkstick'
|
||||
|
||||
SUPPORT_BLINKSTICK = SUPPORT_RGB_COLOR
|
||||
SUPPORT_BLINKSTICK = SUPPORT_BRIGHTNESS | SUPPORT_COLOR
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_SERIAL): cv.string,
|
||||
|
@ -39,7 +41,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
|
||||
stick = blinkstick.find_by_serial(serial)
|
||||
|
||||
add_devices([BlinkStickLight(stick, name)])
|
||||
add_devices([BlinkStickLight(stick, name)], True)
|
||||
|
||||
|
||||
class BlinkStickLight(Light):
|
||||
|
@ -50,7 +52,8 @@ class BlinkStickLight(Light):
|
|||
self._stick = stick
|
||||
self._name = name
|
||||
self._serial = stick.get_serial()
|
||||
self._rgb_color = stick.get_color()
|
||||
self._hs_color = None
|
||||
self._brightness = None
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
@ -63,14 +66,19 @@ class BlinkStickLight(Light):
|
|||
return self._name
|
||||
|
||||
@property
|
||||
def rgb_color(self):
|
||||
def brightness(self):
|
||||
"""Read back the brightness of the light."""
|
||||
return self._brightness
|
||||
|
||||
@property
|
||||
def hs_color(self):
|
||||
"""Read back the color of the light."""
|
||||
return self._rgb_color
|
||||
return self._hs_color
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Check whether any of the LEDs colors are non-zero."""
|
||||
return sum(self._rgb_color) > 0
|
||||
"""Return True if entity is on."""
|
||||
return self._brightness > 0
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
|
@ -79,18 +87,24 @@ class BlinkStickLight(Light):
|
|||
|
||||
def update(self):
|
||||
"""Read back the device state."""
|
||||
self._rgb_color = self._stick.get_color()
|
||||
rgb_color = self._stick.get_color()
|
||||
hsv = color_util.color_RGB_to_hsv(*rgb_color)
|
||||
self._hs_color = hsv[:2]
|
||||
self._brightness = hsv[2]
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
if ATTR_RGB_COLOR in kwargs:
|
||||
self._rgb_color = kwargs[ATTR_RGB_COLOR]
|
||||
if ATTR_HS_COLOR in kwargs:
|
||||
self._hs_color = kwargs[ATTR_HS_COLOR]
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
self._brightness = kwargs[ATTR_BRIGHTNESS]
|
||||
else:
|
||||
self._rgb_color = [255, 255, 255]
|
||||
self._brightness = 255
|
||||
|
||||
self._stick.set_color(red=self._rgb_color[0],
|
||||
green=self._rgb_color[1],
|
||||
blue=self._rgb_color[2])
|
||||
rgb_color = color_util.color_hsv_to_RGB(
|
||||
self._hs_color[0], self._hs_color[1], self._brightness / 255 * 100)
|
||||
self._stick.set_color(
|
||||
red=rgb_color[0], green=rgb_color[1], blue=rgb_color[2])
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn the device off."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue