Skip to content

Commit

Permalink
Set default topic to be the service name + path name
Browse files Browse the repository at this point in the history
- And overrule that when a custom name has been set.
  • Loading branch information
dirkjanfaber committed Nov 6, 2022
1 parent b8a4931 commit b4a1d83
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/nodes/victron-nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = function (RED) {

this.service = nodeDefinition.service
this.path = nodeDefinition.path
this.defaulttopic = nodeDefinition.serviceObj.name + ' - ' + nodeDefinition.pathObj.name

this.configNode = RED.nodes.getNode("victron-client-id")
this.client = this.configNode.client
Expand All @@ -59,9 +60,13 @@ module.exports = function (RED) {
}

this.subscription = this.client.subscribe(this.service, this.path, (msg) => {
var topic = this.defaulttopic
if (this.node.name) {
topic = this.node.name
}
this.node.send({
payload: msg.value,
topic: `${this.service} - ${this.path}`
topic: topic
})
})
}
Expand Down

0 comments on commit b4a1d83

Please sign in to comment.