Skip to content

Commit

Permalink
fix: update valueIds on metadata updated
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Dec 1, 2020
1 parent 6922fca commit a76c096
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions lib/ZwaveClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ function onNodeValueRemoved (zwaveNode, args) {
}

function onNodeMetadataUpdated (zwaveNode, args) {
updateValueMetadata.call(this, zwaveNode, args, args.metadata)
debug(`Node ${zwaveNode.id}: metadata updated: ${getValueID(args)}`)
const valueId = initValue.call(this, zwaveNode, args, args.metadata)
debug(`Node ${valueId.nodeId}: metadata updated: ${getValueID(args)}`)
this.emit(
'event',
eventEmitter.node,
Expand Down Expand Up @@ -711,33 +711,41 @@ function addValue (zwaveNode, zwaveValue) {
} else {
const zwaveValueMeta = zwaveNode.getValueMetadata(zwaveValue)

const valueId = updateValueMetadata.call(
this,
zwaveNode,
zwaveValue,
zwaveValueMeta
)
valueId.value = zwaveNode.getValue(zwaveValue)

if (isCurrentValue(valueId)) {
valueId.isCurrentValue = true
const targetValue = findTargetValue(
valueId,
zwaveNode.getDefinedValueIDs()
)
if (targetValue) {
valueId.targetValue = getValueID(targetValue, false)
}
}
const valueId = initValue.call(this, zwaveNode, zwaveValue, zwaveValueMeta)

debug(`Node ${zwaveNode.id}: value added ${valueId.id} => ${valueId.value}`)

node.values[getValueID(valueId)] = valueId

this.emit('valueChanged', valueId, node)
}
}

function initValue (zwaveNode, zwaveValue, zwaveValueMeta) {
const node = this.nodes[zwaveNode.id]

const valueId = updateValueMetadata.call(
this,
zwaveNode,
zwaveValue,
zwaveValueMeta
)
valueId.value = zwaveNode.getValue(zwaveValue)

if (isCurrentValue(valueId)) {
valueId.isCurrentValue = true
const targetValue = findTargetValue(
valueId,
zwaveNode.getDefinedValueIDs()
)
if (targetValue) {
valueId.targetValue = getValueID(targetValue, false)
}
}

node.values[getValueID(valueId)] = valueId

return valueId
}

// Triggered when a node is ready and a value changes
function updateValue (zwaveNode, args) {
const node = this.nodes[zwaveNode.id]
Expand Down

0 comments on commit a76c096

Please sign in to comment.