Add tests mqtt light with single supported color_mode (#91811)

pull/91856/head
Jan Bouwhuis 2023-04-22 13:55:43 +02:00 committed by GitHub
parent b5fbbf8410
commit 9197316b57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 0 deletions

View File

@ -268,6 +268,49 @@ async def test_fail_setup_if_color_modes_invalid(
assert error in caplog.text
@pytest.mark.parametrize(
"hass_config",
[
{
mqtt.DOMAIN: {
light.DOMAIN: {
"schema": "json",
"name": "test",
"command_topic": "test_light/set",
"state_topic": "test_light",
"color_mode": True,
"supported_color_modes": "color_temp",
}
}
}
],
)
async def test_single_color_mode(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> None:
"""Test setup with single color_mode."""
await mqtt_mock_entry()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
await common.async_turn_on(hass, "light.test", brightness=50, color_temp=192)
async_fire_mqtt_message(
hass,
"test_light",
'{"state": "ON", "brightness": 50, "color_mode": "color_temp", "color_temp": 192}',
)
color_modes = [light.ColorMode.COLOR_TEMP]
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
assert state.attributes.get(light.ATTR_COLOR_TEMP) == 192
assert state.attributes.get(light.ATTR_BRIGHTNESS) == 50
assert state.attributes.get(light.ATTR_COLOR_MODE) == color_modes[0]
@pytest.mark.parametrize(
"hass_config",
[

View File

@ -183,6 +183,45 @@ async def test_rgb_light(
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == expected_features
@pytest.mark.parametrize(
"hass_config",
[
{
mqtt.DOMAIN: {
light.DOMAIN: {
"schema": "template",
"name": "test",
"command_topic": "test_light/set",
"command_on_template": "on,{{ brightness|d }},{{ color_temp|d }}",
"command_off_template": "off",
"brightness_template": "{{ value.split(',')[1] }}",
"color_temp_template": "{{ value.split(',')[2] }}",
}
}
}
],
)
async def test_single_color_mode(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None:
"""Test the color mode when we only have one supported color_mode."""
await mqtt_mock_entry()
state = hass.states.get("light.test")
assert state.state == STATE_UNKNOWN
await common.async_turn_on(hass, "light.test", brightness=50, color_temp=192)
async_fire_mqtt_message(hass, "test_light", "on,50,192")
color_modes = [light.ColorMode.COLOR_TEMP]
state = hass.states.get("light.test")
assert state.state == STATE_ON
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
assert state.attributes.get(light.ATTR_COLOR_TEMP) == 192
assert state.attributes.get(light.ATTR_BRIGHTNESS) == 50
assert state.attributes.get(light.ATTR_COLOR_MODE) == color_modes[0]
@pytest.mark.parametrize(
"hass_config",
[