-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
311 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/panels/config/backup/components/ha-backup-summary-progress.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { html, LitElement } from "lit"; | ||
import { customElement, property } from "lit/decorators"; | ||
import type { ManagerStateEvent } from "../../../../data/backup_manager"; | ||
import type { HomeAssistant } from "../../../../types"; | ||
import "./ha-backup-summary-card"; | ||
|
||
@customElement("ha-backup-summary-progress") | ||
export class HaBackupSummaryProgress extends LitElement { | ||
@property({ attribute: false }) public hass!: HomeAssistant; | ||
|
||
@property({ attribute: false }) public manager!: ManagerStateEvent; | ||
|
||
@property({ type: Boolean, attribute: "has-action" }) | ||
public hasAction = false; | ||
|
||
private get _heading() { | ||
switch (this.manager.manager_state) { | ||
case "create_backup": | ||
return "Creating backup"; | ||
case "restore_backup": | ||
return "Restoring backup"; | ||
case "receive_backup": | ||
return "Receiving backup"; | ||
default: | ||
return ""; | ||
} | ||
} | ||
|
||
private get _description() { | ||
switch (this.manager.manager_state) { | ||
case "create_backup": | ||
switch (this.manager.stage) { | ||
case "addon_repositories": | ||
case "addons": | ||
return "Backing up add-ons"; | ||
case "await_addon_restarts": | ||
return "Waiting for add-ons to restart"; | ||
case "docker_config": | ||
return "Backing up Docker configuration"; | ||
case "finishing_file": | ||
return "Finishing backup file"; | ||
case "folders": | ||
return "Backing up folders"; | ||
case "home_assistant": | ||
return "Backing up Home Assistant"; | ||
case "upload_to_agents": | ||
return "Uploading to locations"; | ||
default: | ||
return ""; | ||
} | ||
case "restore_backup": | ||
switch (this.manager.stage) { | ||
case "addon_repositories": | ||
case "addons": | ||
return "Restoring add-ons"; | ||
case "await_addon_restarts": | ||
return "Waiting for add-ons to restart"; | ||
case "await_home_assistant_restart": | ||
return "Waiting for Home Assistant to restart"; | ||
case "check_home_assistant": | ||
return "Checking Home Assistant"; | ||
case "docker_config": | ||
return "Restoring Docker configuration"; | ||
case "download_from_agent": | ||
return "Downloading from location"; | ||
case "folders": | ||
return "Restoring folders"; | ||
case "home_assistant": | ||
return "Restoring Home Assistant"; | ||
case "remove_delta_addons": | ||
return "Removing delta add-ons"; | ||
default: | ||
return ""; | ||
} | ||
case "receive_backup": | ||
switch (this.manager.stage) { | ||
case "receive_file": | ||
return "Receiving file"; | ||
case "upload_to_agents": | ||
return "Uploading to locations"; | ||
default: | ||
return ""; | ||
} | ||
default: | ||
return ""; | ||
} | ||
} | ||
|
||
protected render() { | ||
return html` | ||
<ha-backup-summary-card | ||
.hass=${this.hass} | ||
.heading=${this._heading} | ||
.description=${this._description} | ||
status="loading" | ||
.hasAction=${this.hasAction} | ||
> | ||
<slot name="action" slot="action"></slot> | ||
</ha-backup-summary-card> | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"ha-backup-summary-progress": HaBackupSummaryProgress; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
src/panels/config/backup/components/ha-backup-summary-status.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { html, LitElement } from "lit"; | ||
import { customElement, property } from "lit/decorators"; | ||
import memoizeOne from "memoize-one"; | ||
import { formatShortDateTime } from "../../../../common/datetime/format_date_time"; | ||
import type { BackupContent } from "../../../../data/backup"; | ||
import type { ManagerStateEvent } from "../../../../data/backup_manager"; | ||
import type { HomeAssistant } from "../../../../types"; | ||
import "./ha-backup-summary-card"; | ||
|
||
@customElement("ha-backup-summary-status") | ||
export class HaBackupSummaryProgress extends LitElement { | ||
@property({ attribute: false }) public hass!: HomeAssistant; | ||
|
||
@property({ attribute: false }) public manager!: ManagerStateEvent; | ||
|
||
@property({ attribute: false }) public backups!: BackupContent[]; | ||
|
||
@property({ type: Boolean, attribute: "has-action" }) | ||
public hasAction = false; | ||
|
||
private _lastBackup = memoizeOne((backups: BackupContent[]) => { | ||
const sortedBackups = backups | ||
// eslint-disable-next-line arrow-body-style | ||
.filter((backup) => { | ||
// TODO : only show backups with default flag | ||
return backup; | ||
}) | ||
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()); | ||
|
||
return sortedBackups[0] as BackupContent | undefined; | ||
}); | ||
|
||
protected render() { | ||
const lastBackup = this._lastBackup(this.backups); | ||
|
||
if (!lastBackup) { | ||
return html` | ||
<ha-backup-summary-card | ||
heading="No backup available" | ||
description="You have not created any backups yet." | ||
.hasAction=${this.hasAction} | ||
status="warning" | ||
> | ||
<slot name="action" slot="action"></slot> | ||
</ha-backup-summary-card> | ||
`; | ||
} | ||
|
||
const lastBackupDate = new Date(lastBackup.date); | ||
const lastBackupPeriod = new Date().getTime() - lastBackupDate.getTime(); | ||
const numberOfDays = Math.floor(lastBackupPeriod / (1000 * 60 * 60 * 24)); | ||
|
||
// TODO : Improve time format | ||
const description = `Last successful backup ${formatShortDateTime(lastBackupDate, this.hass.locale, this.hass.config)} and synced to ${lastBackup.agent_ids?.length} locations`; | ||
if (numberOfDays > 8) { | ||
return html` | ||
<ha-backup-summary-card | ||
heading=${`No backup for ${numberOfDays} days`} | ||
description=${description} | ||
.hasAction=${this.hasAction} | ||
status="warning" | ||
> | ||
<slot name="action" slot="action"></slot> | ||
</ha-backup-summary-card> | ||
`; | ||
} | ||
return html` | ||
<ha-backup-summary-card | ||
heading=${`Backed up`} | ||
description=${description} | ||
.hasAction=${this.hasAction} | ||
status="success" | ||
> | ||
<slot name="action" slot="action"></slot> | ||
</ha-backup-summary-card> | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"ha-backup-summary-status": HaBackupSummaryProgress; | ||
} | ||
} |
Oops, something went wrong.