Skip to content

Commit

Permalink
feat: Rediscover node button to update node discovered values after c…
Browse files Browse the repository at this point in the history
…hanging node name/location #153
  • Loading branch information
robertsLando committed Mar 2, 2020
1 parent d33f0a1 commit be5e356
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ app.startSocket = function (server) {
case 'discover':
gw.publishDiscovery(data.device, data.node_id, false, true)
break;
case 'rediscoverNode':
gw.rediscoverNode(data.node_id)
break;
case 'update':
gw.zwave.updateDevice(data.device, data.node_id)
break;
Expand Down
20 changes: 20 additions & 0 deletions lib/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,26 @@ Gateway.prototype.valueTopic = function (node, valueId, returnObject) {
}
}

Gateway.prototype.rediscoverNode = function (nodeID) {
var node = this.zwave.nodes[nodeID]
if (node) {
// delete all discovered values
onNodeRemoved.call(this, node)
node.hassDevices = {}

// rediscover all values
const nodeDevices = allDevices[node.device_id] || []
nodeDevices.forEach(device => this.discoverDevice(node, device))

// discover node values (that are not part of a device)
for (let id in node.values) {
this.discoverValue(node, node.values[id])
}

this.emitEvent('NODE_UPDATED', node)
}
}

Gateway.prototype.publishDiscovery = function (hassDevice, nodeId, deleteDevice, update) {
try {
// set values as discovered
Expand Down
13 changes: 13 additions & 0 deletions src/components/ControlPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
<v-flex xs12 md6 pa-1>
<v-btn color="blue darken-1" flat @click.native="storeDevices(false)">Store</v-btn>
<v-btn color="red darken-1" flat @click.native="storeDevices(true)">Remove Store</v-btn>
<v-btn color="green darken-1" flat @click.native="rediscoverNode">Rediscover Node</v-btn>

<v-data-table :headers="headers_hass" :items="hassDevices" class="elevation-1">
<template slot="items" slot-scope="props">
Expand Down Expand Up @@ -862,6 +863,18 @@ export default {
})
}
},
rediscoverNode () {
var node = this.selectedNode
if (
node &&
confirm('Are you sure you want to re-discover all node values?')
) {
this.socket.emit(this.socketActions.hass, {
apiName: 'rediscoverNode',
node_id: this.selectedNode.node_id
})
}
},
rediscoverDevice () {
var device = this.selectedDevice
if (
Expand Down

0 comments on commit be5e356

Please sign in to comment.