diff --git a/custom_components/spook/ectoplasms/homeassistant/services/rename_entity.py b/custom_components/spook/ectoplasms/homeassistant/services/rename_entity.py new file mode 100644 index 00000000..6a805ad9 --- /dev/null +++ b/custom_components/spook/ectoplasms/homeassistant/services/rename_entity.py @@ -0,0 +1,35 @@ +"""Spook - 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 rename an entity.""" + + domain = DOMAIN + service = "rename_entity" + schema = { + vol.Required("name"): cv.string, + vol.Required("entity_id"): vol.All(cv.ensure_list, [cv.string]), + } + + async def async_handle_service(self, call: ServiceCall) -> None: + """Handle the service call.""" + entity_registry = er.async_get(self.hass) + for entity_id in call.data["entity_id"]: + entity_registry.async_update_entity( + entity_id=entity_id, + name=call.data["name"], + ) diff --git a/custom_components/spook/services.yaml b/custom_components/spook/services.yaml index 8d0de602..54685040 100644 --- a/custom_components/spook/services.yaml +++ b/custom_components/spook/services.yaml @@ -290,6 +290,25 @@ homeassistant_hide_entity: entity: multiple: true +homeassistant_rename_entity: + name: Rename an entity 👻 + description: >- + Renames an entity (or entities) on the fly. + fields: + entity_id: + name: Entity + description: The entity/entities to rename. + required: true + selector: + entity: + multiple: true + name: + name: Name + description: The new name for the entity/entities. + required: true + selector: + text: + homeassistant_unhide_entity: name: Unhide an entity 👻 description: >- diff --git a/documentation/actions.md b/documentation/actions.md index 95193e3a..42978229 100644 --- a/documentation/actions.md +++ b/documentation/actions.md @@ -124,6 +124,12 @@ Do the math... this action does the reverse of [](#entity-hide). _#reveal_ `homeassistant.unhide_entity`, [Try this action](https://my.home-assistant.io/redirect/developer_call_service/?service=homeassistant.unhide_entity), [documentation](entities#unhide-an-entity) 📚 +## Entity: Rename + +This action can be used to rename an entity on the fly. _#LookMaNewName_ + +`homeassistant.rename_entity`, [Try this action](https://my.home-assistant.io/redirect/developer_call_service/?service=homeassistant.rename_entity), [documentation](entities#rename-an-entity) 📚 + ## Entity: Update ID This action can be used to update the ID of an entity on the fly. _#secret_ diff --git a/documentation/core_extensions.md b/documentation/core_extensions.md index 0f71b4fe..a8007c65 100644 --- a/documentation/core_extensions.md +++ b/documentation/core_extensions.md @@ -26,7 +26,7 @@ Programmatically enable/disable any device in Home Assistant by performing an ac :::{card} Entity management :footer: 📚 [Learn more](entities.md) -Automate entity control with actions: hide/unhide, enable/disable, list, and delete orphaned (database) entities. +Automate entity control with actions: hide/unhide, enable/disable, rename, list, and delete orphaned (database) entities. ::: diff --git a/documentation/entities.md b/documentation/entities.md index 43be3c58..86ce512c 100644 --- a/documentation/entities.md +++ b/documentation/entities.md @@ -286,7 +286,7 @@ This action allows you to update an entity's ID on the fly. - No * - {term}`Action response` - No response -* - {term}`Spook's influence` +* - {term}`Spook's influence ` - Newly added action. * - {term}`Developer tools` - [Try this action](https://my.home-assistant.io/redirect/developer_call_service/?service=homeassistant.update_entity_id) @@ -436,6 +436,63 @@ mode: single That template will find the area ID of the area with the name "Living room". ::: +### Rename an entity + +This action allows you to update an entity friendly_name on the fly. + +```{figure} ./images/entities/rename_entity.png +:alt: Screenshot of the Home Assistant rename entity action in the developer tools. +:align: center +``` + +```{list-table} +:header-rows: 1 +* - Action properties +* - {term}`Action` + - Rename an entity 👻 +* - {term}`Action name` + - `homeassistant.rename_entity` +* - {term}`Action targets` + - No +* - {term}`Action response` + - No response +* - {term}`Spook's influence ` + - Newly added action. +* - {term}`Developer tools` + - [Try this action](https://my.home-assistant.io/redirect/developer_call_service/?service=homeassistant.rename_entity) + [![Open your Home Assistant instance and show your actions developer tools with a specific action selected.](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=homeassistant.rename_entity) +``` + +```{list-table} +:header-rows: 2 +* - Action data parameters +* - Attribute + - Type + - Required + - Default / Example +* - `entity_id` + - {term}`string ` + - Yes + - `"light.living_room"` +* - `name` + - {term}`string ` + - Yes + - `"Living room light"` +``` + +:::{seealso} Example {term}`action ` in {term}`YAML` +:class: dropdown + +```{code-block} yaml +:linenos: +action: homeassistant.rename_entity +data: + entity_id: light.living_room + name: "Living room light" +``` + +::: + ## Blueprints & tutorials There are currently no known {term}`blueprints ` or tutorials for the enhancements Spook provides for these features. If you created one or stumbled upon one, [please let us know in our discussion forums](https://github.com/frenck/spook/discussions). diff --git a/documentation/images/entities/rename_entity.png b/documentation/images/entities/rename_entity.png new file mode 100644 index 00000000..4cb1c650 Binary files /dev/null and b/documentation/images/entities/rename_entity.png differ