From 0133d7132a9b5f4e0874bd2e95eb0fe2e3230f79 Mon Sep 17 00:00:00 2001 From: SMKRV Date: Sun, 8 Mar 2026 02:57:13 +0300 Subject: [PATCH 1/2] Fix LightEntity AttributeError: remove deprecated _attr_color_temp and mireds In Home Assistant 2025.x+, `_attr_color_temp` (mireds) and `_attr_min_mireds`/`_attr_max_mireds` were removed from `LightEntity`. Only kelvin-based attributes remain (`_attr_color_temp_kelvin`, `_attr_min_color_temp_kelvin`, `_attr_max_color_temp_kelvin`). This causes an `AttributeError` on every state update for lights that use mireds-based color temperature: AttributeError: 'LightEntity' object has no attribute '_attr_color_temp'. Did you mean: '_attr_color_mode'? Changes: - on_init: convert mireds range to kelvin using 1000000/mireds formula - get_state: use _attr_color_temp_kelvin instead of _attr_color_temp - set_state: convert incoming mireds values to kelvin before storing --- custom_components/xiaomi_miot/light.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/custom_components/xiaomi_miot/light.py b/custom_components/xiaomi_miot/light.py index 3d695a094..b6417e76d 100644 --- a/custom_components/xiaomi_miot/light.py +++ b/custom_components/xiaomi_miot/light.py @@ -103,8 +103,11 @@ def on_init(self): self._attr_max_color_temp_kelvin = prop.range_max() self._attr_names[ATTR_COLOR_TEMP_KELVIN] = attr else: - self._attr_min_mireds = prop.range_min() - self._attr_max_mireds = prop.range_max() + # Convert mireds range to kelvin (mireds min -> kelvin max) + mireds_min = prop.range_min() + mireds_max = prop.range_max() + self._attr_min_color_temp_kelvin = int(1000000 / mireds_max) if mireds_max else 2000 + self._attr_max_color_temp_kelvin = int(1000000 / mireds_min) if mireds_min else 6500 self._attr_names[ATTR_COLOR_TEMP] = attr elif prop.in_list(['color', color_property]) or isinstance(conv, MiotRgbColorConv): self._attr_names[ATTR_RGB_COLOR] = attr @@ -120,7 +123,7 @@ def get_state(self) -> dict: return { self.attr: self._attr_is_on, ATTR_BRIGHTNESS: self._attr_brightness, - ATTR_COLOR_TEMP: self._attr_color_temp, + ATTR_COLOR_TEMP_KELVIN: self._attr_color_temp_kelvin, } def set_state(self, data: dict): @@ -137,8 +140,9 @@ def set_state(self, data: dict): self._attr_color_temp_kelvin = val self._attr_color_mode = ColorMode.COLOR_TEMP elif (val := data.get(self._attr_names.get(ATTR_COLOR_TEMP))) is not None: - if val != self._attr_color_temp: - self._attr_color_temp = val + kelvin = int(1000000 / val) if val else None + if kelvin and kelvin != self._attr_color_temp_kelvin: + self._attr_color_temp_kelvin = kelvin self._attr_color_mode = ColorMode.COLOR_TEMP if (val := data.get(self._attr_names.get(ATTR_RGB_COLOR))) is not None: if val != self._attr_rgb_color: From 53ee93d61cc789e6f7f103b7cc19b38cd0dba0c7 Mon Sep 17 00:00:00 2001 From: SMKRV Date: Sun, 8 Mar 2026 21:17:01 +0300 Subject: [PATCH 2/2] style: use underscores in numeric literals for readability Replace 1000000 with 1_000_000 in mireds-to-kelvin conversions as suggested in code review. --- custom_components/xiaomi_miot/light.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/xiaomi_miot/light.py b/custom_components/xiaomi_miot/light.py index b6417e76d..f34c6e49e 100644 --- a/custom_components/xiaomi_miot/light.py +++ b/custom_components/xiaomi_miot/light.py @@ -106,8 +106,8 @@ def on_init(self): # Convert mireds range to kelvin (mireds min -> kelvin max) mireds_min = prop.range_min() mireds_max = prop.range_max() - self._attr_min_color_temp_kelvin = int(1000000 / mireds_max) if mireds_max else 2000 - self._attr_max_color_temp_kelvin = int(1000000 / mireds_min) if mireds_min else 6500 + self._attr_min_color_temp_kelvin = int(1_000_000 / mireds_max) if mireds_max else 2000 + self._attr_max_color_temp_kelvin = int(1_000_000 / mireds_min) if mireds_min else 6500 self._attr_names[ATTR_COLOR_TEMP] = attr elif prop.in_list(['color', color_property]) or isinstance(conv, MiotRgbColorConv): self._attr_names[ATTR_RGB_COLOR] = attr @@ -140,7 +140,7 @@ def set_state(self, data: dict): self._attr_color_temp_kelvin = val self._attr_color_mode = ColorMode.COLOR_TEMP elif (val := data.get(self._attr_names.get(ATTR_COLOR_TEMP))) is not None: - kelvin = int(1000000 / val) if val else None + kelvin = int(1_000_000 / val) if val else None if kelvin and kelvin != self._attr_color_temp_kelvin: self._attr_color_temp_kelvin = kelvin self._attr_color_mode = ColorMode.COLOR_TEMP