Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion homeassistant/components/websocket_api/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ async def handle_test_condition(hass, connection, msg):
{
vol.Required("type"): "execute_script",
vol.Required("sequence"): cv.SCRIPT_SCHEMA,
vol.Optional("variables"): dict,
}
)
@decorators.require_admin
Expand All @@ -436,5 +437,5 @@ async def handle_execute_script(hass, connection, msg):

context = connection.context(msg)
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}))
38 changes: 29 additions & 9 deletions tests/components/websocket_api/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,21 +1086,41 @@ async def test_execute_script(hass, websocket_client):
}
)

await hass.async_block_till_done()
await hass.async_block_till_done()
msg_no_var = await websocket_client.receive_json()
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()
assert msg["id"] == 5
assert msg["type"] == const.TYPE_RESULT
assert msg["success"]
await websocket_client.send_json(
{
"id": 6,
"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()

assert len(calls) == 1
call = calls[0]
assert len(calls) == 2

call = calls[0]
assert call.domain == "domain_test"
assert call.service == "test_service"
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"]