From a49d59f4c656dce65006780240a749eacff487e9 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Thu, 1 Jun 2023 00:58:03 +0200 Subject: [PATCH] Fix fetching helper config entry (#16704) * Fix fetching helper config entry * willUpdate --- .../entities/entity-registry-settings.ts | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/panels/config/entities/entity-registry-settings.ts b/src/panels/config/entities/entity-registry-settings.ts index f0d0052ee9..c5c9850cb4 100644 --- a/src/panels/config/entities/entity-registry-settings.ts +++ b/src/panels/config/entities/entity-registry-settings.ts @@ -17,6 +17,7 @@ import { removeEntityRegistryEntry, updateEntityRegistryEntry, } from "../../../data/entity_registry"; +import { fetchIntegrationManifest } from "../../../data/integration"; import { showAlertDialog, showConfirmationDialog, @@ -46,12 +47,32 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) { @query("entity-registry-settings-editor") private _registryEditor?: EntityRegistrySettingsEditor; - protected firstUpdated(changedProps: PropertyValues): void { - super.firstUpdated(changedProps); - if (this.entry.config_entry_id) { - getConfigEntry(this.hass, this.entry.config_entry_id).then((entry) => { - this._helperConfigEntry = entry.config_entry; - }); + protected willUpdate(changedProps: PropertyValues): void { + super.willUpdate(changedProps); + if (changedProps.has("entry")) { + this._fetchHelperConfigEntry(); + } + } + + private async _fetchHelperConfigEntry() { + if (!this.entry?.config_entry_id) { + return; + } + try { + const configEntry = ( + await getConfigEntry(this.hass, this.entry.config_entry_id) + ).config_entry; + const manifest = await fetchIntegrationManifest( + this.hass, + configEntry.domain + ); + if (manifest.integration_type === "helper") { + this._helperConfigEntry = configEntry; + } else { + this._helperConfigEntry = undefined; + } + } catch (err) { + this._helperConfigEntry = undefined; } }