Extract variable rendering (#39934)
This commit is contained in:
1 parent
b107e87d38
commit
8ef04268be
8 files changed
+193
-25
No files matched your search
@@ -1136,7 +1136,7 @@ async def test_logbook_humanify_automation_triggered_event(hass):
|
||||
assert event2["entity_id"] == "automation.bye"
|
||||
|
||||
|
||||
async def test_automation_variables(hass):
|
||||
async def test_automation_variables(hass, caplog):
|
||||
"""Test automation variables."""
|
||||
calls = async_mock_service(hass, "test", "automation")
|
||||
|
||||
@@ -1172,6 +1172,15 @@ async def test_automation_variables(hass):
|
||||
"service": "test.automation",
|
||||
},
|
||||
},
|
||||
{
|
||||
"variables": {
|
||||
"test_var": "{{ trigger.event.data.break + 1 }}",
|
||||
},
|
||||
"trigger": {"platform": "event", "event_type": "test_event_3"},
|
||||
"action": {
|
||||
"service": "test.automation",
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
)
|
||||
@@ -1188,3 +1197,13 @@ async def test_automation_variables(hass):
|
||||
hass.bus.async_fire("test_event_2", {"pass_condition": True})
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 2
|
||||
|
||||
assert "Error rendering variables" not in caplog.text
|
||||
hass.bus.async_fire("test_event_3")
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 2
|
||||
assert "Error rendering variables" in caplog.text
|
||||
|
||||
hass.bus.async_fire("test_event_3", {"break": 0})
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 3
|
||||
@@ -17,6 +17,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import Context, callback, split_entity_id
|
||||
from homeassistant.exceptions import ServiceNotFound
|
||||
from homeassistant.helpers import template
|
||||
from homeassistant.helpers.event import async_track_state_change
|
||||
from homeassistant.helpers.service import async_get_all_descriptions
|
||||
from homeassistant.loader import bind_hass
|
||||
@@ -617,7 +618,7 @@ async def test_concurrent_script(hass, concurrently):
|
||||
assert not script.is_on(hass, "script.script2")
|
||||
|
||||
|
||||
async def test_script_variables(hass):
|
||||
async def test_script_variables(hass, caplog):
|
||||
"""Test defining scripts."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
@@ -652,6 +653,19 @@ async def test_script_variables(hass):
|
||||
},
|
||||
],
|
||||
},
|
||||
"script3": {
|
||||
"variables": {
|
||||
"test_var": "{{ break + 1 }}",
|
||||
},
|
||||
"sequence": [
|
||||
{
|
||||
"service": "test.script",
|
||||
"data": {
|
||||
"value": "{{ test_var }}",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -681,3 +695,14 @@ async def test_script_variables(hass):
|
||||
|
||||
assert len(mock_calls) == 3
|
||||
assert mock_calls[2].data["value"] == "from_service"
|
||||
|
||||
assert "Error rendering variables" not in caplog.text
|
||||
with pytest.raises(template.TemplateError):
|
||||
await hass.services.async_call("script", "script3", blocking=True)
|
||||
assert "Error rendering variables" in caplog.text
|
||||
assert len(mock_calls) == 3
|
||||
|
||||
await hass.services.async_call("script", "script3", {"break": 0}, blocking=True)
|
||||
|
||||
assert len(mock_calls) == 4
|
||||
assert mock_calls[3].data["value"] == "1"
|
||||
Reference in new issue
Block a user