mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Add detail to the device+entity_id rename dialog (#21952)
This commit is contained in:
parent
c6e2e07286
commit
4bd27e5055
@ -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`<li style="white-space: nowrap;">
|
||||
${entity.oldId} -> ${entity.newId}
|
||||
</li>`
|
||||
);
|
||||
const dialogNoRenames = entityIdRenames
|
||||
.filter((entity) => !entity.newId)
|
||||
.map(
|
||||
(entity) =>
|
||||
html`<li style="white-space: nowrap;">${entity.oldId}</li>`
|
||||
);
|
||||
|
||||
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"
|
||||
)} <br /><br />${this.hass.localize(
|
||||
"ui.panel.config.devices.confirm_rename_entity_will_rename"
|
||||
)}:
|
||||
${dialogRenames}
|
||||
${dialogNoRenames.length
|
||||
? html`<br /><br />${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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user