Skip to content

Add support for renaming entities dynamically #877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"],
)
19 changes: 19 additions & 0 deletions custom_components/spook/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: >-
Expand Down
6 changes: 6 additions & 0 deletions documentation/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down
2 changes: 1 addition & 1 deletion documentation/core_extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

:::

Expand Down
59 changes: 58 additions & 1 deletion documentation/entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <influence of spook>`
- Newly added action.
* - {term}`Developer tools`
- [Try this action](https://my.home-assistant.io/redirect/developer_call_service/?service=homeassistant.update_entity_id)
Expand Down Expand Up @@ -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 <influence of spook>`
- 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 <string>`
- Yes
- `"light.living_room"`
* - `name`
- {term}`string <string>`
- Yes
- `"Living room light"`
```

:::{seealso} Example {term}`action <performing actions>` 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 <blueprint>` 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).
Expand Down
Binary file added documentation/images/entities/rename_entity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.