Skip to content

Commit

Permalink
Use last completed automatic backup time instead of last available ba… (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
bramkragten authored Dec 31, 2024
1 parent cd69c4c commit 8daea5b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -119,25 +119,31 @@ class HaBackupOverviewBackups extends LitElement {
`;
}

const nextBackupDescription = this._nextBackupDescription(
this.config.schedule.state
);

if (!lastSuccessfulBackup) {
return html`
<ha-backup-summary-card
heading="No automatic backup available"
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 =
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/backup/ha-config-backup-overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8daea5b

Please sign in to comment.