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:
Adam Mills 2018-03-18 18:00:29 -04:00 committed by Paulus Schoutsen
parent 6b059489a6
commit 89c7c80e42
57 changed files with 898 additions and 965 deletions

View file

@ -12,10 +12,11 @@ import voluptuous as vol
from homeassistant.const import CONF_DEVICES, CONF_NAME, CONF_PROTOCOL
from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_EFFECT, EFFECT_COLORLOOP,
ATTR_BRIGHTNESS, ATTR_HS_COLOR, ATTR_EFFECT, EFFECT_COLORLOOP,
EFFECT_RANDOM, SUPPORT_BRIGHTNESS, SUPPORT_EFFECT,
SUPPORT_RGB_COLOR, Light, PLATFORM_SCHEMA)
SUPPORT_COLOR, Light, PLATFORM_SCHEMA)
import homeassistant.helpers.config_validation as cv
import homeassistant.util.color as color_util
REQUIREMENTS = ['flux_led==0.21']
@ -27,7 +28,7 @@ ATTR_MODE = 'mode'
DOMAIN = 'flux_led'
SUPPORT_FLUX_LED = (SUPPORT_BRIGHTNESS | SUPPORT_EFFECT |
SUPPORT_RGB_COLOR)
SUPPORT_COLOR)
MODE_RGB = 'rgb'
MODE_RGBW = 'rgbw'
@ -183,9 +184,9 @@ class FluxLight(Light):
return self._bulb.brightness
@property
def rgb_color(self):
def hs_color(self):
"""Return the color property."""
return self._bulb.getRgb()
return color_util.color_RGB_to_hs(*self._bulb.getRgb())
@property
def supported_features(self):
@ -202,7 +203,8 @@ class FluxLight(Light):
if not self.is_on:
self._bulb.turnOn()
rgb = kwargs.get(ATTR_RGB_COLOR)
hs_color = kwargs.get(ATTR_HS_COLOR)
rgb = color_util.color_hs_to_RGB(*hs_color)
brightness = kwargs.get(ATTR_BRIGHTNESS)
effect = kwargs.get(ATTR_EFFECT)