Wait for cloud and backup in onboarding (#24997)

This commit is contained in:
Bram Kragten 2025-04-11 13:43:45 +02:00 committed by GitHub
parent 0541270695
commit 929a0b9cd4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 1 deletions

View File

@ -128,3 +128,11 @@ export const forgotPasswordHaCloud = async (email: string) =>
body: JSON.stringify({ email }),
})
);
export const waitForIntegration = (domain: string) =>
handleFetchPromise<{ integration_loaded: boolean }>(
fetch("/api/onboarding/integration/wait", {
method: "POST",
body: JSON.stringify({ domain }),
})
);

View File

@ -15,7 +15,11 @@ import {
} from "../data/backup_onboarding";
import { CLOUD_AGENT, type BackupContentExtended } from "../data/backup";
import { storage } from "../common/decorators/storage";
import { fetchHaCloudStatus, signOutHaCloud } from "../data/onboarding";
import {
fetchHaCloudStatus,
signOutHaCloud,
waitForIntegration,
} from "../data/onboarding";
import type { CloudStatus } from "../data/cloud";
import { showToast } from "../util/toast";
@ -57,8 +61,13 @@ class OnboardingRestoreBackup extends LitElement {
})
private _restoreRunning?: boolean;
private _loadedIntegrations = new Set<string>();
protected render(): TemplateResult {
return html`
${this._error && this._view !== "restore"
? html`<ha-alert alert-type="error">${this._error}</ha-alert>`
: nothing}
${this._view === "loading"
? html`<onboarding-loading></onboarding-loading>`
: this._view === "upload"
@ -125,6 +134,14 @@ class OnboardingRestoreBackup extends LitElement {
private async _loadBackupInfo() {
let onboardingInfo: BackupOnboardingConfig;
try {
if (!this._loadedIntegrations.has("backup")) {
if ((await waitForIntegration("backup")).integration_loaded) {
this._loadedIntegrations.add("backup");
} else {
this._error = "Backup integration not loaded";
return;
}
}
onboardingInfo = await fetchBackupOnboardingInfo();
} catch (err: any) {
if (this._restoreRunning) {
@ -169,6 +186,14 @@ class OnboardingRestoreBackup extends LitElement {
if (this.mode === "cloud") {
try {
if (!this._loadedIntegrations.has("cloud")) {
if ((await waitForIntegration("cloud")).integration_loaded) {
this._loadedIntegrations.add("cloud");
} else {
this._error = "Cloud integration not loaded";
return;
}
}
this._cloudStatus = await fetchHaCloudStatus();
} catch (err: any) {
this._error = err?.message || "Cannot get Home Assistant Cloud status";