1
mirror of https://github.com/home-assistant/core synced 2024-07-12 07:21:24 +02:00

Add unique ID to scripts (#70345)

This commit is contained in:
Franck Nijhof 2022-04-21 20:04:02 +02:00 committed by GitHub
parent ac88d0be14
commit d08b751a85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -319,6 +319,10 @@ class ScriptEntity(ToggleEntity, RestoreEntity):
self.description = cfg[CONF_DESCRIPTION]
self.fields = cfg[CONF_FIELDS]
# The object ID of scripts need / are unique already
# they cannot be changed from the UI after creating
self._attr_unique_id = object_id
self.entity_id = ENTITY_ID_FORMAT.format(object_id)
self.script = Script(
hass,

View File

@ -25,7 +25,7 @@ from homeassistant.core import (
split_entity_id,
)
from homeassistant.exceptions import ServiceNotFound
from homeassistant.helpers import template
from homeassistant.helpers import entity_registry as er, template
from homeassistant.helpers.event import async_track_state_change
from homeassistant.helpers.script import (
SCRIPT_MODE_CHOICES,
@ -205,7 +205,8 @@ async def test_reload_service(hass, running):
await hass.async_block_till_done()
if running != "same":
assert hass.states.get(ENTITY_ID) is None
state = hass.states.get(ENTITY_ID)
assert state.attributes["restored"] is True
assert not hass.services.has_service(script.DOMAIN, "test")
assert hass.states.get("script.test2") is not None
@ -482,6 +483,11 @@ async def test_config_basic(hass):
assert test_script.name == "Script Name"
assert test_script.attributes["icon"] == "mdi:party"
registry = er.async_get(hass)
entry = registry.async_get("script.test_script")
assert entry
assert entry.unique_id == "test_script"
async def test_config_multiple_domains(hass):
"""Test splitting configuration over multiple domains."""