mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 18:56:39 +00:00
Show supervisor addon configuration error (#8950)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
23c1c2f5eb
commit
6e5e2625d6
@ -262,6 +262,11 @@ class HassioAddonConfig extends LitElement {
|
|||||||
|
|
||||||
private async _saveTapped(ev: CustomEvent): Promise<void> {
|
private async _saveTapped(ev: CustomEvent): Promise<void> {
|
||||||
const button = ev.currentTarget as any;
|
const button = ev.currentTarget as any;
|
||||||
|
const eventdata = {
|
||||||
|
success: true,
|
||||||
|
response: undefined,
|
||||||
|
path: "options",
|
||||||
|
};
|
||||||
button.progress = true;
|
button.progress = true;
|
||||||
|
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
@ -272,23 +277,19 @@ class HassioAddonConfig extends LitElement {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this._configHasChanged = false;
|
this._configHasChanged = false;
|
||||||
const eventdata = {
|
|
||||||
success: true,
|
|
||||||
response: undefined,
|
|
||||||
path: "options",
|
|
||||||
};
|
|
||||||
fireEvent(this, "hass-api-called", eventdata);
|
|
||||||
if (this.addon?.state === "started") {
|
if (this.addon?.state === "started") {
|
||||||
await suggestAddonRestart(this, this.hass, this.supervisor, this.addon);
|
await suggestAddonRestart(this, this.hass, this.supervisor, this.addon);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this._error = this.supervisor.localize(
|
this._error = this.supervisor.localize(
|
||||||
"addon.configuration.options.failed_to_save",
|
"addon.failed_to_save",
|
||||||
"error",
|
"error",
|
||||||
extractApiErrorMessage(err)
|
extractApiErrorMessage(err)
|
||||||
);
|
);
|
||||||
|
eventdata.success = false;
|
||||||
}
|
}
|
||||||
button.progress = false;
|
button.progress = false;
|
||||||
|
fireEvent(this, "hass-api-called", eventdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResult[] {
|
static get styles(): CSSResult[] {
|
||||||
|
@ -191,6 +191,10 @@ class HassioAddonDashboard extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _apiCalled(ev): Promise<void> {
|
private async _apiCalled(ev): Promise<void> {
|
||||||
|
if (!ev.detail.success) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const pathSplit: string[] = ev.detail.path?.split("/");
|
const pathSplit: string[] = ev.detail.path?.split("/");
|
||||||
|
|
||||||
if (!pathSplit || pathSplit.length === 0) {
|
if (!pathSplit || pathSplit.length === 0) {
|
||||||
|
@ -2,7 +2,11 @@ import { atLeastVersion } from "../../common/config/version";
|
|||||||
import { HaFormSchema } from "../../components/ha-form/ha-form";
|
import { HaFormSchema } from "../../components/ha-form/ha-form";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import { SupervisorArch } from "../supervisor/supervisor";
|
import { SupervisorArch } from "../supervisor/supervisor";
|
||||||
import { hassioApiResultExtractor, HassioResponse } from "./common";
|
import {
|
||||||
|
extractApiErrorMessage,
|
||||||
|
hassioApiResultExtractor,
|
||||||
|
HassioResponse,
|
||||||
|
} from "./common";
|
||||||
|
|
||||||
export type AddonStage = "stable" | "experimental" | "deprecated";
|
export type AddonStage = "stable" | "experimental" | "deprecated";
|
||||||
export type AddonAppArmour = "disable" | "default" | "profile";
|
export type AddonAppArmour = "disable" | "default" | "profile";
|
||||||
@ -186,16 +190,20 @@ export const setHassioAddonOption = async (
|
|||||||
data: HassioAddonSetOptionParams
|
data: HassioAddonSetOptionParams
|
||||||
) => {
|
) => {
|
||||||
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
|
if (atLeastVersion(hass.config.version, 2021, 2, 4)) {
|
||||||
await hass.callWS({
|
const response = await hass.callWS<HassioResponse<any>>({
|
||||||
type: "supervisor/api",
|
type: "supervisor/api",
|
||||||
endpoint: `/addons/${slug}/options`,
|
endpoint: `/addons/${slug}/options`,
|
||||||
method: "post",
|
method: "post",
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
|
if (response.result === "error") {
|
||||||
|
throw Error(extractApiErrorMessage(response));
|
||||||
|
}
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
await hass.callApi<HassioResponse<void>>(
|
return hass.callApi<HassioResponse<any>>(
|
||||||
"POST",
|
"POST",
|
||||||
`hassio/addons/${slug}/options`,
|
`hassio/addons/${slug}/options`,
|
||||||
data
|
data
|
||||||
|
@ -3,7 +3,8 @@ import { HomeAssistant } from "../../types";
|
|||||||
|
|
||||||
export interface HassioResponse<T> {
|
export interface HassioResponse<T> {
|
||||||
data: T;
|
data: T;
|
||||||
result: "ok";
|
message?: string;
|
||||||
|
result: "ok" | "error";
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HassioStats {
|
export interface HassioStats {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user