Fix LightEntity AttributeError: remove deprecated _attr_color_temp and mireds#2794
Conversation
…d 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
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical compatibility issue with Home Assistant 2025.x+ by updating the xiaomi_miot integration to align with recent changes in the LightEntity class. It transitions from deprecated mireds-based color temperature attributes to the new kelvin-based attributes, preventing runtime errors and ensuring that Xiaomi lights with mireds-based color temperature continue to function correctly. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses an AttributeError caused by the deprecation of mired-based color temperature attributes in Home Assistant. The changes successfully migrate to the new kelvin-based attributes, including the necessary conversions. The logic appears sound. I have a couple of minor suggestions to improve code readability.
| 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 |
There was a problem hiding this comment.
For better readability of large numbers, you can use underscores as a visual separator. This would make the conversion factor 1000000 easier to read.
| 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 | |
There was a problem hiding this comment.
Good catch, thanks! Applied 1_000_000 across all three occurrences in 53ee93d.
| 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 |
There was a problem hiding this comment.
Fixed in the same commit — now uses 1_000_000 here as well.
Replace 1000000 with 1_000_000 in mireds-to-kelvin conversions as suggested in code review.
Summary
Fixes
AttributeError: 'LightEntity' object has no attribute '_attr_color_temp'on Home Assistant 2025.x+ for lights using mireds-based color temperature.In recent HA versions,
_attr_color_temp(mireds),_attr_min_mireds, and_attr_max_miredswere removed fromLightEntity. Only kelvin-based attributes remain:_attr_color_temp_kelvin,_attr_min_color_temp_kelvin,_attr_max_color_temp_kelvin.Error
This error fires on every state update for any Xiaomi light that reports color temperature in mireds.
Changes
on_init: Convert mireds range to kelvin (1000000 / mireds) instead of setting removed_attr_min_mireds/_attr_max_miredsget_state: Return_attr_color_temp_kelvininstead of removed_attr_color_tempset_state: Convert incoming mireds values to kelvin before storing in_attr_color_temp_kelvinTesting
AttributeError