1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Extract variable rendering (#39934)

This commit is contained in:
Paulus Schoutsen
2020-09-11 12:24:16 +02:00
committed by GitHub
parent 9389a7c9be
commit 5117a16841
8 changed files with 193 additions and 25 deletions

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"