mirror of
https://github.com/home-assistant/core.git
synced 2026-02-14 23:28:42 +00:00
Raise error when light reports invalid supported color modes (#162644)
This commit is contained in:
@@ -993,26 +993,13 @@ class LightEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
||||
supported_color_modes: set[ColorMode],
|
||||
) -> None:
|
||||
"""Validate the supported color modes."""
|
||||
if self.__color_mode_reported:
|
||||
return
|
||||
|
||||
try:
|
||||
valid_supported_color_modes(supported_color_modes)
|
||||
except vol.Error:
|
||||
# Warning added in 2024.3, reject in 2025.3
|
||||
if not self.__color_mode_reported and self.__should_report_light_issue():
|
||||
self.__color_mode_reported = True
|
||||
report_issue = self._suggest_report_issue()
|
||||
_LOGGER.warning(
|
||||
(
|
||||
"%s (%s) sets invalid supported color modes %s, this will stop "
|
||||
"working in Home Assistant Core 2025.3, please %s"
|
||||
),
|
||||
self.entity_id,
|
||||
type(self),
|
||||
supported_color_modes,
|
||||
report_issue,
|
||||
)
|
||||
except vol.Error as err:
|
||||
raise HomeAssistantError(
|
||||
f"{self.entity_id} ({type(self)}) sets invalid supported color modes "
|
||||
f"{supported_color_modes}"
|
||||
) from err
|
||||
|
||||
@final
|
||||
@property
|
||||
|
||||
@@ -2438,7 +2438,7 @@ async def test_report_invalid_color_mode(
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("color_mode", "supported_color_modes", "platform_name", "warning_expected"),
|
||||
("color_mode", "supported_color_modes", "platform_name", "error_expected"),
|
||||
[
|
||||
(
|
||||
light.ColorMode.ONOFF,
|
||||
@@ -2464,12 +2464,6 @@ async def test_report_invalid_color_mode(
|
||||
"test",
|
||||
False,
|
||||
),
|
||||
(
|
||||
light.ColorMode.ONOFF,
|
||||
{light.ColorMode.ONOFF, light.ColorMode.BRIGHTNESS},
|
||||
"philips_js", # We don't log issues for philips_js
|
||||
False,
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_report_invalid_color_modes(
|
||||
@@ -2478,7 +2472,7 @@ def test_report_invalid_color_modes(
|
||||
color_mode: str,
|
||||
supported_color_modes: set[str],
|
||||
platform_name: str,
|
||||
warning_expected: bool,
|
||||
error_expected: bool,
|
||||
) -> None:
|
||||
"""Test a light setting an invalid color mode."""
|
||||
|
||||
@@ -2490,9 +2484,13 @@ def test_report_invalid_color_modes(
|
||||
platform = MockEntityPlatform(hass, platform_name=platform_name)
|
||||
|
||||
entity = MockLightEntityEntity()
|
||||
entity._async_calculate_state()
|
||||
expected_warning = "sets invalid supported color modes"
|
||||
assert (expected_warning in caplog.text) is warning_expected
|
||||
raised_error = ""
|
||||
try:
|
||||
entity._async_calculate_state()
|
||||
except HomeAssistantError as err:
|
||||
raised_error = str(err)
|
||||
expected_error = "sets invalid supported color modes"
|
||||
assert (expected_error in raised_error) is error_expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Reference in New Issue
Block a user