Skip to content

Commit

Permalink
Add alert to zwave_js device info page for custom device config (#18686)
Browse files Browse the repository at this point in the history
  • Loading branch information
raman325 authored Nov 26, 2023
1 parent 15a5d2b commit 5965c3f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
9 changes: 5 additions & 4 deletions src/data/zwave_js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
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";

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;
};
3 changes: 2 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 5965c3f

Please sign in to comment.