Skip to content

Commit

Permalink
Improve coverage in light reproduce state (#132929)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Dec 11, 2024
1 parent fa05cc5 commit 0e8fe1e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/components/light/test_reproduce_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down

0 comments on commit 0e8fe1e

Please sign in to comment.