From 2fc61efc87834ef37d1d1311b4b0be8bf797a15c Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 21 May 2021 09:11:06 +0200 Subject: [PATCH] feat: ping node (#1255) Fixes #1253 --- docs/guide/mqtt.md | 1 + lib/ZwaveClient.js | 19 ++++++++++++++++++- src/components/ControlPanel.vue | 2 +- src/components/nodes-table/NodeDetails.vue | 8 ++++++++ types/index.d.ts | 1 + 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/guide/mqtt.md b/docs/guide/mqtt.md index 5e8edf165e..7087f158a1 100644 --- a/docs/guide/mqtt.md +++ b/docs/guide/mqtt.md @@ -64,6 +64,7 @@ This are the available apis: - `removeAllAssociations(nodeId)`: Remove all associations of a specific node - `removeNodeFromAllAssociations(nodeId)`: Remove a node from all associations - `refreshValues(nodeId)`: Refresh all node values +- `pingNode(nodeId)`: Ping a node - `pollValue(valueId)`: Polls a value from the node - `startInclusion()`: Starts the inclusion - `startExclusion()`: Starts the exclusion diff --git a/lib/ZwaveClient.js b/lib/ZwaveClient.js index fb7f866a33..8678a92bf2 100644 --- a/lib/ZwaveClient.js +++ b/lib/ZwaveClient.js @@ -82,7 +82,8 @@ const allowedApis = [ 'writeMulticast', 'driverFunction', 'checkForConfigUpdates', - 'installConfigUpdate' + 'installConfigUpdate', + 'pingNode' ] const ZWAVEJS_LOG_FILE = utils.joinPath(storeDir, `zwavejs_${process.pid}.log`) @@ -1070,6 +1071,22 @@ class ZwaveClient extends EventEmitter { throw Error('Driver is closed') } + /** + * Ping a node + * + * @param {number} nodeId + * @returns {Promise} + */ + async pingNode (nodeId) { + if (this.driver && !this.closed) { + const zwaveNode = this.getNode(nodeId) + + return zwaveNode.ping() + } + + throw Error('Driver is closed') + } + /** * Refresh all node values of a specific CC * diff --git a/src/components/ControlPanel.vue b/src/components/ControlPanel.vue index cf90d85eb8..2d5a75b31d 100644 --- a/src/components/ControlPanel.vue +++ b/src/components/ControlPanel.vue @@ -3,7 +3,7 @@ - + + + Ping + Advanced diff --git a/types/index.d.ts b/types/index.d.ts index b63c5611fc..435b2a0e17 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -382,6 +382,7 @@ export interface ZwaveClient extends EventEmitter { getNodes(): Z2MNode[] getInfo(): Map refreshValues(nodeId: number): Promise + pingNode(nodeId: number): Promise setPollInterval(valueId: Z2MValueId, interval: number): void checkForConfigUpdates(): Promise installConfigUpdate(): Promise