Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 104 additions & 10 deletions hassio/src/system/hassio-supervisor-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
fetchHassioSupervisorInfo,
HassioSupervisorInfo as HassioSupervisorInfoType,
reloadSupervisor,
restartSupervisor,
setSupervisorOption,
SupervisorOptions,
updateSupervisor,
Expand All @@ -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",
Expand All @@ -59,16 +60,38 @@ 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;

@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`
<ha-card header="Supervisor">
<div class="card-content">
Expand Down Expand Up @@ -126,7 +149,7 @@ class HassioSupervisorInfo extends LitElement {
: ""}
</ha-settings-row>

${this.supervisorInfo?.supported
${this.supervisorInfo.supported
? html` <ha-settings-row three-line>
<span slot="heading">
Share Diagnostics
Expand Down Expand Up @@ -157,14 +180,33 @@ class HassioSupervisorInfo extends LitElement {
Learn more
</button>
</div>`}
${!this.supervisorInfo.healthy
? html`<div class="error">
Your installtion is running in an unhealthy state.
<button
class="link"
title="Learn more about why your system is marked as unhealthy"
@click=${this._unhealthyDialog}
>
Learn more
</button>
</div>`
: ""}
</div>
<div class="card-actions">
<ha-progress-button
@click=${this._supervisorReload}
title="Reload parts of the supervisor"
title="Reload parts of the Supervisor"
>
Reload
</ha-progress-button>
<ha-progress-button
class="warning"
@click=${this._supervisorRestart}
title="Restart the Supervisor"
>
Restart
</ha-progress-button>
</div>
</ha-card>
`;
Expand Down Expand Up @@ -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<void> {
Expand All @@ -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<void> {
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<void> {
Expand All @@ -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<void> {
Expand Down Expand Up @@ -285,13 +346,46 @@ class HassioSupervisorInfo extends LitElement {
${resolution.unsupported.map(
(issue) => html`
<li>
${ISSUES[issue]
${UNSUPPORTED_REASON[issue]
? html`<a
href="${documentationUrl(
this.hass,
UNSUPPORTED_REASON[issue].url
)}"
target="_blank"
rel="noreferrer"
>
${UNSUPPORTED_REASON[issue].title}
</a>`
: issue}
</li>
`
)}
</ul>`,
});
}

private async _unhealthyDialog(): Promise<void> {
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. <br /><br />
<ul>
${resolution.unhealthy.map(
(issue) => html`
<li>
${UNHEALTHY_REASON[issue]
? html`<a
href="${documentationUrl(this.hass, ISSUES[issue].url)}"
href="${documentationUrl(
this.hass,
UNHEALTHY_REASON[issue].url
)}"
target="_blank"
rel="noreferrer"
>
${ISSUES[issue].title}
${UNHEALTHY_REASON[issue].title}
</a>`
: issue}
</li>
Expand Down
3 changes: 3 additions & 0 deletions src/data/hassio/resolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 4 additions & 0 deletions src/data/hassio/supervisor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export const reloadSupervisor = async (hass: HomeAssistant) => {
await hass.callApi<HassioResponse<void>>("POST", `hassio/supervisor/reload`);
};

export const restartSupervisor = async (hass: HomeAssistant) => {
await hass.callApi<HassioResponse<void>>("POST", `hassio/supervisor/restart`);
};

export const updateSupervisor = async (hass: HomeAssistant) => {
await hass.callApi<HassioResponse<void>>("POST", `hassio/supervisor/update`);
};
Expand Down