From 2faa3af51f7ea3c5183d16dfa302ef5b033a687a Mon Sep 17 00:00:00 2001 From: FredericMa Date: Sat, 18 Apr 2020 02:25:44 +0200 Subject: [PATCH] =?UTF-8?q?Extend=20knx=20brightness=20with=20rgb=20bright?= =?UTF-8?q?ness=20if=20brightness=20addres=E2=80=A6=20(#33152)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Extend knx brightness with rgb brightness if brightness addresses are not supported * Fix explicit return value * Check for None * Remove not needed check * Disable false positive pylint warning Co-authored-by: Martin Hjelmare --- homeassistant/components/knx/light.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/knx/light.py b/homeassistant/components/knx/light.py index efd1a74f5a2..8570c2eb09a 100644 --- a/homeassistant/components/knx/light.py +++ b/homeassistant/components/knx/light.py @@ -180,9 +180,13 @@ class KNXLight(Light): @property def brightness(self): """Return the brightness of this light between 0..255.""" - if not self.device.supports_brightness: - return None - return self.device.current_brightness + if self.device.supports_brightness: + return self.device.current_brightness + hsv_color = self._hsv_color + if self.device.supports_color and hsv_color: + # pylint: disable=unsubscriptable-object + return round(hsv_color[-1] / 100 * 255) + return None @property def hs_color(self): @@ -192,6 +196,14 @@ class KNXLight(Light): rgb, _ = self.device.current_color return color_util.color_RGB_to_hs(*rgb) if rgb else None + @property + def _hsv_color(self): + """Return the HSV color value.""" + rgb = None + if self.device.supports_rgbw or self.device.supports_color: + rgb, _ = self.device.current_color + return color_util.color_RGB_to_hsv(*rgb) if rgb else None + @property def white_value(self): """Return the white value."""