Add xy attribute to Yeelight (#9957)
Allows using light profiles with yeelight bulbspull/10017/head
parent
5ad715507b
commit
089e1ab6f4
|
@ -13,12 +13,15 @@ import voluptuous as vol
|
||||||
from homeassistant.util.color import (
|
from homeassistant.util.color import (
|
||||||
color_temperature_mired_to_kelvin as mired_to_kelvin,
|
color_temperature_mired_to_kelvin as mired_to_kelvin,
|
||||||
color_temperature_kelvin_to_mired as kelvin_to_mired,
|
color_temperature_kelvin_to_mired as kelvin_to_mired,
|
||||||
color_temperature_to_rgb)
|
color_temperature_to_rgb,
|
||||||
|
color_RGB_to_xy,
|
||||||
|
color_xy_brightness_to_RGB)
|
||||||
from homeassistant.const import CONF_DEVICES, CONF_NAME
|
from homeassistant.const import CONF_DEVICES, CONF_NAME
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_TRANSITION, ATTR_COLOR_TEMP,
|
ATTR_BRIGHTNESS, ATTR_RGB_COLOR, ATTR_TRANSITION, ATTR_COLOR_TEMP,
|
||||||
ATTR_FLASH, FLASH_SHORT, FLASH_LONG, ATTR_EFFECT,
|
ATTR_FLASH, ATTR_XY_COLOR, FLASH_SHORT, FLASH_LONG, ATTR_EFFECT,
|
||||||
SUPPORT_BRIGHTNESS, SUPPORT_RGB_COLOR, SUPPORT_TRANSITION,
|
SUPPORT_BRIGHTNESS, SUPPORT_RGB_COLOR, SUPPORT_XY_COLOR,
|
||||||
|
SUPPORT_TRANSITION,
|
||||||
SUPPORT_COLOR_TEMP, SUPPORT_FLASH, SUPPORT_EFFECT,
|
SUPPORT_COLOR_TEMP, SUPPORT_FLASH, SUPPORT_EFFECT,
|
||||||
Light, PLATFORM_SCHEMA)
|
Light, PLATFORM_SCHEMA)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
@ -51,6 +54,7 @@ SUPPORT_YEELIGHT = (SUPPORT_BRIGHTNESS |
|
||||||
|
|
||||||
SUPPORT_YEELIGHT_RGB = (SUPPORT_YEELIGHT |
|
SUPPORT_YEELIGHT_RGB = (SUPPORT_YEELIGHT |
|
||||||
SUPPORT_RGB_COLOR |
|
SUPPORT_RGB_COLOR |
|
||||||
|
SUPPORT_XY_COLOR |
|
||||||
SUPPORT_EFFECT |
|
SUPPORT_EFFECT |
|
||||||
SUPPORT_COLOR_TEMP)
|
SUPPORT_COLOR_TEMP)
|
||||||
|
|
||||||
|
@ -154,6 +158,7 @@ class YeelightLight(Light):
|
||||||
self._color_temp = None
|
self._color_temp = None
|
||||||
self._is_on = None
|
self._is_on = None
|
||||||
self._rgb = None
|
self._rgb = None
|
||||||
|
self._xy = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
|
@ -236,6 +241,11 @@ class YeelightLight(Light):
|
||||||
"""Return the color property."""
|
"""Return the color property."""
|
||||||
return self._rgb
|
return self._rgb
|
||||||
|
|
||||||
|
@property
|
||||||
|
def xy_color(self) -> tuple:
|
||||||
|
"""Return the XY color value."""
|
||||||
|
return self._xy
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _properties(self) -> dict:
|
def _properties(self) -> dict:
|
||||||
return self._bulb.last_properties
|
return self._bulb.last_properties
|
||||||
|
@ -284,6 +294,12 @@ class YeelightLight(Light):
|
||||||
|
|
||||||
self._rgb = self._get_rgb_from_properties()
|
self._rgb = self._get_rgb_from_properties()
|
||||||
|
|
||||||
|
if self._rgb:
|
||||||
|
xyb = color_RGB_to_xy(*self._rgb)
|
||||||
|
self._xy = (xyb[0], xyb[1])
|
||||||
|
else:
|
||||||
|
self._xy = None
|
||||||
|
|
||||||
self._available = True
|
self._available = True
|
||||||
except yeelight.BulbException as ex:
|
except yeelight.BulbException as ex:
|
||||||
if self._available: # just inform once
|
if self._available: # just inform once
|
||||||
|
@ -410,6 +426,7 @@ class YeelightLight(Light):
|
||||||
rgb = kwargs.get(ATTR_RGB_COLOR)
|
rgb = kwargs.get(ATTR_RGB_COLOR)
|
||||||
flash = kwargs.get(ATTR_FLASH)
|
flash = kwargs.get(ATTR_FLASH)
|
||||||
effect = kwargs.get(ATTR_EFFECT)
|
effect = kwargs.get(ATTR_EFFECT)
|
||||||
|
xy_color = kwargs.get(ATTR_XY_COLOR)
|
||||||
|
|
||||||
duration = int(self.config[CONF_TRANSITION]) # in ms
|
duration = int(self.config[CONF_TRANSITION]) # in ms
|
||||||
if ATTR_TRANSITION in kwargs: # passed kwarg overrides config
|
if ATTR_TRANSITION in kwargs: # passed kwarg overrides config
|
||||||
|
@ -427,6 +444,9 @@ class YeelightLight(Light):
|
||||||
except yeelight.BulbException as ex:
|
except yeelight.BulbException as ex:
|
||||||
_LOGGER.error("Unable to turn on music mode,"
|
_LOGGER.error("Unable to turn on music mode,"
|
||||||
"consider disabling it: %s", ex)
|
"consider disabling it: %s", ex)
|
||||||
|
if xy_color and brightness:
|
||||||
|
rgb = color_xy_brightness_to_RGB(xy_color[0], xy_color[1],
|
||||||
|
brightness)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# values checked for none in methods
|
# values checked for none in methods
|
||||||
|
|
Loading…
Reference in New Issue