Skip to content

Commit

Permalink
feat: Show node name and location of removed nodes #341
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Apr 3, 2020
1 parent ba99789 commit 5309dbb
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function nodeRemoved (nodeid) {

this.emit('nodeRemoved', node)

addEmptyNodes(this.nodes)
this.addEmptyNodes()
this.emitEvent('NODE_REMOVED', this.nodes[nodeid])
}

Expand All @@ -292,7 +292,7 @@ function nodeAdded (nodeid) {
lastActive: null,
status: NODE_STATUS[5] // dead
}
addEmptyNodes(this.nodes)
this.addEmptyNodes()
debug('Node added', nodeid)
}

Expand Down Expand Up @@ -609,25 +609,6 @@ function getDeviceID (ozwnode) {
return `${parseInt(ozwnode.manufacturerid)}-${parseInt(ozwnode.productid)}-${parseInt(ozwnode.producttype)}`
}

/**
* Used to replace `null` nodes in nodes Array
*
* @param {Array} nodes the Zwave nodes Array
*/
function addEmptyNodes (nodes) {
for (var i = 0; i < nodes.length; i++) {
if (!nodes[i]) {
nodes[i] = {
node_id: i,
type: i === 0 ? 'Main controller' : '',
status: i === 0 ? '' : 'Removed',
failed: true,
values: {}
}
}
}
}

/**
* Used to parse a valueId value based on value type
*
Expand Down Expand Up @@ -882,6 +863,25 @@ ZwaveClient.prototype.initNode = function (ozwnode, nodeinfo) {
}
}

/**
* Used to replace `null` nodes in nodes Array
*
*/
ZwaveClient.prototype.addEmptyNodes = function () {
for (var i = 0; i < this.nodes.length; i++) {
if (!this.nodes[i]) {
this.nodes[i] = {
node_id: i,
type: i === 0 ? 'Main controller' : '',
status: i === 0 ? '' : 'Removed',
name: this.zwcfg_nodes[i] ? this.zwcfg_nodes[i].name : '',
loc: this.zwcfg_nodes[i] ? this.zwcfg_nodes[i].loc : '',
failed: true,
values: {}
}
}
}
}
/**
* Popolate node `groups` property by creating an array of groups `{text: <groupLabel>, value: <groupIndex>}`
*
Expand Down

0 comments on commit 5309dbb

Please sign in to comment.