Skip to content

Commit

Permalink
fix: manually add missing values on updates (#1056)
Browse files Browse the repository at this point in the history
* fix: manually add missing values on updates

* fix: dedupe updates
  • Loading branch information
robertsLando authored Apr 13, 2021
1 parent bf8db55 commit c2600df
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ function updateValueMetadata (zwaveNode, zwaveValue, zwaveValueMeta) {
description: zwaveValueMeta.description,
label: zwaveValueMeta.label || zwaveValue.propertyName + ' (property)', // when label is missing, re use propertyName. Usefull for webinterface
default: zwaveValueMeta.default,
stateless: false // used for notifications to specify that this should not be persisted (retained)
stateless: zwaveValue.stateless || false // used for notifications to specify that this should not be persisted (retained)
}

if (zwaveValueMeta.ccSpecific) {
Expand Down Expand Up @@ -1150,6 +1150,15 @@ function updateValue (zwaveNode, args) {
if (!node) {
logger.info(`valueChanged: no such node: ${zwaveNode.id} error`)
} else {
let skipUpdate = false

// notifications events are not defined as values, manually create them once we get the first update
if (!node.values[getValueID(args)]) {
addValue.call(this, zwaveNode, args)
// addValue call already trigger valueChanged event
skipUpdate = true
}

const valueId = node.values[getValueID(args)]

if (valueId) {
Expand All @@ -1173,10 +1182,9 @@ function updateValue (zwaveNode, args) {
valueId.value = new Duration(undefined, 'seconds')
}

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

// if valueId is stateless, automatically reset the value after 1 sec
Expand Down

0 comments on commit c2600df

Please sign in to comment.