1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-15 07:36:16 +00:00
This commit is contained in:
epenet
2026-02-09 13:45:39 +00:00
parent 8ffede54d9
commit 78dedc1f21
2 changed files with 21 additions and 17 deletions

View File

@@ -74,9 +74,11 @@ def filter_supported_color_modes(color_modes: Iterable[ColorMode]) -> set[ColorM
def valid_supported_color_modes(
color_modes: Iterable[ColorMode],
color_modes: Iterable[ColorMode] | None,
) -> set[ColorMode]:
"""Validate the given color modes."""
if color_modes is None:
raise vol.Error(f"Invalid supported_color_modes {color_modes}")
color_modes = set(color_modes)
if (
not color_modes

View File

@@ -2354,7 +2354,7 @@ def test_filter_supported_color_modes() -> None:
@pytest.mark.parametrize(
("color_mode", "supported_color_modes", "warning_expected"),
("color_mode", "supported_color_modes", "error_expected"),
[
(light.ColorMode.ONOFF, None, True),
(light.ColorMode.ONOFF, {light.ColorMode.ONOFF}, False),
@@ -2365,7 +2365,7 @@ async def test_report_no_color_modes(
caplog: pytest.LogCaptureFixture,
color_mode: str,
supported_color_modes: set[str],
warning_expected: bool,
error_expected: bool,
) -> None:
"""Test a light setting no color mode."""
@@ -2378,9 +2378,13 @@ async def test_report_no_color_modes(
entity = MockLightEntityEntity()
platform = MockEntityPlatform(hass, domain="test", platform_name="test")
await platform.async_add_entities([entity])
entity._async_calculate_state()
expected_warning = "does not set supported color modes"
assert (expected_warning in caplog.text) is warning_expected
raised_error = ""
try:
entity._async_calculate_state()
except vol.Error as err:
raised_error = str(err)
expected_error = "Invalid supported_color_modes"
assert (expected_error in raised_error) is error_expected
@pytest.mark.parametrize(
@@ -2438,7 +2442,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 +2468,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 +2476,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 +2488,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 vol.Error as err:
raised_error = str(err)
expected_error = "Invalid supported_color_modes"
assert (expected_error in raised_error) is error_expected
@pytest.mark.parametrize(