mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +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 type { TemplateResult } from "lit";
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import "./restore-backup/onboarding-restore-backup-restore";
|
import { storage } from "../common/decorators/storage";
|
||||||
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 { navigate } from "../common/navigate";
|
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 {
|
import {
|
||||||
fetchBackupOnboardingInfo,
|
fetchBackupOnboardingInfo,
|
||||||
type BackupOnboardingConfig,
|
type BackupOnboardingConfig,
|
||||||
type BackupOnboardingInfo,
|
type BackupOnboardingInfo,
|
||||||
} from "../data/backup_onboarding";
|
} from "../data/backup_onboarding";
|
||||||
import { CLOUD_AGENT, type BackupContentExtended } from "../data/backup";
|
import type { CloudStatus } from "../data/cloud";
|
||||||
import { storage } from "../common/decorators/storage";
|
|
||||||
import {
|
import {
|
||||||
fetchHaCloudStatus,
|
fetchHaCloudStatus,
|
||||||
signOutHaCloud,
|
signOutHaCloud,
|
||||||
waitForIntegration,
|
waitForIntegration,
|
||||||
} from "../data/onboarding";
|
} from "../data/onboarding";
|
||||||
import type { CloudStatus } from "../data/cloud";
|
|
||||||
import { showToast } from "../util/toast";
|
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;
|
const STATUS_INTERVAL_IN_MS = 5000;
|
||||||
|
|
||||||
@ -133,15 +133,26 @@ class OnboardingRestoreBackup extends LitElement {
|
|||||||
|
|
||||||
private async _loadBackupInfo() {
|
private async _loadBackupInfo() {
|
||||||
let onboardingInfo: BackupOnboardingConfig;
|
let onboardingInfo: BackupOnboardingConfig;
|
||||||
|
if (this._restoreRunning || !this._loadedIntegrations.has("backup")) {
|
||||||
try {
|
try {
|
||||||
if (!this._loadedIntegrations.has("backup")) {
|
|
||||||
if ((await waitForIntegration("backup")).integration_loaded) {
|
if ((await waitForIntegration("backup")).integration_loaded) {
|
||||||
this._loadedIntegrations.add("backup");
|
this._loadedIntegrations.add("backup");
|
||||||
} else {
|
} else {
|
||||||
this._error = "Backup integration not loaded";
|
this._error = "Backup integration not loaded";
|
||||||
return;
|
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();
|
onboardingInfo = await fetchBackupOnboardingInfo();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (this._restoreRunning) {
|
if (this._restoreRunning) {
|
||||||
@ -157,9 +168,7 @@ class OnboardingRestoreBackup extends LitElement {
|
|||||||
|
|
||||||
// core seems to be back up restored
|
// core seems to be back up restored
|
||||||
if (err.status_code === 404) {
|
if (err.status_code === 404) {
|
||||||
this._restoreRunning = undefined;
|
this._resetAndReload();
|
||||||
this._backupId = undefined;
|
|
||||||
window.location.replace("/");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,13 +259,19 @@ class OnboardingRestoreBackup extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _resetAndReload() {
|
||||||
|
this._restoreRunning = undefined;
|
||||||
|
this._backupId = undefined;
|
||||||
|
window.location.replace("/");
|
||||||
|
}
|
||||||
|
|
||||||
private _showCloudBackup() {
|
private _showCloudBackup() {
|
||||||
this._view = "loading";
|
this._view = "loading";
|
||||||
this._loadBackupInfo();
|
this._loadBackupInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _scheduleLoadBackupInfo() {
|
private _scheduleLoadBackupInfo(delay: number = STATUS_INTERVAL_IN_MS) {
|
||||||
setTimeout(() => this._loadBackupInfo(), STATUS_INTERVAL_IN_MS);
|
setTimeout(() => this._loadBackupInfo(), delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _backupUploaded(ev: CustomEvent) {
|
private async _backupUploaded(ev: CustomEvent) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user