From 0ef8881660612d39ae43494b0a933a169753ac83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Mon, 23 Nov 2020 17:24:26 +0100 Subject: [PATCH] Add unhealthy dialog and SU restart button (#7781) --- hassio/src/system/hassio-supervisor-info.ts | 114 ++++++++++++++++++-- src/data/hassio/resolution.ts | 3 + src/data/hassio/supervisor.ts | 4 + 3 files changed, 111 insertions(+), 10 deletions(-) diff --git a/hassio/src/system/hassio-supervisor-info.ts b/hassio/src/system/hassio-supervisor-info.ts index 9a1fa07f5f..23e8eef590 100644 --- a/hassio/src/system/hassio-supervisor-info.ts +++ b/hassio/src/system/hassio-supervisor-info.ts @@ -19,6 +19,7 @@ import { fetchHassioSupervisorInfo, HassioSupervisorInfo as HassioSupervisorInfoType, reloadSupervisor, + restartSupervisor, setSupervisorOption, SupervisorOptions, updateSupervisor, @@ -32,7 +33,7 @@ import { HomeAssistant } from "../../../src/types"; import { documentationUrl } from "../../../src/util/documentation-url"; import { hassioStyle } from "../resources/hassio-style"; -const ISSUES = { +const UNSUPPORTED_REASON = { container: { title: "Containers known to cause issues", url: "/more-info/unsupported/container", @@ -59,6 +60,25 @@ const ISSUES = { systemd: { title: "Systemd", url: "/more-info/unsupported/systemd" }, }; +const UNHEALTHY_REASON = { + privileged: { + title: "Supervisor is not privileged", + url: "/more-info/unsupported/privileged", + }, + supervisor: { + title: "Supervisor was not able to update", + url: "/more-info/unhealthy/supervisor", + }, + setup: { + title: "Setup of the Supervisor failed", + url: "/more-info/unhealthy/setup", + }, + docker: { + title: "The Docker environment is not working properly", + url: "/more-info/unhealthy/docker", + }, +}; + @customElement("hassio-supervisor-info") class HassioSupervisorInfo extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @@ -66,9 +86,12 @@ class HassioSupervisorInfo extends LitElement { @property({ attribute: false }) public supervisorInfo!: HassioSupervisorInfoType; - @property() public hostInfo!: HassioHostInfoType; + @property({ attribute: false }) public hostInfo!: HassioHostInfoType; protected render(): TemplateResult | void { + if (!this.hass || !this.supervisorInfo || !this.hostInfo) { + return html``; + } return html`
@@ -126,7 +149,7 @@ class HassioSupervisorInfo extends LitElement { : ""} - ${this.supervisorInfo?.supported + ${this.supervisorInfo.supported ? html` Share Diagnostics @@ -157,14 +180,33 @@ class HassioSupervisorInfo extends LitElement { Learn more
`} + ${!this.supervisorInfo.healthy + ? html`
+ Your installtion is running in an unhealthy state. + +
` + : ""}
Reload + + Restart +
`; @@ -213,8 +255,9 @@ class HassioSupervisorInfo extends LitElement { title: "Failed to set supervisor option", text: extractApiErrorMessage(err), }); + } finally { + button.progress = false; } - button.progress = false; } private async _supervisorReload(ev: CustomEvent): Promise { @@ -229,8 +272,25 @@ class HassioSupervisorInfo extends LitElement { title: "Failed to reload the supervisor", text: extractApiErrorMessage(err), }); + } finally { + button.progress = false; + } + } + + private async _supervisorRestart(ev: CustomEvent): Promise { + const button = ev.currentTarget as any; + button.progress = true; + + try { + await restartSupervisor(this.hass); + } catch (err) { + showAlertDialog(this, { + title: "Failed to restart the supervisor", + text: extractApiErrorMessage(err), + }); + } finally { + button.progress = false; } - button.progress = false; } private async _supervisorUpdate(ev: CustomEvent): Promise { @@ -256,8 +316,9 @@ class HassioSupervisorInfo extends LitElement { title: "Failed to update the supervisor", text: extractApiErrorMessage(err), }); + } finally { + button.progress = false; } - button.progress = false; } private async _diagnosticsInformationDialog(): Promise { @@ -285,13 +346,46 @@ class HassioSupervisorInfo extends LitElement { ${resolution.unsupported.map( (issue) => html`
  • - ${ISSUES[issue] + ${UNSUPPORTED_REASON[issue] ? html` - ${ISSUES[issue].title} + ${UNSUPPORTED_REASON[issue].title} + ` + : issue} +
  • + ` + )} + `, + }); + } + + private async _unhealthyDialog(): Promise { + const resolution = await fetchHassioResolution(this.hass); + await showAlertDialog(this, { + title: "Your installation is unhealthy", + text: html`Running an unhealthy installation will cause issues. Below is a + list of issues found with your installation, click on the links to learn + how you can resolve the issues.

    +
      + ${resolution.unhealthy.map( + (issue) => html` +
    • + ${UNHEALTHY_REASON[issue] + ? html` + ${UNHEALTHY_REASON[issue].title} ` : issue}
    • diff --git a/src/data/hassio/resolution.ts b/src/data/hassio/resolution.ts index 8f85943de3..677404f551 100644 --- a/src/data/hassio/resolution.ts +++ b/src/data/hassio/resolution.ts @@ -3,6 +3,9 @@ import { hassioApiResultExtractor, HassioResponse } from "./common"; export interface HassioResolution { unsupported: string[]; + unhealthy: string[]; + issues: string[]; + suggestions: string[]; } export const fetchHassioResolution = async (hass: HomeAssistant) => { diff --git a/src/data/hassio/supervisor.ts b/src/data/hassio/supervisor.ts index b21039bb1b..6cc6b04433 100644 --- a/src/data/hassio/supervisor.ts +++ b/src/data/hassio/supervisor.ts @@ -76,6 +76,10 @@ export const reloadSupervisor = async (hass: HomeAssistant) => { await hass.callApi>("POST", `hassio/supervisor/reload`); }; +export const restartSupervisor = async (hass: HomeAssistant) => { + await hass.callApi>("POST", `hassio/supervisor/restart`); +}; + export const updateSupervisor = async (hass: HomeAssistant) => { await hass.callApi>("POST", `hassio/supervisor/update`); };