hassio-addon-network feedback (#6733)

This commit is contained in:
Joakim Sørensen 2020-09-03 10:33:45 +02:00 committed by GitHub
parent 35923709e2
commit 6d8d263ca6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 47 additions and 35 deletions

View File

@ -21,6 +21,7 @@ import { haStyle } from "../../../../src/resources/styles";
import { HomeAssistant } from "../../../../src/types"; import { HomeAssistant } from "../../../../src/types";
import { suggestAddonRestart } from "../../dialogs/suggestAddonRestart"; import { suggestAddonRestart } from "../../dialogs/suggestAddonRestart";
import { hassioStyle } from "../../resources/hassio-style"; import { hassioStyle } from "../../resources/hassio-style";
import "../../../../src/components/buttons/ha-progress-button";
interface NetworkItem { interface NetworkItem {
description: string; description: string;
@ -85,38 +86,17 @@ class HassioAddonNetwork extends LitElement {
</table> </table>
</div> </div>
<div class="card-actions"> <div class="card-actions">
<mwc-button class="warning" @click=${this._resetTapped}> <ha-progress-button class="warning" @click=${this._resetTapped}>
Reset to defaults Reset to defaults </ha-progress-button
</mwc-button> >>
<mwc-button @click=${this._saveTapped}>Save</mwc-button> <ha-progress-button @click=${this._saveTapped}>
Save
</ha-progress-button>
</div> </div>
</ha-card> </ha-card>
`; `;
} }
static get styles(): CSSResult[] {
return [
haStyle,
hassioStyle,
css`
:host {
display: block;
}
ha-card {
display: block;
}
.errors {
color: var(--error-color);
margin-bottom: 16px;
}
.card-actions {
display: flex;
justify-content: space-between;
}
`,
];
}
protected update(changedProperties: PropertyValues): void { protected update(changedProperties: PropertyValues): void {
super.update(changedProperties); super.update(changedProperties);
if (changedProperties.has("addon")) { if (changedProperties.has("addon")) {
@ -149,7 +129,10 @@ class HassioAddonNetwork extends LitElement {
}); });
} }
private async _resetTapped(): Promise<void> { private async _resetTapped(ev: CustomEvent): Promise<void> {
const button = ev.target as any;
button.progress = true;
const data: HassioAddonSetOptionParams = { const data: HassioAddonSetOptionParams = {
network: null, network: null,
}; };
@ -162,17 +145,22 @@ class HassioAddonNetwork extends LitElement {
path: "option", path: "option",
}; };
fireEvent(this, "hass-api-called", eventdata); fireEvent(this, "hass-api-called", eventdata);
if (this.addon?.state === "started") {
await suggestAddonRestart(this, this.hass, this.addon);
}
} catch (err) { } catch (err) {
this._error = `Failed to set addon network configuration, ${ this._error = `Failed to set addon network configuration, ${
err.body?.message || err err.body?.message || err
}`; }`;
} }
if (!this._error && this.addon?.state === "started") {
await suggestAddonRestart(this, this.hass, this.addon); button.progress = false;
}
} }
private async _saveTapped(): Promise<void> { private async _saveTapped(ev: CustomEvent): Promise<void> {
const button = ev.target as any;
button.progress = true;
this._error = undefined; this._error = undefined;
const networkconfiguration = {}; const networkconfiguration = {};
this._config!.forEach((item) => { this._config!.forEach((item) => {
@ -191,14 +179,38 @@ class HassioAddonNetwork extends LitElement {
path: "option", path: "option",
}; };
fireEvent(this, "hass-api-called", eventdata); fireEvent(this, "hass-api-called", eventdata);
if (this.addon?.state === "started") {
await suggestAddonRestart(this, this.hass, this.addon);
}
} catch (err) { } catch (err) {
this._error = `Failed to set addon network configuration, ${ this._error = `Failed to set addon network configuration, ${
err.body?.message || err err.body?.message || err
}`; }`;
} }
if (!this._error && this.addon?.state === "started") { button.progress = false;
await suggestAddonRestart(this, this.hass, this.addon); }
}
static get styles(): CSSResult[] {
return [
haStyle,
hassioStyle,
css`
:host {
display: block;
}
ha-card {
display: block;
}
.errors {
color: var(--error-color);
margin-bottom: 16px;
}
.card-actions {
display: flex;
justify-content: space-between;
}
`,
];
} }
} }