Add automatic backup toggle to OS update (#24995)

This commit is contained in:
Wendelin 2025-04-11 15:10:43 +02:00 committed by GitHub
parent 14e0666c3a
commit 1dfd937c94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 13 deletions

View File

@ -207,7 +207,11 @@ export const computeUpdateStateDisplay = (
return hass.formatEntityState(stateObj);
};
export type UpdateType = "addon" | "home_assistant" | "generic";
export type UpdateType =
| "addon"
| "home_assistant"
| "home_assistant_os"
| "generic";
export const getUpdateType = (
stateObj: UpdateEntity,
@ -215,6 +219,7 @@ export const getUpdateType = (
): UpdateType => {
const entity_id = stateObj.entity_id;
const domain = entitySources[entity_id]?.domain;
if (domain !== "hassio") {
return "generic";
}
@ -224,13 +229,11 @@ export const getUpdateType = (
return "home_assistant";
}
if (
![
HOME_ASSISTANT_CORE_TITLE,
HOME_ASSISTANT_SUPERVISOR_TITLE,
HOME_ASSISTANT_OS_TITLE,
].includes(title)
) {
if (title === HOME_ASSISTANT_OS_TITLE) {
return "home_assistant_os";
}
if (title !== HOME_ASSISTANT_SUPERVISOR_TITLE) {
return "addon";
}
return "generic";

View File

@ -64,7 +64,8 @@ class MoreInfoUpdate extends LitElement {
try {
const config = await getSupervisorUpdateConfig(this.hass);
if (type === "home_assistant") {
// for home assistant and OS updates
if (this._isHaOrOsUpdate(type)) {
this._createBackup = config.core_backup_before_update;
return;
}
@ -83,6 +84,10 @@ class MoreInfoUpdate extends LitElement {
this._entitySources = await fetchEntitySourcesWithCache(this.hass);
}
private _isHaOrOsUpdate(type: UpdateType): boolean {
return ["home_assistant", "home_assistant_os"].includes(type);
}
private _computeCreateBackupTexts():
| { title: string; description?: string }
| undefined {
@ -97,8 +102,7 @@ class MoreInfoUpdate extends LitElement {
? getUpdateType(this.stateObj, this._entitySources)
: "generic";
// Automatic or manual for Home Assistant update
if (updateType === "home_assistant") {
if (this._isHaOrOsUpdate(updateType)) {
const isBackupConfigValid =
!!this._backupConfig &&
!!this._backupConfig.automatic_backups_configured &&
@ -350,11 +354,12 @@ class MoreInfoUpdate extends LitElement {
const type = getUpdateType(this.stateObj!, this._entitySources!);
if (
isComponentLoaded(this.hass, "hassio") &&
["home_assistant", "addon"].includes(type)
["addon", "home_assistant", "home_assistant_os"].includes(type)
) {
this._fetchUpdateBackupConfig(type);
}
if (type === "home_assistant") {
if (this._isHaOrOsUpdate(type)) {
this._fetchBackupConfig();
}
});