Improve coverage in light reproduce state (#132929)

This commit is contained in:
epenet 2024-12-11 19:15:36 +01:00 committed by GitHub
parent fa05cc5e70
commit 0e8fe1eb41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -193,6 +193,54 @@ async def test_filter_color_modes(
assert len(turn_on_calls) == 1
async def test_filter_color_modes_missing_attributes(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test warning on missing attribute when filtering for color mode."""
color_mode = light.ColorMode.COLOR_TEMP
hass.states.async_set("light.entity", "off", {})
expected_log = (
"Color mode color_temp specified "
"but attribute color_temp missing for: light.entity"
)
turn_on_calls = async_mock_service(hass, "light", "turn_on")
all_colors = {
**VALID_COLOR_TEMP,
**VALID_HS_COLOR,
**VALID_RGB_COLOR,
**VALID_RGBW_COLOR,
**VALID_RGBWW_COLOR,
**VALID_XY_COLOR,
**VALID_BRIGHTNESS,
}
# Test missing `color_temp` attribute
stored_attributes = {**all_colors}
stored_attributes.pop("color_temp")
caplog.clear()
await async_reproduce_state(
hass,
[State("light.entity", "on", {**stored_attributes, "color_mode": color_mode})],
)
assert len(turn_on_calls) == 0
assert expected_log in caplog.text
# Test with correct `color_temp` attribute
stored_attributes["color_temp"] = 240
expected = {"brightness": 180, "color_temp": 240}
caplog.clear()
await async_reproduce_state(
hass,
[State("light.entity", "on", {**all_colors, "color_mode": color_mode})],
)
assert len(turn_on_calls) == 1
assert turn_on_calls[0].domain == "light"
assert dict(turn_on_calls[0].data) == {"entity_id": "light.entity", **expected}
assert expected_log not in caplog.text
@pytest.mark.parametrize(
"saved_state",
[