Skip to content

Commit

Permalink
Remove backup toggle from supervisor addon page when update available (
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten committed Jan 6, 2025
1 parent a755af9 commit 760d898
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 58 deletions.
47 changes: 2 additions & 45 deletions hassio/src/update-available/update-available-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import "../../../src/components/ha-checkbox";
import "../../../src/components/ha-faded";
import "../../../src/components/ha-icon-button";
import "../../../src/components/ha-markdown";
import "../../../src/components/ha-settings-row";
import "../../../src/components/ha-svg-icon";
import "../../../src/components/ha-switch";
import type { HaSwitch } from "../../../src/components/ha-switch";
import type { HassioAddonDetails } from "../../../src/data/hassio/addon";
import {
fetchHassioAddonChangelog,
Expand Down Expand Up @@ -163,19 +160,6 @@ class UpdateAvailableCard extends LitElement {
)}
</p>
</div>
${["core", "addon"].includes(this._updateType)
? html`
<hr />
<ha-settings-row>
<span slot="heading">
${this.supervisor.localize(
"update_available.create_backup"
)}
</span>
<ha-switch id="create_backup" checked></ha-switch>
</ha-settings-row>
`
: nothing}
`
: html`<ha-circular-progress
aria-label="Updating"
Expand Down Expand Up @@ -243,19 +227,6 @@ class UpdateAvailableCard extends LitElement {
}
}

get _shouldCreateBackup(): boolean {
if (this._updateType && !["core", "addon"].includes(this._updateType)) {
return false;
}
const createBackupSwitch = this.shadowRoot?.getElementById(
"create-backup"
) as HaSwitch;
if (createBackupSwitch) {
return createBackupSwitch.checked;
}
return true;
}

get _version(): string {
return this._updateType
? this._updateType === "addon"
Expand Down Expand Up @@ -370,23 +341,14 @@ class UpdateAvailableCard extends LitElement {
}

private async _update() {
if (this._shouldCreateBackup && this.supervisor.info.state === "freeze") {
this._error = this.supervisor.localize("backup.backup_already_running");
return;
}

this._error = undefined;
this._updating = true;

try {
if (this._updateType === "addon") {
await updateHassioAddon(
this.hass,
this.addonSlug!,
this._shouldCreateBackup
);
await updateHassioAddon(this.hass, this.addonSlug!);
} else if (this._updateType === "core") {
await updateCore(this.hass, this._shouldCreateBackup);
await updateCore(this.hass);
} else if (this._updateType === "os") {
await updateOS(this.hass);
} else if (this._updateType === "supervisor") {
Expand Down Expand Up @@ -436,11 +398,6 @@ class UpdateAvailableCard extends LitElement {
padding-bottom: 8px;
}
ha-settings-row {
padding: 0;
margin-bottom: -16px;
}
hr {
border-color: var(--divider-color);
border-bottom: none;
Expand Down
7 changes: 2 additions & 5 deletions src/data/hassio/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,22 +313,19 @@ export const installHassioAddon = async (

export const updateHassioAddon = async (
hass: HomeAssistant,
slug: string,
backup: boolean
slug: string
): Promise<void> => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
await hass.callWS({
type: "supervisor/api",
endpoint: `/store/addons/${slug}/update`,
method: "post",
timeout: null,
data: { backup },
});
} else {
await hass.callApi<HassioResponse<void>>(
"POST",
`hassio/addons/${slug}/update`,
{ backup }
`hassio/addons/${slug}/update`
);
}
};
Expand Down
7 changes: 2 additions & 5 deletions src/data/supervisor/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ export const restartCore = async (hass: HomeAssistant) => {
await hass.callService("homeassistant", "restart");
};

export const updateCore = async (hass: HomeAssistant, backup: boolean) => {
export const updateCore = async (hass: HomeAssistant) => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
await hass.callWS({
type: "supervisor/api",
endpoint: "/core/update",
method: "post",
timeout: null,
data: { backup },
});
} else {
await hass.callApi<HassioResponse<void>>("POST", `hassio/core/update`, {
backup,
});
await hass.callApi<HassioResponse<void>>("POST", "hassio/core/update");
}
};
4 changes: 1 addition & 3 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,6 @@
"clear_skipped": "Clear skipped",
"install": "Install",
"update": "Update",
"create_backup": "Create backup before updating",
"auto_update_enabled_title": "Can not skip version",
"auto_update_enabled_text": "Automatic updates for this item have been enabled; skipping it is, therefore, unavailable. You can either install this update now or wait for Home Assistant to do it automatically."
},
Expand Down Expand Up @@ -8001,8 +8000,7 @@
"update_available": {
"update_name": "Update {name}",
"open_release_notes": "Open release notes",
"create_backup": "Create backup before updating",
"description": "You have {version} installed. Click update to update to version {newest_version}",
"description": "You have {version} installed. Press update to update to version {newest_version}",
"updating": "Updating {name} to version {version}",
"no_update": "No update available for {name}"
},
Expand Down

0 comments on commit 760d898

Please sign in to comment.