diff --git a/src/panels/config/devices/ha-config-device-page.ts b/src/panels/config/devices/ha-config-device-page.ts
index ef6e98f2b3..1ea9c90b1c 100644
--- a/src/panels/config/devices/ha-config-device-page.ts
+++ b/src/panels/config/devices/ha-config-device-page.ts
@@ -1330,19 +1330,71 @@ export class HaConfigDevicePage extends LitElement {
}
const entities = this._entities(this.deviceId, this._entityReg);
- const renameEntityid =
- this.showAdvanced &&
- (await showConfirmationDialog(this, {
- title: this.hass.localize(
- "ui.panel.config.devices.confirm_rename_entity_ids"
- ),
- text: this.hass.localize(
- "ui.panel.config.devices.confirm_rename_entity_ids_warning"
- ),
- confirmText: this.hass.localize("ui.common.rename"),
- dismissText: this.hass.localize("ui.common.no"),
- warning: true,
- }));
+ let renameEntityid = false;
+ let entityIdRenames: { oldId: string; newId?: string }[] = [];
+
+ if (this.showAdvanced) {
+ const oldDeviceSlug = slugify(oldDeviceName);
+ const newDeviceSlug = slugify(newDeviceName);
+ entityIdRenames = entities.map((entity) => {
+ const oldId = entity.entity_id;
+ if (oldId.includes(oldDeviceSlug)) {
+ const newId = oldId.replace(oldDeviceSlug, newDeviceSlug);
+ return { oldId, newId };
+ }
+ return { oldId };
+ });
+
+ const dialogRenames = entityIdRenames
+ .filter((entity) => entity.newId)
+ .map(
+ (entity) =>
+ html`
+ ${entity.oldId} -> ${entity.newId}
+ `
+ );
+ const dialogNoRenames = entityIdRenames
+ .filter((entity) => !entity.newId)
+ .map(
+ (entity) =>
+ html`${entity.oldId}`
+ );
+
+ if (dialogRenames.length) {
+ renameEntityid = await showConfirmationDialog(this, {
+ title: this.hass.localize(
+ "ui.panel.config.devices.confirm_rename_entity_ids"
+ ),
+ text: html`${this.hass.localize(
+ "ui.panel.config.devices.confirm_rename_entity_ids_warning"
+ )}
${this.hass.localize(
+ "ui.panel.config.devices.confirm_rename_entity_will_rename"
+ )}:
+ ${dialogRenames}
+ ${dialogNoRenames.length
+ ? html`
${this.hass.localize(
+ "ui.panel.config.devices.confirm_rename_entity_wont_rename",
+ { deviceSlug: oldDeviceSlug }
+ )}:
+ ${dialogNoRenames}`
+ : nothing}`,
+ confirmText: this.hass.localize("ui.common.rename"),
+ dismissText: this.hass.localize("ui.common.no"),
+ warning: true,
+ });
+ } else if (dialogNoRenames.length) {
+ await showAlertDialog(this, {
+ title: this.hass.localize(
+ "ui.panel.config.devices.confirm_rename_entity_no_renamable_entity_ids"
+ ),
+ text: html`${this.hass.localize(
+ "ui.panel.config.devices.confirm_rename_entity_wont_rename",
+ { deviceSlug: oldDeviceSlug }
+ )}:
+ ${dialogNoRenames}`,
+ });
+ }
+ }
const updateProms = entities.map((entity) => {
const name = entity.name || entity.stateName;
@@ -1369,13 +1421,12 @@ export class HaConfigDevicePage extends LitElement {
}
if (renameEntityid) {
- const oldSearch = slugify(oldDeviceName);
- if (entity.entity_id.includes(oldSearch)) {
+ const entityRename = entityIdRenames?.find(
+ (item) => item.oldId === entity.entity_id
+ );
+ if (entityRename?.newId) {
shouldUpdateEntityId = true;
- newEntityId = entity.entity_id.replace(
- oldSearch,
- slugify(newDeviceName)
- );
+ newEntityId = entityRename.newId;
}
}
diff --git a/src/translations/en.json b/src/translations/en.json
index e460303633..62e90780ea 100644
--- a/src/translations/en.json
+++ b/src/translations/en.json
@@ -4080,6 +4080,9 @@
},
"confirm_rename_entity_ids": "Do you also want to rename the entity IDs of your entities?",
"confirm_rename_entity_ids_warning": "This will not change any configuration (like automations, scripts, scenes, dashboards) that is currently using these entities! You will have to update them yourself to use the new entity IDs!",
+ "confirm_rename_entity_will_rename": "The following entity IDs will be renamed",
+ "confirm_rename_entity_wont_rename": "The following entity IDs will not be renamed as they do not contain the current device name ({deviceSlug})",
+ "confirm_rename_entity_no_renamable_entity_ids": "No renamable entity IDs",
"confirm_disable_config_entry": "There are no more devices for the config entry {entry_name}, do you want to instead disable the config entry?",
"update_device_error": "Updating the device failed",
"disabled": "Disabled",