Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: zwave-js server support #248

Merged
merged 10 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 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 @@ -1289,6 +1291,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 @@ -1579,6 +1585,10 @@ 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('ZwaveServer') })
await this.server.start()
}
logger.info(`Connecting to ${this.cfg.port}`)

await this.driver.start()
Expand Down
Loading