Skip to content

Commit

Permalink
feat: disable discovery #405 (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored May 13, 2020
1 parent c87c8d2 commit c72f250
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ app.startSocket = function (server) {
case 'rediscoverNode':
gw.rediscoverNode(data.node_id)
break;
case 'disableDiscovery':
gw.disableDiscovery(data.node_id)
break;
case 'update':
gw.zwave.updateDevice(data.device, data.node_id)
break;
Expand Down
17 changes: 17 additions & 0 deletions lib/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,25 @@ Gateway.prototype.rediscoverNode = function (nodeID) {
}
}

Gateway.prototype.disableDiscovery = function (nodeID) {
var node = this.zwave.nodes[nodeID]
if (node && node.hassDevices) {
for (const id in node.hassDevices) {
node.hassDevices[id].ignoreDiscovery = true
}

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

Gateway.prototype.publishDiscovery = function (hassDevice, nodeId, deleteDevice, update) {
try {
if (hassDevice.ignoreDiscovery) {
return
} else {
hassDevice.ignoreDiscovery = false
}

// set values as discovered
for (let k = 0; k < hassDevice.values.length; k++) {
this.discovered[nodeId + '-' + hassDevice.values[k]] = hassDevice
Expand Down
16 changes: 14 additions & 2 deletions src/components/ControlPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<v-tabs-items v-model="currentTab">
<!-- TAB NODE INFO -->
<v-tab-item key="node">
<v-container v-if="selectedNode" grid-list-md>
<v-container v-if="selectedNode" style="min-width:90%" grid-list-md>
<v-layout row>
<v-flex xs3>
<v-select
Expand Down Expand Up @@ -234,6 +234,7 @@
<v-btn color="blue darken-1" text @click.native="storeDevices(false)">Store</v-btn>
<v-btn color="red darken-1" text @click.native="storeDevices(true)">Remove Store</v-btn>
<v-btn color="green darken-1" text @click.native="rediscoverNode">Rediscover Node</v-btn>
<v-btn color="yellow darken-1" text @click.native="disableDiscovery">Disable Discovery</v-btn>

<v-data-table :headers="headers_hass" :items="hassDevices" class="elevation-1">
<template v-slot:item="{ item }">
Expand All @@ -246,6 +247,7 @@
<td class="text-xs">{{ item.type }}</td>
<td class="text-xs">{{ item.object_id }}</td>
<td class="text-xs">{{ item.persistent ? 'Yes' : 'No' }}</td>
<td class="text-xs">{{ item.ignoreDiscovery ? 'Disabled' : 'Enabled' }}</td>
</tr>
</template>
</v-data-table>
Expand Down Expand Up @@ -608,7 +610,8 @@ export default {
{ text: 'Id', value: 'id' },
{ text: 'Type', value: 'type' },
{ text: 'Object id', value: 'object_id' },
{ text: 'Persistent', value: 'persistent' }
{ text: 'Persistent', value: 'persistent' },
{ text: 'Discovery', value: 'ignoreDiscovery' }
],
selectedDevice: null,
errorDevice: false,
Expand Down Expand Up @@ -927,6 +930,15 @@ export default {
})
}
},
async disableDiscovery () {
var node = this.selectedNode
if (node && await this.confirm('Rediscover node', 'Are you sure you want to disable discovery of all values? In order to make this persistent remember to click on Store')) {
this.socket.emit(this.socketActions.hass, {
apiName: 'disableDiscovery',
node_id: this.selectedNode.node_id
})
}
},
async rediscoverDevice () {
var device = this.selectedDevice
if (device && await this.confirm('Are you sure you want to re-discover selected device?')) {
Expand Down

0 comments on commit c72f250

Please sign in to comment.