Fix overriding a script's entity_id (#78765)

This commit is contained in:
Erik Montnemery
2022-09-28 10:37:34 +02:00
committed by GitHub
parent 4a432db611
commit 6ef33b1d39
2 changed files with 57 additions and 18 deletions

View File

@ -1023,3 +1023,44 @@ async def test_setup_with_duplicate_scripts(
)
assert "Duplicate script detected with name: 'duplicate'" in caplog.text
assert len(hass.states.async_entity_ids("script")) == 1
async def test_script_service_changed_entity_id(hass: HomeAssistant) -> None:
"""Test the script service works for scripts with overridden entity_id."""
entity_reg = er.async_get(hass)
entry = entity_reg.async_get_or_create("script", "script", "test")
entry = entity_reg.async_update_entity(
entry.entity_id, new_entity_id="script.custom_entity_id"
)
assert entry.entity_id == "script.custom_entity_id"
calls = []
@callback
def record_call(service):
"""Add recorded event to set."""
calls.append(service)
hass.services.async_register("test", "script", record_call)
assert await async_setup_component(
hass,
"script",
{
"script": {
"test": {
"sequence": {
"service": "test.script",
"data_template": {"entity_id": "{{ this.entity_id }}"},
}
}
}
},
)
await hass.services.async_call(DOMAIN, "test", {"greeting": "world"})
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data["entity_id"] == "script.custom_entity_id"