Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make nodes a map instead of an array #710

Merged
merged 14 commits into from
Feb 24, 2021
Merged
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function setupSocket (server) {
socketManager.on(inboundEvents.init, function (socket) {
if (gw.zwave) {
socket.emit(socketEvents.init, {
nodes: gw.zwave.nodes,
nodes: gw.zwave.getNodes(),
info: gw.zwave.getInfo(),
error: gw.zwave.error,
cntStatus: gw.zwave.cntStatus
Expand Down
18 changes: 9 additions & 9 deletions lib/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ Gateway.prototype.parsePayload = function (payload, valueId, valueConf) {
}

if (valueConf.parseReceive) {
const node = this.zwave.nodes[valueId.nodeId]
const node = this.zwave.nodes.get(valueId.nodeId)
const parsedVal = evalFunction(
valueConf.receiveFunction,
valueId,
Expand Down Expand Up @@ -1091,7 +1091,7 @@ Gateway.prototype.valueTopic = function (node, valueId, returnObject = false) {
* @param {number} nodeID
*/
Gateway.prototype.rediscoverNode = function (nodeID) {
const node = this.zwave.nodes[nodeID]
const node = this.zwave.nodes.get(nodeID)
if (node) {
robertsLando marked this conversation as resolved.
Show resolved Hide resolved
// delete all discovered values
onNodeRemoved.call(this, node)
Expand All @@ -1117,7 +1117,7 @@ Gateway.prototype.rediscoverNode = function (nodeID) {
* @param {number} nodeID
*/
Gateway.prototype.disableDiscovery = function (nodeID) {
const node = this.zwave.nodes[nodeID]
const node = this.zwave.nodes.get(nodeID)
if (node && node.hassDevices) {
for (const id in node.hassDevices) {
node.hassDevices[id].ignoreDiscovery = true
Expand Down Expand Up @@ -1219,15 +1219,15 @@ Gateway.prototype.rediscoverAll = function () {
if (!this.config.hassDiscovery) return

const nodes = this.zwave ? this.zwave.nodes : []
for (let i = 0; i < nodes.length; i++) {
const devices = nodes[i] && nodes[i].hassDevices ? nodes[i].hassDevices : {}
for (const [nodeId, node] of nodes) {
const devices = node.hassDevices ? node.hassDevices : {}
robertsLando marked this conversation as resolved.
Show resolved Hide resolved
for (const id in devices) {
const d = devices[id]
if (d && d.discoveryTopic && d.discovery_payload) {
this.publishDiscovery(d, i)
this.publishDiscovery(d, nodeId)
}
} // end foreach hassdevice
} // end foreach node
}
}

/**
Expand Down Expand Up @@ -2126,7 +2126,7 @@ Gateway.prototype.discoverValue = function (node, vId) {
* @param {number} nodeId
*/
Gateway.prototype.updateNodeTopics = function (nodeId) {
const node = this.zwave.nodes[nodeId]
const node = this.zwave.nodes.get(nodeId)
if (node) {
const topics = Object.keys(this.topicValues).filter(
k => this.topicValues[k].nodeId === node.id
Expand All @@ -2147,7 +2147,7 @@ Gateway.prototype.updateNodeTopics = function (nodeId) {
* @param {number} nodeId
*/
Gateway.prototype.removeNodeRetained = function (nodeId) {
const node = this.zwave.nodes[nodeId]
const node = this.zwave.nodes.get(nodeId)
if (node) {
const topics = Object.keys(node.values).map(v =>
this.valueTopic(node, node.values[v])
Expand Down
Loading