From 9b4fc8d1b8fce47f49a573f6cf43642045dc01a7 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 20 Mar 2020 17:49:18 +0100 Subject: [PATCH] feat: Inclusion timeout #244 --- README.md | 1 + lib/ZwaveClient.js | 29 +++++++++++++++++++++++++++-- src/components/Settings.vue | 11 +++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d06ed7804f6..ddd93dacbcd 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,7 @@ Zwave settings: - **Auto Heal Network**: Enable this to schedule automatic network heals to a specfic time - **Heal hours**: When auto heal is enabled, specified the hours at which `healNetwork` will be daily triggered (0-23) - **Poll interval**: Interval in milliseconds between polls (should not be less than 1s per device) +- **Inclusion timeout**: Seconds to wait before automatically stop inclusion - **Configuration Path**: The path to Openzwave devices config db - **Assume Awake**: Assume Devices that support the Wakeup Class are awake when starting up OZW - **Auto Update Config File**: Auto update Zwave devices database diff --git a/lib/ZwaveClient.js b/lib/ZwaveClient.js index 5b27bbea1e6..4e117472b31 100644 --- a/lib/ZwaveClient.js +++ b/lib/ZwaveClient.js @@ -796,6 +796,10 @@ ZwaveClient.prototype.close = function () { this.tail.unwatch() } + if (this.inclusionTimeout) { + this.stopInclusion() + } + if (this.connected && this.client) { if (this.cfg.saveConfig && typeof this.client.writeConfig === 'function') { this.client.writeConfig() @@ -818,7 +822,7 @@ ZwaveClient.prototype.getStatus = function () { var status = {} status.status = this.connected - status.config = this.config + status.config = this.cfg return status } @@ -1171,6 +1175,23 @@ ZwaveClient.prototype.getInfo = function () { return this.ozwConfig } +ZwaveClient.prototype.startInclusion = function (secure) { + if (this.client && !this.closed) { + this.inclusionTimeout = setTimeout(this.stopInclusion.bind(this), (this.cfg.inclusionTimeout * 1000) || 30000) + this.client.addNode(secure) + } +} + +ZwaveClient.prototype.stopInclusion = function () { + if (this.client && !this.closed) { + if (this.inclusionTimeout) { + clearTimeout(this.inclusionTimeout) + this.inclusionTimeout = null + } + this.client.cancelControllerCommand() + } +} + /** * Calls a specific `client` or `ZwaveClient` method based on `apiName` * ZwaveClients methods used are the ones that overrides default Zwave methods @@ -1193,10 +1214,14 @@ ZwaveClient.prototype.callApi = async function (apiName, ...args) { this.client.assignReturnRoute(nodeid) node.failed = this.client.hasNodeFailed(nodeid) } + } else if (apiName === 'addNode') { + apiName = 'startInclusion' + } else if (apiName === 'cancelControllerCommand') { + apiName = 'stopInclusion' } // ZwaveClient Apis that can be called with MQTT apis - var curtomApis = ['_setNodeName', '_setNodeLocation', 'refreshNeighborns', 'getNodes', 'getInfo', '_createScene', '_removeScene', '_setScenes', '_getScenes', '_sceneGetValues', '_addSceneValue', '_removeSceneValue', '_activateScene'] + var curtomApis = ['_setNodeName', '_setNodeLocation', 'refreshNeighborns', 'getNodes', 'getInfo', '_createScene', '_removeScene', '_setScenes', '_getScenes', '_sceneGetValues', '_addSceneValue', '_removeSceneValue', '_activateScene', 'startInclusion', 'stopInclusion'] // Check if I need to call a ZwaveClient function or this.client function var useCustom = typeof this[apiName] === 'function' && curtomApis.indexOf(apiName) >= 0 diff --git a/src/components/Settings.vue b/src/components/Settings.vue index 0579c8122ff..20f153b0f78 100644 --- a/src/components/Settings.vue +++ b/src/components/Settings.vue @@ -106,6 +106,17 @@ type="number" > + + +