mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 18:28:14 +02:00
Fix overriding a script's entity_id (#78765)
This commit is contained in:
@ -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"
|
||||
|
Reference in New Issue
Block a user