mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +00:00
Don't set name for entities that use device name already (#16613)
This commit is contained in:
parent
a09db75980
commit
ef51336770
@ -1224,6 +1224,7 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
),
|
),
|
||||||
text: err.message,
|
text: err.message,
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -1251,16 +1252,32 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
|
|
||||||
const updateProms = entities.map((entity) => {
|
const updateProms = entities.map((entity) => {
|
||||||
const name = entity.name || entity.stateName;
|
const name = entity.name || entity.stateName;
|
||||||
let newEntityId: string | null = null;
|
let newEntityId: string | undefined;
|
||||||
let newName: string | null = null;
|
let newName: string | null | undefined;
|
||||||
|
|
||||||
if (name && name.includes(oldDeviceName)) {
|
let shouldUpdateName: boolean;
|
||||||
|
let shouldUpdateEntityId = false;
|
||||||
|
|
||||||
|
if (entity.has_entity_name && !entity.name) {
|
||||||
|
shouldUpdateName = false;
|
||||||
|
} else if (
|
||||||
|
entity.has_entity_name &&
|
||||||
|
(entity.name === oldDeviceName || entity.name === newDeviceName)
|
||||||
|
) {
|
||||||
|
shouldUpdateName = true;
|
||||||
|
// clear name if it matches the device name and it uses the device name (entity naming)
|
||||||
|
newName = null;
|
||||||
|
} else if (name && name.includes(oldDeviceName)) {
|
||||||
|
shouldUpdateName = true;
|
||||||
newName = name.replace(oldDeviceName, newDeviceName);
|
newName = name.replace(oldDeviceName, newDeviceName);
|
||||||
|
} else {
|
||||||
|
shouldUpdateName = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renameEntityid) {
|
if (renameEntityid) {
|
||||||
const oldSearch = slugify(oldDeviceName);
|
const oldSearch = slugify(oldDeviceName);
|
||||||
if (entity.entity_id.includes(oldSearch)) {
|
if (entity.entity_id.includes(oldSearch)) {
|
||||||
|
shouldUpdateEntityId = true;
|
||||||
newEntityId = entity.entity_id.replace(
|
newEntityId = entity.entity_id.replace(
|
||||||
oldSearch,
|
oldSearch,
|
||||||
slugify(newDeviceName)
|
slugify(newDeviceName)
|
||||||
@ -1268,13 +1285,13 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!newName && !newEntityId) {
|
if (newName === undefined && newEntityId === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateEntityRegistryEntry(this.hass!, entity.entity_id, {
|
return updateEntityRegistryEntry(this.hass!, entity.entity_id, {
|
||||||
name: newName || name,
|
name: shouldUpdateName ? newName : undefined,
|
||||||
new_entity_id: newEntityId || entity.entity_id,
|
new_entity_id: shouldUpdateEntityId ? newEntityId : undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
await Promise.all(updateProms);
|
await Promise.all(updateProms);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user