Extract variable rendering (#39934)

This commit is contained in:
Paulus Schoutsen committed 2020-09-11 12:15:28 +00:00
1 parent b107e87d38
commit 8ef04268be
8 files changed
+193 -25

No files matched your search

+26 -1
View File
@@ -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"