Skip to content

Commit

Permalink
Fix calling the right delete on restored legacy helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
karwosts committed Oct 28, 2024
1 parent ed925f5 commit 3c17ebb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/common/entity/delete_entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
);
}

Expand All @@ -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;
}
Expand Down
9 changes: 5 additions & 4 deletions src/panels/config/entities/ha-config-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1335,7 +1335,7 @@ ${rejected
this._manifests!,
this._entities,
this._entries!,
uiHelpers
fetchedHelpers
)
);
showConfirmationDialog(this, {
Expand Down Expand Up @@ -1364,7 +1364,8 @@ ${rejected
entity_id,
this._manifests!,
this._entities,
this._entries!
this._entries!,
fetchedHelpers
)
);
this._clearSelection();
Expand Down

0 comments on commit 3c17ebb

Please sign in to comment.