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):