Move zwave_js node comments from device config to info page (#12625)

Co-authored-by: Zack Barett <zackbarett@hey.com>
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Raman Gupta 2022-05-24 22:16:07 -04:00 committed by GitHub
parent 7cc576a616
commit 966a624ef6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 83 additions and 19 deletions

View File

@ -167,6 +167,9 @@ export interface ZwaveJSNodeMetadata {
wakeup: string; wakeup: string;
reset: string; reset: string;
device_database_url: string; device_database_url: string;
}
export interface ZwaveJSNodeComments {
comments: ZWaveJSNodeComment[]; comments: ZWaveJSNodeComment[];
} }
@ -442,6 +445,15 @@ export const fetchZwaveNodeMetadata = (
device_id, device_id,
}); });
export const fetchZwaveNodeComments = (
hass: HomeAssistant,
device_id: string
): Promise<ZwaveJSNodeComments> =>
hass.callWS({
type: "zwave_js/node_comments",
device_id,
});
export const fetchZwaveNodeConfigParameters = ( export const fetchZwaveNodeConfigParameters = (
hass: HomeAssistant, hass: HomeAssistant,
device_id: string device_id: string

View File

@ -0,0 +1,52 @@
import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import { DeviceRegistryEntry } from "../../../../../../data/device_registry";
import {
ZwaveJSNodeComments,
fetchZwaveNodeComments,
} from "../../../../../../data/zwave_js";
import { HomeAssistant } from "../../../../../../types";
@customElement("ha-device-alerts-zwave_js")
export class HaDeviceAlertsZWaveJS extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public device!: DeviceRegistryEntry;
@state() private _nodeComments?: ZwaveJSNodeComments;
protected willUpdate(changedProperties: PropertyValues) {
super.willUpdate(changedProperties);
if (changedProperties.has("device")) {
this._fetchNodeDetails();
}
}
private async _fetchNodeDetails() {
this._nodeComments = await fetchZwaveNodeComments(
this.hass,
this.device.id
);
}
protected render(): TemplateResult {
if (this._nodeComments && this._nodeComments.comments?.length > 0) {
return html`
<div>
${this._nodeComments.comments.map(
(comment) => html`<ha-alert .alertType=${comment.level}>
${comment.text}
</ha-alert>`
)}
</div>
`;
}
return html``;
}
}
declare global {
interface HTMLElementTagNameMap {
"ha-device-alerts-zwave_js": HaDeviceAlertsZWaveJS;
}
}

View File

@ -389,6 +389,7 @@ export class HaConfigDevicePage extends LitElement {
: device.configuration_url; : device.configuration_url;
const deviceInfo: TemplateResult[] = []; const deviceInfo: TemplateResult[] = [];
const deviceAlerts: TemplateResult[] = [];
if (device.disabled_by) { if (device.disabled_by) {
deviceInfo.push( deviceInfo.push(
@ -445,7 +446,8 @@ export class HaConfigDevicePage extends LitElement {
device, device,
integrations, integrations,
deviceInfo, deviceInfo,
deviceActions deviceActions,
deviceAlerts
); );
if (Array.isArray(this._diagnosticDownloadLinks)) { if (Array.isArray(this._diagnosticDownloadLinks)) {
@ -547,6 +549,11 @@ export class HaConfigDevicePage extends LitElement {
</div> </div>
</div> </div>
<div class="column"> <div class="column">
${
deviceAlerts.length
? html` <div class="fullwidth">${deviceAlerts}</div> `
: ""
}
<ha-device-info-card <ha-device-info-card
.hass=${this.hass} .hass=${this.hass}
.areas=${this.areas} .areas=${this.areas}
@ -928,7 +935,8 @@ export class HaConfigDevicePage extends LitElement {
device: DeviceRegistryEntry, device: DeviceRegistryEntry,
integrations: ConfigEntry[], integrations: ConfigEntry[],
deviceInfo: TemplateResult[], deviceInfo: TemplateResult[],
deviceActions: (string | TemplateResult)[] deviceActions: (string | TemplateResult)[],
deviceAlerts: TemplateResult[]
) { ) {
const domains = integrations.map((int) => int.domain); const domains = integrations.map((int) => int.domain);
if (domains.includes("mqtt")) { if (domains.includes("mqtt")) {
@ -959,12 +967,21 @@ export class HaConfigDevicePage extends LitElement {
`); `);
} }
if (domains.includes("zwave_js")) { if (domains.includes("zwave_js")) {
import(
"./device-detail/integration-elements/zwave_js/ha-device-alerts-zwave_js"
);
import( import(
"./device-detail/integration-elements/zwave_js/ha-device-info-zwave_js" "./device-detail/integration-elements/zwave_js/ha-device-info-zwave_js"
); );
import( import(
"./device-detail/integration-elements/zwave_js/ha-device-actions-zwave_js" "./device-detail/integration-elements/zwave_js/ha-device-actions-zwave_js"
); );
deviceAlerts.push(html`
<ha-device-alerts-zwave_js
.hass=${this.hass}
.device=${device}
></ha-device-alerts-zwave_js>
`);
deviceInfo.push(html` deviceInfo.push(html`
<ha-device-info-zwave_js <ha-device-info-zwave_js
.hass=${this.hass} .hass=${this.hass}

View File

@ -546,12 +546,6 @@ class ZWaveJSConfigDashboard extends LitElement {
max-width: 600px; max-width: 600px;
} }
button.dump {
width: 100%;
text-align: center;
color: var(--secondary-text-color);
}
[hidden] { [hidden] {
display: none; display: none;
} }

View File

@ -166,17 +166,6 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
</em> </em>
</p> </p>
</div> </div>
${this._nodeMetadata.comments?.length > 0
? html`
<div>
${this._nodeMetadata.comments.map(
(comment) => html`<ha-alert .alertType=${comment.level}>
${comment.text}
</ha-alert>`
)}
</div>
`
: ``}
<ha-card> <ha-card>
${Object.entries(this._config).map( ${Object.entries(this._config).map(
([id, item]) => html` <ha-settings-row ([id, item]) => html` <ha-settings-row