Skip to content

Commit

Permalink
fix: notification event not publiished to mqtt (#1055)
Browse files Browse the repository at this point in the history
* fix: notification event not publiished to mqtt

Fixes #1044

* fix: reset timeout
  • Loading branch information
robertsLando authored Apr 13, 2021
1 parent caf0c2a commit bf8db55
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ function onNodeValueNotification (zwaveNode, args) {
args.newValue = args.value
// specify that this is stateless
args.stateless = true

onNodeValueUpdated.call(this, zwaveNode, args)
}

Expand Down Expand Up @@ -1066,7 +1067,7 @@ function updateValueMetadata (zwaveNode, zwaveValue, zwaveValueMeta) {
*
* @param { import('zwave-js').ZWaveNode } zwaveNode
* @param { import('zwave-js').TranslatedValueID } zwaveValue
* @param {Map<string, import('../types/index.js').Z2MValueId} oldValues old valueIds, used to check if the value was existing or not
* @param { Map<string, import('../types/index.js').Z2MValueId | undefined } oldValues old valueIds, used to check if the value was existing or not
*/
function addValue (zwaveNode, zwaveValue, oldValues) {
const node = this.nodes.get(zwaveNode.id)
Expand Down Expand Up @@ -1173,20 +1174,23 @@ function updateValue (zwaveNode, args) {
}

this.emit('valueChanged', valueId, node, prevValue !== newValue)
} else {
// notifications don't hava a defined valueId, manually create a value
addValue.call(this, zwaveNode, args)
}

const self = this

if (valueId.stateless) {
if (this.statelessTimeouts[valueId.id]) {
clearTimeout(this.statelessTimeouts[valueId.id])
}

this.statelessTimeouts[valueId.id] = setTimeout(() => {
valueId.value = undefined
self.emit('valueChanged', valueId, node, false)
}, 1000)
// if valueId is stateless, automatically reset the value after 1 sec
if (valueId.stateless) {
if (this.statelessTimeouts[valueId.id]) {
clearTimeout(this.statelessTimeouts[valueId.id])
}

this.statelessTimeouts[valueId.id] = setTimeout(() => {
valueId.value = undefined
this.emit('valueChanged', valueId, node, false)
}, 1000)
}

node.lastActive = Date.now()
}
}
Expand Down

0 comments on commit bf8db55

Please sign in to comment.