Skip to content

Commit

Permalink
feat: ping node (#1255)
Browse files Browse the repository at this point in the history
Fixes #1253
  • Loading branch information
robertsLando authored May 21, 2021
1 parent 79e283a commit 2fc61ef
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/guide/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ const allowedApis = [
'writeMulticast',
'driverFunction',
'checkForConfigUpdates',
'installConfigUpdate'
'installConfigUpdate',
'pingNode'
]

const ZWAVEJS_LOG_FILE = utils.joinPath(storeDir, `zwavejs_${process.pid}.log`)
Expand Down Expand Up @@ -1070,6 +1071,22 @@ class ZwaveClient extends EventEmitter {
throw Error('Driver is closed')
}

/**
* Ping a node
*
* @param {number} nodeId
* @returns {Promise<boolean>}
*/
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
*
Expand Down
2 changes: 1 addition & 1 deletion src/components/ControlPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<v-card>
<v-card-text>
<v-container fluid>
<v-row justify="start">
<v-row style="max-width:800px" justify="start">
<v-col cols="12" sm="4" md="3" style="text-align:center">
<v-btn
depressed
Expand Down
8 changes: 8 additions & 0 deletions src/components/nodes-table/NodeDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

<v-row>
<v-col cols="8" style="max-width:300px">
<v-btn
dark
color="primary"
@click.stop="apiRequest('pingNode', [node.id])"
depressed
>
Ping
</v-btn>
<v-btn dark color="green" depressed @click="advancedShowDialog = true">
Advanced
</v-btn>
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ export interface ZwaveClient extends EventEmitter {
getNodes(): Z2MNode[]
getInfo(): Map<string, any>
refreshValues(nodeId: number): Promise<void>
pingNode(nodeId: number): Promise<boolean>
setPollInterval(valueId: Z2MValueId, interval: number): void
checkForConfigUpdates(): Promise<string | undefined>
installConfigUpdate(): Promise<boolean>
Expand Down

0 comments on commit 2fc61ef

Please sign in to comment.