Skip to content

Fix LightEntity AttributeError: remove deprecated _attr_color_temp and mireds#2794

Merged
al-one merged 2 commits intoal-one:masterfrom
smkrv:fix/light-remove-deprecated-color-temp-mireds
Mar 9, 2026
Merged

Fix LightEntity AttributeError: remove deprecated _attr_color_temp and mireds#2794
al-one merged 2 commits intoal-one:masterfrom
smkrv:fix/light-remove-deprecated-color-temp-mireds

Conversation

@smkrv
Copy link
Contributor

@smkrv smkrv commented Mar 7, 2026

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_mireds were removed from LightEntity. Only kelvin-based attributes remain: _attr_color_temp_kelvin, _attr_min_color_temp_kelvin, _attr_max_color_temp_kelvin.

Error

File "custom_components/xiaomi_miot/light.py", line 123, in get_state
    ATTR_COLOR_TEMP: self._attr_color_temp,
                     ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'LightEntity' object has no attribute '_attr_color_temp'. Did you mean: '_attr_color_mode'?

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_mireds
  • get_state: Return _attr_color_temp_kelvin instead of removed _attr_color_temp
  • set_state: Convert incoming mireds values to kelvin before storing in _attr_color_temp_kelvin

Testing

  • Tested on HA 2026.3.0 with xiaomi_miot 1.1.2
  • Lights with mireds-based color temp no longer produce AttributeError
  • Kelvin and percentage-based lights are unaffected (different code path)

…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
@gemini-code-assist
Copy link

Summary of Changes

Hello, 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

  • Deprecated Attributes: Replaced deprecated _attr_color_temp, _attr_min_mireds, and _attr_max_mireds with their kelvin-based equivalents (_attr_color_temp_kelvin, _attr_min_color_temp_kelvin, _attr_max_color_temp_kelvin) to ensure compatibility with Home Assistant 2025.x+.
  • Color Temperature Conversion: Implemented logic to convert mireds values to kelvin for color temperature ranges during initialization and for incoming state updates, maintaining correct color temperature representation.
  • Error Resolution: Fixed AttributeError: 'LightEntity' object has no attribute '_attr_color_temp' that occurred on Home Assistant 2025.x+ for lights reporting mireds-based color temperature.
Changelog
  • custom_components/xiaomi_miot/light.py
    • Updated the on_init method to convert mireds range values to kelvin and assign them to _attr_min_color_temp_kelvin and _attr_max_color_temp_kelvin, replacing the use of deprecated mireds attributes.
    • Modified the get_state method to return _attr_color_temp_kelvin instead of the removed _attr_color_temp.
    • Adjusted the set_state method to convert incoming mireds color temperature values to kelvin before storing them in _attr_color_temp_kelvin.
Activity
  • No human activity has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +109 to +110
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability of large numbers, you can use underscores as a visual separator. This would make the conversion factor 1000000 easier to read.

Suggested change
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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability of large numbers, you can use underscores as a visual separator. This would make the conversion factor 1000000 easier to read.

            kelvin = int(1_000_000 / val) if val else None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants