Skip to content

Commit

Permalink
fix: use getNeighbors method (#1146)
Browse files Browse the repository at this point in the history
* fix: use `getNeighbors` method

* fix: refresh neighbors button

* chore(deps): bump zwave-js@7.4.0
  • Loading branch information
robertsLando authored May 11, 2021
1 parent 2ec1213 commit fa50cf1
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 58 deletions.
45 changes: 36 additions & 9 deletions lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const allowedApis = [
'_removeSceneValue',
'_activateScene',
'refreshNeighbors',
'getNodeNeighbors',
'getAssociations',
'addAssociations',
'removeAssociations',
Expand Down Expand Up @@ -370,7 +371,7 @@ async function onNodeReady (zwaveNode) {
node.ready = false
node.values = {}

dumpNode.call(this, zwaveNode)
await dumpNode.call(this, zwaveNode)

const values = zwaveNode.getDefinedValueIDs()

Expand Down Expand Up @@ -459,11 +460,11 @@ function onNodeInterviewStageCompleted (zwaveNode, stageName) {
*
* @param {import('zwave-js').ZWaveNode} zwaveNode
*/
function onNodeInterviewCompleted (zwaveNode) {
async function onNodeInterviewCompleted (zwaveNode) {
const node = this.nodes.get(zwaveNode.id)

if (node.manufacturerId === undefined) {
dumpNode.call(this, zwaveNode)
await dumpNode.call(this, zwaveNode)
}

logger.info(
Expand Down Expand Up @@ -861,7 +862,7 @@ function removeNode (nodeid) {
* @param {import('zwave-js').ZWaveNode} zwaveNode
* @returns {import('../types/index.js').Z2MNode}
*/
function addNode (zwaveNode) {
async function addNode (zwaveNode) {
const nodeId = zwaveNode.id

let node = this.nodes.get(nodeId)
Expand Down Expand Up @@ -906,7 +907,7 @@ function addNode (zwaveNode) {

this.nodes.set(nodeId, node)

dumpNode.call(this, zwaveNode)
await dumpNode.call(this, zwaveNode)

onNodeStatus.call(this, zwaveNode)
logger.debug(`Node ${nodeId} has been added to nodes array`)
Expand All @@ -921,7 +922,7 @@ function addNode (zwaveNode) {
*
* @param {import('zwave-js').ZWaveNode} zwaveNode
*/
function dumpNode (zwaveNode) {
async function dumpNode (zwaveNode) {
const nodeId = zwaveNode.id

const node = this.nodes.get(nodeId)
Expand Down Expand Up @@ -978,7 +979,7 @@ function dumpNode (zwaveNode) {
specific: deviceClass.specific.key
}

node.neighbors = zwaveNode.neighbors
node.neighbors = await this.getNodeNeighbors(nodeId, true)

const storedNode = this.storeNodes[nodeId]

Expand Down Expand Up @@ -1808,15 +1809,41 @@ ZwaveClient.prototype.removeNodeFromAllAssociations = async function (nodeId) {
* @returns {Map<number, number[]>} The nodes array where `nodeId` is the array index and the value is the array
* of neighburns of that `nodeId`
*/
ZwaveClient.prototype.refreshNeighbors = function () {
ZwaveClient.prototype.refreshNeighbors = async function () {
const toReturn = {}
for (const [nodeId, node] of this.nodes) {
node.neighbors = this.getNode(nodeId).neighbors
try {
node.neighbors = await this.getNodeNeighbors(nodeId, true)
} catch (error) {}
toReturn[nodeId] = node.neighbors
}

return toReturn
}

/**
* Get neighbors of a specific node
*
* @param {number} nodeId
* @param {boolean} dontThrow
* @returns {number[]} Node neighbors
* of neighburns of that `nodeId`
*/
ZwaveClient.prototype.getNodeNeighbors = async function (nodeId, dontThrow) {
let neighbors = []
try {
neighbors = await this.driver.controller.getNodeNeighbors(nodeId)
} catch (error) {
logger.error(
`Node ${nodeId} error while updating Neighbors: ${error.message}`
)
if (!dontThrow) {
throw error
}
}

return neighbors
}
/**
* Execute a custom function with the driver
*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"vuetify": "^2.4.8",
"vuex": "^3.6.2",
"winston": "^3.3.3",
"zwave-js": "^7.3.0"
"zwave-js": "^7.4.0"
},
"devDependencies": {
"@babel/cli": "^7.13.16",
Expand Down
26 changes: 14 additions & 12 deletions src/components/Mesh.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,18 @@
</v-list-item>
</v-list>
</div>

<!-- <v-speed-dial bottom fab right fixed v-model="fab">
<template v-slot:activator>
<v-btn color="blue darken-2" dark fab hover v-model="fab">
<v-icon v-if="fab">close</v-icon>
<v-icon v-else>add</v-icon>
</v-btn>
</template>
<v-btn fab dark small color="green" @click="refresh">
<v-icon>refresh</v-icon>
</v-btn>
</v-speed-dial> -->
</v-card>
<v-speed-dial style="left:100px" bottom fab left fixed v-model="fab">
<template v-slot:activator>
<v-btn color="blue darken-2" dark fab hover v-model="fab">
<v-icon v-if="fab">close</v-icon>
<v-icon v-else>add</v-icon>
</v-btn>
</template>
<v-btn fab dark small color="green" @click="debounceRefresh">
<v-icon>refresh</v-icon>
</v-btn>
</v-speed-dial>
</v-container>
</template>

Expand Down Expand Up @@ -145,6 +144,7 @@ export default {
if (data.success) {
switch (data.api) {
case 'refreshNeighbors': {
this.showSnackbar('Nodes Neighbors updated')
const neighbors = data.result
for (const nodeId in neighbors) {
this.setNeighbors({
Expand Down Expand Up @@ -209,6 +209,8 @@ export default {
},
true
)
this.debounceRefresh()
},
beforeDestroy () {
if (this.refreshTimeout) {
Expand Down
3 changes: 2 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ export interface ZwaveClient extends EventEmitter {
): Promise<void>
removeAllAssociations(nodeId: number): Promise<void>
removeNodeFromAllAssociations(nodeId: number): Promise<void>
refreshNeighbors(): void
refreshNeighbors(): Promise<Map<number, number[]>>
getNodeNeighbors(): Promise<number[]>
driverFunction(code: string): Promise<void>
connect(): Promise<void>
sendToSocket(evtName: string, data: any): void
Expand Down
88 changes: 53 additions & 35 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
alcalzone-shared "^3.0.2"
fs-extra "^9.1.0"

"@alcalzone/pak@^0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@alcalzone/pak/-/pak-0.3.1.tgz#2c0a99dcf4757e025c5d8b7fcb88342973836b8c"
integrity sha512-8NBymgHauGk5ARmVyhOh+5bLxH0cQXV52MUPVvw/IJZck4gugu+7v28fiJR5ddciOe1QZcLTUbc2qTptDVklPQ==
"@alcalzone/pak@^0.6.0":
version "0.6.0"
resolved "https://registry.yarnpkg.com/@alcalzone/pak/-/pak-0.6.0.tgz#fa1d47758593d20e0472d843351aa1ac4fc01c63"
integrity sha512-uX5Yl7GFFX5auw9ZLCuXZ7vuWYzHaOtXTvKWKWs8VSUqTIHtWe6Vdy+WAA3SbH9ZnjT8gcXW5Rvt4mGmjFmliQ==
dependencies:
axios "^0.21.1"
execa "^5.0.0"
Expand Down Expand Up @@ -1782,13 +1782,13 @@
resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==

"@zwave-js/config@7.3.0":
version "7.3.0"
resolved "https://registry.yarnpkg.com/@zwave-js/config/-/config-7.3.0.tgz#57cccfa1f5bca7130d1101e13f8a1894a9bb0be2"
integrity sha512-SbotlQqysG+alqXHlVgvvoYc85xyVfTfJkC6lMCoKWu40s3JMwbPVorgAq6JbXsX+OY5vEWJVr+oQEwmssy0XQ==
"@zwave-js/config@7.4.0":
version "7.4.0"
resolved "https://registry.yarnpkg.com/@zwave-js/config/-/config-7.4.0.tgz#1cc6b53fdedecad68222da908bec4cf35b536fed"
integrity sha512-hm25fVZEY8MjuEhISn/EZI4/1Bnt4vEPp0NjKa6/1YjM2vhQA2TEA/5i2tcHrm6DyJwZ7ei3jEZKGpwfNt3gMw==
dependencies:
"@zwave-js/core" "7.3.0"
"@zwave-js/shared" "7.3.0"
"@zwave-js/core" "7.4.0"
"@zwave-js/shared" "7.4.0"
alcalzone-shared "^3.0.3"
ansi-colors "^4.1.1"
fs-extra "^9.0.1"
Expand All @@ -1797,26 +1797,27 @@
semver "^7.3.2"
winston "^3.3.3"

"@zwave-js/core@7.3.0":
version "7.3.0"
resolved "https://registry.yarnpkg.com/@zwave-js/core/-/core-7.3.0.tgz#c7e4676d787c104e152a8c15f28f4427575b9ed5"
integrity sha512-ZcxqgNNvMwmXZZ1sBgBh+SX57K7EJBFsDKPfmOP2Tz3LuyfGIEnmZiWlqD+47yjwvuJbDSL/JfgUyIRtyD2FhQ==
"@zwave-js/core@7.4.0":
version "7.4.0"
resolved "https://registry.yarnpkg.com/@zwave-js/core/-/core-7.4.0.tgz#bb471404cc20d99a82fa5d0c5f6f0996ea508edf"
integrity sha512-1gHVQRrJ1On4AmSBQNLVh9XmG3+IYARjj8xikgxljVfe4Dn+i40zT9iYRTa/FBIc+EjdiGu0wI0bBZgippZuNQ==
dependencies:
"@alcalzone/jsonl-db" "^1.2.4"
"@zwave-js/shared" "7.3.0"
"@zwave-js/shared" "7.4.0"
alcalzone-shared "^3.0.3"
ansi-colors "^4.1.1"
moment "^2.29.0"
moment-timezone "^0.5.33"
nrf-intel-hex "^1.3.0"
winston "^3.3.3"
winston-daily-rotate-file "^4.5.5"

"@zwave-js/serial@7.3.0":
version "7.3.0"
resolved "https://registry.yarnpkg.com/@zwave-js/serial/-/serial-7.3.0.tgz#23d38002c1d476ffb63bdc9a1569a750c3f8d11d"
integrity sha512-53qtx61FtL0Qx9EaxOfuzHB7kXyHMTE7iCX9oOIOmomSrPB+OuoJz/biBPtDHTlKGStCrzse1VjSxM1jF4bt8w==
"@zwave-js/serial@7.4.0":
version "7.4.0"
resolved "https://registry.yarnpkg.com/@zwave-js/serial/-/serial-7.4.0.tgz#815720efe3bad04db1c5445096a3b3751d73025b"
integrity sha512-VlKkZXaTugMZjp89pF/SpkSVTNkNQU4TYVArgT0W8T67toBlaPT1KZl1EcYCT042OcZLui7z9YduEZsu8SrZpg==
dependencies:
"@zwave-js/core" "7.3.0"
"@zwave-js/core" "7.4.0"
alcalzone-shared "^3.0.3"
serialport "^9.0.7"
winston "^3.3.3"
Expand All @@ -1829,10 +1830,10 @@
minimist "^1.2.5"
ws "^7.4.2"

"@zwave-js/shared@7.3.0":
version "7.3.0"
resolved "https://registry.yarnpkg.com/@zwave-js/shared/-/shared-7.3.0.tgz#4d1bf884bbaa6e10f9f357bbf86a759325b21ea4"
integrity sha512-0DADiZFr59Ij5dKaHA38x8bwRGGSF56IYncDYMqA8Ek8ftIX0K5AVpAZzSZvnJDanRIhIbbAftkmb9U42BeBcg==
"@zwave-js/shared@7.4.0":
version "7.4.0"
resolved "https://registry.yarnpkg.com/@zwave-js/shared/-/shared-7.4.0.tgz#db006a787b673df9d6b516ee8b86642c123af03a"
integrity sha512-NhIq+9v35cCiQDUvOpV/fiPymrDsIaDmaYIWvJgugz90brbEx+psLclisRLfb6mPmUJej3xvnka5WdJw0syH8A==
dependencies:
alcalzone-shared "^3.0.3"

Expand Down Expand Up @@ -5469,6 +5470,13 @@ file-loader@^6.2.0:
loader-utils "^2.0.0"
schema-utils "^3.0.0"

file-stream-rotator@^0.5.7:
version "0.5.7"
resolved "https://registry.yarnpkg.com/file-stream-rotator/-/file-stream-rotator-0.5.7.tgz#868a2e5966f7640a17dd86eda0e4467c089f6286"
integrity sha512-VYb3HZ/GiAGUCrfeakO8Mp54YGswNUHvL7P09WQcXAJNSj3iQ5QraYSp3cIn1MUyw6uzfgN/EFOarCNa4JvUHQ==
dependencies:
moment "^2.11.2"

file-uri-to-path@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
Expand Down Expand Up @@ -8307,7 +8315,7 @@ moment-timezone@^0.5.33:
dependencies:
moment ">= 2.9.0"

"moment@>= 2.9.0", moment@^2.29.0:
"moment@>= 2.9.0", moment@^2.11.2, moment@^2.29.0:
version "2.29.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
Expand Down Expand Up @@ -8733,7 +8741,7 @@ object-copy@^0.1.0:
define-property "^0.2.5"
kind-of "^3.0.3"

object-hash@^2.0.3:
object-hash@^2.0.1, object-hash@^2.0.3:
version "2.1.1"
resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-2.1.1.tgz#9447d0279b4fcf80cff3259bf66a1dc73afabe09"
integrity sha512-VOJmgmS+7wvXf8CjbQmimtCnEx3IAoLxI3fp2fbWehxrWBcAQFbk+vcwb6vzR0VZv/eNCJ/27j151ZTwqW/JeQ==
Expand Down Expand Up @@ -12481,6 +12489,16 @@ windows-release@^4.0.0:
dependencies:
execa "^4.0.2"

winston-daily-rotate-file@^4.5.5:
version "4.5.5"
resolved "https://registry.yarnpkg.com/winston-daily-rotate-file/-/winston-daily-rotate-file-4.5.5.tgz#cfa3a89f4eb0e4126917592b375759b772bcd972"
integrity sha512-ds0WahIjiDhKCiMXmY799pDBW+58ByqIBtUcsqr4oDoXrAI3Zn+hbgFdUxzMfqA93OG0mPLYVMiotqTgE/WeWQ==
dependencies:
file-stream-rotator "^0.5.7"
object-hash "^2.0.1"
triple-beam "^1.3.0"
winston-transport "^4.4.0"

winston-transport@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/winston-transport/-/winston-transport-4.4.0.tgz#17af518daa690d5b2ecccaa7acf7b20ca7925e59"
Expand Down Expand Up @@ -12718,19 +12736,19 @@ zip-stream@^4.1.0:
compress-commons "^4.1.0"
readable-stream "^3.6.0"

zwave-js@^7.3.0:
version "7.3.0"
resolved "https://registry.yarnpkg.com/zwave-js/-/zwave-js-7.3.0.tgz#c0929f5e473f018480f9ed36ee1fa88c695d8513"
integrity sha512-ja5K2U7Q4NiHQ3I07SiBL/qmMDkEf7mOXR1bOwAbe2EzjtDhU6jD2KJhelDoZMFoOEy9mjk8cI2ToDR3CKN8cw==
zwave-js@^7.4.0:
version "7.4.0"
resolved "https://registry.yarnpkg.com/zwave-js/-/zwave-js-7.4.0.tgz#c193ad35bacd21d9c80a4c4fbd27a925259149ed"
integrity sha512-szrk5sS2NuT/Y65n4V6pVsUOY++vQXVl2xXtTX3e3AtkPM3FSUdOWqfJ5InLSqUeW6+ckEzI/HQbeg30AU6Saw==
dependencies:
"@alcalzone/jsonl-db" "^1.2.4"
"@alcalzone/pak" "^0.3.1"
"@alcalzone/pak" "^0.6.0"
"@sentry/integrations" "^6.3.0"
"@sentry/node" "^6.3.0"
"@zwave-js/config" "7.3.0"
"@zwave-js/core" "7.3.0"
"@zwave-js/serial" "7.3.0"
"@zwave-js/shared" "7.3.0"
"@zwave-js/config" "7.4.0"
"@zwave-js/core" "7.4.0"
"@zwave-js/serial" "7.4.0"
"@zwave-js/shared" "7.4.0"
alcalzone-shared "^3.0.3"
ansi-colors "^4.1.1"
axios "^0.21.1"
Expand Down

0 comments on commit fa50cf1

Please sign in to comment.