mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-24 21:37:21 +00:00
Support requesting multiple integration manifests in a single request (#12706)
* Support requesting multiple integration manifests in a single request * only fetch if there are some to actually fetch * handle empty * not truthy, wrong language * Do not copy params Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
f4f51e1de5
commit
2796c3570a
@ -42,8 +42,18 @@ export const domainToName = (
|
||||
manifest?: IntegrationManifest
|
||||
) => localize(`component.${domain}.title`) || manifest?.name || domain;
|
||||
|
||||
export const fetchIntegrationManifests = (hass: HomeAssistant) =>
|
||||
hass.callWS<IntegrationManifest[]>({ type: "manifest/list" });
|
||||
export const fetchIntegrationManifests = (
|
||||
hass: HomeAssistant,
|
||||
integrations?: string[]
|
||||
) => {
|
||||
const params: any = {
|
||||
type: "manifest/list",
|
||||
};
|
||||
if (integrations) {
|
||||
params.integrations = integrations;
|
||||
}
|
||||
return hass.callWS<IntegrationManifest[]>(params);
|
||||
};
|
||||
|
||||
export const fetchIntegrationManifest = (
|
||||
hass: HomeAssistant,
|
||||
|
@ -46,7 +46,6 @@ import {
|
||||
} from "../../../data/entity_registry";
|
||||
import {
|
||||
domainToName,
|
||||
fetchIntegrationManifest,
|
||||
fetchIntegrationManifests,
|
||||
IntegrationManifest,
|
||||
} from "../../../data/integration";
|
||||
@ -157,17 +156,19 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
||||
}),
|
||||
subscribeConfigFlowInProgress(this.hass, async (flowsInProgress) => {
|
||||
const integrations: Set<string> = new Set();
|
||||
const manifests: Set<string> = new Set();
|
||||
flowsInProgress.forEach((flow) => {
|
||||
// To render title placeholders
|
||||
if (flow.context.title_placeholders) {
|
||||
integrations.add(flow.handler);
|
||||
}
|
||||
this._fetchManifest(flow.handler);
|
||||
manifests.add(flow.handler);
|
||||
});
|
||||
await this.hass.loadBackendTranslation(
|
||||
"config",
|
||||
Array.from(integrations)
|
||||
);
|
||||
this._fetchIntegrationManifests(manifests);
|
||||
await nextRender();
|
||||
this._configEntriesInProgress = flowsInProgress.map((flow) => ({
|
||||
...flow,
|
||||
@ -566,8 +567,8 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
||||
await scanUSBDevices(this.hass);
|
||||
}
|
||||
|
||||
private async _fetchManifests() {
|
||||
const fetched = await fetchIntegrationManifests(this.hass);
|
||||
private async _fetchManifests(integrations?: string[]) {
|
||||
const fetched = await fetchIntegrationManifests(this.hass, integrations);
|
||||
// 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 };
|
||||
@ -575,23 +576,25 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
|
||||
this._manifests = manifests;
|
||||
}
|
||||
|
||||
private async _fetchManifest(domain: string) {
|
||||
if (domain in this._manifests) {
|
||||
return;
|
||||
}
|
||||
if (this._extraFetchedManifests) {
|
||||
if (this._extraFetchedManifests.has(domain)) {
|
||||
return;
|
||||
private async _fetchIntegrationManifests(integrations: Set<string>) {
|
||||
const manifestsToFetch: string[] = [];
|
||||
for (const integration of integrations) {
|
||||
if (integration in this._manifests) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
this._extraFetchedManifests = new Set();
|
||||
if (this._extraFetchedManifests) {
|
||||
if (this._extraFetchedManifests.has(integration)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
this._extraFetchedManifests = new Set();
|
||||
}
|
||||
this._extraFetchedManifests.add(integration);
|
||||
manifestsToFetch.push(integration);
|
||||
}
|
||||
if (manifestsToFetch.length) {
|
||||
await this._fetchManifests(manifestsToFetch);
|
||||
}
|
||||
this._extraFetchedManifests.add(domain);
|
||||
const manifest = await fetchIntegrationManifest(this.hass, domain);
|
||||
this._manifests = {
|
||||
...this._manifests,
|
||||
[domain]: manifest,
|
||||
};
|
||||
}
|
||||
|
||||
private _handleEntryRemoved(ev: HASSDomEvent<ConfigEntryRemovedEvent>) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user