Skip to content
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

Added service to update an entity's ID #537

Merged
merged 1 commit into from
Jan 11, 2024
Merged
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,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"],
)
18 changes: 18 additions & 0 deletions custom_components/spook/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: >-
Expand Down
57 changes: 57 additions & 0 deletions documentation/entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string>`
- Yes
- `"light.living_room"`
* - `new_entity_id`
- {term}`string <string>`
- Yes
- `"light.dining_room"`
```

:::{seealso} Example {term}`service call <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.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions documentation/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,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_
Expand Down