From b8d6b1ebddcc48d9d7df0189438564f780f6f97a Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 26 Apr 2021 07:33:00 -0700 Subject: [PATCH] Fetch manifests for discovered flows (#8987) --- .../integrations/ha-config-integrations.ts | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/panels/config/integrations/ha-config-integrations.ts b/src/panels/config/integrations/ha-config-integrations.ts index 3ea886368..3bfe8bb69 100644 --- a/src/panels/config/integrations/ha-config-integrations.ts +++ b/src/panels/config/integrations/ha-config-integrations.ts @@ -38,6 +38,7 @@ import { } from "../../../data/entity_registry"; import { domainToName, + fetchIntegrationManifest, fetchIntegrationManifests, IntegrationManifest, } from "../../../data/integration"; @@ -127,6 +128,8 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) { @internalProperty() private _manifests: Record = {}; + private _extraFetchedManifests?: Set; + @internalProperty() private _showIgnored = false; @internalProperty() private _showDisabled = false; @@ -154,15 +157,14 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) { this.hass.loadBackendTranslation("config", flow.handler) ); } + this._fetchManifest(flow.handler); }); await Promise.all(translationsPromisses); await nextRender(); - this._configEntriesInProgress = flowsInProgress.map((flow) => { - return { - ...flow, - localized_title: localizeConfigFlowTitle(this.hass.localize, flow), - }; - }); + this._configEntriesInProgress = flowsInProgress.map((flow) => ({ + ...flow, + localized_title: localizeConfigFlowTitle(this.hass.localize, flow), + })); }), ]; } @@ -496,12 +498,33 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) { } private async _fetchManifests() { - const manifests = {}; const fetched = await fetchIntegrationManifests(this.hass); + // Make a copy so we can keep track of previously loaded manifests + // for discovered flows (which are not part of these results) + const manifests = { ...this._manifests }; for (const manifest of fetched) manifests[manifest.domain] = manifest; this._manifests = manifests; } + private async _fetchManifest(domain: string) { + if (domain in this._manifests) { + return; + } + if (this._extraFetchedManifests) { + if (this._extraFetchedManifests.has(domain)) { + return; + } + } else { + this._extraFetchedManifests = new Set(); + } + this._extraFetchedManifests.add(domain); + const manifest = await fetchIntegrationManifest(this.hass, domain); + this._manifests = { + ...this._manifests, + [domain]: manifest, + }; + } + private _handleEntryRemoved(ev: HASSDomEvent) { this._configEntries = this._configEntries!.filter( (entry) => entry.entry_id !== ev.detail.entryId