mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Wait for backup integration to setup before subscribing (#25012)
This commit is contained in:
parent
ae4f43496e
commit
add417a166
@ -112,7 +112,7 @@
|
|||||||
"google-timezones-json": "1.2.0",
|
"google-timezones-json": "1.2.0",
|
||||||
"gulp-zopfli-green": "6.0.2",
|
"gulp-zopfli-green": "6.0.2",
|
||||||
"hls.js": "patch:hls.js@npm%3A1.5.7#~/.yarn/patches/hls.js-npm-1.5.7-f5bbd3d060.patch",
|
"hls.js": "patch:hls.js@npm%3A1.5.7#~/.yarn/patches/hls.js-npm-1.5.7-f5bbd3d060.patch",
|
||||||
"home-assistant-js-websocket": "9.4.0",
|
"home-assistant-js-websocket": "9.5.0",
|
||||||
"idb-keyval": "6.2.1",
|
"idb-keyval": "6.2.1",
|
||||||
"intl-messageformat": "10.7.16",
|
"intl-messageformat": "10.7.16",
|
||||||
"js-yaml": "4.1.0",
|
"js-yaml": "4.1.0",
|
||||||
|
@ -66,11 +66,16 @@ export type ManagerStateEvent =
|
|||||||
|
|
||||||
export const subscribeBackupEvents = (
|
export const subscribeBackupEvents = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
callback: (event: ManagerStateEvent) => void
|
callback: (event: ManagerStateEvent) => void,
|
||||||
|
preCheck?: () => boolean | Promise<boolean>
|
||||||
) =>
|
) =>
|
||||||
hass.connection.subscribeMessage<ManagerStateEvent>(callback, {
|
hass.connection.subscribeMessage<ManagerStateEvent>(
|
||||||
type: "backup/subscribe_events",
|
callback,
|
||||||
});
|
{
|
||||||
|
type: "backup/subscribe_events",
|
||||||
|
},
|
||||||
|
{ preCheck }
|
||||||
|
);
|
||||||
|
|
||||||
export const DEFAULT_MANAGER_STATE: ManagerStateEvent = {
|
export const DEFAULT_MANAGER_STATE: ManagerStateEvent = {
|
||||||
manager_state: "idle",
|
manager_state: "idle",
|
||||||
|
@ -154,3 +154,9 @@ export const subscribeLogInfo = (
|
|||||||
conn,
|
conn,
|
||||||
onChange
|
onChange
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const waitForIntegrationSetup = (hass: HomeAssistant, domain: string) =>
|
||||||
|
hass.callWS<{ integration_loaded: boolean }>({
|
||||||
|
type: "integration/wait",
|
||||||
|
domain,
|
||||||
|
});
|
||||||
|
@ -30,6 +30,7 @@ import type { HassDialog } from "../../../../dialogs/make-dialog-manager";
|
|||||||
import { haStyle, haStyleDialog } from "../../../../resources/styles";
|
import { haStyle, haStyleDialog } from "../../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import type { RestoreBackupDialogParams } from "./show-dialog-restore-backup";
|
import type { RestoreBackupDialogParams } from "./show-dialog-restore-backup";
|
||||||
|
import { waitForIntegrationSetup } from "../../../../data/integration";
|
||||||
|
|
||||||
interface FormData {
|
interface FormData {
|
||||||
encryption_key_type: "config" | "custom";
|
encryption_key_type: "config" | "custom";
|
||||||
@ -280,26 +281,36 @@ class DialogRestoreBackup extends LitElement implements HassDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _subscribeBackupEvents() {
|
private _subscribeBackupEvents() {
|
||||||
this._unsub = subscribeBackupEvents(this.hass!, (event) => {
|
this._unsub = subscribeBackupEvents(
|
||||||
if (event.manager_state === "idle" && this._state === "in_progress") {
|
this.hass!,
|
||||||
this.closeDialog();
|
(event) => {
|
||||||
|
if (event.manager_state === "idle" && this._state === "in_progress") {
|
||||||
|
this.closeDialog();
|
||||||
|
}
|
||||||
|
if (event.manager_state !== "restore_backup") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._state = event.state;
|
||||||
|
if (event.state === "completed") {
|
||||||
|
this.closeDialog();
|
||||||
|
}
|
||||||
|
if (event.state === "failed") {
|
||||||
|
this._error = this.hass.localize(
|
||||||
|
"ui.panel.config.backup.dialogs.restore.restore_failed"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (event.state === "in_progress") {
|
||||||
|
this._stage = event.stage;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async () => {
|
||||||
|
if (isComponentLoaded(this.hass, "backup")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return (await waitForIntegrationSetup(this.hass, "backup"))
|
||||||
|
.integration_loaded;
|
||||||
}
|
}
|
||||||
if (event.manager_state !== "restore_backup") {
|
);
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._state = event.state;
|
|
||||||
if (event.state === "completed") {
|
|
||||||
this.closeDialog();
|
|
||||||
}
|
|
||||||
if (event.state === "failed") {
|
|
||||||
this._error = this.hass.localize(
|
|
||||||
"ui.panel.config.backup.dialogs.restore.restore_failed"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (event.state === "in_progress") {
|
|
||||||
this._stage = event.stage;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _unsubscribe() {
|
private _unsubscribe() {
|
||||||
|
10
yarn.lock
10
yarn.lock
@ -9483,7 +9483,7 @@ __metadata:
|
|||||||
gulp-rename: "npm:2.0.0"
|
gulp-rename: "npm:2.0.0"
|
||||||
gulp-zopfli-green: "npm:6.0.2"
|
gulp-zopfli-green: "npm:6.0.2"
|
||||||
hls.js: "patch:hls.js@npm%3A1.5.7#~/.yarn/patches/hls.js-npm-1.5.7-f5bbd3d060.patch"
|
hls.js: "patch:hls.js@npm%3A1.5.7#~/.yarn/patches/hls.js-npm-1.5.7-f5bbd3d060.patch"
|
||||||
home-assistant-js-websocket: "npm:9.4.0"
|
home-assistant-js-websocket: "npm:9.5.0"
|
||||||
html-minifier-terser: "npm:7.2.0"
|
html-minifier-terser: "npm:7.2.0"
|
||||||
husky: "npm:9.1.7"
|
husky: "npm:9.1.7"
|
||||||
idb-keyval: "npm:6.2.1"
|
idb-keyval: "npm:6.2.1"
|
||||||
@ -9546,10 +9546,10 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"home-assistant-js-websocket@npm:9.4.0":
|
"home-assistant-js-websocket@npm:9.5.0":
|
||||||
version: 9.4.0
|
version: 9.5.0
|
||||||
resolution: "home-assistant-js-websocket@npm:9.4.0"
|
resolution: "home-assistant-js-websocket@npm:9.5.0"
|
||||||
checksum: 10/af886bdd5d9200a7fd279082b2a108ce9deeb97e3fe9cb363e8e74ec87960d303ecb58b4ebf40efb325738f8190d4f152503bfe47e85ab6e5bf9209b0e91f838
|
checksum: 10/42f991b3b85aa61be28984f099a001ac083fb3da54b2777283d0c97976c564a303d8d4ba467e1b8e29cbc33151cd6eef64c1a7d3392d62bbb9cbb27aa7ca9942
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user