Fix my link add integration: search for discovered items (#16315)

* fix my link add integration

* add confirm back

* Update dialog-add-integration.ts
This commit is contained in:
Bram Kragten 2023-04-26 12:02:50 +02:00 committed by GitHub
parent 10d476195d
commit 63de324224
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 20 deletions

View File

@ -92,14 +92,24 @@ class AddIntegrationDialog extends LitElement {
private _height?: number; private _height?: number;
public showDialog(params?: AddIntegrationDialogParams): void { public async showDialog(params?: AddIntegrationDialogParams): Promise<void> {
this._load(); const loadPromise = this._load();
this._open = true; this._open = true;
this._pickedBrand = params?.brand; this._pickedBrand = params?.brand;
this._initialFilter = params?.initialFilter; this._initialFilter = params?.initialFilter;
this._narrow = matchMedia( this._narrow = matchMedia(
"all and (max-width: 450px), all and (max-height: 500px)" "all and (max-width: 450px), all and (max-height: 500px)"
).matches; ).matches;
if (params?.domain) {
this._createFlow(params.domain);
}
if (params?.brand) {
await loadPromise;
const brand = this._integrations?.[params.brand];
if (brand && "integrations" in brand && brand.integrations) {
this._fetchFlowsInProgress(Object.keys(brand.integrations));
}
}
} }
public closeDialog() { public closeDialog() {
@ -543,7 +553,7 @@ class AddIntegrationDialog extends LitElement {
} }
if (integration.config_flow) { if (integration.config_flow) {
this._createFlow(integration); this._createFlow(integration.domain);
return; return;
} }
@ -563,25 +573,20 @@ class AddIntegrationDialog extends LitElement {
showYamlIntegrationDialog(this, { manifest }); showYamlIntegrationDialog(this, { manifest });
} }
private async _createFlow(integration: IntegrationListItem) { private async _createFlow(domain: string) {
const flowsInProgress = await this._fetchFlowsInProgress([ const flowsInProgress = await this._fetchFlowsInProgress([domain]);
integration.domain,
]);
if (flowsInProgress?.length) { if (flowsInProgress?.length) {
this._pickedBrand = integration.domain; this._pickedBrand = domain;
return; return;
} }
const manifest = await fetchIntegrationManifest( const manifest = await fetchIntegrationManifest(this.hass, domain);
this.hass,
integration.domain
);
this.closeDialog(); this.closeDialog();
showConfigFlowDialog(this, { showConfigFlowDialog(this, {
startFlowHandler: integration.domain, startFlowHandler: domain,
showAdvanced: this.hass.userData?.showAdvanced, showAdvanced: this.hass.userData?.showAdvanced,
manifest, manifest,
}); });

View File

@ -731,13 +731,8 @@ class HaConfigIntegrations extends SubscribeMixin(LitElement) {
}), }),
}) })
) { ) {
showConfigFlowDialog(this, { showAddIntegrationDialog(this, {
dialogClosedCallback: () => { domain,
this._handleFlowUpdated();
},
startFlowHandler: domain,
manifest: await fetchIntegrationManifest(this.hass, domain),
showAdvanced: this.hass.userData?.showAdvanced,
}); });
} }
return; return;

View File

@ -3,6 +3,7 @@ import { IntegrationManifest } from "../../../data/integration";
export interface AddIntegrationDialogParams { export interface AddIntegrationDialogParams {
brand?: string; brand?: string;
domain?: string;
initialFilter?: string; initialFilter?: string;
} }