From e238ae14cb38ee91e94291355c89935b8393b8c3 Mon Sep 17 00:00:00 2001 From: V Aretakis Date: Fri, 19 Feb 2021 14:07:52 +0100 Subject: [PATCH] fix(discovery): prioritized CCs discovery order (#625) --- lib/Gateway.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/Gateway.js b/lib/Gateway.js index 5963395046f..03617ebec5f 100755 --- a/lib/Gateway.js +++ b/lib/Gateway.js @@ -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) } } @@ -567,6 +568,27 @@ function getNodeName (node, ignoreLoc) { ) } +/** + * Return re-arranged based on critical CCs + * + * @param {Map} 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 * @@ -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) }