Skip to content

Commit

Permalink
fix(discovery): prioritized CCs discovery order (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
varet80 authored Feb 19, 2021
1 parent 22aa868 commit e238ae1
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lib/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ function onNodeStatus (node) {
nodeDevices.forEach(device => this.discoverDevice(node, device))

// discover node values (that are not part of a device)
for (const id in node.values) {
// iterate prioritized first, then the remaining
for (const id of getPriorityCCFirst(node.values)) {
this.discoverValue(node, id)
}
}
Expand Down Expand Up @@ -567,6 +568,27 @@ function getNodeName (node, ignoreLoc) {
)
}

/**
* Return re-arranged based on critical CCs
*
* @param {Map<string, import('../types').Z2MValueId>} node values map
* @returns {string[]} Array of values Ids sorteb by CC discovery priority
*/

function getPriorityCCFirst (values) {
const priorityCC = [CommandClasses['Color Switch']]
const prioritizedValueIds = []

for (const id in values) {
if (priorityCC.includes(values[id].commandClass)) {
prioritizedValueIds.unshift(id)
} else {
prioritizedValueIds.push(id)
}
}
return prioritizedValueIds
}

/**
* Deep copy of an object
*
Expand Down Expand Up @@ -1080,7 +1102,8 @@ Gateway.prototype.rediscoverNode = function (nodeID) {
nodeDevices.forEach(device => this.discoverDevice(node, device))

// discover node values (that are not part of a device)
for (const id in node.values) {
// iterate prioritized first, then the remaining
for (const id of getPriorityCCFirst(node.values)) {
this.discoverValue(node, id)
}

Expand Down

0 comments on commit e238ae1

Please sign in to comment.