New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-red-contrib-knx-ultimate

Package Overview
Dependencies
Maintainers
1
Versions
461
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-red-contrib-knx-ultimate - npm Package Compare versions

Comparing version

to
3.0.5

98

nodes/knxUltimateAutoResponder.js
module.exports = function (RED) {
const dptlib = require('knxultimate').dptlib;
// msg is:

@@ -48,2 +49,3 @@ // // Build final input message object

node.decodedRespondToList = [];
node.sysLogger = require('./utils/sysLogger.js').get({ loglevel: node.server.loglevel || 'error' }); // 08/04/2021 new logger to adhere to the loglevel selected in the config-window

@@ -64,36 +66,44 @@ // Used to call the status update from the config node.

if (node.server.csv === undefined || node.server.csv === '' || node.server.csv.length === 0) {
node.setNodeStatus({ fill: 'red', shape: '', text: 'No ETS file imported', payload: '', dpt: '', devicename: '' });
return;
node.status({ fill: 'grey', shape: 'ring', text: 'No ETS file imported', payload: '', dpt: '', devicename: '' });
//return;
} else {
node.server.csv.forEach(element => {
node.exposedGAs.push({ address: element.ga, dpt: element.dpt, devicename: element.devicename, payload: undefined })
})
node.status({ fill: 'green', shape: 'ring', text: 'ETS file loaded', payload: '', dpt: '', devicename: '' });
}
node.server.csv.forEach(element => {
node.exposedGAs.push({ address: element.ga, dpt: element.dpt, devicename: element.devicename, payload: undefined })
})
// Fill the filter list
try {
node.commandText = config.commandText.split('\n');
if (node.commandText === undefined || node.commandText.length === 0) {
node.setNodeStatus({ fill: 'red', shape: '', text: 'Respond to list must be filled', payload: '', dpt: '', devicename: '' });
return;
}
node.commandText = JSON.parse(config.commandText);
} catch (error) {
node.status({ fill: 'red', shape: 'dot', text: 'JSON error: ' + error.message, payload: '', dpt: '', devicename: '' });
if (node.sysLogger !== undefined && node.sysLogger !== null) node.sysLogger.error(`knxUltimateAutoResponder: node.commandText = JSON.parse(config.commandText) ${error.stack}`);
return;
}
// Decode the commandText list be exploding the format 2/x, 2/2/x
for (let index = 0; index < node.commandText.length; index++) {
const element = node.commandText[index];
let defaultVal = element.split(':')[1];
if (element.split(':')[0].includes('x')) {
for (let index = 0; index < 257; index++) {
let decAdd = element.split(':')[0].replace(/x/g, index)
node.decodedRespondToList.push({ address: decAdd, default: defaultVal })
// Decode the commandText list be exploding the format 2/2/..
node.commandText.forEach(element => {
if (element.ga !== undefined && element.default !== undefined) {
let defaultVal = element.default;
if (element.ga.includes('..')) {
const start = Number(element.ga.substring(element.ga.lastIndexOf("/") + 1, element.ga.indexOf("..")));
const end = Number(element.ga.substring(element.ga.indexOf("..") + 2));
const twoLevel = element.ga.substring(0, element.ga.lastIndexOf("/") + 1);
for (let index = start; index < end; index++) {
const decAdd = twoLevel + index;
node.decodedRespondToList.push({ address: decAdd, default: defaultVal });
}
} else {
node.decodedRespondToList.push({ address: element.ga, default: defaultVal })
}
node.status({ fill: 'green', shape: 'ring', text: 'JSON parsed: ' + node.decodedRespondToList.length + " directive(s).", payload: '', dpt: '', devicename: '' });
} else {
node.decodedRespondToList.push({ address: element.split(':')[0], default: defaultVal })
// Error
node.status({ fill: 'red', shape: 'dot', text: 'JSON error: ga or default keys not set. Abort.', payload: '', dpt: '', devicename: '' });
if (node.sysLogger !== undefined && node.sysLogger !== null) node.sysLogger.error(`knxUltimateAutoResponder: node.commandText.forEach(element.. JSON error: ga or default keys not set. Abort.`);
return;
}
}
});
// This function is called by the knx-ultimate config node, to output a msg.payload.

@@ -108,6 +118,24 @@ node.handleSend = msg => {

} catch (error) {
console.log(error)
if (node.sysLogger !== undefined && node.sysLogger !== null) node.sysLogger.error(`knxUltimateAutoResponder: var oGa = node.exposedGAs.find(ga => ga.address === msg.knx.destination) ${error.stack}`);
}
if (oGa === undefined) {
node.exposedGAs.push({ address: msg.knx.destination, devicename: undefined, dpt: msg.knx.dpt, payload: msg.payload })
let datapoint;
let decodedPayload;
if (msg.knx !== undefined && msg.knx.dpt !== undefined) {
// There is the CSV file imported
datapoint = msg.knx.dpt;
decodedPayload = msg.payload;
} else {
// Must get the dpt from the decodedRespondToList list, then decode the payload
try {
datapoint = node.decodedRespondToList.find(x => x.address === msg.knx.destination).dpt;
const dpt = dptlib.resolve(datapoint);
const decodedPayload = dptlib.fromBuffer(msg.knx.rawValue, dpt);
} catch (error) {
node.status({ fill: 'red', shape: 'dot', text: 'datapoint = node.decodedRespondToList ' + error.message, payload: '', dpt: '', devicename: '' });
if (node.sysLogger !== undefined && node.sysLogger !== null) node.sysLogger.error(`knxUltimateAutoResponder: datapoint = node.decodedRespondToList.find(x => x.address === msg.knx.destination).dpt ${error.stack}`);
}
}
if (decodedPayload !== undefined && datapoint !== undefined) node.exposedGAs.push({ address: msg.knx.destination, devicename: undefined, dpt: datapoint, payload: decodedPayload })
} else {

@@ -123,9 +151,13 @@ oGa.dpt = msg.knx.dpt

// Can i handle the incoming message?
for (let index = 0; index < node.decodedRespondToList.length; index++) {
const element = node.decodedRespondToList[index];
if (msg.knx.destination === element.address) {
defaultValue = element.default;
bFound = true;
break;
try {
for (let index = 0; index < node.decodedRespondToList.length; index++) {
const element = node.decodedRespondToList[index];
if (msg.knx.destination === element.address) {
defaultValue = element.default;
bFound = true;
break;
}
}
} catch (error) {
if (node.sysLogger !== undefined && node.sysLogger !== null) node.sysLogger.error(`knxUltimateAutoResponder: before bFound ${error.stack}`);
}

@@ -151,3 +183,3 @@ if (!bFound) return;

} catch (error) {
console.log(error)
if (node.sysLogger !== undefined && node.sysLogger !== null) node.sysLogger.error(`knxUltimateAutoResponder: after bFound ${error.stack}`);
}

@@ -162,4 +194,4 @@ }

node.on('close', function (done) {
if (node.timerExposedGAs !== null) clearTimeout(node.timerExposedGAs)
node.exposedGAs = []
node.exposedGAs = [];
node.decodedRespondToList = [];
if (node.server) {

@@ -166,0 +198,0 @@ node.server.removeClient(node)

@@ -6,3 +6,3 @@ {

},
"version": "3.0.4",
"version": "3.0.5",
"description": "Control your KNX intallation via Node-Red! A bunch of KNX nodes, with integrated Philips HUE control and ETS group address importer. Easy to use and highly configurable.",

@@ -9,0 +9,0 @@ "dependencies": {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet