Skip to content

Commit

Permalink
Move add-on rebuild over to WS for newer core versions (#16180)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Apr 14, 2023
1 parent fa4550a commit 3a1fff8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
28 changes: 19 additions & 9 deletions hassio/src/addon-view/info/hassio-addon-info.ts
Expand Up @@ -29,7 +29,6 @@ import memoizeOne from "memoize-one";
import { atLeastVersion } from "../../../../src/common/config/version";
import { fireEvent } from "../../../../src/common/dom/fire_event";
import { navigate } from "../../../../src/common/navigate";
import "../../../../src/components/buttons/ha-call-api-button";
import "../../../../src/components/buttons/ha-progress-button";
import "../../../../src/components/ha-alert";
import "../../../../src/components/ha-card";
Expand All @@ -47,6 +46,7 @@ import {
HassioAddonSetOptionParams,
HassioAddonSetSecurityParams,
installHassioAddon,
rebuildLocalAddon,
restartHassioAddon,
setHassioAddonOption,
setHassioAddonSecurity,
Expand Down Expand Up @@ -640,13 +640,12 @@ class HassioAddonInfo extends LitElement {
</ha-progress-button>
${this.addon.build
? html`
<ha-call-api-button
<ha-progress-button
class="warning"
.hass=${this.hass}
.path="hassio/addons/${this.addon.slug}/rebuild"
@click=${this._rebuildClicked}
>
${this.supervisor.localize("addon.dashboard.rebuild")}
</ha-call-api-button>
</ha-progress-button>
`
: ""}`
: ""}
Expand Down Expand Up @@ -966,6 +965,21 @@ class HassioAddonInfo extends LitElement {
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> {
const button = ev.currentTarget as any;
button.progress = true;
Expand Down Expand Up @@ -1124,10 +1138,6 @@ class HassioAddonInfo extends LitElement {
ha-svg-icon.stopped {
color: var(--error-color);
}
ha-call-api-button {
font-weight: 500;
color: var(--primary-color);
}
protection-enable mwc-button {
--mdc-theme-primary: white;
}
Expand Down
20 changes: 20 additions & 0 deletions src/data/hassio/addon.ts
Expand Up @@ -381,3 +381,23 @@ export const fetchAddonInfo = (
? `/store/addons/${addonSlug}` // Use /store/addons when add-on is not 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;
};
1 change: 1 addition & 0 deletions src/translations/en.json
Expand Up @@ -5373,6 +5373,7 @@
"uninstall": "Failed to uninstall add-on",
"install": "Failed to install add-on",
"stop": "Failed to stop add-on",
"rebuild": "Failed to rebuild add-on",
"restart": "Failed to restart add-on",
"start": "Failed to start add-on",
"go_to_config": "Edit Config",
Expand Down

0 comments on commit 3a1fff8

Please sign in to comment.