From b5e63bed6e76b96f9bacc7a6501afb9db053dd97 Mon Sep 17 00:00:00 2001 From: monty68 <4341648+monty68@users.noreply.github.com> Date: Tue, 20 Feb 2024 07:37:08 +0000 Subject: [PATCH 1/4] Fix Issue #57 - SP617E detection --- custom_components/uniled/lib/ble/banlanx2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/uniled/lib/ble/banlanx2.py b/custom_components/uniled/lib/ble/banlanx2.py index 40003d8..955dbd4 100644 --- a/custom_components/uniled/lib/ble/banlanx2.py +++ b/custom_components/uniled/lib/ble/banlanx2.py @@ -707,7 +707,9 @@ def fetch_chip_order_list( id=0x617E, name="SP617E", info="SPI RGB(W) (Music) Controller", - data=b"\x17\x10", + # Fix: Issue #57 - Second byte can be different so only check first byte + # data=b"\x17\x10", + data=b"\x17", colors=4, intmic=True, ) From e411ec6e5162c77d00fb4f319344009c577feda8 Mon Sep 17 00:00:00 2001 From: monty68 <4341648+monty68@users.noreply.github.com> Date: Tue, 20 Feb 2024 07:38:45 +0000 Subject: [PATCH 2/4] Bump --- custom_components/uniled/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/uniled/manifest.json b/custom_components/uniled/manifest.json index c3d6e7a..1ebdedb 100644 --- a/custom_components/uniled/manifest.json +++ b/custom_components/uniled/manifest.json @@ -19,5 +19,5 @@ "pycryptodome>=3.17", "cryptography" ], - "version": "2.2.4" + "version": "2.2.5" } From 37408480106ef8373ec12214f7a0378289b8695f Mon Sep 17 00:00:00 2001 From: monty68 <4341648+monty68@users.noreply.github.com> Date: Tue, 20 Feb 2024 07:39:45 +0000 Subject: [PATCH 3/4] Bump --- README.md | 2 +- info.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 288906c..8ceb26f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![GitHub Activity][commits-shield]][commits] [![License][license-shield]][license] -# ![HA][ha-logo] UniLED v2.2.0 - The Universal Light Controller +# ![HA][ha-logo] UniLED v2.2.5 - The Universal Light Controller ### UniLED supports the following range of BLE LED controllers: diff --git a/info.md b/info.md index 71507d9..42a8d44 100644 --- a/info.md +++ b/info.md @@ -5,7 +5,7 @@ [![GitHub Activity][commits-shield]][commits] [![License][license-shield]][license] -# UniLED v2.2.0 - The Universal Light Controller +# UniLED v2.2.5 - The Universal Light Controller ### UniLED supports the following range of BLE LED controllers: From 0335ab7bdb6b7fa88e5ba70a3abb75f38f288e10 Mon Sep 17 00:00:00 2001 From: monty68 <4341648+monty68@users.noreply.github.com> Date: Tue, 20 Feb 2024 07:51:48 +0000 Subject: [PATCH 4/4] supported_color_modes must be a set --- custom_components/uniled/lib/ble/banlanx2.py | 12 ++++++------ custom_components/uniled/lib/ble/banlanx3.py | 12 ++++++------ custom_components/uniled/lib/ble/banlanx_6xx.py | 10 +++++----- custom_components/uniled/light.py | 10 +++++++++- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/custom_components/uniled/lib/ble/banlanx2.py b/custom_components/uniled/lib/ble/banlanx2.py index 955dbd4..eaa4448 100644 --- a/custom_components/uniled/lib/ble/banlanx2.py +++ b/custom_components/uniled/lib/ble/banlanx2.py @@ -435,7 +435,7 @@ def parse_notifications( { ATTR_UL_DEVICE_FORCE_REFRESH: True, ATTR_UL_POWER: data[0] == 1, - ATTR_HA_SUPPORTED_COLOR_MODES: [COLOR_MODE_BRIGHTNESS], + ATTR_HA_SUPPORTED_COLOR_MODES: {COLOR_MODE_BRIGHTNESS}, ATTR_HA_COLOR_MODE: COLOR_MODE_BRIGHTNESS, ATTR_UL_CHIP_ORDER: self.chip_order_name( UNILED_CHIP_ORDER_RGBW @@ -465,10 +465,10 @@ def parse_notifications( if self.colors == 4: device.master.set(ATTR_HA_WHITE, cold) device.master.set( - ATTR_HA_SUPPORTED_COLOR_MODES, [COLOR_MODE_RGB, COLOR_MODE_WHITE] + ATTR_HA_SUPPORTED_COLOR_MODES, {COLOR_MODE_RGB, COLOR_MODE_WHITE} ) else: - device.master.set(ATTR_HA_SUPPORTED_COLOR_MODES, [COLOR_MODE_RGB]) + device.master.set(ATTR_HA_SUPPORTED_COLOR_MODES, {COLOR_MODE_RGB}) if effect in BANLANX2_EFFECTS_SOUND: device.master.set(ATTR_UL_EFFECT_TYPE, UNILED_EFFECT_TYPE_SOUND) @@ -477,7 +477,7 @@ def parse_notifications( ATTR_UL_AUDIO_INPUT, self.str_if_key_in(input, BANLANX2_AUDIO_INPUTS, UNILED_UNKNOWN), ) - device.master.set(ATTR_HA_SUPPORTED_COLOR_MODES, [COLOR_MODE_ONOFF]) + device.master.set(ATTR_HA_SUPPORTED_COLOR_MODES, {COLOR_MODE_ONOFF}) device.master.set(ATTR_HA_COLOR_MODE, COLOR_MODE_ONOFF) device.master.set(ATTR_UL_COLOR_LEVEL, level) device.master.set(ATTR_HA_BRIGHTNESS, None) @@ -486,7 +486,7 @@ def parse_notifications( if effect == BANLANX2_EFFECT_WHITE: device.master.set( ATTR_HA_SUPPORTED_COLOR_MODES, - [COLOR_MODE_RGB, COLOR_MODE_WHITE], + {COLOR_MODE_RGB, COLOR_MODE_WHITE}, ) device.master.set(ATTR_HA_COLOR_MODE, COLOR_MODE_WHITE) device.master.set(ATTR_HA_BRIGHTNESS, cold) @@ -505,7 +505,7 @@ def parse_notifications( device.master.set(ATTR_UL_EFFECT_LENGTH, length) device.master.set(ATTR_UL_EFFECT_TYPE, UNILED_EFFECT_TYPE_DYNAMIC) elif mode == BANLANX2_LIGHT_MODE_AUTO_SOUND: - device.master.set(ATTR_HA_SUPPORTED_COLOR_MODES, [COLOR_MODE_ONOFF]) + device.master.set(ATTR_HA_SUPPORTED_COLOR_MODES, {COLOR_MODE_ONOFF}) device.master.set(ATTR_HA_COLOR_MODE, COLOR_MODE_ONOFF) device.master.set(ATTR_UL_COLOR_LEVEL, level) device.master.set(ATTR_HA_BRIGHTNESS, None) diff --git a/custom_components/uniled/lib/ble/banlanx3.py b/custom_components/uniled/lib/ble/banlanx3.py index 5e0d2a0..375b240 100644 --- a/custom_components/uniled/lib/ble/banlanx3.py +++ b/custom_components/uniled/lib/ble/banlanx3.py @@ -285,7 +285,7 @@ def parse_notifications( { ATTR_UL_DEVICE_FORCE_REFRESH: True, ATTR_UL_POWER: data[0] == 1, - ATTR_HA_SUPPORTED_COLOR_MODES: [COLOR_MODE_BRIGHTNESS], + ATTR_HA_SUPPORTED_COLOR_MODES: {COLOR_MODE_BRIGHTNESS}, ATTR_HA_COLOR_MODE: COLOR_MODE_BRIGHTNESS, ATTR_UL_CHIP_ORDER: self.chip_order_name( UNILED_CHIP_ORDER_RGBW @@ -315,10 +315,10 @@ def parse_notifications( if self.colors == 4: device.master.set(ATTR_HA_WHITE, cold) device.master.set( - ATTR_HA_SUPPORTED_COLOR_MODES, [COLOR_MODE_RGB, COLOR_MODE_WHITE] + ATTR_HA_SUPPORTED_COLOR_MODES, {COLOR_MODE_RGB, COLOR_MODE_WHITE} ) else: - device.master.set(ATTR_HA_SUPPORTED_COLOR_MODES, [COLOR_MODE_RGB]) + device.master.set(ATTR_HA_SUPPORTED_COLOR_MODES, {COLOR_MODE_RGB}) if effect >= BANLANX3_EFFECT_SOUND and effect < BANLANX3_EFFECT_WHITE: device.master.set(ATTR_UL_EFFECT_TYPE, UNILED_EFFECT_TYPE_SOUND) @@ -327,7 +327,7 @@ def parse_notifications( ATTR_UL_AUDIO_INPUT, self.str_if_key_in(input, BANLANX3_AUDIO_INPUTS, UNILED_UNKNOWN), ) - device.master.set(ATTR_HA_SUPPORTED_COLOR_MODES, [COLOR_MODE_ONOFF]) + device.master.set(ATTR_HA_SUPPORTED_COLOR_MODES, {COLOR_MODE_ONOFF}) device.master.set(ATTR_HA_COLOR_MODE, COLOR_MODE_ONOFF) device.master.set(ATTR_UL_COLOR_LEVEL, level) device.master.set(ATTR_HA_BRIGHTNESS, None) @@ -336,7 +336,7 @@ def parse_notifications( if effect == BANLANX3_EFFECT_WHITE: device.master.set( ATTR_HA_SUPPORTED_COLOR_MODES, - [COLOR_MODE_RGB, COLOR_MODE_WHITE], + {COLOR_MODE_RGB, COLOR_MODE_WHITE}, ) device.master.set(ATTR_HA_COLOR_MODE, COLOR_MODE_WHITE) device.master.set(ATTR_HA_BRIGHTNESS, cold) @@ -355,7 +355,7 @@ def parse_notifications( elif mode == BANLANX3_LIGHT_MODE_AUTO_SOUND: device.master.set(ATTR_UL_EFFECT_TYPE, UNILED_EFFECT_TYPE_SOUND) device.master.set(ATTR_UL_SENSITIVITY, gain) - device.master.set(ATTR_HA_SUPPORTED_COLOR_MODES, [COLOR_MODE_ONOFF]) + device.master.set(ATTR_HA_SUPPORTED_COLOR_MODES, {COLOR_MODE_ONOFF}) device.master.set(ATTR_HA_COLOR_MODE, COLOR_MODE_ONOFF) device.master.set(ATTR_UL_COLOR_LEVEL, level) device.master.set(ATTR_HA_BRIGHTNESS, None) diff --git a/custom_components/uniled/lib/ble/banlanx_6xx.py b/custom_components/uniled/lib/ble/banlanx_6xx.py index c930d15..bddaeb6 100644 --- a/custom_components/uniled/lib/ble/banlanx_6xx.py +++ b/custom_components/uniled/lib/ble/banlanx_6xx.py @@ -1067,21 +1067,21 @@ def parse_notifications( device.master.set(ATTR_HA_RGBW_COLOR, (data[37], data[38], data[39], white_level)) elif cfg.hue or cfg.cct or cfg.white: white_mode = COLOR_MODE_BRIGHTNESS - supported_color_modes = [] + supported_color_modes = set() if cfg.hue: device.master.set(ATTR_HA_RGB_COLOR, (data[37], data[38], data[39])) - supported_color_modes.append(COLOR_MODE_RGB) + supported_color_modes.add(COLOR_MODE_RGB) if cfg.cct: device.master.set(ATTR_UL_CCT_COLOR, (data[40], data[41], white_level, None)) white_mode = COLOR_MODE_COLOR_TEMP - supported_color_modes.append(white_mode) + supported_color_modes.add(white_mode) elif cfg.white and cfg.hue: device.master.set(ATTR_HA_WHITE, white_level) white_mode = COLOR_MODE_WHITE - supported_color_modes.append(white_mode) + supported_color_modes.add(white_mode) else: - supported_color_modes = [white_mode] + supported_color_modes = set(white_mode) device.master.set(ATTR_HA_SUPPORTED_COLOR_MODES, supported_color_modes) device.master.set(ATTR_HA_COLOR_MODE, COLOR_MODE_RGB diff --git a/custom_components/uniled/light.py b/custom_components/uniled/light.py index b11d16b..c1ef128 100644 --- a/custom_components/uniled/light.py +++ b/custom_components/uniled/light.py @@ -156,7 +156,15 @@ def color_mode(self) -> ColorMode | str | None: @property def supported_color_modes(self) -> set[ColorMode] | set[str] | None: - """Flag supported color modes.""" + """Supported color modes.""" + modes = self.__supported_color_modes + if not isinstance(modes, set): + _LOGGER.warning("%s: Modes: %s is not a set!", self.device.name, modes) + return modes + + @property + def __supported_color_modes(self) -> set[ColorMode] | set[str] | None: + """Supported color modes.""" if self.channel.has(ATTR_SUPPORTED_COLOR_MODES): return self.channel.get(ATTR_SUPPORTED_COLOR_MODES, {ColorMode.ONOFF}) elif self.channel.has(ATTR_RGBWW_COLOR):