Skip to content

Commit

Permalink
fix(mqtt): handel numbers to bool coerce and value conf on current value
Browse files Browse the repository at this point in the history
This fixes cases where a valueId configuration of a `currentValue` is not picked up when receiving write requests
  • Loading branch information
robertsLando committed Jan 29, 2024
1 parent b86b84c commit 49ac0a3
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions api/lib/Gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ export default class Gateway {
payload = payload ? 0xff : valueId.min
}

// 1/0 becomes true/false
if (typeof payload === 'number' && valueId.type === 'boolean') {
payload = payload > 0
}

if (
valueId.commandClass === CommandClasses['Binary Toggle Switch']
) {
Expand Down Expand Up @@ -2000,9 +2005,16 @@ export default class Gateway {
valueId.conf = valueConf
}

this.topicValues[topic] = valueId.targetValue
? node.values[valueId.targetValue]
: valueId
// handle the case the conf is set on current value but not in target value
if (valueId.targetValue && node.values[valueId.targetValue]) {
const targetValueId = utils.copy(
node.values[valueId.targetValue],
)
targetValueId.conf = valueConf
this.topicValues[topic] = targetValueId
} else {
this.topicValues[topic] = valueId
}
}

let mqttOptions: IClientPublishOptions = valueId.stateless
Expand Down

0 comments on commit 49ac0a3

Please sign in to comment.