Skip to content

Commit

Permalink
fix: battery devices not ready (#1195)
Browse files Browse the repository at this point in the history
* fix: battery devices not ready

Fixes zwave-js/node-zwave-js#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
  • Loading branch information
robertsLando authored May 12, 2021
1 parent 9b5ead9 commit 78dec83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
27 changes: 13 additions & 14 deletions lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ class ZwaveClient extends EventEmitter {
*
* @param {number} nodeId
* @param {boolean} dontThrow
* @returns {number[]} Node neighbors
* @returns {Promise<number[]>} Node neighbors
* of neighburns of that `nodeId`
*/
async getNodeNeighbors (nodeId, dontThrow) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/nodes-table/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@
</td>
</template>
<template v-slot:[`item.manufacturer`]="{ item }">
{{ item.ready ? item.manufacturer : '' }}
{{ item.manufacturer }}
</template>
<template v-slot:[`item.productDescription`]="{ item }">
{{ item.ready ? item.productDescription : '' }}
{{ item.productDescription }}
</template>
<template v-slot:[`item.productLabel`]="{ item }">
{{ item.ready ? item.productLabel : '' }}
{{ item.productLabel }}
</template>
<template v-slot:[`item.name`]="{ item }">
{{ item.name || '' }}
Expand Down

0 comments on commit 78dec83

Please sign in to comment.