Skip to content

Commit

Permalink
Improve onboarding backup restore (#23340)
Browse files Browse the repository at this point in the history
* Improve onboarding backup restore

* Fix onboarding backup restore

* Fix restoring value in onboarding-restore-backup
  • Loading branch information
wendevlin authored Dec 20, 2024
1 parent f1f53b9 commit 37aa2bd
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 207 deletions.
23 changes: 20 additions & 3 deletions hassio/src/components/hassio-upload-backup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mdiFolderUpload } from "@mdi/js";
import type { TemplateResult } from "lit";
import { html, LitElement } from "lit";
import { customElement, state } from "lit/decorators";
import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../../../src/common/dom/fire_event";
import "../../../src/components/ha-circular-progress";
import "../../../src/components/ha-file-upload";
Expand All @@ -10,17 +10,21 @@ import { uploadBackup } from "../../../src/data/hassio/backup";
import { extractApiErrorMessage } from "../../../src/data/hassio/common";
import { showAlertDialog } from "../../../src/dialogs/generic/show-dialog-box";
import type { HomeAssistant } from "../../../src/types";
import type { LocalizeFunc } from "../../../src/common/translations/localize";

declare global {
interface HASSDomEvents {
"backup-uploaded": { backup: HassioBackup };
"backup-cleared": void;
}
}

@customElement("hassio-upload-backup")
export class HassioUploadBackup extends LitElement {
public hass?: HomeAssistant;

@property({ attribute: false }) public localize?: LocalizeFunc;

@state() public value: string | null = null;

@state() private _uploading = false;
Expand All @@ -32,13 +36,26 @@ export class HassioUploadBackup extends LitElement {
.uploading=${this._uploading}
.icon=${mdiFolderUpload}
accept="application/x-tar"
label="Upload backup"
supports="Supports .TAR files"
.label=${this.localize?.(
"ui.panel.page-onboarding.restore.upload_backup"
) || "Upload backup"}
.supports=${this.localize?.(
"ui.panel.page-onboarding.restore.upload_supports"
) || "Supports .TAR files"}
.secondary=${this.localize?.(
"ui.panel.page-onboarding.restore.upload_drop"
) || "Or drop your file here"}
@file-picked=${this._uploadFile}
@files-cleared=${this._clear}
></ha-file-upload>
`;
}

private _clear() {
this.value = null;
fireEvent(this, "backup-cleared");
}

private async _uploadFile(ev) {
const file = ev.detail.files[0];

Expand Down
14 changes: 9 additions & 5 deletions hassio/src/components/supervisor-backup-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const _computeAddons = (addons): AddonCheckboxItem[] =>

@customElement("supervisor-backup-content")
export class SupervisorBackupContent extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public hass?: HomeAssistant;

@property({ attribute: false }) public localize?: LocalizeFunc;

Expand Down Expand Up @@ -186,12 +186,13 @@ export class SupervisorBackupContent extends LitElement {
.iconPath=${mdiHomeAssistant}
.version=${this.backup
? this.backup.homeassistant
: this.hass.config.version}
: this.hass?.config.version}
>
</supervisor-formfield-label>`}
>
<ha-checkbox
.checked=${this.homeAssistant}
.checked=${this.onboarding || this.homeAssistant}
.disabled=${this.onboarding}
@change=${this._toggleHomeAssistant}
>
</ha-checkbox>
Expand Down Expand Up @@ -334,7 +335,7 @@ export class SupervisorBackupContent extends LitElement {
| HassioFullBackupCreateParams {
const data: any = {};

if (!this.backup) {
if (!this.backup && this.hass) {
data.name =
this.backupName ||
formatDate(new Date(), this.hass.locale, this.hass.config);
Expand Down Expand Up @@ -364,7 +365,9 @@ export class SupervisorBackupContent extends LitElement {
if (folders?.length) {
data.folders = folders;
}
data.homeassistant = this.homeAssistant;

// onboarding needs at least homeassistant to restore
data.homeassistant = this.onboarding || this.homeAssistant;

return data;
}
Expand All @@ -386,6 +389,7 @@ export class SupervisorBackupContent extends LitElement {
.iconPath=${section === "addons" ? mdiPuzzle : mdiFolder}
.imageUrl=${section === "addons" &&
!this.onboarding &&
this.hass &&
atLeastVersion(this.hass.config.version, 0, 105) &&
addons?.get(item.slug)?.icon
? `/api/hassio/addons/${item.slug}/icon`
Expand Down
Loading

0 comments on commit 37aa2bd

Please sign in to comment.