From 8daea5b565b92c955e29f8f9d5e2b80af644471a Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Tue, 31 Dec 2024 18:14:16 +0100 Subject: [PATCH] =?UTF-8?q?Use=20last=20completed=20automatic=20backup=20t?= =?UTF-8?q?ime=20instead=20of=20last=20available=20ba=E2=80=A6=20(#23522)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use last completed automatic backup time instead of last available backup * Update ha-backup-overview-summary.ts * Update src/panels/config/backup/components/overview/ha-backup-overview-summary.ts * Update ha-config-backup-overview.ts --- .../overview/ha-backup-overview-summary.ts | 28 +++++++++++-------- .../backup/ha-config-backup-overview.ts | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/panels/config/backup/components/overview/ha-backup-overview-summary.ts b/src/panels/config/backup/components/overview/ha-backup-overview-summary.ts index 198797e6a6..e6e4d78195 100644 --- a/src/panels/config/backup/components/overview/ha-backup-overview-summary.ts +++ b/src/panels/config/backup/components/overview/ha-backup-overview-summary.ts @@ -84,21 +84,21 @@ class HaBackupOverviewBackups extends LitElement { const lastSuccessfulBackup = this._lastSuccessfulBackup(this.backups); - const lastSuccessfulBackupDate = lastSuccessfulBackup - ? new Date(lastSuccessfulBackup.date) - : new Date(0); - const lastAttempt = this.config.last_attempted_automatic_backup ? new Date(this.config.last_attempted_automatic_backup) : undefined; + const lastCompletedBackupDate = this.config.last_completed_automatic_backup + ? new Date(this.config.last_completed_automatic_backup) + : undefined; + const now = new Date(); const lastBackupDescription = lastSuccessfulBackup - ? `Last successful backup ${relativeTime(lastSuccessfulBackupDate, this.hass.locale, now, true)} and stored in ${lastSuccessfulBackup.agent_ids?.length} locations.` + ? `Last successful backup ${relativeTime(new Date(lastSuccessfulBackup.date), this.hass.locale, now, true)} and stored in ${lastSuccessfulBackup.agent_ids?.length} locations.` : "You have no successful backups."; - if (lastAttempt && lastAttempt > lastSuccessfulBackupDate) { + if (lastAttempt && lastAttempt > (lastCompletedBackupDate || 0)) { const lastAttemptDescription = `The last automatic backup triggered ${relativeTime(lastAttempt, this.hass.locale, now, true)} wasn't successful.`; return html` + + + + ${nextBackupDescription} + + `; } - const nextBackupDescription = this._nextBackupDescription( - this.config.schedule.state - ); - const numberOfDays = differenceInDays( // Subtract a few hours to avoid showing as overdue if it's just a few hours (e.g. daylight saving) addHours(now, -OVERDUE_MARGIN_HOURS), - lastSuccessfulBackupDate + new Date(lastSuccessfulBackup.date) ); const isOverdue = diff --git a/src/panels/config/backup/ha-config-backup-overview.ts b/src/panels/config/backup/ha-config-backup-overview.ts index 0a132b799f..bc86bc8cc2 100644 --- a/src/panels/config/backup/ha-config-backup-overview.ts +++ b/src/panels/config/backup/ha-config-backup-overview.ts @@ -127,7 +127,7 @@ class HaConfigBackupOverview extends LitElement { } private get _needsOnboarding() { - return !this.config?.create_backup.password; + return this.config && !this.config.create_backup.password; } protected render(): TemplateResult {