From 78dec83a4df22718c5161a17353b1c2f1e48c869 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Wed, 12 May 2021 17:09:08 +0200 Subject: [PATCH] fix: battery devices not ready (#1195) * fix: battery devices not ready Fixes https://github.com/zwave-js/node-zwave-js/issues/2600 * fix: await `_addNode` * fix: await _nodeReady * fix: types * fix: fetch neighbors only on node ready event, remove useless async/await * fix(ui): show hidden informations when node is not ready * fix: remove useless async --- lib/ZwaveClient.js | 27 +++++++++++++-------------- src/components/nodes-table/index.vue | 6 +++--- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/ZwaveClient.js b/lib/ZwaveClient.js index cac73321a4..fa41fac851 100644 --- a/lib/ZwaveClient.js +++ b/lib/ZwaveClient.js @@ -630,7 +630,7 @@ class ZwaveClient extends EventEmitter { * * @param {number} nodeId * @param {boolean} dontThrow - * @returns {number[]} Node neighbors + * @returns {Promise} Node neighbors * of neighburns of that `nodeId` */ async getNodeNeighbors (nodeId, dontThrow) { @@ -1672,7 +1672,7 @@ class ZwaveClient extends EventEmitter { // ---------- DRIVER EVENTS ------------------------------------- - _onDriverReady () { + async _onDriverReady () { /* Now the controller interview is complete. This means we know which nodes are included in the network, but they might not be ready yet. @@ -1704,7 +1704,9 @@ class ZwaveClient extends EventEmitter { this._addNode(node) // Make sure we didn't miss the ready event - if (node.ready) this._onNodeReady(node) + if (node.ready) { + await this._onNodeReady(node) + } } this.driverInfo.homeid = this.driver.controller.homeId @@ -1903,7 +1905,8 @@ class ZwaveClient extends EventEmitter { node.ready = false node.values = {} - await this._dumpNode(zwaveNode) + this._dumpNode(zwaveNode) + node.neighbors = await this.getNodeNeighbors(zwaveNode.id, true) const values = zwaveNode.getDefinedValueIDs() @@ -1999,11 +2002,11 @@ class ZwaveClient extends EventEmitter { * * @param {import('zwave-js').ZWaveNode} zwaveNode */ - async _onNodeInterviewCompleted (zwaveNode) { + _onNodeInterviewCompleted (zwaveNode) { const node = this.nodes.get(zwaveNode.id) if (node.manufacturerId === undefined) { - await this._dumpNode(zwaveNode) + this._dumpNode(zwaveNode) } logger.info( @@ -2410,7 +2413,7 @@ class ZwaveClient extends EventEmitter { * @param {import('zwave-js').ZWaveNode} zwaveNode * @returns {import('../types/index.js').Z2MNode} */ - async _addNode (zwaveNode) { + _addNode (zwaveNode) { const nodeId = zwaveNode.id let node = this.nodes.get(nodeId) @@ -2455,13 +2458,11 @@ class ZwaveClient extends EventEmitter { this.nodes.set(nodeId, node) - await this._dumpNode(zwaveNode) - + this._dumpNode(zwaveNode) + this._bindNodeEvents(zwaveNode) this._onNodeStatus(zwaveNode) logger.debug(`Node ${nodeId} has been added to nodes array`) - this._bindNodeEvents(zwaveNode) - return node } @@ -2470,7 +2471,7 @@ class ZwaveClient extends EventEmitter { * * @param {import('zwave-js').ZWaveNode} zwaveNode */ - async _dumpNode (zwaveNode) { + _dumpNode (zwaveNode) { const nodeId = zwaveNode.id const node = this.nodes.get(nodeId) @@ -2527,8 +2528,6 @@ class ZwaveClient extends EventEmitter { specific: deviceClass.specific.key } - node.neighbors = await this.getNodeNeighbors(nodeId, true) - const storedNode = this.storeNodes[nodeId] if (storedNode) { diff --git a/src/components/nodes-table/index.vue b/src/components/nodes-table/index.vue index 419c08d1cb..b93fc4a637 100644 --- a/src/components/nodes-table/index.vue +++ b/src/components/nodes-table/index.vue @@ -113,13 +113,13 @@