Move order of restore around (#23391)

This commit is contained in:
Bram Kragten 2024-12-23 11:56:54 +01:00 committed by GitHub
parent 6afcd4d770
commit 56f9165323
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -88,11 +88,7 @@ class DialogRestoreBackup extends LitElement implements HassDialog {
this._error = undefined; this._error = undefined;
this._stage = undefined; this._stage = undefined;
this._step = undefined; this._step = undefined;
if (this._unsub) { this._unsubscribe();
this._unsub.then((unsub) => unsub());
this._unsub = undefined;
}
window.removeEventListener("connection-status", this._connectionStatus);
fireEvent(this, "dialog-closed", { dialog: this.localName }); fireEvent(this, "dialog-closed", { dialog: this.localName });
} }
@ -189,15 +185,16 @@ class DialogRestoreBackup extends LitElement implements HassDialog {
} }
private async _restoreBackup() { private async _restoreBackup() {
this._unsubscribe();
try { try {
this._step = "progress"; this._step = "progress";
window.addEventListener("connection-status", this._connectionStatus); window.addEventListener("connection-status", this._connectionStatus);
this._subscribeBackupEvents();
await this._doRestoreBackup( await this._doRestoreBackup(
this._userPassword || this._backupEncryptionKey this._userPassword || this._backupEncryptionKey
); );
this._subscribeBackupEvents();
} catch (e: any) { } catch (e: any) {
window.removeEventListener("connection-status", this._connectionStatus); this._unsubscribe();
if (e.code === "password_incorrect") { if (e.code === "password_incorrect") {
this._step = "encryption"; this._step = "encryption";
} else { } else {
@ -229,6 +226,14 @@ class DialogRestoreBackup extends LitElement implements HassDialog {
}); });
} }
private _unsubscribe() {
window.removeEventListener("connection-status", this._connectionStatus);
if (this._unsub) {
this._unsub.then((unsub) => unsub());
this._unsub = undefined;
}
}
private _restoreState() { private _restoreState() {
switch (this._stage) { switch (this._stage) {
case "addon_repositories": case "addon_repositories":