From 574ffad0f3f8799f224dc22e6034549079c65a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ercan=20Aky=C3=BCrek?= Date: Fri, 3 Jan 2025 11:39:51 +0000 Subject: [PATCH 1/9] added white support to light entity --- custom_components/localtuya/const.py | 1 + custom_components/localtuya/light.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/custom_components/localtuya/const.py b/custom_components/localtuya/const.py index bf74e5252..c1f809e66 100644 --- a/custom_components/localtuya/const.py +++ b/custom_components/localtuya/const.py @@ -93,6 +93,7 @@ CONF_COLOR_MODE_SET = "color_mode_set" CONF_COLOR_TEMP_MIN_KELVIN = "color_temp_min_kelvin" CONF_COLOR_TEMP_MAX_KELVIN = "color_temp_max_kelvin" +CONF_COLOR_HAS_WHITE_CHANNEL = "color_has_white_channel" CONF_COLOR_TEMP_REVERSE = "color_temp_reverse" CONF_MUSIC_MODE = "music_mode" CONF_SCENE_VALUES = "scene_values" diff --git a/custom_components/localtuya/light.py b/custom_components/localtuya/light.py index 8818060b8..22f16f0e0 100644 --- a/custom_components/localtuya/light.py +++ b/custom_components/localtuya/light.py @@ -11,6 +11,7 @@ from homeassistant.components.light import ( ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, + ATTR_WHITE, ATTR_EFFECT, ATTR_HS_COLOR, DOMAIN, @@ -26,6 +27,7 @@ CONF_BRIGHTNESS_LOWER, CONF_BRIGHTNESS_UPPER, CONF_COLOR, + CONF_COLOR_HAS_WHITE_CHANNEL, CONF_COLOR_MODE, CONF_COLOR_MODE_SET, CONF_COLOR_TEMP_MAX_KELVIN, @@ -143,6 +145,9 @@ def flow_schema(dps): vol.Optional(CONF_COLOR_TEMP_MAX_KELVIN, default=DEFAULT_MAX_KELVIN): vol.All( vol.Coerce(int), vol.Range(min=1500, max=8000) ), + vol.Optional( + CONF_COLOR_HAS_WHITE_CHANNEL, default=False + ): selector.BooleanSelector(), vol.Optional(CONF_COLOR_TEMP_REVERSE, default=DEFAULT_COLOR_TEMP_REVERSE): bool, vol.Optional(CONF_SCENE): col_to_select(dps, is_dps=True), vol.Optional(CONF_SCENE_VALUES, default={}): selector.ObjectSelector(), @@ -300,6 +305,8 @@ def supported_color_modes(self) -> set[ColorMode] | set[str] | None: color_modes.add(ColorMode.COLOR_TEMP) if self.has_config(CONF_COLOR): color_modes.add(ColorMode.HS) + if self.has_config(CONF_COLOR_HAS_WHITE_CHANNEL): + color_modes.add(ColorMode.WHITE) if not color_modes and self.has_config(CONF_BRIGHTNESS): return {ColorMode.BRIGHTNESS} @@ -349,6 +356,8 @@ def color_mode(self) -> ColorMode: if self.is_color_mode: return ColorMode.HS + if self.is_white_mode and self.has_config(CONF_COLOR_HAS_WHITE_CHANNEL): + return ColorMode.WHITE if self.is_white_mode: return ColorMode.COLOR_TEMP if self._brightness: @@ -481,6 +490,10 @@ async def async_turn_on(self, **kwargs): states[self._config.get(CONF_BRIGHTNESS)] = brightness states[self._config.get(CONF_COLOR_TEMP)] = color_temp + if ATTR_WHITE in kwargs and ColorMode.WHITE in color_modes: + states[self._config.get(CONF_COLOR_MODE)] = self._modes.white + states[self._config.get(CONF_BRIGHTNESS)] = brightness + await self._device.set_dps(states) async def async_turn_off(self, **kwargs): From 9d72c175e9777e41c79c129141eacc3002c7c76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ercan=20Aky=C3=BCrek?= Date: Fri, 3 Jan 2025 11:46:45 +0000 Subject: [PATCH 2/9] added translations --- custom_components/localtuya/const.py | 2 +- custom_components/localtuya/light.py | 8 ++++---- custom_components/localtuya/translations/en.json | 1 + custom_components/localtuya/translations/it.json | 1 + custom_components/localtuya/translations/pl.json | 1 + custom_components/localtuya/translations/pt-BR.json | 1 + 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/custom_components/localtuya/const.py b/custom_components/localtuya/const.py index c1f809e66..371ee2526 100644 --- a/custom_components/localtuya/const.py +++ b/custom_components/localtuya/const.py @@ -93,7 +93,7 @@ CONF_COLOR_MODE_SET = "color_mode_set" CONF_COLOR_TEMP_MIN_KELVIN = "color_temp_min_kelvin" CONF_COLOR_TEMP_MAX_KELVIN = "color_temp_max_kelvin" -CONF_COLOR_HAS_WHITE_CHANNEL = "color_has_white_channel" +CONF_COLOR_HAS_SINGLE_WHITE_CHANNEL = "color_has_single_white_channel" CONF_COLOR_TEMP_REVERSE = "color_temp_reverse" CONF_MUSIC_MODE = "music_mode" CONF_SCENE_VALUES = "scene_values" diff --git a/custom_components/localtuya/light.py b/custom_components/localtuya/light.py index 22f16f0e0..828fad369 100644 --- a/custom_components/localtuya/light.py +++ b/custom_components/localtuya/light.py @@ -27,7 +27,7 @@ CONF_BRIGHTNESS_LOWER, CONF_BRIGHTNESS_UPPER, CONF_COLOR, - CONF_COLOR_HAS_WHITE_CHANNEL, + CONF_COLOR_HAS_SINGLE_WHITE_CHANNEL, CONF_COLOR_MODE, CONF_COLOR_MODE_SET, CONF_COLOR_TEMP_MAX_KELVIN, @@ -146,7 +146,7 @@ def flow_schema(dps): vol.Coerce(int), vol.Range(min=1500, max=8000) ), vol.Optional( - CONF_COLOR_HAS_WHITE_CHANNEL, default=False + CONF_COLOR_HAS_SINGLE_WHITE_CHANNEL, default=False ): selector.BooleanSelector(), vol.Optional(CONF_COLOR_TEMP_REVERSE, default=DEFAULT_COLOR_TEMP_REVERSE): bool, vol.Optional(CONF_SCENE): col_to_select(dps, is_dps=True), @@ -305,7 +305,7 @@ def supported_color_modes(self) -> set[ColorMode] | set[str] | None: color_modes.add(ColorMode.COLOR_TEMP) if self.has_config(CONF_COLOR): color_modes.add(ColorMode.HS) - if self.has_config(CONF_COLOR_HAS_WHITE_CHANNEL): + if self.has_config(CONF_COLOR_HAS_SINGLE_WHITE_CHANNEL): color_modes.add(ColorMode.WHITE) if not color_modes and self.has_config(CONF_BRIGHTNESS): @@ -356,7 +356,7 @@ def color_mode(self) -> ColorMode: if self.is_color_mode: return ColorMode.HS - if self.is_white_mode and self.has_config(CONF_COLOR_HAS_WHITE_CHANNEL): + if self.is_white_mode and self.has_config(CONF_COLOR_HAS_SINGLE_WHITE_CHANNEL): return ColorMode.WHITE if self.is_white_mode: return ColorMode.COLOR_TEMP diff --git a/custom_components/localtuya/translations/en.json b/custom_components/localtuya/translations/en.json index fed2f0ee7..2e95bca96 100644 --- a/custom_components/localtuya/translations/en.json +++ b/custom_components/localtuya/translations/en.json @@ -191,6 +191,7 @@ "color_temp_reverse": "Reverse Color Temperature?", "color": "Color", "color_mode": "Color Mode aka Work Mode", + "color_has_single_white_channel": "Has Single White Channel", "color_temp_min_kelvin": "Minimum Color Temperature in K", "color_temp_max_kelvin": "Maximum Color Temperature in K", "music_mode": "Music mode available?", diff --git a/custom_components/localtuya/translations/it.json b/custom_components/localtuya/translations/it.json index 994d56b5d..0224edb3c 100644 --- a/custom_components/localtuya/translations/it.json +++ b/custom_components/localtuya/translations/it.json @@ -186,6 +186,7 @@ "color_temp_reverse": "Reverse Color Temperature?", "color": "Color", "color_mode": "Color Mode aka Work Mode", + "color_has_single_white_channel": "Has Single White Channel", "color_temp_min_kelvin": "Minimum Color Temperature in K", "color_temp_max_kelvin": "Maximum Color Temperature in K", "music_mode": "Music mode available?", diff --git a/custom_components/localtuya/translations/pl.json b/custom_components/localtuya/translations/pl.json index 55b5651a5..b0e7bb508 100644 --- a/custom_components/localtuya/translations/pl.json +++ b/custom_components/localtuya/translations/pl.json @@ -191,6 +191,7 @@ "color_temp_reverse": "Odwrócona temperatura barwy", "color": "Kolor", "color_mode": "Tryb koloru, czyli tryb pracy", + "color_has_single_white_channel": "Has Single White Channel", "color_temp_min_kelvin": "Minimalna temperatura barwowa w K", "color_temp_max_kelvin": "Maksymalna temperatura barwowa w K", "music_mode": "Dostępny tryb muzyczny", diff --git a/custom_components/localtuya/translations/pt-BR.json b/custom_components/localtuya/translations/pt-BR.json index 33dea5769..e4cbec792 100644 --- a/custom_components/localtuya/translations/pt-BR.json +++ b/custom_components/localtuya/translations/pt-BR.json @@ -186,6 +186,7 @@ "color_temp_reverse": "Reverse Color Temperature?", "color": "Color", "color_mode": "Color Mode aka Work Mode", + "color_has_single_white_channel": "Has Single White Channel", "color_temp_min_kelvin": "Minimum Color Temperature in K", "color_temp_max_kelvin": "Maximum Color Temperature in K", "music_mode": "Music mode available?", From 79f39becb85e50b1108989d49bee0daaa6ff48eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ercan=20Aky=C3=BCrek?= Date: Fri, 3 Jan 2025 16:43:38 +0000 Subject: [PATCH 3/9] fixed a bug in has_config when checking for boolean selectors --- custom_components/localtuya/entity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/localtuya/entity.py b/custom_components/localtuya/entity.py index b3bc9b74e..e2d1323e1 100644 --- a/custom_components/localtuya/entity.py +++ b/custom_components/localtuya/entity.py @@ -264,7 +264,7 @@ def device_class(self): def has_config(self, attr) -> bool: """Return if a config parameter has a valid value.""" value = self._config.get(attr, "-1") - return value is not None and value != "-1" + return value is not None and value is not False and value != "-1" def dp_value(self, key, default=None) -> Any | None: """Return cached value for DPS index or Entity Config Key. else default None""" From 907cc8355bca12ef3c9df73482a508bfdc32d34d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ercan=20Aky=C3=BCrek?= Date: Fri, 3 Jan 2025 16:50:11 +0000 Subject: [PATCH 4/9] bumped version --- custom_components/localtuya/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/localtuya/manifest.json b/custom_components/localtuya/manifest.json index 092cc596f..b6350f8a3 100644 --- a/custom_components/localtuya/manifest.json +++ b/custom_components/localtuya/manifest.json @@ -9,5 +9,5 @@ "iot_class": "local_push", "issue_tracker": "https://github.com/xZetsubou/hass-localtuya/issues", "requirements": [], - "version": "2024.12.1" + "version": "2024.12.2" } From db6171c65ce1ce62e47fe064ee95987333939971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ercan=20Aky=C3=BCrek?= Date: Sat, 4 Jan 2025 01:21:30 +0000 Subject: [PATCH 5/9] reverted some changes, removed white channel option in flow, now deriving single channel with existing logic and aligning with current architecture --- custom_components/localtuya/const.py | 1 - custom_components/localtuya/entity.py | 2 +- custom_components/localtuya/light.py | 22 ++++++++++--------- custom_components/localtuya/manifest.json | 2 +- .../localtuya/templates/rgbcct.yaml | 17 ++++++++++++++ .../localtuya/templates/schlafzimmer.yaml | 21 ++++++++++++++++++ .../localtuya/translations/en.json | 1 - .../localtuya/translations/it.json | 1 - .../localtuya/translations/pl.json | 1 - .../localtuya/translations/pt-BR.json | 1 - 10 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 custom_components/localtuya/templates/rgbcct.yaml create mode 100644 custom_components/localtuya/templates/schlafzimmer.yaml diff --git a/custom_components/localtuya/const.py b/custom_components/localtuya/const.py index 371ee2526..bf74e5252 100644 --- a/custom_components/localtuya/const.py +++ b/custom_components/localtuya/const.py @@ -93,7 +93,6 @@ CONF_COLOR_MODE_SET = "color_mode_set" CONF_COLOR_TEMP_MIN_KELVIN = "color_temp_min_kelvin" CONF_COLOR_TEMP_MAX_KELVIN = "color_temp_max_kelvin" -CONF_COLOR_HAS_SINGLE_WHITE_CHANNEL = "color_has_single_white_channel" CONF_COLOR_TEMP_REVERSE = "color_temp_reverse" CONF_MUSIC_MODE = "music_mode" CONF_SCENE_VALUES = "scene_values" diff --git a/custom_components/localtuya/entity.py b/custom_components/localtuya/entity.py index e2d1323e1..b3bc9b74e 100644 --- a/custom_components/localtuya/entity.py +++ b/custom_components/localtuya/entity.py @@ -264,7 +264,7 @@ def device_class(self): def has_config(self, attr) -> bool: """Return if a config parameter has a valid value.""" value = self._config.get(attr, "-1") - return value is not None and value is not False and value != "-1" + return value is not None and value != "-1" def dp_value(self, key, default=None) -> Any | None: """Return cached value for DPS index or Entity Config Key. else default None""" diff --git a/custom_components/localtuya/light.py b/custom_components/localtuya/light.py index 828fad369..694cadbd1 100644 --- a/custom_components/localtuya/light.py +++ b/custom_components/localtuya/light.py @@ -27,7 +27,6 @@ CONF_BRIGHTNESS_LOWER, CONF_BRIGHTNESS_UPPER, CONF_COLOR, - CONF_COLOR_HAS_SINGLE_WHITE_CHANNEL, CONF_COLOR_MODE, CONF_COLOR_MODE_SET, CONF_COLOR_TEMP_MAX_KELVIN, @@ -145,9 +144,6 @@ def flow_schema(dps): vol.Optional(CONF_COLOR_TEMP_MAX_KELVIN, default=DEFAULT_MAX_KELVIN): vol.All( vol.Coerce(int), vol.Range(min=1500, max=8000) ), - vol.Optional( - CONF_COLOR_HAS_SINGLE_WHITE_CHANNEL, default=False - ): selector.BooleanSelector(), vol.Optional(CONF_COLOR_TEMP_REVERSE, default=DEFAULT_COLOR_TEMP_REVERSE): bool, vol.Optional(CONF_SCENE): col_to_select(dps, is_dps=True), vol.Optional(CONF_SCENE_VALUES, default={}): selector.ObjectSelector(), @@ -305,9 +301,12 @@ def supported_color_modes(self) -> set[ColorMode] | set[str] | None: color_modes.add(ColorMode.COLOR_TEMP) if self.has_config(CONF_COLOR): color_modes.add(ColorMode.HS) - if self.has_config(CONF_COLOR_HAS_SINGLE_WHITE_CHANNEL): - color_modes.add(ColorMode.WHITE) - + if ( + self.has_config(CONF_COLOR) + and self.has_config(CONF_BRIGHTNESS) + and not self.has_config(CONF_COLOR_TEMP) + ): + return {ColorMode.HS, ColorMode.WHITE} if not color_modes and self.has_config(CONF_BRIGHTNESS): return {ColorMode.BRIGHTNESS} @@ -356,10 +355,11 @@ def color_mode(self) -> ColorMode: if self.is_color_mode: return ColorMode.HS - if self.is_white_mode and self.has_config(CONF_COLOR_HAS_SINGLE_WHITE_CHANNEL): - return ColorMode.WHITE if self.is_white_mode: - return ColorMode.COLOR_TEMP + if self.has_config(CONF_COLOR_TEMP): + return ColorMode.COLOR_TEMP + if not self.has_config(CONF_COLOR_TEMP): + return ColorMode.WHITE if self._brightness: return ColorMode.BRIGHTNESS @@ -491,6 +491,8 @@ async def async_turn_on(self, **kwargs): states[self._config.get(CONF_COLOR_TEMP)] = color_temp if ATTR_WHITE in kwargs and ColorMode.WHITE in color_modes: + if brightness is None: + brightness = self._brightness states[self._config.get(CONF_COLOR_MODE)] = self._modes.white states[self._config.get(CONF_BRIGHTNESS)] = brightness diff --git a/custom_components/localtuya/manifest.json b/custom_components/localtuya/manifest.json index b6350f8a3..03cbb0f16 100644 --- a/custom_components/localtuya/manifest.json +++ b/custom_components/localtuya/manifest.json @@ -9,5 +9,5 @@ "iot_class": "local_push", "issue_tracker": "https://github.com/xZetsubou/hass-localtuya/issues", "requirements": [], - "version": "2024.12.2" + "version": "2025.1.1" } diff --git a/custom_components/localtuya/templates/rgbcct.yaml b/custom_components/localtuya/templates/rgbcct.yaml new file mode 100644 index 000000000..dbaf01e36 --- /dev/null +++ b/custom_components/localtuya/templates/rgbcct.yaml @@ -0,0 +1,17 @@ +- light: + brightness: '22' + brightness_lower: 10 + brightness_upper: 1000 + color: '24' + color_mode: '21' + color_temp: '23' + color_temp_max_kelvin: 6500 + color_temp_min_kelvin: 2700 + color_temp_reverse: false + entity_category: None + friendly_name: rgbcct + icon: '' + id: '20' + music_mode: false + platform: light + scene_values: {} diff --git a/custom_components/localtuya/templates/schlafzimmer.yaml b/custom_components/localtuya/templates/schlafzimmer.yaml new file mode 100644 index 000000000..36c7d9193 --- /dev/null +++ b/custom_components/localtuya/templates/schlafzimmer.yaml @@ -0,0 +1,21 @@ +- light: + color: "24" + color_mode: "55" + friendly_name: RGB + id: "54" + platform: light +- light: + brightness: "22" + brightness_lower: 10 + brightness_upper: 1000 + color_mode: "21" + color_temp: "23" + color_temp_max_kelvin: 6500 + color_temp_min_kelvin: 2700 + color_temp_reverse: false + entity_category: None + friendly_name: White + id: "63" + music_mode: false + platform: light + scene_values: {} diff --git a/custom_components/localtuya/translations/en.json b/custom_components/localtuya/translations/en.json index 2e95bca96..fed2f0ee7 100644 --- a/custom_components/localtuya/translations/en.json +++ b/custom_components/localtuya/translations/en.json @@ -191,7 +191,6 @@ "color_temp_reverse": "Reverse Color Temperature?", "color": "Color", "color_mode": "Color Mode aka Work Mode", - "color_has_single_white_channel": "Has Single White Channel", "color_temp_min_kelvin": "Minimum Color Temperature in K", "color_temp_max_kelvin": "Maximum Color Temperature in K", "music_mode": "Music mode available?", diff --git a/custom_components/localtuya/translations/it.json b/custom_components/localtuya/translations/it.json index 0224edb3c..994d56b5d 100644 --- a/custom_components/localtuya/translations/it.json +++ b/custom_components/localtuya/translations/it.json @@ -186,7 +186,6 @@ "color_temp_reverse": "Reverse Color Temperature?", "color": "Color", "color_mode": "Color Mode aka Work Mode", - "color_has_single_white_channel": "Has Single White Channel", "color_temp_min_kelvin": "Minimum Color Temperature in K", "color_temp_max_kelvin": "Maximum Color Temperature in K", "music_mode": "Music mode available?", diff --git a/custom_components/localtuya/translations/pl.json b/custom_components/localtuya/translations/pl.json index b0e7bb508..55b5651a5 100644 --- a/custom_components/localtuya/translations/pl.json +++ b/custom_components/localtuya/translations/pl.json @@ -191,7 +191,6 @@ "color_temp_reverse": "Odwrócona temperatura barwy", "color": "Kolor", "color_mode": "Tryb koloru, czyli tryb pracy", - "color_has_single_white_channel": "Has Single White Channel", "color_temp_min_kelvin": "Minimalna temperatura barwowa w K", "color_temp_max_kelvin": "Maksymalna temperatura barwowa w K", "music_mode": "Dostępny tryb muzyczny", diff --git a/custom_components/localtuya/translations/pt-BR.json b/custom_components/localtuya/translations/pt-BR.json index e4cbec792..33dea5769 100644 --- a/custom_components/localtuya/translations/pt-BR.json +++ b/custom_components/localtuya/translations/pt-BR.json @@ -186,7 +186,6 @@ "color_temp_reverse": "Reverse Color Temperature?", "color": "Color", "color_mode": "Color Mode aka Work Mode", - "color_has_single_white_channel": "Has Single White Channel", "color_temp_min_kelvin": "Minimum Color Temperature in K", "color_temp_max_kelvin": "Maximum Color Temperature in K", "music_mode": "Music mode available?", From c15c75397290c640213b591b3e65e2732657c89d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ercan=20Aky=C3=BCrek?= Date: Sat, 4 Jan 2025 01:23:27 +0000 Subject: [PATCH 6/9] reverted some changes, removed white channel option in flow, now deriving single channel with existing logic and aligning with current architecture --- custom_components/localtuya/light.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/custom_components/localtuya/light.py b/custom_components/localtuya/light.py index 694cadbd1..d4a037a85 100644 --- a/custom_components/localtuya/light.py +++ b/custom_components/localtuya/light.py @@ -358,8 +358,7 @@ def color_mode(self) -> ColorMode: if self.is_white_mode: if self.has_config(CONF_COLOR_TEMP): return ColorMode.COLOR_TEMP - if not self.has_config(CONF_COLOR_TEMP): - return ColorMode.WHITE + return ColorMode.WHITE if self._brightness: return ColorMode.BRIGHTNESS From fed6c8546259ddae59f54014fd94226b7c9b8f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ercan=20Aky=C3=BCrek?= Date: Sat, 4 Jan 2025 01:25:02 +0000 Subject: [PATCH 7/9] removed some templates which are pushed by accident --- .../localtuya/templates/rgbcct.yaml | 17 --------------- .../localtuya/templates/schlafzimmer.yaml | 21 ------------------- 2 files changed, 38 deletions(-) delete mode 100644 custom_components/localtuya/templates/rgbcct.yaml delete mode 100644 custom_components/localtuya/templates/schlafzimmer.yaml diff --git a/custom_components/localtuya/templates/rgbcct.yaml b/custom_components/localtuya/templates/rgbcct.yaml deleted file mode 100644 index dbaf01e36..000000000 --- a/custom_components/localtuya/templates/rgbcct.yaml +++ /dev/null @@ -1,17 +0,0 @@ -- light: - brightness: '22' - brightness_lower: 10 - brightness_upper: 1000 - color: '24' - color_mode: '21' - color_temp: '23' - color_temp_max_kelvin: 6500 - color_temp_min_kelvin: 2700 - color_temp_reverse: false - entity_category: None - friendly_name: rgbcct - icon: '' - id: '20' - music_mode: false - platform: light - scene_values: {} diff --git a/custom_components/localtuya/templates/schlafzimmer.yaml b/custom_components/localtuya/templates/schlafzimmer.yaml deleted file mode 100644 index 36c7d9193..000000000 --- a/custom_components/localtuya/templates/schlafzimmer.yaml +++ /dev/null @@ -1,21 +0,0 @@ -- light: - color: "24" - color_mode: "55" - friendly_name: RGB - id: "54" - platform: light -- light: - brightness: "22" - brightness_lower: 10 - brightness_upper: 1000 - color_mode: "21" - color_temp: "23" - color_temp_max_kelvin: 6500 - color_temp_min_kelvin: 2700 - color_temp_reverse: false - entity_category: None - friendly_name: White - id: "63" - music_mode: false - platform: light - scene_values: {} From 6e6105f5d74c4539da2634acd7802a9881ec4e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ercan=20Aky=C3=BCrek?= Date: Sun, 5 Jan 2025 16:49:41 +0000 Subject: [PATCH 8/9] changed supported_color_modes slightly for better readability --- custom_components/localtuya/light.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/custom_components/localtuya/light.py b/custom_components/localtuya/light.py index d4a037a85..096cdb7a5 100644 --- a/custom_components/localtuya/light.py +++ b/custom_components/localtuya/light.py @@ -297,17 +297,16 @@ def supported_color_modes(self) -> set[ColorMode] | set[str] | None: """Flag supported color modes.""" color_modes: set[ColorMode] = set() - if self.has_config(CONF_COLOR_TEMP): - color_modes.add(ColorMode.COLOR_TEMP) + if self.has_config(CONF_BRIGHTNESS): + if self.has_config(CONF_COLOR_TEMP): + color_modes.add(ColorMode.COLOR_TEMP) + else: + color_modes.add(ColorMode.WHITE) + if self.has_config(CONF_COLOR): color_modes.add(ColorMode.HS) - if ( - self.has_config(CONF_COLOR) - and self.has_config(CONF_BRIGHTNESS) - and not self.has_config(CONF_COLOR_TEMP) - ): - return {ColorMode.HS, ColorMode.WHITE} - if not color_modes and self.has_config(CONF_BRIGHTNESS): + + if color_modes == {ColorMode.WHITE}: return {ColorMode.BRIGHTNESS} if not color_modes: From 395f6d8253b417c612e350e7c6ceaa4e13fc5601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ercan=20Aky=C3=BCrek?= Date: Mon, 6 Jan 2025 08:38:59 +0000 Subject: [PATCH 9/9] changed supported modes 'brigthness' logic a bit --- custom_components/localtuya/light.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/custom_components/localtuya/light.py b/custom_components/localtuya/light.py index 096cdb7a5..f64496930 100644 --- a/custom_components/localtuya/light.py +++ b/custom_components/localtuya/light.py @@ -297,11 +297,12 @@ def supported_color_modes(self) -> set[ColorMode] | set[str] | None: """Flag supported color modes.""" color_modes: set[ColorMode] = set() - if self.has_config(CONF_BRIGHTNESS): - if self.has_config(CONF_COLOR_TEMP): - color_modes.add(ColorMode.COLOR_TEMP) - else: - color_modes.add(ColorMode.WHITE) + if self.has_config(CONF_COLOR_TEMP): + color_modes.add(ColorMode.COLOR_TEMP) + elif self.has_config(CONF_BRIGHTNESS): + color_modes.add(ColorMode.WHITE) + if self.has_config(CONF_COLOR): + color_modes.add(ColorMode.HS) if self.has_config(CONF_COLOR): color_modes.add(ColorMode.HS)