From 54320c3dbfa06ed6bb00bafa982e096ac702ffb3 Mon Sep 17 00:00:00 2001
From: Petar Petrov
Date: Tue, 22 Oct 2024 19:30:32 +0300
Subject: [PATCH] Add option to delete add-on config on uninstall (#22268)
---
.../src/addon-view/info/hassio-addon-info.ts | 21 +++++++++++++++++--
src/data/hassio/addon.ts | 9 +++++---
src/translations/en.json | 2 +-
3 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/hassio/src/addon-view/info/hassio-addon-info.ts b/hassio/src/addon-view/info/hassio-addon-info.ts
index fe8f4f4308dc..0a9ace35a56f 100644
--- a/hassio/src/addon-view/info/hassio-addon-info.ts
+++ b/hassio/src/addon-view/info/hassio-addon-info.ts
@@ -38,6 +38,7 @@ 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 {
AddonCapability,
HassioAddonDetails,
@@ -1119,12 +1120,28 @@ class HassioAddonInfo extends LitElement {
private async _uninstallClicked(ev: CustomEvent): Promise {
const button = ev.currentTarget as any;
button.progress = true;
+ let removeData = false;
+ const _removeDataToggled = (e: Event) => {
+ removeData = (e.target as HaSwitch).checked;
+ };
const confirmed = await showConfirmationDialog(this, {
title: this.supervisor.localize("dialog.uninstall_addon.title", {
name: this.addon.name,
}),
- text: this.supervisor.localize("dialog.uninstall_addon.text"),
+ text: html`
+
+ ${this.supervisor.localize("dialog.uninstall_addon.remove_data")}
+
`}
+ >
+
+
+ `,
confirmText: this.supervisor.localize("dialog.uninstall_addon.uninstall"),
dismissText: this.supervisor.localize("common.cancel"),
destructive: true,
@@ -1137,7 +1154,7 @@ class HassioAddonInfo extends LitElement {
this._error = undefined;
try {
- await uninstallHassioAddon(this.hass, this.addon.slug);
+ await uninstallHassioAddon(this.hass, this.addon.slug, removeData);
const eventdata = {
success: true,
response: undefined,
diff --git a/src/data/hassio/addon.ts b/src/data/hassio/addon.ts
index def1e765e586..b60c31008d68 100644
--- a/src/data/hassio/addon.ts
+++ b/src/data/hassio/addon.ts
@@ -358,21 +358,24 @@ export const restartHassioAddon = async (
export const uninstallHassioAddon = async (
hass: HomeAssistant,
- slug: string
-) => {
+ slug: string,
+ removeData: boolean
+): Promise => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
await hass.callWS({
type: "supervisor/api",
endpoint: `/addons/${slug}/uninstall`,
method: "post",
timeout: null,
+ data: { remove_config: removeData },
});
return;
}
await hass.callApi>(
"POST",
- `hassio/addons/${slug}/uninstall`
+ `hassio/addons/${slug}/uninstall`,
+ { remove_config: removeData }
);
};
diff --git a/src/translations/en.json b/src/translations/en.json
index 1f1964330484..d0a62f91b975 100644
--- a/src/translations/en.json
+++ b/src/translations/en.json
@@ -7754,7 +7754,7 @@
},
"uninstall_addon": {
"title": "Uninstall {name}?",
- "text": "Its configuration will be permanently deleted.",
+ "remove_data": "Also permanently delete this addon's data",
"uninstall": "Uninstall"
},
"hardware": {