Skip to content

Commit

Permalink
fix: correctly parse node notification (#170)
Browse files Browse the repository at this point in the history
* fix: correctly parse notification

* fix: correctly parse Duration

* fix: ignore CC notification

* fix: lint issues
  • Loading branch information
robertsLando authored Jan 12, 2021
1 parent cf71d1f commit af41778
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ const {
Driver,
NodeStatus,
InterviewStage,
extractFirmware
extractFirmware,
CommandClass
} = require('zwave-js')
const { CommandClasses } = require('@zwave-js/core')
const { CommandClasses, Duration } = require('@zwave-js/core')
const utils = reqlib('/lib/utils.js')
const EventEmitter = require('events')
const jsonStore = reqlib('/lib/jsonStore.js')
Expand Down Expand Up @@ -546,12 +547,32 @@ function onNodeMetadataUpdated (zwaveNode, args) {
* @param {Buffer|Duration|undefined} parameters
*/
function onNodeNotification (zwaveNode, notificationLabel, parameters) {
parameters = parseNotification(parameters)

logger.info(
`Node ${zwaveNode.id}: notification: ${notificationLabel} ${
parameters ? 'with ' + parameters.toString() : ''
}`
)
this.emit('notification', zwaveNode, notificationLabel, parameters)

if (parameters instanceof CommandClass) {
logger.info('Command class notification received, ignoring it')
return
}

if (typeof parameters === 'object') {
for (const key in parameters) {
this.emit(
'notification',
zwaveNode,
notificationLabel + '_' + key,
parameters[key]
)
}
} else {
this.emit('notification', zwaveNode, notificationLabel, parameters)
}

this.emit(
'event',
eventEmitter.node,
Expand Down Expand Up @@ -951,6 +972,16 @@ function removeValue (zwaveNode, args) {

// ------- Utils ------------------------

function parseNotification (parameters) {
if (Buffer.isBuffer(parameters)) {
return parameters.toString('hex')
} else if (parameters instanceof Duration) {
return parameters.toMilliseconds()
} else {
return parameters
}
}

/**
* Get the device id of a specific node
*
Expand Down

0 comments on commit af41778

Please sign in to comment.