Skip to content

Commit

Permalink
feat: allow custom ZwaveOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Dec 23, 2020
1 parent e1bcbcb commit f1bf0b4
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -1281,21 +1281,23 @@ ZwaveClient.prototype.connect = async function () {
// this could happen when the driver fails the connect and a reconnect timeout triggers
if (this.closed) return

let networkKey

if (this.cfg.networkKey && this.cfg.networkKey.length === 32) {
networkKey = Buffer.from(this.cfg.networkKey, 'hex')
// extend options with hidden `options`
const zwaveOptions = Object.assign({
cacheDir: storeDir,
networkKey: this.cfg.networkKey
}, this.cfg.options)

// transform network key to buffer
if (zwaveOptions.networkKey && zwaveOptions.networkKey.length === 32) {
zwaveOptions.networkKey = Buffer.from(zwaveOptions.networkKey, 'hex')
} else {
networkKey = undefined
delete zwaveOptions.networkKey
}

try {
// init driver here because if connect fails the driver is destroyed
// this could throw so include in the try/catch
this.driver = new Driver(this.cfg.port, {
cacheDir: storeDir,
networkKey: networkKey
})
this.driver = new Driver(this.cfg.port, zwaveOptions)

this.driver.on('error', driverError.bind(this))
this.driver.once('driver ready', driverReady.bind(this))
Expand Down

0 comments on commit f1bf0b4

Please sign in to comment.