From dfbf20e2eadecf442339b3b122e352b8279a3f8e Mon Sep 17 00:00:00 2001 From: Raul Go Date: Fri, 8 Nov 2024 23:50:35 +0100 Subject: [PATCH] HA 2025.3 deprecated warning fix (#25) * fix 2025.3 warning message * version bump --- custom_components/lednetwf_ble/lednetwf.py | 8 +++----- custom_components/lednetwf_ble/light.py | 16 +++++++++++++--- custom_components/lednetwf_ble/manifest.json | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/custom_components/lednetwf_ble/lednetwf.py b/custom_components/lednetwf_ble/lednetwf.py index 5a05e4c..4107672 100644 --- a/custom_components/lednetwf_ble/lednetwf.py +++ b/custom_components/lednetwf_ble/lednetwf.py @@ -165,7 +165,7 @@ def __init__(self, mac, hass, data={}, options={}) -> None: self._min_color_temp_kelvin = 2700 self._max_color_temp_kelvin = 6500 self._model = self._detect_model(service_info['manufacturer_data']) - self._color_mode = ColorMode.HS if self._model == RING_LIGHT_MODEL else ColorMode.RGB #COlorMode.RGB IS GETTING DEPRECATED, CHANGE !!!!!!!!!! + self._color_mode = ColorMode.HS if self._model == RING_LIGHT_MODEL else ColorMode.RGB self._write_uuid = None self._read_uuid = None self._led_count = options.get(CONF_LEDCOUNT, None) @@ -195,7 +195,8 @@ def _detect_model(self, manu_data): formatted_str = ' '.join(formatted) self.log(f"DM:\t\t Manu data: {formatted_str}") - self._color_mode = ColorMode.BRIGHTNESS ## ColorMode.Brigtness is getting deprecated, change !!!!!!!!!!! + self._color_mode = ColorMode.UNKNOWN + # 2025.3 Setting color mode as UNKNOWN will avoid throwing error on unsupported color mode self._fw_major = manu_data_data[0] self._fw_minor = f'{manu_data_data[8]:02X}{manu_data_data[9]:02X}.{manu_data_data[10]:02X}' @@ -206,9 +207,6 @@ def _detect_model(self, manu_data): # Colour mode (RGB & Whites) and "Static" effects if manu_data_data[16] == 0xf0: # RGB Mode - - ### ColorMode.RGB is getting deprecated, change !!!!!!!!!!!! - r,g,b = manu_data_data[18], manu_data_data[19], manu_data_data[20] if self._fw_major == RING_LIGHT_MODEL: self._rgb_color = (r,g,b) diff --git a/custom_components/lednetwf_ble/light.py b/custom_components/lednetwf_ble/light.py index f8dd064..01f4935 100644 --- a/custom_components/lednetwf_ble/light.py +++ b/custom_components/lednetwf_ble/light.py @@ -44,11 +44,14 @@ def __init__( ) -> None: self._instance = lednetwfinstance self._entry_id = entry_id + # 2025.3 ColorMode.BRIGHTNESS should not be specified with other combination of supported color modes, as it will throw an error, but is is supported + # when lights are rendering an effect automatically + # https://developers.home-assistant.io/docs/core/entity/light/#color-modes if self._instance._model == RING_LIGHT_MODEL: - self._attr_supported_color_modes = {ColorMode.BRIGHTNESS, ColorMode.COLOR_TEMP, ColorMode.HS} + self._attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS} self._color_temp_kelvin: self._instance._color_temp_kelvin else: - self._attr_supported_color_modes = {ColorMode.BRIGHTNESS, ColorMode.RGB} + self._attr_supported_color_modes = {ColorMode.RGB} self._attr_supported_features = LightEntityFeature.EFFECT self._attr_name = name self._attr_unique_id = self._instance.mac @@ -218,7 +221,14 @@ def light_local_callback(self): def update_ha_state(self) -> None: LOGGER.debug("update_ha_state called") if self.hs_color is None and self.color_temp_kelvin is None and self.rgb_color is None: - self._color_mode = ColorMode.BRIGHTNESS #2024.2 We can use brightness color mode so even when we don't know the state of the light the brightness can be controlled + if self._instance._effect is not None and self._instance._effect is not EFFECT_OFF: + self._color_mode = ColorMode.BRIGHTNESS + #2024.2 We can use brightness color mode so even when we don't know the state of the light the brightness can be controlled + #2025.3 ColorMode.BRIGHTNESS is not considered a valid supported color when on standalone, this gets ignored when + #light is rendering an effect + else: + self._color_mode = ColorMode.UNKNOWN + #2025.3 When not sure of color mode ColorMode.UNKNOWN avoids throwing errors on unsupported combination of color modes elif self.hs_color is not None: self._color_mode = ColorMode.HS elif self.rgb_color is not None: diff --git a/custom_components/lednetwf_ble/manifest.json b/custom_components/lednetwf_ble/manifest.json index 937e45d..06c3c83 100644 --- a/custom_components/lednetwf_ble/manifest.json +++ b/custom_components/lednetwf_ble/manifest.json @@ -22,5 +22,5 @@ "bleak-retry-connector>=1.17.1", "bleak>=0.17.0" ], - "version": "0.0.10" + "version": "0.0.12" }