1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-02 06:32:14 +01:00

Add WS command blueprint/substitute (#119890)

This commit is contained in:
Erik Montnemery
2024-06-25 20:15:11 +02:00
committed by GitHub
parent 9dc26652ee
commit 7d2ae5b3a5
2 changed files with 200 additions and 26 deletions

View File

@@ -9,7 +9,7 @@ import yaml
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from homeassistant.util.yaml import parse_yaml
from homeassistant.util.yaml import UndefinedSubstitution, parse_yaml
from tests.test_util.aiohttp import AiohttpClientMocker
from tests.typing import WebSocketGenerator
@@ -454,9 +454,124 @@ async def test_delete_blueprint_in_use_by_script(
msg = await client.receive_json()
assert not unlink_mock.mock_calls
assert msg["id"] == 9
assert not msg["success"]
assert msg["error"] == {
"code": "home_assistant_error",
"message": "Blueprint in use",
}
async def test_substituting_blueprint_inputs(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test substituting blueprint inputs."""
client = await hass_ws_client(hass)
await client.send_json_auto_id(
{
"type": "blueprint/substitute",
"domain": "automation",
"path": "test_event_service.yaml",
"input": {
"trigger_event": "test_event",
"service_to_call": "test.automation",
"a_number": 5,
},
}
)
msg = await client.receive_json()
assert msg["success"]
assert msg["result"]["substituted_config"] == {
"action": {
"entity_id": "light.kitchen",
"service": "test.automation",
},
"trigger": {
"event_type": "test_event",
"platform": "event",
},
}
async def test_substituting_blueprint_inputs_unknown_domain(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test substituting blueprint inputs."""
client = await hass_ws_client(hass)
await client.send_json_auto_id(
{
"type": "blueprint/substitute",
"domain": "donald_duck",
"path": "test_event_service.yaml",
"input": {
"trigger_event": "test_event",
"service_to_call": "test.automation",
"a_number": 5,
},
}
)
msg = await client.receive_json()
assert not msg["success"]
assert msg["error"] == {
"code": "invalid_format",
"message": "Unsupported domain",
}
async def test_substituting_blueprint_inputs_incomplete_input(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test substituting blueprint inputs."""
client = await hass_ws_client(hass)
await client.send_json_auto_id(
{
"type": "blueprint/substitute",
"domain": "automation",
"path": "test_event_service.yaml",
"input": {
"service_to_call": "test.automation",
"a_number": 5,
},
}
)
msg = await client.receive_json()
assert not msg["success"]
assert msg["error"] == {
"code": "unknown_error",
"message": "Missing input trigger_event",
}
async def test_substituting_blueprint_inputs_incomplete_input_2(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator
) -> None:
"""Test substituting blueprint inputs."""
client = await hass_ws_client(hass)
with patch(
"homeassistant.components.blueprint.models.BlueprintInputs.async_substitute",
side_effect=UndefinedSubstitution("blah"),
):
await client.send_json_auto_id(
{
"type": "blueprint/substitute",
"domain": "automation",
"path": "test_event_service.yaml",
"input": {
"trigger_event": "test_event",
"service_to_call": "test.automation",
"a_number": 5,
},
}
)
msg = await client.receive_json()
assert not msg["success"]
assert msg["error"] == {
"code": "unknown_error",
"message": "No substitution found for input blah",
}