diff --git a/custom_components/spook/ectoplasms/homeassistant/services/update_entity_id.py b/custom_components/spook/ectoplasms/homeassistant/services/update_entity_id.py new file mode 100644 index 00000000..3f14758e --- /dev/null +++ b/custom_components/spook/ectoplasms/homeassistant/services/update_entity_id.py @@ -0,0 +1,33 @@ +"""Spook - Not your homie.""" +from __future__ import annotations + +from typing import TYPE_CHECKING + +import voluptuous as vol + +from homeassistant.components.homeassistant import DOMAIN +from homeassistant.helpers import config_validation as cv, entity_registry as er + +from ....services import AbstractSpookAdminService + +if TYPE_CHECKING: + from homeassistant.core import ServiceCall + + +class SpookService(AbstractSpookAdminService): + """Home Assistant Core integration service to update an entity's ID.""" + + domain = DOMAIN + service = "update_entity_id" + schema = { + vol.Required("entity_id"): cv.entity_id, + vol.Required("new_entity_id"): cv.entity_id, + } + + async def async_handle_service(self, call: ServiceCall) -> None: + """Handle the service call.""" + entity_registry = er.async_get(self.hass) + entity_registry.async_update_entity( + entity_id=call.data["entity_id"], + new_entity_id=call.data["new_entity_id"], + ) diff --git a/custom_components/spook/services.yaml b/custom_components/spook/services.yaml index 95e9e1fa..87111df4 100644 --- a/custom_components/spook/services.yaml +++ b/custom_components/spook/services.yaml @@ -224,6 +224,24 @@ homeassistant_enable_device: selector: device: +homeassistant_update_entity_id: + name: Update an entity's ID 👻 + description: >- + Updates an entity's ID on the fly. + fields: + entity_id: + name: Entity + description: The entity/entities to update. + required: true + selector: + entity: + new_entity_id: + name: New Entity ID + description: The new ID for the entity + required: true + selector: + text: + homeassistant_disable_entity: name: Disable an entity 👻 description: >- diff --git a/documentation/entities.md b/documentation/entities.md index 7365e9da..7ec25832 100644 --- a/documentation/entities.md +++ b/documentation/entities.md @@ -266,6 +266,63 @@ data: ::: +### Update an entity's ID + +This service allows you to update an entity's ID on the fly. + +```{figure} ./images/entities/update_entity_id.png +:alt: Screenshot of the Home Assistant update entity ID service call in the developer tools. +:align: center +``` + +```{list-table} +:header-rows: 1 +* - Service properties +* - {term}`Service` + - Update an entity's ID 👻 +* - {term}`Service name` + - `homeassistant.update_entity_id` +* - {term}`Service targets` + - No +* - {term}`Service response` + - No response +* - {term}`Spook's influence` + - Newly added service. +* - {term}`Developer tools` + - [Try this service](https://my.home-assistant.io/redirect/developer_call_service/?service=homeassistant.update_entity_id) + [![Open your Home Assistant instance and show your service developer tools with a specific service selected.](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=homeassistant.update_entity_id) +``` + +```{list-table} +:header-rows: 2 +* - Service call data +* - Attribute + - Type + - Required + - Default / Example +* - `entity_id` + - {term}`string ` + - Yes + - `"light.living_room"` +* - `new_entity_id` + - {term}`string ` + - Yes + - `"light.dining_room"` +``` + +:::{seealso} Example {term}`service call ` in {term}`YAML` +:class: dropdown + +```{code-block} yaml +:linenos: +service: homeassistant.update_entity_id +data: + entity_id: light.living_room + new_entity_id: light.dining_room +``` + +::: + ### Delete all orphaned entities Mass clean up your Home Assistant by deleting all orphaned entities in one go. diff --git a/documentation/images/entities/update_entity_id.png b/documentation/images/entities/update_entity_id.png new file mode 100644 index 00000000..2149ac7a Binary files /dev/null and b/documentation/images/entities/update_entity_id.png differ diff --git a/documentation/services.md b/documentation/services.md index b936836e..0b37b848 100644 --- a/documentation/services.md +++ b/documentation/services.md @@ -124,6 +124,12 @@ Do the math... this service does the reverse of [](#entity-hide). _#reveal_ `homeassistant.unhide_entity`, [try this service](https://my.home-assistant.io/redirect/developer_call_service/?service=homeassistant.unhide_entity), [documentation](entities#unhide-an-entity) 📚 +## Entity: Update ID + +This service can be used to update the ID of an entity on the fly. _#secret_ + +`homeassistant.hide_entity`, [try this service](https://my.home-assistant.io/redirect/developer_call_service/?service=homeassistant.update_entity_id), [documentation](entities#update-an-entitys_id) 📚 + ## Ignore all discovered devices & services Click ignore on all discovered items on the integration dashboard; optionally only for specific integration (like, `bluetooth`). _#talktothehand_