Move System Health to a page (#12412)

This commit is contained in:
Zack Barett 2022-04-25 13:26:53 -05:00 committed by GitHub
parent b70a523bdf
commit f8a52d250e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 110 additions and 95 deletions

View File

@ -6,6 +6,7 @@ import {
mdiCog, mdiCog,
mdiDatabase, mdiDatabase,
mdiDevices, mdiDevices,
mdiHeart,
mdiInformation, mdiInformation,
mdiInformationOutline, mdiInformationOutline,
mdiLightningBolt, mdiLightningBolt,
@ -316,6 +317,13 @@ export const configSections: { [name: string]: PageNavigation[] } = {
iconColor: "#301A8E", iconColor: "#301A8E",
component: "hassio", component: "hassio",
}, },
{
path: "/config/system_health",
translationKey: "ui.panel.config.system_health.caption",
iconPath: mdiHeart,
iconColor: "#507FfE",
component: "system_health",
},
], ],
about: [ about: [
{ {
@ -438,6 +446,10 @@ class HaPanelConfig extends HassRouterPage {
tag: "ha-config-section-storage", tag: "ha-config-section-storage",
load: () => import("./core/ha-config-section-storage"), load: () => import("./core/ha-config-section-storage"),
}, },
system_health: {
tag: "ha-config-system-health",
load: () => import("./system-health/ha-config-system-health"),
},
updates: { updates: {
tag: "ha-config-section-updates", tag: "ha-config-section-updates",
load: () => import("./core/ha-config-section-updates"), load: () => import("./core/ha-config-section-updates"),

View File

@ -6,7 +6,6 @@ import { haStyle } from "../../../resources/styles";
import { HomeAssistant, Route } from "../../../types"; import { HomeAssistant, Route } from "../../../types";
import { documentationUrl } from "../../../util/documentation-url"; import { documentationUrl } from "../../../util/documentation-url";
import "./integrations-card"; import "./integrations-card";
import "./system-health-card";
const JS_TYPE = __BUILD__; const JS_TYPE = __BUILD__;
const JS_VERSION = __VERSION__; const JS_VERSION = __VERSION__;
@ -131,7 +130,6 @@ class HaConfigInfo extends LitElement {
</p> </p>
</div> </div>
<div> <div>
<system-health-card .hass=${this.hass}></system-health-card>
<integrations-card <integrations-card
.hass=${this.hass} .hass=${this.hass}
.narrow=${this.narrow} .narrow=${this.narrow}
@ -180,7 +178,6 @@ class HaConfigInfo extends LitElement {
color: var(--primary-color); color: var(--primary-color);
} }
system-health-card,
integrations-card { integrations-card {
display: block; display: block;
max-width: 600px; max-width: 600px;

View File

@ -1,24 +1,21 @@
import "@material/mwc-button/mwc-button"; import { ActionDetail } from "@material/mwc-list";
import { ActionDetail } from "@material/mwc-list/mwc-list-foundation";
import "@material/mwc-list/mwc-list-item"; import "@material/mwc-list/mwc-list-item";
import { mdiContentCopy } from "@mdi/js"; import { mdiContentCopy } from "@mdi/js";
import "@polymer/paper-tooltip/paper-tooltip";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
import { formatDateTime } from "../../../common/datetime/format_date_time"; import { formatDateTime } from "../../../common/datetime/format_date_time";
import { copyToClipboard } from "../../../common/util/copy-clipboard"; import { copyToClipboard } from "../../../common/util/copy-clipboard";
import "../../../components/ha-button-menu"; import "../../../components/ha-button-menu";
import "../../../components/ha-card"; import "../../../components/ha-card";
import "../../../components/ha-circular-progress"; import "../../../components/ha-circular-progress";
import "../../../components/ha-icon-button";
import { domainToName } from "../../../data/integration"; import { domainToName } from "../../../data/integration";
import { import {
subscribeSystemHealthInfo, subscribeSystemHealthInfo,
SystemCheckValueObject, SystemCheckValueObject,
SystemHealthInfo, SystemHealthInfo,
} from "../../../data/system_health"; } from "../../../data/system_health";
import { HomeAssistant } from "../../../types"; import "../../../layouts/hass-subpage";
import type { HomeAssistant } from "../../../types";
import { showToast } from "../../../util/toast"; import { showToast } from "../../../util/toast";
const sortKeys = (a: string, b: string) => { const sortKeys = (a: string, b: string) => {
@ -37,15 +34,25 @@ const sortKeys = (a: string, b: string) => {
return 0; return 0;
}; };
class SystemHealthCard extends LitElement { @customElement("ha-config-system-health")
class HaConfigSystemHealth extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property({ type: Boolean }) public narrow!: boolean;
@state() private _info?: SystemHealthInfo; @state() private _info?: SystemHealthInfo;
protected firstUpdated(changedProps) {
super.firstUpdated(changedProps);
this.hass!.loadBackendTranslation("system_health");
subscribeSystemHealthInfo(this.hass!, (info) => {
this._info = info;
});
}
protected render(): TemplateResult { protected render(): TemplateResult {
if (!this.hass) {
return html``;
}
const sections: TemplateResult[] = []; const sections: TemplateResult[] = [];
if (!this._info) { if (!this._info) {
@ -139,57 +146,38 @@ class SystemHealthCard extends LitElement {
} }
return html` return html`
<ha-card> <hass-subpage
<h1 class="card-header"> .hass=${this.hass}
<div class="card-header-text"> .narrow=${this.narrow}
${domainToName(this.hass.localize, "system_health")} back-path="/config/system"
</div> .header=${this.hass.localize("ui.panel.config.system_health.caption")}
<ha-button-menu >
corner="BOTTOM_START" <ha-button-menu
slot="toolbar-icon" corner="BOTTOM_START"
@action=${this._copyInfo} slot="toolbar-icon"
> @action=${this._copyInfo}
<ha-icon-button >
slot="trigger" <ha-icon-button
.label=${this.hass.localize("ui.panel.config.info.copy_menu")} slot="trigger"
.path=${mdiContentCopy} .label=${this.hass.localize("ui.panel.config.info.copy_menu")}
></ha-icon-button> .path=${mdiContentCopy}
<mwc-list-item> ></ha-icon-button>
${this.hass.localize("ui.panel.config.info.copy_raw")} <mwc-list-item>
</mwc-list-item> ${this.hass.localize("ui.panel.config.info.copy_raw")}
<mwc-list-item> </mwc-list-item>
${this.hass.localize("ui.panel.config.info.copy_github")} <mwc-list-item>
</mwc-list-item> ${this.hass.localize("ui.panel.config.info.copy_github")}
</ha-button-menu> </mwc-list-item>
</h1> </ha-button-menu>
<div class="card-content">${sections}</div> <div class="content">
</ha-card> <ha-card outlined>
<div class="card-content">${sections}</div>
</ha-card>
</div>
</hass-subpage>
`; `;
} }
protected firstUpdated(changedProps) {
super.firstUpdated(changedProps);
this.hass!.loadBackendTranslation("system_health");
if (!isComponentLoaded(this.hass!, "system_health")) {
this._info = {
system_health: {
info: {
error: this.hass.localize(
"ui.panel.config.info.system_health_error"
),
},
},
};
return;
}
subscribeSystemHealthInfo(this.hass!, (info) => {
this._info = info;
});
}
private async _copyInfo(ev: CustomEvent<ActionDetail>): Promise<void> { private async _copyInfo(ev: CustomEvent<ActionDetail>): Promise<void> {
const github = ev.detail.index === 1; const github = ev.detail.index === 1;
let haContent: string | undefined; let haContent: string | undefined;
@ -254,45 +242,59 @@ class SystemHealthCard extends LitElement {
}); });
} }
static get styles(): CSSResultGroup { static styles: CSSResultGroup = css`
return css` .content {
table { padding: 28px 20px 0;
width: 100%; max-width: 1040px;
} margin: 0 auto;
}
ha-card {
display: block;
max-width: 500px;
margin: 0 auto;
padding-bottom: 16px;
margin-bottom: max(24px, env(safe-area-inset-bottom));
}
table {
width: 100%;
}
td:first-child { td:first-child {
width: 45%; width: 45%;
} }
td:last-child { td:last-child {
direction: ltr; direction: ltr;
} }
.loading-container { .loading-container {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.card-header { .card-header {
justify-content: space-between; justify-content: space-between;
display: flex; display: flex;
align-items: center; align-items: center;
} }
.error { .error {
color: var(--error-color); color: var(--error-color);
} }
a { a {
color: var(--primary-color); color: var(--primary-color);
} }
a.manage { a.manage {
text-decoration: none; text-decoration: none;
} }
`; `;
}
} }
customElements.define("system-health-card", SystemHealthCard); declare global {
interface HTMLElementTagNameMap {
"ha-config-system-health": HaConfigSystemHealth;
}
}

View File

@ -1676,6 +1676,7 @@
} }
} }
}, },
"automation": { "automation": {
"caption": "Automations", "caption": "Automations",
"description": "Create custom behavior rules for your home", "description": "Create custom behavior rules for your home",
@ -3151,6 +3152,9 @@
"caption": "Storage", "caption": "Storage",
"used_space": "Used Space", "used_space": "Used Space",
"emmc_lifetime_used": "eMMC Lifetime Used" "emmc_lifetime_used": "eMMC Lifetime Used"
},
"system_health": {
"caption": "System Health"
} }
}, },
"lovelace": { "lovelace": {