Skip to content

Commit

Permalink
feat: zwave-js server support (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Jan 19, 2021
1 parent cec2d0d commit 3ad9ee6
Show file tree
Hide file tree
Showing 5 changed files with 20,279 additions and 14,373 deletions.
15 changes: 14 additions & 1 deletion lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ const jsonStore = reqlib('/lib/jsonStore.js')
const { socketEvents } = reqlib('/lib/SocketManager.js')
const store = reqlib('config/store.js')
const storeDir = utils.joinPath(true, reqlib('config/app.js').storeDir)
const logger = require('./logger.js').module('Zwave')
const LogManager = require('./logger.js')
const logger = LogManager.module('Zwave')
const inherits = require('util').inherits
const loglevels = require('triple-beam').configs.npm.levels
const { ZwavejsServer } = require('@zwave-js/server')

const ZWAVE_STATUS = {
connected: 'connected',
Expand Down Expand Up @@ -1302,6 +1304,10 @@ ZwaveClient.prototype.close = async function () {
}
}

if (this.server) {
await this.server.destroy()
}

if (this.driver) {
this.driverReady = false
this.removeAllListeners()
Expand Down Expand Up @@ -1593,6 +1599,13 @@ ZwaveClient.prototype.connect = async function () {
this.driver.once('driver ready', driverReady.bind(this))
this.driver.on('all nodes ready', scanComplete.bind(this))

if (this.cfg.serverEnabled) {
this.server = new ZwavejsServer(this.driver, {
port: this.cfg.serverPort || 3000,
logger: LogManager.module('Zwave-Server')
})
await this.server.start()
}
logger.info(`Connecting to ${this.cfg.port}`)

await this.driver.start()
Expand Down
Loading

0 comments on commit 3ad9ee6

Please sign in to comment.