mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 03:36:44 +00:00
Wait for backup integration when doing a restore (#25188)
Co-authored-by: Wendelin <w@pe8.at>
This commit is contained in:
parent
1b79869c87
commit
6442606fc5
@ -1,27 +1,27 @@
|
||||
import type { TemplateResult } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import "./restore-backup/onboarding-restore-backup-restore";
|
||||
import "./restore-backup/onboarding-restore-backup-status";
|
||||
import type { LocalizeFunc } from "../common/translations/localize";
|
||||
import "./onboarding-loading";
|
||||
import { removeSearchParam } from "../common/url/search-params";
|
||||
import { storage } from "../common/decorators/storage";
|
||||
import { navigate } from "../common/navigate";
|
||||
import { onBoardingStyles } from "./styles";
|
||||
import type { LocalizeFunc } from "../common/translations/localize";
|
||||
import { removeSearchParam } from "../common/url/search-params";
|
||||
import { CLOUD_AGENT, type BackupContentExtended } from "../data/backup";
|
||||
import {
|
||||
fetchBackupOnboardingInfo,
|
||||
type BackupOnboardingConfig,
|
||||
type BackupOnboardingInfo,
|
||||
} from "../data/backup_onboarding";
|
||||
import { CLOUD_AGENT, type BackupContentExtended } from "../data/backup";
|
||||
import { storage } from "../common/decorators/storage";
|
||||
import type { CloudStatus } from "../data/cloud";
|
||||
import {
|
||||
fetchHaCloudStatus,
|
||||
signOutHaCloud,
|
||||
waitForIntegration,
|
||||
} from "../data/onboarding";
|
||||
import type { CloudStatus } from "../data/cloud";
|
||||
import { showToast } from "../util/toast";
|
||||
import "./onboarding-loading";
|
||||
import "./restore-backup/onboarding-restore-backup-restore";
|
||||
import "./restore-backup/onboarding-restore-backup-status";
|
||||
import { onBoardingStyles } from "./styles";
|
||||
|
||||
const STATUS_INTERVAL_IN_MS = 5000;
|
||||
|
||||
@ -133,15 +133,26 @@ class OnboardingRestoreBackup extends LitElement {
|
||||
|
||||
private async _loadBackupInfo() {
|
||||
let onboardingInfo: BackupOnboardingConfig;
|
||||
if (this._restoreRunning || !this._loadedIntegrations.has("backup")) {
|
||||
try {
|
||||
if (!this._loadedIntegrations.has("backup")) {
|
||||
if ((await waitForIntegration("backup")).integration_loaded) {
|
||||
this._loadedIntegrations.add("backup");
|
||||
} else {
|
||||
this._error = "Backup integration not loaded";
|
||||
return;
|
||||
}
|
||||
} catch (err: any) {
|
||||
// core seems to be back up restored
|
||||
if (err.status_code === 404) {
|
||||
this._resetAndReload();
|
||||
return;
|
||||
}
|
||||
|
||||
this._scheduleLoadBackupInfo(1000);
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
onboardingInfo = await fetchBackupOnboardingInfo();
|
||||
} catch (err: any) {
|
||||
if (this._restoreRunning) {
|
||||
@ -157,9 +168,7 @@ class OnboardingRestoreBackup extends LitElement {
|
||||
|
||||
// core seems to be back up restored
|
||||
if (err.status_code === 404) {
|
||||
this._restoreRunning = undefined;
|
||||
this._backupId = undefined;
|
||||
window.location.replace("/");
|
||||
this._resetAndReload();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -250,13 +259,19 @@ class OnboardingRestoreBackup extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private _resetAndReload() {
|
||||
this._restoreRunning = undefined;
|
||||
this._backupId = undefined;
|
||||
window.location.replace("/");
|
||||
}
|
||||
|
||||
private _showCloudBackup() {
|
||||
this._view = "loading";
|
||||
this._loadBackupInfo();
|
||||
}
|
||||
|
||||
private _scheduleLoadBackupInfo() {
|
||||
setTimeout(() => this._loadBackupInfo(), STATUS_INTERVAL_IN_MS);
|
||||
private _scheduleLoadBackupInfo(delay: number = STATUS_INTERVAL_IN_MS) {
|
||||
setTimeout(() => this._loadBackupInfo(), delay);
|
||||
}
|
||||
|
||||
private async _backupUploaded(ev: CustomEvent) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user