Add alert to zwave_js device info page for custom device config (#18686)

This commit is contained in:
Raman Gupta 2023-11-26 05:09:02 -05:00 committed by GitHub
parent 15a5d2bc38
commit 5965c3fdaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 13 deletions

View File

@ -219,8 +219,9 @@ export interface ZwaveJSNodeMetadata {
device_database_url: string;
}
export interface ZwaveJSNodeComments {
export interface ZwaveJSNodeAlerts {
comments: ZWaveJSNodeComment[];
is_embedded: boolean | null;
}
export interface ZWaveJSNodeConfigParams {
@ -601,12 +602,12 @@ export const fetchZwaveNodeMetadata = (
device_id,
});
export const fetchZwaveNodeComments = (
export const fetchZwaveNodeAlerts = (
hass: HomeAssistant,
device_id: string
): Promise<ZwaveJSNodeComments> =>
): Promise<ZwaveJSNodeAlerts> =>
hass.callWS({
type: "zwave_js/node_comments",
type: "zwave_js/node_alerts",
device_id,
});

View File

@ -1,5 +1,5 @@
import { DeviceRegistryEntry } from "../../../../../../data/device_registry";
import { fetchZwaveNodeComments } from "../../../../../../data/zwave_js";
import { fetchZwaveNodeAlerts } from "../../../../../../data/zwave_js";
import { HomeAssistant } from "../../../../../../types";
import { DeviceAlert } from "../../../ha-config-device-page";
@ -7,14 +7,27 @@ export const getZwaveDeviceAlerts = async (
hass: HomeAssistant,
device: DeviceRegistryEntry
): Promise<DeviceAlert[]> => {
const nodeComments = await fetchZwaveNodeComments(hass, device.id);
const nodeAlerts = await fetchZwaveNodeAlerts(hass, device.id);
const deviceAlerts: DeviceAlert[] = [];
if (!nodeComments?.comments?.length) {
return [];
if (nodeAlerts?.is_embedded === false) {
deviceAlerts.push({
level: "info",
text: hass.localize(
"ui.panel.config.zwave_js.device_info.custom_device_config"
),
});
}
return nodeComments.comments.map((comment) => ({
level: comment.level,
text: comment.text,
}));
if (!nodeAlerts?.comments?.length) {
return deviceAlerts;
}
deviceAlerts.push(
...nodeAlerts.comments.map((comment) => ({
level: comment.level,
text: comment.text,
}))
);
return deviceAlerts;
};

View File

@ -4064,7 +4064,8 @@
"unknown": "Unknown",
"zwave_plus": "Z-Wave Plus",
"zwave_plus_version": "Version {version}",
"node_statistics": "Statistics"
"node_statistics": "Statistics",
"custom_device_config": "This device is using a custom device config file not provided by Z-Wave JS. If you want to use the default device config provided by Z-Wave JS, you must remove the custom device config file from the folder that Z-Wave JS is reading from."
},
"hard_reset_controller": {
"NotStarted": {