For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /developers/blog/2026-02-23-remove-deprecate-light-features.md.

移除已弃用的 light features

变更摘要

2022 年 10 月,Home Assistant 将首选色温单位从 mired 迁移到了 kelvin。

2024 年 2 月,Home Assistant 要求显式提供 supported_color_modescolor_mode 属性(触发了对传统 fallback color mode 支持的弃用)。

2024 年 12 月,Home Assistant 要求显式支持 Kelvin(触发了对 mired 支持的弃用)。

现在是清理遗留代码并移除相应属性、常量和属性的时候了:

  • 移除已弃用的 ATTR_COLOR_TEMPATTR_MIN_MIREDSATTR_MAX_MIREDSATTR_KELVINCOLOR_MODE_***SUPPORT_*** 常量
  • 移除已弃用的 state 属性 ATTR_COLOR_TEMPATTR_MIN_MIREDSATTR_MAX_MIREDS
  • 移除 light.turn_on 服务调用中对 ATTR_KELVINATTR_COLOR_TEMP 参数的已弃用支持
  • 移除 entity 中对 LightEntity.color_tempLightEntity.min_miredsLightEntity.max_mireds 属性的已弃用支持
  • 移除 entity 中对 LightEntity._attr_color_tempLightEntity._attr_min_miredsLightEntity._attr_max_mireds 简写属性的已弃用支持

此外,未提供有效的 supported_color_modescolor_mode 属性将不再可行,并会引发错误。

示例

自定义最小/最大色温

class MyLight(LightEntity):
    """Representation of a light."""

    # 旧
    # _attr_min_mireds = 200 # 5000K
    # _attr_max_mireds = 400 # 2500K

    # 新
    _attr_min_color_temp_kelvin = 2500 # 400 mireds
    _attr_max_color_temp_kelvin = 5000 # 200 mireds

默认最小/最大色温

from homeassistant.components.light import DEFAULT_MAX_KELVIN, DEFAULT_MIN_KELVIN

class MyLight(LightEntity):
    """Representation of a light."""

    # 旧方式无需设置 _attr_min_mireds / _attr_max_mireds
    # 新方式需要显式设置默认值
    _attr_min_color_temp_kelvin = DEFAULT_MIN_KELVIN
    _attr_max_color_temp_kelvin = DEFAULT_MAX_KELVIN

动态最小/最大色温

from homeassistant.util import color as color_util

class MyLight(LightEntity):
    """Representation of a light."""

    # 旧
    # def min_mireds(self) -> int:
    #     """Return the coldest color_temp that this light supports."""
    #     return device.coldest_temperature
    #
    # def max_mireds(self) -> int:
    #     """Return the warmest color_temp that this light supports."""
    #     return device.warmest_temperature

    # 新
    def min_color_temp_kelvin(self) -> int:
        """Return the warmest color_temp that this light supports."""
        return color_util.color_temperature_mired_to_kelvin(device.warmest_temperature)

    def max_color_temp_kelvin(self) -> int:
        """Return the coldest color_temp that this light supports."""
        return color_util.color_temperature_mired_to_kelvin(device.coldest_temperature)

在服务调用中检查色温

from homeassistant.components.light import ATTR_COLOR_TEMP_KELVIN
from homeassistant.util import color as color_util

class MyLight(LightEntity):
    """Representation of a light."""
    def turn_on(self, **kwargs: Any) -> None:
        """Turn on the light."""
        # 旧
        # if ATTR_COLOR_TEMP in kwargs:
        #     color_temp_mired = kwargs[ATTR_COLOR_TEMP]
        #     color_temp_kelvin = color_util.color_temperature_mired_to_kelvin(color_temp_mired)

        # 旧
        # if ATTR_KELVIN in kwargs:
        #     color_temp_kelvin = kwargs[ATTR_KELVIN]
        #     color_temp_mired = color_util.color_temperature_kelvin_to_mired(color_temp_kelvin)

        # 新
        if ATTR_COLOR_TEMP_KELVIN in kwargs:
            color_temp_kelvin = kwargs[ATTR_COLOR_TEMP_KELVIN]
            color_temp_mired = color_util.color_temperature_kelvin_to_mired(color_temp_kelvin)

背景信息