Add hs_command_template and xy_command_template to mqtt light default schema (#84988)
* Add mqtt light hs_command_template * Add mqtt light xy_command_template
This commit is contained in:
parent
e7e1a7d46e
commit
a0d41e1d97
3 changed files with 96 additions and 8 deletions
|
@ -2861,18 +2861,18 @@ async def test_max_mireds(hass, mqtt_mock_entry_with_yaml_config):
|
|||
"hs_command_topic",
|
||||
{"rgb_color": [255, 128, 0]},
|
||||
"30.118,100.0",
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
"hs_command_template",
|
||||
"hue",
|
||||
b"3",
|
||||
),
|
||||
(
|
||||
light.SERVICE_TURN_ON,
|
||||
"xy_command_topic",
|
||||
{"hs_color": [30.118, 100.0]},
|
||||
"0.611,0.375",
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
"xy_command_template",
|
||||
"x * 10",
|
||||
b"6",
|
||||
),
|
||||
(
|
||||
light.SERVICE_TURN_OFF,
|
||||
|
@ -3113,6 +3113,78 @@ async def test_sending_mqtt_effect_command_with_template(
|
|||
assert state.attributes.get("effect") == "colorloop"
|
||||
|
||||
|
||||
async def test_sending_mqtt_hs_command_with_template(
|
||||
hass, mqtt_mock_entry_with_yaml_config
|
||||
):
|
||||
"""Test the sending of HS Color command with template."""
|
||||
config = {
|
||||
light.DOMAIN: {
|
||||
"name": "test",
|
||||
"command_topic": "test_light_hs/set",
|
||||
"hs_command_topic": "test_light_hs/hs_color/set",
|
||||
"hs_command_template": '{"hue": {{ hue | int }}, "sat": {{ sat | int}}}',
|
||||
"qos": 0,
|
||||
}
|
||||
}
|
||||
|
||||
assert await async_setup_component(hass, mqtt.DOMAIN, {mqtt.DOMAIN: config})
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
await common.async_turn_on(hass, "light.test", hs_color=(30, 100))
|
||||
|
||||
mqtt_mock.async_publish.assert_has_calls(
|
||||
[
|
||||
call("test_light_hs/set", "ON", 0, False),
|
||||
call("test_light_hs/hs_color/set", '{"hue": 30, "sat": 100}', 0, False),
|
||||
],
|
||||
any_order=True,
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes["hs_color"] == (30, 100)
|
||||
|
||||
|
||||
async def test_sending_mqtt_xy_command_with_template(
|
||||
hass, mqtt_mock_entry_with_yaml_config
|
||||
):
|
||||
"""Test the sending of XY Color command with template."""
|
||||
config = {
|
||||
light.DOMAIN: {
|
||||
"name": "test",
|
||||
"command_topic": "test_light_xy/set",
|
||||
"xy_command_topic": "test_light_xy/xy_color/set",
|
||||
"xy_command_template": '{"Color": "{{ (x * 65536) | round | int }},{{ (y * 65536) | round | int }}"}',
|
||||
"qos": 0,
|
||||
}
|
||||
}
|
||||
|
||||
assert await async_setup_component(hass, mqtt.DOMAIN, {mqtt.DOMAIN: config})
|
||||
await hass.async_block_till_done()
|
||||
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
await common.async_turn_on(hass, "light.test", xy_color=(0.151, 0.343))
|
||||
|
||||
mqtt_mock.async_publish.assert_has_calls(
|
||||
[
|
||||
call("test_light_xy/set", "ON", 0, False),
|
||||
call("test_light_xy/xy_color/set", '{"Color": "9896,22479"}', 0, False),
|
||||
],
|
||||
any_order=True,
|
||||
)
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes["xy_color"] == (0.151, 0.343)
|
||||
|
||||
|
||||
async def test_setup_manual_entity_from_yaml(hass):
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
platform = light.DOMAIN
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue