Fetch manifests for discovered flows (#8987)

This commit is contained in:
Paulus Schoutsen 2021-04-26 07:33:00 -07:00 committed by GitHub
parent 8ca1b9320d
commit b8d6b1ebdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,6 +38,7 @@ import {
} from "../../../data/entity_registry"; } from "../../../data/entity_registry";
import { import {
domainToName, domainToName,
fetchIntegrationManifest,
fetchIntegrationManifests, fetchIntegrationManifests,
IntegrationManifest, IntegrationManifest,
} from "../../../data/integration"; } from "../../../data/integration";
@ -127,6 +128,8 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
@internalProperty() @internalProperty()
private _manifests: Record<string, IntegrationManifest> = {}; private _manifests: Record<string, IntegrationManifest> = {};
private _extraFetchedManifests?: Set<string>;
@internalProperty() private _showIgnored = false; @internalProperty() private _showIgnored = false;
@internalProperty() private _showDisabled = false; @internalProperty() private _showDisabled = false;
@ -154,15 +157,14 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
this.hass.loadBackendTranslation("config", flow.handler) this.hass.loadBackendTranslation("config", flow.handler)
); );
} }
this._fetchManifest(flow.handler);
}); });
await Promise.all(translationsPromisses); await Promise.all(translationsPromisses);
await nextRender(); await nextRender();
this._configEntriesInProgress = flowsInProgress.map((flow) => { this._configEntriesInProgress = flowsInProgress.map((flow) => ({
return { ...flow,
...flow, localized_title: localizeConfigFlowTitle(this.hass.localize, flow),
localized_title: localizeConfigFlowTitle(this.hass.localize, flow), }));
};
});
}), }),
]; ];
} }
@ -496,12 +498,33 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
} }
private async _fetchManifests() { private async _fetchManifests() {
const manifests = {};
const fetched = await fetchIntegrationManifests(this.hass); 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; for (const manifest of fetched) manifests[manifest.domain] = manifest;
this._manifests = manifests; 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<ConfigEntryRemovedEvent>) { private _handleEntryRemoved(ev: HASSDomEvent<ConfigEntryRemovedEvent>) {
this._configEntries = this._configEntries!.filter( this._configEntries = this._configEntries!.filter(
(entry) => entry.entry_id !== ev.detail.entryId (entry) => entry.entry_id !== ev.detail.entryId