mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Color fixes for Wink lights (#14263)
This commit is contained in:
parent
b49d98407c
commit
fa0ad7b317
@ -5,7 +5,6 @@ For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/light.wink/
|
||||
"""
|
||||
import asyncio
|
||||
import colorsys
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_HS_COLOR, SUPPORT_BRIGHTNESS,
|
||||
@ -54,29 +53,19 @@ class WinkLight(WinkDevice, Light):
|
||||
return int(self.wink.brightness() * 255)
|
||||
return None
|
||||
|
||||
@property
|
||||
def rgb_color(self):
|
||||
"""Define current bulb color in RGB."""
|
||||
if not self.wink.supports_hue_saturation():
|
||||
return None
|
||||
else:
|
||||
hue = self.wink.color_hue()
|
||||
saturation = self.wink.color_saturation()
|
||||
value = int(self.wink.brightness() * 255)
|
||||
if hue is None or saturation is None or value is None:
|
||||
return None
|
||||
rgb = colorsys.hsv_to_rgb(hue, saturation, value)
|
||||
r_value = int(round(rgb[0]))
|
||||
g_value = int(round(rgb[1]))
|
||||
b_value = int(round(rgb[2]))
|
||||
return r_value, g_value, b_value
|
||||
|
||||
@property
|
||||
def hs_color(self):
|
||||
"""Define current bulb color."""
|
||||
if not self.wink.supports_xy_color():
|
||||
return None
|
||||
return color_util.color_xy_to_hs(*self.wink.color_xy())
|
||||
if self.wink.supports_xy_color():
|
||||
return color_util.color_xy_to_hs(*self.wink.color_xy())
|
||||
|
||||
if self.wink.supports_hue_saturation():
|
||||
hue = self.wink.color_hue()
|
||||
saturation = self.wink.color_saturation()
|
||||
if hue is not None and saturation is not None:
|
||||
return hue*360, saturation*100
|
||||
|
||||
return None
|
||||
|
||||
@property
|
||||
def color_temp(self):
|
||||
@ -104,7 +93,8 @@ class WinkLight(WinkDevice, Light):
|
||||
xy_color = color_util.color_hs_to_xy(*hs_color)
|
||||
state_kwargs['color_xy'] = xy_color
|
||||
if self.wink.supports_hue_saturation():
|
||||
state_kwargs['color_hue_saturation'] = hs_color
|
||||
hs_scaled = hs_color[0]/360, hs_color[1]/100
|
||||
state_kwargs['color_hue_saturation'] = hs_scaled
|
||||
|
||||
if color_temp_mired:
|
||||
state_kwargs['color_kelvin'] = mired_to_kelvin(color_temp_mired)
|
||||
|
Loading…
x
Reference in New Issue
Block a user