diff --git a/src/common/entity/delete_entity.ts b/src/common/entity/delete_entity.ts index 4a32ef45a712..4430170f3d63 100644 --- a/src/common/entity/delete_entity.ts +++ b/src/common/entity/delete_entity.ts @@ -16,7 +16,7 @@ export const isDeletableEntity = ( manifests: IntegrationManifest[], entityRegistry: EntityRegistryEntry[], configEntries: ConfigEntry[], - uiHelpers: Helper[] + fetchedHelpers: Helper[] ): boolean => { const restored = !!hass.states[entity_id]?.attributes.restored; if (restored) { @@ -29,7 +29,7 @@ export const isDeletableEntity = ( return !!( isComponentLoaded(hass, domain) && entityRegEntry && - uiHelpers.some((e) => e.id === entityRegEntry.unique_id) + fetchedHelpers.some((e) => e.id === entityRegEntry.unique_id) ); } @@ -49,14 +49,18 @@ export const deleteEntity = ( entity_id: string, manifests: IntegrationManifest[], entityRegistry: EntityRegistryEntry[], - configEntries: ConfigEntry[] + configEntries: ConfigEntry[], + fetchedHelpers: Helper[] ) => { // This function assumes the entity_id already was validated by isDeletableEntity and does not repeat all those checks. const domain = computeDomain(entity_id); const entityRegEntry = entityRegistry.find((e) => e.entity_id === entity_id); if (isHelperDomain(domain)) { if (isComponentLoaded(hass, domain)) { - if (entityRegEntry) { + if ( + entityRegEntry && + fetchedHelpers.some((e) => e.id === entityRegEntry.unique_id) + ) { HELPERS_CRUD[domain].delete(hass, entityRegEntry.unique_id); return; } diff --git a/src/panels/config/entities/ha-config-entities.ts b/src/panels/config/entities/ha-config-entities.ts index 9075fe23fd03..2911bc450585 100644 --- a/src/panels/config/entities/ha-config-entities.ts +++ b/src/panels/config/entities/ha-config-entities.ts @@ -1317,9 +1317,9 @@ ${rejected HELPERS_CRUD[d].fetch(this.hass) ); const helpersResult = await Promise.all(domainProms); - let uiHelpers: Helper[] = []; + let fetchedHelpers: Helper[] = []; helpersResult.forEach((r) => { - uiHelpers = uiHelpers.concat(r); + fetchedHelpers = fetchedHelpers.concat(r); }); if (manifestsProm) { this._manifests = await manifestsProm; @@ -1335,7 +1335,7 @@ ${rejected this._manifests!, this._entities, this._entries!, - uiHelpers + fetchedHelpers ) ); showConfirmationDialog(this, { @@ -1364,7 +1364,8 @@ ${rejected entity_id, this._manifests!, this._entities, - this._entries! + this._entries!, + fetchedHelpers ) ); this._clearSelection();