node-red-contrib-knx-ultimate
Advanced tools
Comparing version
module.exports = function (RED) { | ||
const dptlib = require('knxultimate').dptlib; | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
// msg is: | ||
@@ -63,2 +66,31 @@ // // Build final input message object | ||
node.saveExposedGAs = () => { | ||
const sFile = path.join(node.server.userDir, "knxpersistvalues", "knxpersist" + node.id + ".json"); | ||
try { | ||
if (node.exposedGAs.length > 0) { | ||
fs.writeFileSync(sFile, JSON.stringify(node.exposedGAs)); | ||
if (node.sysLogger !== undefined && node.sysLogger !== null) node.sysLogger.info("knxUltimateAutoResponder: wrote peristent values to the file " + sFile); | ||
} | ||
} catch (err) { | ||
if (node.sysLogger !== undefined && node.sysLogger !== null) node.sysLogger.error("knxUltimateAutoResponder: unable to write peristent values to the file " + sFile + " " + err.message); | ||
} | ||
} | ||
node.loadExposedGAs = () => { | ||
const sFile = path.join(node.server.userDir, "knxpersistvalues", "knxpersist" + node.id + ".json"); | ||
try { | ||
node.exposedGAs = JSON.parse(fs.readFileSync(sFile, "utf8")); | ||
} catch (err) { | ||
node.exposedGAs = []; | ||
if (node.sysLogger !== undefined && node.sysLogger !== null) node.sysLogger.warn("knxUltimateAutoResponder: unable to read peristent file " + sFile + " " + err.message); | ||
} | ||
} | ||
// Load persistent file | ||
try { | ||
node.loadExposedGAs() | ||
} catch (error) { | ||
} | ||
// Add the ETS CSV file list to exposedGAs | ||
if (node.server.csv === undefined || node.server.csv === '' || node.server.csv.length === 0) { | ||
@@ -69,3 +101,6 @@ node.status({ fill: 'grey', shape: 'ring', text: 'No ETS file imported', payload: '', dpt: '', devicename: '' }); | ||
node.server.csv.forEach(element => { | ||
node.exposedGAs.push({ address: element.ga, dpt: element.dpt, default: undefined, payload: undefined }) | ||
const curGa = node.exposedGAs.find(a => a.address === element.ga); | ||
if (curGa === undefined) { | ||
node.exposedGAs.push({ address: element.ga, dpt: element.dpt, default: undefined, payload: undefined }); | ||
} | ||
}) | ||
@@ -137,4 +172,4 @@ node.status({ fill: 'green', shape: 'ring', text: 'ETS file loaded', payload: '', dpt: '', devicename: '' }); | ||
} 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}`); | ||
node.status({ fill: 'red', shape: 'dot', text: 'const decodedPayload = dptlib.fromBuffer(msg.knx.rawValue, dptlib.resolve(oGa.dpt)); ' + error.message, payload: '', dpt: '', devicename: '' }); | ||
if (node.sysLogger !== undefined && node.sysLogger !== null) node.sysLogger.error(`knxUltimateAutoResponder: const decodedPayload = dptlib.fromBuffer(msg.knx.rawValue, dptlib.resolve(oGa.dpt)); ${error.stack}`); | ||
} | ||
@@ -170,4 +205,8 @@ oGa.payload = decodedPayload | ||
node.on('close', function (done) { | ||
try { | ||
node.saveExposedGAs(); | ||
} catch (error) { | ||
} | ||
node.exposedGAs = []; | ||
node.decodedRespondToList = []; | ||
if (node.server) { | ||
@@ -174,0 +213,0 @@ node.server.removeClient(node) |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "3.0.6", | ||
"version": "3.0.7", | ||
"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": { |
@@ -34,3 +34,3 @@  | ||
## NODE LIST | ||
## NODE'S LIST | ||
@@ -45,5 +45,6 @@ * **KNX-ULTIMATE node** [here](https://github.com/Supergiovane/node-red-contrib-knx-ultimate/wiki/2.-Node-Configuration), allow you to control your *KNX installation* via Node-Red. You can control all your KNX devices as well as create a *Virtual Device* in Node-Red, to link external *non KNX* devices, and make it compatible with your KNX installation. I'ts very SIMPLE TO USE thus very customizable. | ||
* **VIEWER node** [here](https://github.com/Supergiovane/node-red-contrib-knx-ultimate/wiki/knxUltimateViewer). View all Group Addresses and values of your KNX BUS, in the Node-Red Dashboard. | ||
* **AUTO RESPONDER node** responds to read requests coming from the bus. Used mainly for virtual group addresses. | ||
* **PHILIPS HUE nodeset** [here](https://github.com/Supergiovane/node-red-contrib-knx-ultimate/wiki/en-hue-configuration). Link HUE devices to KNX in a simple way. | ||
* **HOME ASSISTANT translator node** translates the HA input msg, to a KNX value. Comes with a built-in translation table, that's user editable. | ||
* **AUTO RESPONDER node** responds to read requests coming from the bus. Used mainly for virtual group addresses. | ||
<br> | ||
@@ -50,0 +51,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
7626229
0.02%20139
0.17%335
0.3%7
16.67%