Move add-on rebuild over to WS for newer core versions (#16180)

This commit is contained in:
Joakim Sørensen 2023-04-14 13:33:03 +02:00 committed by GitHub
parent fa4550a848
commit 3a1fff81b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 9 deletions

View File

@ -29,7 +29,6 @@ import memoizeOne from "memoize-one";
import { atLeastVersion } from "../../../../src/common/config/version"; import { atLeastVersion } from "../../../../src/common/config/version";
import { fireEvent } from "../../../../src/common/dom/fire_event"; import { fireEvent } from "../../../../src/common/dom/fire_event";
import { navigate } from "../../../../src/common/navigate"; import { navigate } from "../../../../src/common/navigate";
import "../../../../src/components/buttons/ha-call-api-button";
import "../../../../src/components/buttons/ha-progress-button"; import "../../../../src/components/buttons/ha-progress-button";
import "../../../../src/components/ha-alert"; import "../../../../src/components/ha-alert";
import "../../../../src/components/ha-card"; import "../../../../src/components/ha-card";
@ -47,6 +46,7 @@ import {
HassioAddonSetOptionParams, HassioAddonSetOptionParams,
HassioAddonSetSecurityParams, HassioAddonSetSecurityParams,
installHassioAddon, installHassioAddon,
rebuildLocalAddon,
restartHassioAddon, restartHassioAddon,
setHassioAddonOption, setHassioAddonOption,
setHassioAddonSecurity, setHassioAddonSecurity,
@ -640,13 +640,12 @@ class HassioAddonInfo extends LitElement {
</ha-progress-button> </ha-progress-button>
${this.addon.build ${this.addon.build
? html` ? html`
<ha-call-api-button <ha-progress-button
class="warning" class="warning"
.hass=${this.hass} @click=${this._rebuildClicked}
.path="hassio/addons/${this.addon.slug}/rebuild"
> >
${this.supervisor.localize("addon.dashboard.rebuild")} ${this.supervisor.localize("addon.dashboard.rebuild")}
</ha-call-api-button> </ha-progress-button>
` `
: ""}` : ""}`
: ""} : ""}
@ -966,6 +965,21 @@ class HassioAddonInfo extends LitElement {
button.progress = false; button.progress = false;
} }
private async _rebuildClicked(ev: CustomEvent): Promise<void> {
const button = ev.currentTarget as any;
button.progress = true;
try {
await rebuildLocalAddon(this.hass, this.addon.slug);
} catch (err: any) {
showAlertDialog(this, {
title: this.supervisor.localize("addon.dashboard.action_error.rebuild"),
text: extractApiErrorMessage(err),
});
}
button.progress = false;
}
private async _startClicked(ev: CustomEvent): Promise<void> { private async _startClicked(ev: CustomEvent): Promise<void> {
const button = ev.currentTarget as any; const button = ev.currentTarget as any;
button.progress = true; button.progress = true;
@ -1124,10 +1138,6 @@ class HassioAddonInfo extends LitElement {
ha-svg-icon.stopped { ha-svg-icon.stopped {
color: var(--error-color); color: var(--error-color);
} }
ha-call-api-button {
font-weight: 500;
color: var(--primary-color);
}
protection-enable mwc-button { protection-enable mwc-button {
--mdc-theme-primary: white; --mdc-theme-primary: white;
} }

View File

@ -381,3 +381,23 @@ export const fetchAddonInfo = (
? `/store/addons/${addonSlug}` // Use /store/addons when add-on is not installed ? `/store/addons/${addonSlug}` // Use /store/addons when add-on is not installed
: `/addons/${addonSlug}/info` // Use /addons when add-on is installed : `/addons/${addonSlug}/info` // Use /addons when add-on is installed
); );
export const rebuildLocalAddon = async (
hass: HomeAssistant,
slug: string
): Promise<void> => {
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
return hass.callWS<void>({
type: "supervisor/api",
endpoint: `/addons/${slug}/rebuild`,
method: "post",
timeout: null,
});
}
return (
await hass.callApi<HassioResponse<void>>(
"POST",
`hassio/addons/${slug}rebuild`
)
).data;
};

View File

@ -5373,6 +5373,7 @@
"uninstall": "Failed to uninstall add-on", "uninstall": "Failed to uninstall add-on",
"install": "Failed to install add-on", "install": "Failed to install add-on",
"stop": "Failed to stop add-on", "stop": "Failed to stop add-on",
"rebuild": "Failed to rebuild add-on",
"restart": "Failed to restart add-on", "restart": "Failed to restart add-on",
"start": "Failed to start add-on", "start": "Failed to start add-on",
"go_to_config": "Edit Config", "go_to_config": "Edit Config",