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

View File

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