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

@ -11,15 +11,16 @@ import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.components.light import (
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, ATTR_RGB_COLOR, SUPPORT_RGB_COLOR,
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, ATTR_HS_COLOR, SUPPORT_COLOR,
Light, PLATFORM_SCHEMA)
from homeassistant.const import CONF_NAME
import homeassistant.util.color as color_util
REQUIREMENTS = ['piglow==1.2.4']
_LOGGER = logging.getLogger(__name__)
SUPPORT_PIGLOW = (SUPPORT_BRIGHTNESS | SUPPORT_RGB_COLOR)
SUPPORT_PIGLOW = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR)
DEFAULT_NAME = 'Piglow'
@ -50,7 +51,7 @@ class PiglowLight(Light):
self._name = name
self._is_on = False
self._brightness = 255
self._rgb_color = [255, 255, 255]
self._hs_color = [0, 0]
@property
def name(self):
@ -63,9 +64,9 @@ class PiglowLight(Light):
return self._brightness
@property
def rgb_color(self):
def hs_color(self):
"""Read back the color of the light."""
return self._rgb_color
return self._hs_color
@property
def supported_features(self):
@ -93,15 +94,15 @@ class PiglowLight(Light):
if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs[ATTR_BRIGHTNESS]
percent_bright = (self._brightness / 255)
if ATTR_RGB_COLOR in kwargs:
self._rgb_color = kwargs[ATTR_RGB_COLOR]
self._piglow.red(int(self._rgb_color[0] * percent_bright))
self._piglow.green(int(self._rgb_color[1] * percent_bright))
self._piglow.blue(int(self._rgb_color[2] * percent_bright))
else:
self._piglow.all(self._brightness)
if ATTR_HS_COLOR in kwargs:
self._hs_color = kwargs[ATTR_HS_COLOR]
rgb = color_util.color_hsv_to_RGB(
self._hs_color[0], self._hs_color[1], self._brightness / 255 * 100)
self._piglow.red(rgb[0])
self._piglow.green(rgb[1])
self._piglow.blue(rgb[2])
self._piglow.show()
self._is_on = True
self.schedule_update_ha_state()