Use last completed automatic backup time instead of last available ba… (#23522)

* 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
This commit is contained in:
Bram Kragten 2024-12-31 18:14:16 +01:00
parent c697843c34
commit 48a160f057
2 changed files with 18 additions and 12 deletions

View File

@ -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`
<ha-backup-summary-card
@ -119,6 +119,10 @@ class HaBackupOverviewBackups extends LitElement {
`;
}
const nextBackupDescription = this._nextBackupDescription(
this.config.schedule.state
);
if (!lastSuccessfulBackup) {
return html`
<ha-backup-summary-card
@ -126,18 +130,20 @@ class HaBackupOverviewBackups extends LitElement {
description="You have no automatic backups yet."
status="warning"
>
<ha-md-list>
<ha-md-list-item>
<ha-svg-icon slot="start" .path=${mdiCalendar}></ha-svg-icon>
<span slot="headline">${nextBackupDescription}</span>
</ha-md-list-item>
</ha-md-list>
</ha-backup-summary-card>
`;
}
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 =

View File

@ -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 {