Skip to content

Commit

Permalink
Store all objects homogeneously as global objects (issue #198)
Browse files Browse the repository at this point in the history
Make sure to also remove the 'com.' part for service paths where
there is no device instance for that service.
  • Loading branch information
dirkjanfaber committed Oct 6, 2024
1 parent 253d758 commit 55af5a0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/nodes/victron-nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ module.exports = function (RED) {
return
}
if (this.configNode && (this.configNode.contextStore || typeof this.configNode.contextStore === 'undefined')) {
const transform = (input) => {
return input.replace('/\/(\d+\b)?|\/|(\b\d+\b)/g', (match, p1, p2) => {
if (p1) return `._${p1}`;
if (p2) return `_${p2}`;
return '.';
})
};
const globalContext = this.node.context().global
const v = `${this.service}${this.path}`.replace(/\//g, '.').replace(/com\.victronenergy\.(.+?)\.(\d+)\.(\w+)/, 'victronenergy.$1._$2.$3')
globalContext.set(v, msg.value)
globalContext.set(transform(`${this.service}${this.path}`), msg.value)
}
this.node.previousvalue = msg.value
const outmsg = {
Expand Down

0 comments on commit 55af5a0

Please sign in to comment.