Skip to content

Opt in to in-place entity_id changes (async_entity_id_changed) #152

Open

Description

@emontnemery

Nothing in calendar_event breaks with this change; this is only an optional opt-in and a small cleanup.

From Home Assistant Core 2026.11, an entity whose entity_id is changed in the entity registry (for example renamed by a user in the UI) is no longer removed and added again. It is updated in place: the state under the old entity_id is removed, self.entity_id is set to the new value, and the state is written under the new entity_id. async_will_remove_from_hass, async_added_to_hass and callbacks registered with async_on_remove are not called. Entities can implement a new @callback method, async_entity_id_changed(self, old_entity_id), to update anything that is keyed on their own entity_id.

Custom integrations get a transition period. An entity is still removed and added again if one of the integration's own classes in its class hierarchy defines async_prepare_to_add_to_hass, async_added_to_hass or async_will_remove_from_hass, and neither that class nor a subclass of it defines async_entity_id_changed. Base classes from Home Assistant Core, such as CoordinatorEntity or SensorEntity, don't count. This backwards compatibility will be removed in Home Assistant Core 2027.11; from then on, every entity is changed in place.

What in calendar_event depends on the entity_id

CalendarEventBinarySensor.async_added_to_hass tracks registry updates of its own entity_id with async_track_entity_registry_updated_event(self._hass, self.entity_id, ...) (custom_components/calendar_event/binary_sensor.py:123-129). After an in-place entity_id change, that tracker keeps watching the old entity_id and no longer fires.

Its only job is to cancel the timer and update task when the entity is disabled (_entity_registry_updated). Home Assistant already removes an entity when it's disabled, and async_will_remove_from_hass (binary_sensor.py:159-163) cancels both, so the tracker isn't needed. Nothing else depends on the own entity_id; _calendar_entity_id is the source calendar's entity_id.

Suggested fix

Optionally remove the tracker and _entity_registry_updated. To get in-place entity_id changes before 2027.11, add an empty hook to CalendarEventBinarySensor (binary_sensor.py:70):

@callback
def async_entity_id_changed(self, old_entity_id: str) -> None:
    super().async_entity_id_changed(old_entity_id)

Without the hook, the entity keeps being removed and added again on an entity_id change until 2027.11, and is changed in place after that.


This is based on reading the code as of 2026-09-30 (line numbers refer to that version); the relevant code is unchanged on the default branch as of 2026-10-12. It may be outdated, so please double-check against the current code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions