Skip to content

Commit

Permalink
feat: markNodeAsFailed api (#263)
Browse files Browse the repository at this point in the history
* feat: markNodeAsFailed api

* docs: add to list of allowed apis
  • Loading branch information
robertsLando authored Jan 19, 2021
1 parent 0187e09 commit c00f50a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/guide/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ This are the available apis:
- `beginHealingNetwork()`: Starts healing the network
- `stopHealingNetwork()`: Stops network healing
- `isFailedNode(nodeId)`: Checks if a node is failed
- `markNodeAsFailed(nodeId)`: Pings a node few times and marks it as failed if it doesn't answer. This is different from the previous api as that only checks the controller failed node list
- `removeFailedNode(nodeId)`: Remove a failed node
- `refreshInfo(nodeId)`: Re-interview a node to fetch its info and supported CCs
- `beginFirmwareUpdate(nodeId, fileName, data)`: Starts a firmware update of a node. The `fileName` is used to check the extension (used to detect the firmware file type) and data is a `Buffer`
Expand Down
22 changes: 22 additions & 0 deletions lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -1973,11 +1973,32 @@ ZwaveClient.prototype.healNode = async function (nodeId) {
throw Error('Driver is closed')
}

ZwaveClient.prototype.markNodeAsFailed = async function (nodeId) {
if (this.driver && !this.closed) {
const node = this.nodes[nodeId]
const zwaveNode = this.getNode(nodeId)

// ping a node a couple of times, returns `true` if it's failed
const result = await this.driver.controller.markNodeAsFailed(nodeId)
if (node) {
node.failed = result
}

if (zwaveNode) {
onNodeStatus.call(this, zwaveNode)
}
return result
}

throw Error('Driver is closed')
}

ZwaveClient.prototype.isFailedNode = async function (nodeId) {
if (this.driver && !this.closed) {
const node = this.nodes[nodeId]
const zwaveNode = this.getNode(nodeId)

// checks if a node was marked as failed in the controller
const result = await this.driver.controller.isFailedNode(nodeId)
if (node) {
node.failed = result
Expand Down Expand Up @@ -2141,6 +2162,7 @@ ZwaveClient.prototype.callApi = async function (apiName, ...args) {
'beginHealingNetwork',
'stopHealingNetwork',
'isFailedNode',
'markNodeAsFailed',
'removeFailedNode',
'refreshInfo',
'beginFirmwareUpdate',
Expand Down
4 changes: 4 additions & 0 deletions src/components/ControlPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,10 @@ export default {
text: 'Is Failed Node',
value: 'isFailedNode'
},
{
text: 'Mark Node as Failed',
value: 'markNodeAsFailed'
},
{
text: 'Remove failed node',
value: 'removeFailedNode'
Expand Down

0 comments on commit c00f50a

Please sign in to comment.