From ab816ad5295042962f6541d81dad8ef2ba5aeb79 Mon Sep 17 00:00:00 2001
From: Paulus Schoutsen
Date: Tue, 29 Jan 2019 16:32:34 -0800
Subject: [PATCH] Add system health card
---
src/data/system_health.ts | 23 +++++
src/panels/dev-info/ha-panel-dev-info.ts | 8 ++
src/panels/dev-info/system-health-card.ts | 118 ++++++++++++++++++++++
src/translations/en.json | 7 +-
4 files changed, 154 insertions(+), 2 deletions(-)
create mode 100644 src/data/system_health.ts
create mode 100644 src/panels/dev-info/system-health-card.ts
diff --git a/src/data/system_health.ts b/src/data/system_health.ts
new file mode 100644
index 0000000000..7d6073f4d7
--- /dev/null
+++ b/src/data/system_health.ts
@@ -0,0 +1,23 @@
+import { HomeAssistant } from "../types";
+
+export interface SystemHealthInfo {
+ homeassistant: {
+ version: string;
+ dev: boolean;
+ hassio: boolean;
+ virtualenv: string;
+ python_version: string;
+ docker: boolean;
+ arch: string;
+ timezone: string;
+ os_name: string;
+ };
+ [domain: string]: { [key: string]: string | number | boolean };
+}
+
+export const fetchSystemHealthInfo = (
+ hass: HomeAssistant
+): Promise =>
+ hass.callWS({
+ type: "system_health/info",
+ });
diff --git a/src/panels/dev-info/ha-panel-dev-info.ts b/src/panels/dev-info/ha-panel-dev-info.ts
index 5de2a09317..1a6ca63b6c 100644
--- a/src/panels/dev-info/ha-panel-dev-info.ts
+++ b/src/panels/dev-info/ha-panel-dev-info.ts
@@ -16,6 +16,7 @@ import { haStyle } from "../../resources/ha-style";
import "./system-log-card";
import "./error-log-card";
+import "./system-health-card";
const JS_VERSION = __BUILD__;
const OPT_IN_PANEL = "states";
@@ -142,6 +143,7 @@ class HaPanelDevInfo extends LitElement {
+
@@ -201,6 +203,12 @@ class HaPanelDevInfo extends LitElement {
.about a {
color: var(--dark-primary-color);
}
+
+ system-health-card {
+ display: block;
+ max-width: 600px;
+ margin: 0 auto;
+ }
`,
];
}
diff --git a/src/panels/dev-info/system-health-card.ts b/src/panels/dev-info/system-health-card.ts
new file mode 100644
index 0000000000..2214d9c452
--- /dev/null
+++ b/src/panels/dev-info/system-health-card.ts
@@ -0,0 +1,118 @@
+import {
+ LitElement,
+ html,
+ CSSResult,
+ css,
+ PropertyDeclarations,
+ TemplateResult,
+} from "lit-element";
+import "@polymer/paper-card/paper-card";
+import "@polymer/paper-spinner/paper-spinner";
+
+import { HomeAssistant } from "../../types";
+import {
+ SystemHealthInfo,
+ fetchSystemHealthInfo,
+} from "../../data/system_health";
+
+const sortKeys = (a: string, b: string) => {
+ if (a === "homeassistant") {
+ return -1;
+ }
+ if (b === "homeassistant") {
+ return 1;
+ }
+ if (a < b) {
+ return -1;
+ }
+ if (b < a) {
+ return 1;
+ }
+ return 0;
+};
+
+class SystemHealthCard extends LitElement {
+ public hass?: HomeAssistant;
+ private _info?: SystemHealthInfo;
+
+ static get properties(): PropertyDeclarations {
+ return {
+ hass: {},
+ _info: {},
+ };
+ }
+
+ protected render(): TemplateResult | void {
+ if (!this.hass) {
+ return;
+ }
+ const sections: TemplateResult[] = [];
+
+ if (!this._info) {
+ sections.push(
+ html`
+
+ `
+ );
+ } else {
+ const domains = Object.keys(this._info).sort(sortKeys);
+ for (const domain of domains) {
+ const keys: TemplateResult[] = [];
+
+ for (const key of Object.keys(this._info[domain]).sort()) {
+ keys.push(html`
+
+ ${key} |
+ ${this._info[domain][key]} |
+
+ `);
+ }
+ if (domain !== "homeassistant") {
+ sections.push(
+ html`
+ ${this.hass.localize(`domain.${domain}`) || domain}
+ `
+ );
+ }
+ sections.push(html`
+
+ `);
+ }
+ }
+
+ return html`
+
+ ${sections}
+
+ `;
+ }
+
+ protected firstUpdated(changedProps) {
+ super.firstUpdated(changedProps);
+ this._fetchInfo();
+ }
+
+ private async _fetchInfo() {
+ this._info = await fetchSystemHealthInfo(this.hass!);
+ }
+
+ static get styles(): CSSResult {
+ return css`
+ paper-card {
+ display: block;
+ }
+
+ table {
+ width: 100%;
+ }
+
+ td:first-child {
+ width: 33%;
+ }
+ `;
+ }
+}
+
+customElements.define("system-health-card", SystemHealthCard);
diff --git a/src/translations/en.json b/src/translations/en.json
index db2ae19271..321056438a 100644
--- a/src/translations/en.json
+++ b/src/translations/en.json
@@ -11,16 +11,19 @@
"cover": "Cover",
"device_tracker": "Device tracker",
"fan": "Fan",
- "history_graph": "History graph",
"group": "Group",
+ "hassio": "Hass.io",
+ "history_graph": "History graph",
+ "homeassistant": "Home Assistant",
"image_processing": "Image processing",
"input_boolean": "Input boolean",
"input_datetime": "Input datetime",
- "input_select": "Input select",
"input_number": "Input number",
+ "input_select": "Input select",
"input_text": "Input text",
"light": "Light",
"lock": "Lock",
+ "lovelace": "Lovelace",
"mailbox": "Mailbox",
"media_player": "Media player",
"notify": "Notify",