Skip to content

Commit

Permalink
feat: Inclusion timeout #244
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Mar 20, 2020
1 parent 6b07091 commit 9b4fc8d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 27 additions & 2 deletions lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -818,7 +822,7 @@ ZwaveClient.prototype.getStatus = function () {
var status = {}

status.status = this.connected
status.config = this.config
status.config = this.cfg

return status
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@
type="number"
></v-text-field>
</v-flex>
<v-flex xs6>
<v-text-field
v-model.number="zwave.inclusionTimeout"
label="Inclusion timeout"
:rules="[rules.required]"
required
suffix="seconds"
hint="Seconds to wait before stopping inclusion"
type="number"
></v-text-field>
</v-flex>
<v-flex xs6>
<v-text-field
v-model.trim="zwave.configPath"
Expand Down

0 comments on commit 9b4fc8d

Please sign in to comment.