mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 02:36:37 +00:00
Use backend logic for partial backup while updating (#11364)
This commit is contained in:
parent
930c7e4afa
commit
7ad0b37a9e
@ -29,10 +29,6 @@ import {
|
|||||||
HassioAddonDetails,
|
HassioAddonDetails,
|
||||||
updateHassioAddon,
|
updateHassioAddon,
|
||||||
} from "../../../src/data/hassio/addon";
|
} from "../../../src/data/hassio/addon";
|
||||||
import {
|
|
||||||
createHassioPartialBackup,
|
|
||||||
HassioPartialBackupCreateParams,
|
|
||||||
} from "../../../src/data/hassio/backup";
|
|
||||||
import {
|
import {
|
||||||
extractApiErrorMessage,
|
extractApiErrorMessage,
|
||||||
ignoreSupervisorError,
|
ignoreSupervisorError,
|
||||||
@ -103,7 +99,7 @@ class UpdateAvailableCard extends LitElement {
|
|||||||
|
|
||||||
@state() private _addonInfo?: HassioAddonDetails;
|
@state() private _addonInfo?: HassioAddonDetails;
|
||||||
|
|
||||||
@state() private _action: "backup" | "update" | null = null;
|
@state() private _updating = false;
|
||||||
|
|
||||||
@state() private _error?: string;
|
@state() private _error?: string;
|
||||||
|
|
||||||
@ -138,7 +134,7 @@ class UpdateAvailableCard extends LitElement {
|
|||||||
name: this._name,
|
name: this._name,
|
||||||
})}
|
})}
|
||||||
</p>`
|
</p>`
|
||||||
: this._action === null
|
: !this._updating
|
||||||
? html`
|
? html`
|
||||||
${this._changelogContent
|
${this._changelogContent
|
||||||
? html`
|
? html`
|
||||||
@ -172,18 +168,13 @@ class UpdateAvailableCard extends LitElement {
|
|||||||
: html`<ha-circular-progress alt="Updating" size="large" active>
|
: html`<ha-circular-progress alt="Updating" size="large" active>
|
||||||
</ha-circular-progress>
|
</ha-circular-progress>
|
||||||
<p class="progress-text">
|
<p class="progress-text">
|
||||||
${this._action === "update"
|
${this.supervisor.localize("update_available.updating", {
|
||||||
? this.supervisor.localize("update_available.updating", {
|
|
||||||
name: this._name,
|
name: this._name,
|
||||||
version: this._version_latest,
|
version: this._version_latest,
|
||||||
})
|
})}
|
||||||
: this.supervisor.localize(
|
|
||||||
"update_available.creating_backup",
|
|
||||||
{ name: this._name }
|
|
||||||
)}
|
|
||||||
</p>`}
|
</p>`}
|
||||||
</div>
|
</div>
|
||||||
${this._version !== this._version_latest && this._action === null
|
${this._version !== this._version_latest && !this._updating
|
||||||
? html`
|
? html`
|
||||||
<div class="card-actions">
|
<div class="card-actions">
|
||||||
${changelog
|
${changelog
|
||||||
@ -319,37 +310,16 @@ class UpdateAvailableCard extends LitElement {
|
|||||||
|
|
||||||
private async _update() {
|
private async _update() {
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
if (this._shouldCreateBackup) {
|
this._updating = true;
|
||||||
let backupArgs: HassioPartialBackupCreateParams;
|
|
||||||
if (this._updateType === "addon") {
|
|
||||||
backupArgs = {
|
|
||||||
name: `addon_${this.addonSlug}_${this._version}`,
|
|
||||||
addons: [this.addonSlug!],
|
|
||||||
homeassistant: false,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
backupArgs = {
|
|
||||||
name: `${this._updateType}_${this._version}`,
|
|
||||||
folders: ["homeassistant"],
|
|
||||||
homeassistant: true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
this._action = "backup";
|
|
||||||
try {
|
|
||||||
await createHassioPartialBackup(this.hass, backupArgs);
|
|
||||||
} catch (err: any) {
|
|
||||||
this._error = extractApiErrorMessage(err);
|
|
||||||
this._action = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this._action = "update";
|
|
||||||
try {
|
try {
|
||||||
if (this._updateType === "addon") {
|
if (this._updateType === "addon") {
|
||||||
await updateHassioAddon(this.hass, this.addonSlug!);
|
await updateHassioAddon(
|
||||||
|
this.hass,
|
||||||
|
this.addonSlug!,
|
||||||
|
this._shouldCreateBackup
|
||||||
|
);
|
||||||
} else if (this._updateType === "core") {
|
} else if (this._updateType === "core") {
|
||||||
await updateCore(this.hass);
|
await updateCore(this.hass, this._shouldCreateBackup);
|
||||||
} else if (this._updateType === "os") {
|
} else if (this._updateType === "os") {
|
||||||
await updateOS(this.hass);
|
await updateOS(this.hass);
|
||||||
} else if (this._updateType === "supervisor") {
|
} else if (this._updateType === "supervisor") {
|
||||||
@ -358,11 +328,12 @@ class UpdateAvailableCard extends LitElement {
|
|||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (this.hass.connection.connected && !ignoreSupervisorError(err)) {
|
if (this.hass.connection.connected && !ignoreSupervisorError(err)) {
|
||||||
this._error = extractApiErrorMessage(err);
|
this._error = extractApiErrorMessage(err);
|
||||||
this._action = null;
|
this._updating = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fireEvent(this, "update-complete");
|
fireEvent(this, "update-complete");
|
||||||
|
this._updating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
|
@ -302,7 +302,8 @@ export const installHassioAddon = async (
|
|||||||
|
|
||||||
export const updateHassioAddon = async (
|
export const updateHassioAddon = async (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
slug: string
|
slug: string,
|
||||||
|
backup: boolean
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
|
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
|
||||||
await hass.callWS({
|
await hass.callWS({
|
||||||
@ -310,11 +311,13 @@ export const updateHassioAddon = async (
|
|||||||
endpoint: `/store/addons/${slug}/update`,
|
endpoint: `/store/addons/${slug}/update`,
|
||||||
method: "post",
|
method: "post",
|
||||||
timeout: null,
|
timeout: null,
|
||||||
|
data: { backup },
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await hass.callApi<HassioResponse<void>>(
|
await hass.callApi<HassioResponse<void>>(
|
||||||
"POST",
|
"POST",
|
||||||
`hassio/addons/${slug}/update`
|
`hassio/addons/${slug}/update`,
|
||||||
|
{ backup }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -6,15 +6,18 @@ export const restartCore = async (hass: HomeAssistant) => {
|
|||||||
await hass.callService("homeassistant", "restart");
|
await hass.callService("homeassistant", "restart");
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateCore = async (hass: HomeAssistant) => {
|
export const updateCore = async (hass: HomeAssistant, backup: boolean) => {
|
||||||
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
|
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
|
||||||
await hass.callWS({
|
await hass.callWS({
|
||||||
type: "supervisor/api",
|
type: "supervisor/api",
|
||||||
endpoint: "/core/update",
|
endpoint: "/core/update",
|
||||||
method: "post",
|
method: "post",
|
||||||
timeout: null,
|
timeout: null,
|
||||||
|
data: { backup },
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await hass.callApi<HassioResponse<void>>("POST", `hassio/core/update`);
|
await hass.callApi<HassioResponse<void>>("POST", `hassio/core/update`, {
|
||||||
|
backup,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -4296,7 +4296,6 @@
|
|||||||
"create_backup": "Create backup before updating",
|
"create_backup": "Create backup before updating",
|
||||||
"description": "You have {version} installed. Click update to update to version {newest_version}",
|
"description": "You have {version} installed. Click update to update to version {newest_version}",
|
||||||
"updating": "Updating {name} to version {version}",
|
"updating": "Updating {name} to version {version}",
|
||||||
"creating_backup": "Creating backup of {name}",
|
|
||||||
"no_update": "No update available for {name}"
|
"no_update": "No update available for {name}"
|
||||||
},
|
},
|
||||||
"confirm": {
|
"confirm": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user