Include blueprint input in automation trace (#48575)

This commit is contained in:
Erik Montnemery 2021-04-01 22:34:47 +02:00 committed by GitHub
parent 528095b9b6
commit 76d0f93ec1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 88 additions and 5 deletions

View file

@ -169,6 +169,7 @@ async def test_get_trace(
assert trace["trace"][f"{prefix}/0"][0]["error"]
assert trace["trace"][f"{prefix}/0"][0]["result"] == sun_action
_assert_raw_config(domain, sun_config, trace)
assert trace["blueprint_inputs"] is None
assert trace["context"]
assert trace["error"] == "Unable to find service test.automation"
assert trace["state"] == "stopped"
@ -210,6 +211,7 @@ async def test_get_trace(
assert "error" not in trace["trace"][f"{prefix}/0"][0]
assert trace["trace"][f"{prefix}/0"][0]["result"] == moon_action
_assert_raw_config(domain, moon_config, trace)
assert trace["blueprint_inputs"] is None
assert trace["context"]
assert "error" not in trace
assert trace["state"] == "stopped"
@ -1162,3 +1164,71 @@ async def test_script_mode_2(hass, hass_ws_client, script_mode, script_execution
trace = _find_traces(response["result"], "script", "script1")[1]
assert trace["state"] == "stopped"
assert trace["script_execution"] == "finished"
async def test_trace_blueprint_automation(hass, hass_ws_client):
"""Test trace of blueprint automation."""
id = 1
def next_id():
nonlocal id
id += 1
return id
domain = "automation"
sun_config = {
"id": "sun",
"use_blueprint": {
"path": "test_event_service.yaml",
"input": {
"trigger_event": "blueprint_event",
"service_to_call": "test.automation",
},
},
}
sun_action = {
"limit": 10,
"params": {
"domain": "test",
"service": "automation",
"service_data": {},
"target": {"entity_id": ["light.kitchen"]},
},
"running_script": False,
}
assert await async_setup_component(hass, "automation", {"automation": sun_config})
client = await hass_ws_client()
hass.bus.async_fire("blueprint_event")
await hass.async_block_till_done()
# List traces
await client.send_json({"id": next_id(), "type": "trace/list", "domain": domain})
response = await client.receive_json()
assert response["success"]
run_id = _find_run_id(response["result"], domain, "sun")
# Get trace
await client.send_json(
{
"id": next_id(),
"type": "trace/get",
"domain": domain,
"item_id": "sun",
"run_id": run_id,
}
)
response = await client.receive_json()
assert response["success"]
trace = response["result"]
assert set(trace["trace"]) == {"trigger/0", "action/0"}
assert len(trace["trace"]["action/0"]) == 1
assert trace["trace"]["action/0"][0]["error"]
assert trace["trace"]["action/0"][0]["result"] == sun_action
assert trace["config"]["id"] == "sun"
assert trace["blueprint_inputs"] == sun_config
assert trace["context"]
assert trace["error"] == "Unable to find service test.automation"
assert trace["state"] == "stopped"
assert trace["script_execution"] == "error"
assert trace["item_id"] == "sun"
assert trace.get("trigger", UNDEFINED) == "event 'blueprint_event'"