From e7476d442826e7770ff6ede98707740c13e2d8a3 Mon Sep 17 00:00:00 2001 From: Krzysztof Sasiak Date: Thu, 17 Aug 2023 15:46:09 +0200 Subject: [PATCH] * Fix unique entity ID * Add support for cool and warm white LEDs --- .../custom_components/dohome/light.py | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/DoHome_HassAssistant_Component/custom_components/dohome/light.py b/DoHome_HassAssistant_Component/custom_components/dohome/light.py index b53b23a..963e93d 100644 --- a/DoHome_HassAssistant_Component/custom_components/dohome/light.py +++ b/DoHome_HassAssistant_Component/custom_components/dohome/light.py @@ -13,11 +13,12 @@ ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_EFFECT, - ATTR_HS_COLOR, + ATTR_RGBWW_COLOR, PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS, SUPPORT_COLOR, LightEntity, + ColorMode ) from . import (DOHOME_GATEWAY, DoHomeDevice) @@ -43,7 +44,7 @@ def __init__(self, hass, device): self._device = device self._state = False - self._rgb = (255, 255, 255) + self._rgb = (255, 255, 255, 255, 255) self._brightness = 100 self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) @@ -55,9 +56,9 @@ def brightness(self): return self._brightness @property - def hs_color(self): + def rgbww_color(self): """Return the color property.""" - return color_util.color_RGB_to_hs(*self._rgb) + return self._rgb @property def is_on(self): @@ -69,10 +70,24 @@ def supported_features(self): """Return the supported features.""" return SUPPORT_BRIGHTNESS | SUPPORT_COLOR + @property + def supported_color_modes(self): + """Return the supported color modes.""" + return [ColorMode.RGBWW] + + @property + def color_mode(self): + """Return the supported color modes.""" + return ColorMode.RGBWW + + @property + def unique_id(self): + return self._device["name"] + def turn_on(self, **kwargs): """Turn the light on.""" - if ATTR_HS_COLOR in kwargs: - self._rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) + if ATTR_RGBWW_COLOR in kwargs: + self._rgb = kwargs[ATTR_RGBWW_COLOR] if ATTR_BRIGHTNESS in kwargs: self._brightness = int(100 * kwargs[ATTR_BRIGHTNESS] / 255) @@ -83,8 +98,9 @@ def turn_on(self, **kwargs): "r":int(50 * self._rgb[0] / 255)*self._brightness, "g":int(50 * self._rgb[1] / 255)*self._brightness, "b":int(50 * self._rgb[2] / 255)*self._brightness, - "w":0, - "m":0} + "w":int(50 * self._rgb[3] / 255)*self._brightness, + "m":int(50 * self._rgb[4] / 255)*self._brightness + } op = json.dumps(data) self._send_cmd(self._device,'cmd=ctrl&devices={[' + self._device["sid"] + ']}&op=' + op + '}', 6) @@ -123,4 +139,4 @@ def _send_cmd(self, device, cmd, rtn_cmd): return resp else: _LOGGER.debug("Non matching response. device %s, but got %s", device["sid"], dic["dev"][8:12]) - return None \ No newline at end of file + return None