From d391b9f2014c1edfaff707b867179bfc62f55f3b Mon Sep 17 00:00:00 2001 From: Sanjoy Ghosh Date: Sun, 24 Mar 2024 10:15:49 +0530 Subject: [PATCH] Fixed color mode / brightness as per latest developer documentation --- custom_components/dirigera_platform/light.py | 15 ++++++++++++--- .../dirigera_platform/mocks/ikea_bulb_mock.py | 8 +++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/custom_components/dirigera_platform/light.py b/custom_components/dirigera_platform/light.py index 2c67239..707771f 100644 --- a/custom_components/dirigera_platform/light.py +++ b/custom_components/dirigera_platform/light.py @@ -65,7 +65,7 @@ def set_state(self): can_receive = self._json_data.capabilities.can_receive logger.debug("Got can_receive in state") logger.debug(can_receive) - self._color_mode = ColorMode.UNKNOWN + self._color_mode = ColorMode.ONOFF for cap in can_receive: if cap == "lightLevel": color_modes.append(ColorMode.BRIGHTNESS) @@ -74,9 +74,17 @@ def set_state(self): elif cap == "colorHue" or cap == "colorSaturation": color_modes.append(ColorMode.HS) + # Based on documentation here + # https://developers.home-assistant.io/docs/core/entity/light#color-modes + if len(color_modes) > 1: + # If there are more color modes which means we have either temperature + # or HueSaturation. then lets make sure BRIGHTNESS is not part of it + # as per above documentation + color_modes.remove(ColorMode.BRIGHTNESS) + if len(color_modes) == 0: logger.debug("Color modes array is zero, setting to UNKNOWN") - self._supported_color_modes = [ColorMode.UNKNOWN] + self._supported_color_modes = [ColorMode.ONOFF] else: self._supported_color_modes = color_modes if ColorMode.HS in self._supported_color_modes: @@ -86,8 +94,9 @@ def set_state(self): elif ColorMode.BRIGHTNESS in self._supported_color_modes: self._color_mode = ColorMode.BRIGHTNESS - logger.debug("supported color mode set to ") + logger.debug("supported color mode set to:") logger.debug(self._supported_color_modes) + logger.debug("color mode set to:") logger.debug(self._color_mode) @property diff --git a/custom_components/dirigera_platform/mocks/ikea_bulb_mock.py b/custom_components/dirigera_platform/mocks/ikea_bulb_mock.py index 5383ff0..f4c79b2 100644 --- a/custom_components/dirigera_platform/mocks/ikea_bulb_mock.py +++ b/custom_components/dirigera_platform/mocks/ikea_bulb_mock.py @@ -31,7 +31,13 @@ def __init__(self) -> None: ColorMode.COLOR_TEMP, ColorMode.HS, ] - + + if len(self._supported_color_modes) > 1: + # If there are more color modes which means we have either temperature + # or HueSaturation. then lets make sure BRIGHTNESS is not part of it + # as per above documentation + self._supported_color_modes.remove(ColorMode.BRIGHTNESS) + if len(self._supported_color_modes) == 0: logger.debug("Color modes array is zero, setting to UNKNOWN") self._supported_color_modes = [ColorMode.UNKNOWN]