mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add variables to execute script (#48613)
This commit is contained in:
parent
e76b653246
commit
bdbb4f939f
@ -424,6 +424,7 @@ async def handle_test_condition(hass, connection, msg):
|
|||||||
{
|
{
|
||||||
vol.Required("type"): "execute_script",
|
vol.Required("type"): "execute_script",
|
||||||
vol.Required("sequence"): cv.SCRIPT_SCHEMA,
|
vol.Required("sequence"): cv.SCRIPT_SCHEMA,
|
||||||
|
vol.Optional("variables"): dict,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@decorators.require_admin
|
@decorators.require_admin
|
||||||
@ -436,5 +437,5 @@ async def handle_execute_script(hass, connection, msg):
|
|||||||
|
|
||||||
context = connection.context(msg)
|
context = connection.context(msg)
|
||||||
script_obj = Script(hass, msg["sequence"], f"{const.DOMAIN} script", const.DOMAIN)
|
script_obj = Script(hass, msg["sequence"], f"{const.DOMAIN} script", const.DOMAIN)
|
||||||
await script_obj.async_run(context=context)
|
await script_obj.async_run(msg.get("variables"), context=context)
|
||||||
connection.send_message(messages.result_message(msg["id"], {"context": context}))
|
connection.send_message(messages.result_message(msg["id"], {"context": context}))
|
||||||
|
@ -1086,21 +1086,41 @@ async def test_execute_script(hass, websocket_client):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
msg_no_var = await websocket_client.receive_json()
|
||||||
await hass.async_block_till_done()
|
assert msg_no_var["id"] == 5
|
||||||
|
assert msg_no_var["type"] == const.TYPE_RESULT
|
||||||
|
assert msg_no_var["success"]
|
||||||
|
|
||||||
msg = await websocket_client.receive_json()
|
await websocket_client.send_json(
|
||||||
assert msg["id"] == 5
|
{
|
||||||
assert msg["type"] == const.TYPE_RESULT
|
"id": 6,
|
||||||
assert msg["success"]
|
"type": "execute_script",
|
||||||
|
"sequence": {
|
||||||
|
"service": "domain_test.test_service",
|
||||||
|
"data": {"hello": "{{ name }}"},
|
||||||
|
},
|
||||||
|
"variables": {"name": "From variable"},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
msg_var = await websocket_client.receive_json()
|
||||||
|
assert msg_var["id"] == 6
|
||||||
|
assert msg_var["type"] == const.TYPE_RESULT
|
||||||
|
assert msg_var["success"]
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(calls) == 1
|
assert len(calls) == 2
|
||||||
|
|
||||||
call = calls[0]
|
call = calls[0]
|
||||||
|
|
||||||
assert call.domain == "domain_test"
|
assert call.domain == "domain_test"
|
||||||
assert call.service == "test_service"
|
assert call.service == "test_service"
|
||||||
assert call.data == {"hello": "world"}
|
assert call.data == {"hello": "world"}
|
||||||
assert call.context.as_dict() == msg["result"]["context"]
|
assert call.context.as_dict() == msg_no_var["result"]["context"]
|
||||||
|
|
||||||
|
call = calls[1]
|
||||||
|
assert call.domain == "domain_test"
|
||||||
|
assert call.service == "test_service"
|
||||||
|
assert call.data == {"hello": "From variable"}
|
||||||
|
assert call.context.as_dict() == msg_var["result"]["context"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user