From fa0ad7b3171d6abcf0b765558a1f1c824323fd94 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Fri, 4 May 2018 12:28:56 +0200 Subject: [PATCH] Color fixes for Wink lights (#14263) --- homeassistant/components/light/wink.py | 34 +++++++++----------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/light/wink.py b/homeassistant/components/light/wink.py index fd957f8f11d..04e9c34b0f6 100644 --- a/homeassistant/components/light/wink.py +++ b/homeassistant/components/light/wink.py @@ -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)