mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +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 entities = this._entities(this.deviceId, this._entityReg);
|
||||||
|
|
||||||
const renameEntityid =
|
let renameEntityid = false;
|
||||||
this.showAdvanced &&
|
let entityIdRenames: { oldId: string; newId?: string }[] = [];
|
||||||
(await showConfirmationDialog(this, {
|
|
||||||
title: this.hass.localize(
|
if (this.showAdvanced) {
|
||||||
"ui.panel.config.devices.confirm_rename_entity_ids"
|
const oldDeviceSlug = slugify(oldDeviceName);
|
||||||
),
|
const newDeviceSlug = slugify(newDeviceName);
|
||||||
text: this.hass.localize(
|
entityIdRenames = entities.map((entity) => {
|
||||||
"ui.panel.config.devices.confirm_rename_entity_ids_warning"
|
const oldId = entity.entity_id;
|
||||||
),
|
if (oldId.includes(oldDeviceSlug)) {
|
||||||
confirmText: this.hass.localize("ui.common.rename"),
|
const newId = oldId.replace(oldDeviceSlug, newDeviceSlug);
|
||||||
dismissText: this.hass.localize("ui.common.no"),
|
return { oldId, newId };
|
||||||
warning: true,
|
}
|
||||||
}));
|
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 updateProms = entities.map((entity) => {
|
||||||
const name = entity.name || entity.stateName;
|
const name = entity.name || entity.stateName;
|
||||||
@ -1369,13 +1421,12 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (renameEntityid) {
|
if (renameEntityid) {
|
||||||
const oldSearch = slugify(oldDeviceName);
|
const entityRename = entityIdRenames?.find(
|
||||||
if (entity.entity_id.includes(oldSearch)) {
|
(item) => item.oldId === entity.entity_id
|
||||||
|
);
|
||||||
|
if (entityRename?.newId) {
|
||||||
shouldUpdateEntityId = true;
|
shouldUpdateEntityId = true;
|
||||||
newEntityId = entity.entity_id.replace(
|
newEntityId = entityRename.newId;
|
||||||
oldSearch,
|
|
||||||
slugify(newDeviceName)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4080,6 +4080,9 @@
|
|||||||
},
|
},
|
||||||
"confirm_rename_entity_ids": "Do you also want to rename the entity IDs of your entities?",
|
"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_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?",
|
"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",
|
"update_device_error": "Updating the device failed",
|
||||||
"disabled": "Disabled",
|
"disabled": "Disabled",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user