node-red-contrib-ccu 4.10.3 → 4.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,35 @@ Notable changes to node-red-contrib-ccu. Format follows
|
|
|
5
5
|
user-visible symptom and the cause, not the commit list (the release notes
|
|
6
6
|
append commits automatically).
|
|
7
7
|
|
|
8
|
+
## 4.11.0 (2026-11-20)
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **Far fewer writes to the SD card.** The connection used to rewrite its
|
|
13
|
+
cache files more often than needed: the device table at every start, the
|
|
14
|
+
names file on a CCU at every names re-read (every 15 minutes by default,
|
|
15
|
+
even when nothing had changed), the value cache twice per redeploy or
|
|
16
|
+
restart, and `paramsets.json` (several megabytes) whole after every 30
|
|
17
|
+
fetched descriptions. Now the device table and the names file are written
|
|
18
|
+
only when their content changed, the names file no longer carries system
|
|
19
|
+
variable and program values (they were never read back),
|
|
20
|
+
`paramsets.json` is written once per fetch round and only when it gained a
|
|
21
|
+
new description (the shipped file is read directly instead of being
|
|
22
|
+
copied), and the value cache is written at stop and otherwise at most every
|
|
23
|
+
60 minutes. A redeploy now writes about half as much, and on a CCU the
|
|
24
|
+
connection writes nothing while idle.
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- **Setting "Value cache write (min)"** in the connection node: how often the
|
|
29
|
+
value cache is written while Node-RED runs (default 60, 0 = only at stop).
|
|
30
|
+
A longer interval writes less; after a power cut the cache is at most that
|
|
31
|
+
old, and the values are read fresh from the CCU at the next start anyway.
|
|
32
|
+
- **A warning when the connection's values go into a file context store.**
|
|
33
|
+
Node-RED's `localfilesystem` store rewrites the whole global context on
|
|
34
|
+
every change, which writes a lot with many devices; the help text explains
|
|
35
|
+
it.
|
|
36
|
+
|
|
8
37
|
## 4.10.3 (2026-11-20)
|
|
9
38
|
|
|
10
39
|
### Fixed
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
regaPoll: {value: true},
|
|
39
39
|
regaInterval: {value: 30},
|
|
40
40
|
regaMetaInterval: {value: 15},
|
|
41
|
+
valuesSaveInterval: {value: 60},
|
|
41
42
|
|
|
42
43
|
rpcPing: {value: true},
|
|
43
44
|
rpcPingTimeout: {value: 60},
|
|
@@ -92,6 +93,11 @@
|
|
|
92
93
|
$('#node-config-input-regaMetaInterval').val(15);
|
|
93
94
|
}
|
|
94
95
|
|
|
96
|
+
if (typeof this.valuesSaveInterval === 'undefined') {
|
|
97
|
+
this.valuesSaveInterval = 60;
|
|
98
|
+
$('#node-config-input-valuesSaveInterval').val(60);
|
|
99
|
+
}
|
|
100
|
+
|
|
95
101
|
const $nodeConfigInputHost = $('#node-config-input-host');
|
|
96
102
|
const $nodeConfigInputName = $('#node-config-input-name');
|
|
97
103
|
const $nodeConfigInputRpcServerHost = $('#node-config-input-rpcServerHost');
|
|
@@ -423,6 +429,11 @@
|
|
|
423
429
|
<input type="text" id="node-config-input-regaMetaInterval">
|
|
424
430
|
<small>How often channel names, rooms and functions are re-read. 0 = never (the behaviour before 4.3.0).</small>
|
|
425
431
|
</div>
|
|
432
|
+
<div class="form-row">
|
|
433
|
+
<label for="node-config-input-valuesSaveInterval"><i class="icon-tag"></i> Value cache write (min)</label>
|
|
434
|
+
<input type="text" id="node-config-input-valuesSaveInterval">
|
|
435
|
+
<small>The file with the last values (the cache for the next start) is written when Node-RED stops, and while it runs at most this often. 0 = only when stopping: fewest writes to the SD card, but after a power cut the file holds the values of the last stop.</small>
|
|
436
|
+
</div>
|
|
426
437
|
<div class="form-row">
|
|
427
438
|
<label for="node-config-input-queueTimeout"><i class="icon-tag"></i> Queue timeout (ms)</label>
|
|
428
439
|
<input type="text" id="node-config-input-queueTimeout">
|
package/nodes/ccu-connection.js
CHANGED
|
@@ -20,7 +20,14 @@ const metaProvider = require('./lib/metaprovider.js');
|
|
|
20
20
|
const {InitRetry, retryDelay, RETRY_INTERVAL} = require('./lib/initretry.js');
|
|
21
21
|
const lite = require('./lib/lite.js');
|
|
22
22
|
const {Pairings} = require('./lib/pairing.js');
|
|
23
|
-
const {
|
|
23
|
+
const {
|
|
24
|
+
writeJsonAtomic,
|
|
25
|
+
writeJsonIfChanged,
|
|
26
|
+
readText,
|
|
27
|
+
lastWritten,
|
|
28
|
+
contextStoreModule,
|
|
29
|
+
DebouncedSave,
|
|
30
|
+
} = require('./lib/cachefile.js');
|
|
24
31
|
const {SubscriptionIndex, matches: filterMatches} = require('./lib/subscriptions.js');
|
|
25
32
|
const xmlrpc = require('homematic-xmlrpc');
|
|
26
33
|
const binrpc = require('binrpc');
|
|
@@ -667,6 +674,16 @@ module.exports = function (RED) {
|
|
|
667
674
|
|
|
668
675
|
this.globalContext = this.context().global;
|
|
669
676
|
this.contextStore = config.contextStore;
|
|
677
|
+
if (contextStoreModule(RED.settings, this.contextStore) === 'localfilesystem') {
|
|
678
|
+
// the values object goes into the global context once and changes in place: a
|
|
679
|
+
// file store writes the whole global context, these values with it, whenever
|
|
680
|
+
// anything else in it is set
|
|
681
|
+
this.logger.warn(
|
|
682
|
+
'context store "' +
|
|
683
|
+
this.contextStore +
|
|
684
|
+
'" keeps the global context in a file: every change of the global context rewrites it with all values of this connection - a memory store writes nothing to disk',
|
|
685
|
+
);
|
|
686
|
+
}
|
|
670
687
|
|
|
671
688
|
if (ccu.network.listen.includes(config.rpcServerHost)) {
|
|
672
689
|
this.rpcServerHost = config.rpcServerHost;
|
|
@@ -747,6 +764,14 @@ module.exports = function (RED) {
|
|
|
747
764
|
this.regaMetaInterval =
|
|
748
765
|
config.regaMetaInterval === undefined ? 15 : Number.parseInt(config.regaMetaInterval, 10) || 0;
|
|
749
766
|
this.regaInterval = Number.parseInt(config.regaInterval, 10);
|
|
767
|
+
// the values cache file is written at stop, and while running at most every this many
|
|
768
|
+
// minutes (after the start's read of all values, a resync, a prune); 0 = only at stop.
|
|
769
|
+
// A write is the whole file - megabytes on a big system, on the SD card.
|
|
770
|
+
this.valuesSaveInterval =
|
|
771
|
+
config.valuesSaveInterval === undefined || config.valuesSaveInterval === ''
|
|
772
|
+
? 60
|
|
773
|
+
: Math.max(0, Number.parseInt(config.valuesSaveInterval, 10) || 0);
|
|
774
|
+
this.valuesSaveTimer = null;
|
|
750
775
|
this.hadTimeout = new Set();
|
|
751
776
|
|
|
752
777
|
this.enabledIfaces = [];
|
|
@@ -754,7 +779,6 @@ module.exports = function (RED) {
|
|
|
754
779
|
this.clients = {};
|
|
755
780
|
this.servers = {};
|
|
756
781
|
|
|
757
|
-
this.newParamsetDescriptionCount = 0;
|
|
758
782
|
this.paramsetQueue = [];
|
|
759
783
|
// B-36: iface/address/paramset whose description the interface refused
|
|
760
784
|
// with a fault (-2 Invalid device for an address it does not know) - not
|
|
@@ -1219,8 +1243,11 @@ module.exports = function (RED) {
|
|
|
1219
1243
|
*/
|
|
1220
1244
|
writeCache(file, what, data) {
|
|
1221
1245
|
try {
|
|
1222
|
-
|
|
1223
|
-
|
|
1246
|
+
if (writeJsonIfChanged(file, data)) {
|
|
1247
|
+
this.logger.info(what + ' saved to', file);
|
|
1248
|
+
} else {
|
|
1249
|
+
this.logger.debug(what + ' unchanged, not written');
|
|
1250
|
+
}
|
|
1224
1251
|
} catch (error) {
|
|
1225
1252
|
this.logger.error(what + ' not saved to ' + file + ': ' + error.message);
|
|
1226
1253
|
}
|
|
@@ -1240,18 +1267,44 @@ module.exports = function (RED) {
|
|
|
1240
1267
|
rooms: this.rooms,
|
|
1241
1268
|
functions: this.functions,
|
|
1242
1269
|
groups: this.groups,
|
|
1243
|
-
|
|
1244
|
-
|
|
1270
|
+
// no system variables and programs: they are not read back at start (see
|
|
1271
|
+
// loadRegadata), and their values and timestamps made the file differ at every
|
|
1272
|
+
// write, so it was rewritten although nothing it is read for had changed
|
|
1245
1273
|
});
|
|
1246
1274
|
return Promise.resolve();
|
|
1247
1275
|
}
|
|
1248
1276
|
|
|
1249
1277
|
/**
|
|
1250
|
-
*
|
|
1278
|
+
* The values cache file. At stop and after a prune (`now`: datapoints of deleted devices
|
|
1279
|
+
* must leave the file) it is written at once; otherwise at most every `valuesSaveInterval`
|
|
1280
|
+
* minutes, counted from the file's last write (the one at the previous stop too), so a
|
|
1281
|
+
* redeploy or a restart does not write it twice - the values in it are the cache for the
|
|
1282
|
+
* next start, the live ones come from the interfaces.
|
|
1283
|
+
* @param {boolean} [now] write at once
|
|
1251
1284
|
* @returns {Promise<any>}
|
|
1252
1285
|
*/
|
|
1253
|
-
saveValues() {
|
|
1254
|
-
|
|
1286
|
+
saveValues(now) {
|
|
1287
|
+
clearTimeout(this.valuesSaveTimer);
|
|
1288
|
+
this.valuesSaveTimer = null;
|
|
1289
|
+
if (now) {
|
|
1290
|
+
this.writeCache(this.valuesFile, 'values', {values: this.values});
|
|
1291
|
+
return Promise.resolve();
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
if (!this.valuesSaveInterval) {
|
|
1295
|
+
return Promise.resolve();
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
const due = lastWritten(this.valuesFile) + this.valuesSaveInterval * 60000 - Date.now();
|
|
1299
|
+
if (due <= 0) {
|
|
1300
|
+
this.writeCache(this.valuesFile, 'values', {values: this.values});
|
|
1301
|
+
} else {
|
|
1302
|
+
this.valuesSaveTimer = setTimeout(() => this.saveValues(), Math.min(due, 2147483647));
|
|
1303
|
+
if (typeof this.valuesSaveTimer.unref === 'function') {
|
|
1304
|
+
this.valuesSaveTimer.unref();
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1255
1308
|
return Promise.resolve();
|
|
1256
1309
|
}
|
|
1257
1310
|
|
|
@@ -1262,7 +1315,7 @@ module.exports = function (RED) {
|
|
|
1262
1315
|
loadMetadata() {
|
|
1263
1316
|
return new Promise((resolve) => {
|
|
1264
1317
|
try {
|
|
1265
|
-
this.metadata = JSON.parse(
|
|
1318
|
+
this.metadata = JSON.parse(readText(this.metadataFile));
|
|
1266
1319
|
this.logger.info('metadata loaded from', this.metadataFile);
|
|
1267
1320
|
resolve();
|
|
1268
1321
|
} catch {
|
|
@@ -1283,7 +1336,7 @@ module.exports = function (RED) {
|
|
|
1283
1336
|
loadRegadata() {
|
|
1284
1337
|
return new Promise((resolve) => {
|
|
1285
1338
|
try {
|
|
1286
|
-
const regadata = JSON.parse(
|
|
1339
|
+
const regadata = JSON.parse(readText(this.regadataFile));
|
|
1287
1340
|
this.logger.info('regadata loaded from', this.regadataFile);
|
|
1288
1341
|
this.channelNames = regadata.channelNames;
|
|
1289
1342
|
this.regaIdChannel = regadata.regaIdChannel;
|
|
@@ -1301,7 +1354,7 @@ module.exports = function (RED) {
|
|
|
1301
1354
|
this.functions = regadata.functions;
|
|
1302
1355
|
}
|
|
1303
1356
|
|
|
1304
|
-
/*
|
|
1357
|
+
/* system variables and programs are polled anew and no longer saved in the file
|
|
1305
1358
|
this.sysvar = regadata.sysvar;
|
|
1306
1359
|
Object.keys(this.sysvar).forEach(s => {
|
|
1307
1360
|
this.sysvar[s].fromFile = true;
|
|
@@ -1360,7 +1413,8 @@ module.exports = function (RED) {
|
|
|
1360
1413
|
* Merges the descriptions fetched since the last save into the file on disk. The file
|
|
1361
1414
|
* holds every description ever known (the vendored ones and the fetched ones, in the
|
|
1362
1415
|
* format other consumers and the editor read); the memory holds only the present types,
|
|
1363
|
-
* so the file is read, merged and written back atomically (task 28).
|
|
1416
|
+
* so the file is read, merged and written back atomically (task 28). Descriptions the
|
|
1417
|
+
* file holds as they are already are no reason to write it.
|
|
1364
1418
|
* @returns {Promise<any>}
|
|
1365
1419
|
*/
|
|
1366
1420
|
saveParamsets() {
|
|
@@ -1373,16 +1427,25 @@ module.exports = function (RED) {
|
|
|
1373
1427
|
|
|
1374
1428
|
try {
|
|
1375
1429
|
const all = this.readParamsetFile() || {};
|
|
1376
|
-
|
|
1430
|
+
const changed = names.filter(
|
|
1431
|
+
(name) => JSON.stringify(all[name]) !== JSON.stringify(this.paramsetNew[name]),
|
|
1432
|
+
);
|
|
1433
|
+
for (const name of changed) {
|
|
1377
1434
|
all[name] = this.paramsetNew[name];
|
|
1378
1435
|
}
|
|
1379
1436
|
|
|
1380
|
-
writeJsonAtomic(this.paramsetFile, all, ' ');
|
|
1381
1437
|
this.paramsetNew = {};
|
|
1438
|
+
if (changed.length === 0) {
|
|
1439
|
+
this.logger.debug('paramsets: the fetched descriptions are in the file already');
|
|
1440
|
+
resolve();
|
|
1441
|
+
return;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
writeJsonAtomic(this.paramsetFile, all, ' ');
|
|
1382
1445
|
this.logger.info(
|
|
1383
1446
|
'paramsets saved to',
|
|
1384
1447
|
this.paramsetFile,
|
|
1385
|
-
|
|
1448
|
+
changed.length,
|
|
1386
1449
|
'new,',
|
|
1387
1450
|
Object.keys(all).length,
|
|
1388
1451
|
'total',
|
|
@@ -1396,23 +1459,18 @@ module.exports = function (RED) {
|
|
|
1396
1459
|
}
|
|
1397
1460
|
|
|
1398
1461
|
/**
|
|
1399
|
-
* Parses the paramsets file - the userDir's, or the
|
|
1400
|
-
* yet
|
|
1462
|
+
* Parses the paramsets file - the userDir's, or the shipped one while the userDir has none
|
|
1463
|
+
* yet. The userDir's is written the first time a description the shipped file lacks is
|
|
1464
|
+
* saved (the whole set, in the same format); a copy of 14 MB at the first start, before,
|
|
1465
|
+
* was a write for nothing on a system whose devices the shipped file knows.
|
|
1401
1466
|
* @returns {object|null} every description the file holds, or null when there is none
|
|
1402
1467
|
*/
|
|
1403
1468
|
readParamsetFile() {
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
fs.copyFileSync(vendored, this.paramsetFile);
|
|
1408
|
-
this.logger.info('paramsets copied from', vendored, 'to', this.paramsetFile);
|
|
1409
|
-
} catch (error) {
|
|
1410
|
-
this.logger.error('error copying paramsets ' + error.message);
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1469
|
+
const file = fs.existsSync(this.paramsetFile)
|
|
1470
|
+
? this.paramsetFile
|
|
1471
|
+
: path.join(__dirname, '..', 'paramsets.json');
|
|
1414
1472
|
try {
|
|
1415
|
-
return JSON.parse(fs.readFileSync(
|
|
1473
|
+
return JSON.parse(fs.readFileSync(file));
|
|
1416
1474
|
} catch (error) {
|
|
1417
1475
|
if (error.code === 'ENOENT') {
|
|
1418
1476
|
this.logger.info('paramsets new empty');
|
|
@@ -1569,7 +1627,9 @@ module.exports = function (RED) {
|
|
|
1569
1627
|
|
|
1570
1628
|
this.metadataSave.flush();
|
|
1571
1629
|
this.saveRegadata();
|
|
1572
|
-
this.saveValues();
|
|
1630
|
+
this.saveValues(true);
|
|
1631
|
+
// descriptions fetched since the last save (a stop in the middle of the queue)
|
|
1632
|
+
this.saveParamsets();
|
|
1573
1633
|
|
|
1574
1634
|
this.rpcClose()
|
|
1575
1635
|
.then(() => {
|
|
@@ -3744,16 +3804,13 @@ module.exports = function (RED) {
|
|
|
3744
3804
|
this.methodCall(iface, 'getParamsetDescription', [address, paramset], {quiet: true})
|
|
3745
3805
|
.then((res) => {
|
|
3746
3806
|
//this.logger.trace('paramsetDescription', name);
|
|
3747
|
-
this.newParamsetDescriptionCount += 1;
|
|
3748
3807
|
this.newParamsetDescription = true;
|
|
3749
3808
|
this.paramsetDescriptions[name] = res;
|
|
3750
3809
|
this.paramsetNew[name] = res;
|
|
3751
3810
|
this.paramsetFileMissing.delete(name);
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
this.saveParamsets();
|
|
3756
|
-
}
|
|
3811
|
+
// saved once the queue is through (or at stop): every save rewrites the
|
|
3812
|
+
// whole file, 14 MB and more - one every 30 descriptions was a dozen
|
|
3813
|
+
// rewrites for a system whose firmwares the shipped file lacks
|
|
3757
3814
|
})
|
|
3758
3815
|
.catch((error) => {
|
|
3759
3816
|
// B-36: one line naming the address and the paramset; a
|
|
@@ -3960,7 +4017,7 @@ module.exports = function (RED) {
|
|
|
3960
4017
|
const pruned = this.pruneValues();
|
|
3961
4018
|
if (pruned) {
|
|
3962
4019
|
this.logger.info('values cache: dropped', pruned, 'values of devices not in the device table');
|
|
3963
|
-
this.saveValues();
|
|
4020
|
+
this.saveValues(true);
|
|
3964
4021
|
}
|
|
3965
4022
|
}
|
|
3966
4023
|
|
|
@@ -3977,7 +4034,7 @@ module.exports = function (RED) {
|
|
|
3977
4034
|
const pruned = this.pruneValues();
|
|
3978
4035
|
if (pruned) {
|
|
3979
4036
|
this.logger.info('values cache: dropped', pruned, 'values of devices not in the device table');
|
|
3980
|
-
this.saveValues();
|
|
4037
|
+
this.saveValues(true);
|
|
3981
4038
|
}
|
|
3982
4039
|
}, this.valuesPruneDelay);
|
|
3983
4040
|
}
|
package/nodes/lib/cachefile.js
CHANGED
|
@@ -8,11 +8,51 @@
|
|
|
8
8
|
* A burst of changes is written once: `DebouncedSave` collects the requests of a short window into
|
|
9
9
|
* one write - at start every interface reports its device list within the same second, and before
|
|
10
10
|
* there was one full rewrite and one log line per interface.
|
|
11
|
+
*
|
|
12
|
+
* Nothing unchanged is written: `writeJsonIfChanged` keeps a digest of what each file holds (what
|
|
13
|
+
* was written, or read at start) and skips a write whose content is the same. On a CCU the names
|
|
14
|
+
* are re-read every 15 minutes and every start re-sent the same device table - each of them was a
|
|
15
|
+
* full rewrite on the SD card before. `lastWritten` lets the values file wait for its interval
|
|
16
|
+
* across a redeploy or a restart.
|
|
11
17
|
*/
|
|
12
18
|
|
|
19
|
+
const crypto = require('crypto');
|
|
13
20
|
const fs = require('fs');
|
|
14
21
|
const path = require('path');
|
|
15
22
|
|
|
23
|
+
/** file -> {hash, ino, size, mtimeMs} of the content it holds, as far as this process knows */
|
|
24
|
+
const digests = new Map();
|
|
25
|
+
|
|
26
|
+
/** @param {string} text @returns {string} */
|
|
27
|
+
function digest(text) {
|
|
28
|
+
return crypto.createHash('sha1').update(text).digest('hex');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** remembers what `file` holds now; its size and time tell a later change from outside */
|
|
32
|
+
function remember(file, hash) {
|
|
33
|
+
try {
|
|
34
|
+
const {ino, size, mtimeMs} = fs.statSync(file);
|
|
35
|
+
digests.set(file, {hash, ino, size, mtimeMs});
|
|
36
|
+
} catch {
|
|
37
|
+
digests.delete(file);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** whether `file` still holds the content with this digest */
|
|
42
|
+
function holds(file, hash) {
|
|
43
|
+
const known = digests.get(file);
|
|
44
|
+
if (!known || known.hash !== hash) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const {ino, size, mtimeMs} = fs.statSync(file);
|
|
50
|
+
return ino === known.ino && size === known.size && mtimeMs === known.mtimeMs;
|
|
51
|
+
} catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
16
56
|
/**
|
|
17
57
|
* Writes `data` as JSON to `file` by way of a temporary file and a rename; an existing file's mode
|
|
18
58
|
* is kept.
|
|
@@ -21,12 +61,21 @@ const path = require('path');
|
|
|
21
61
|
* @param {string|number} [indent] JSON.stringify's third argument
|
|
22
62
|
*/
|
|
23
63
|
function writeJsonAtomic(file, data, indent) {
|
|
64
|
+
writeTextAtomic(file, JSON.stringify(data, null, indent));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Writes `text` to `file` by way of a temporary file and a rename; an existing file's mode is kept.
|
|
69
|
+
* @param {string} file
|
|
70
|
+
* @param {string} text
|
|
71
|
+
*/
|
|
72
|
+
function writeTextAtomic(file, text) {
|
|
24
73
|
const temporary = path.join(
|
|
25
74
|
path.dirname(file),
|
|
26
75
|
'.' + path.basename(file) + '.' + process.pid + '.' + Date.now().toString(36) + '.tmp',
|
|
27
76
|
);
|
|
28
77
|
try {
|
|
29
|
-
fs.writeFileSync(temporary,
|
|
78
|
+
fs.writeFileSync(temporary, text);
|
|
30
79
|
// the rename replaces the inode: an existing file's mode is kept (0600 on a system that
|
|
31
80
|
// made it so), a new one gets the umask's
|
|
32
81
|
let mode;
|
|
@@ -39,7 +88,9 @@ function writeJsonAtomic(file, data, indent) {
|
|
|
39
88
|
}
|
|
40
89
|
|
|
41
90
|
fs.renameSync(temporary, file);
|
|
91
|
+
remember(file, digest(text));
|
|
42
92
|
} catch (error) {
|
|
93
|
+
digests.delete(file);
|
|
43
94
|
try {
|
|
44
95
|
fs.unlinkSync(temporary);
|
|
45
96
|
} catch {}
|
|
@@ -48,6 +99,34 @@ function writeJsonAtomic(file, data, indent) {
|
|
|
48
99
|
}
|
|
49
100
|
}
|
|
50
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Writes `data` as JSON to `file` atomically - unless the file holds exactly that already.
|
|
104
|
+
* @param {string} file
|
|
105
|
+
* @param {*} data
|
|
106
|
+
* @param {string|number} [indent] JSON.stringify's third argument
|
|
107
|
+
* @returns {boolean} whether the file was written
|
|
108
|
+
*/
|
|
109
|
+
function writeJsonIfChanged(file, data, indent) {
|
|
110
|
+
const text = JSON.stringify(data, null, indent);
|
|
111
|
+
if (holds(file, digest(text))) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
writeTextAtomic(file, text);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Reads a file and remembers its digest, so the same content is not written back.
|
|
121
|
+
* @param {string} file
|
|
122
|
+
* @returns {string} the file's text
|
|
123
|
+
*/
|
|
124
|
+
function readText(file) {
|
|
125
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
126
|
+
remember(file, digest(text));
|
|
127
|
+
return text;
|
|
128
|
+
}
|
|
129
|
+
|
|
51
130
|
class DebouncedSave {
|
|
52
131
|
/**
|
|
53
132
|
* @param {Function} write does the write; called once per burst
|
|
@@ -102,4 +181,42 @@ class DebouncedSave {
|
|
|
102
181
|
}
|
|
103
182
|
}
|
|
104
183
|
|
|
105
|
-
|
|
184
|
+
/**
|
|
185
|
+
* When `file` was last written, ms since the epoch (its modification time - a write of this
|
|
186
|
+
* process or of the one before a restart), 0 when there is none.
|
|
187
|
+
* @param {string} file
|
|
188
|
+
* @returns {number}
|
|
189
|
+
*/
|
|
190
|
+
function lastWritten(file) {
|
|
191
|
+
try {
|
|
192
|
+
return fs.statSync(file).mtimeMs;
|
|
193
|
+
} catch {
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* The module of one of Node-RED's context stores - a file store ('localfilesystem') writes the
|
|
200
|
+
* connection's values to disk with every change of the global context ('memory', 'localfilesystem', ...), undefined
|
|
201
|
+
* when there is no such store. `default` may name another store.
|
|
202
|
+
* @param {object} settings RED.settings
|
|
203
|
+
* @param {string} name
|
|
204
|
+
* @returns {string|undefined}
|
|
205
|
+
*/
|
|
206
|
+
function contextStoreModule(settings, name) {
|
|
207
|
+
let stores;
|
|
208
|
+
try {
|
|
209
|
+
stores = settings.contextStorage;
|
|
210
|
+
} catch {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (!stores || !name) {
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const store = typeof stores[name] === 'string' ? stores[stores[name]] : stores[name];
|
|
219
|
+
return store && typeof store.module === 'string' ? store.module : undefined;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
module.exports = {writeJsonAtomic, writeJsonIfChanged, readText, lastWritten, contextStoreModule, DebouncedSave};
|
|
@@ -48,10 +48,16 @@
|
|
|
48
48
|
<li><b>ReGaHSS Poll-Interval</b>:
|
|
49
49
|
Das Zeitintervall in Sekunden in dem Systemvariablen von der CCU abgefragt werden.</li>
|
|
50
50
|
</ul>
|
|
51
|
+
<ul>
|
|
52
|
+
<li><b>Names/rooms refresh (min)</b>: Wie oft Kanalnamen, Räume und Gewerke neu gelesen werden; 0 nie. Die Datei mit den Namen wird nur geschrieben, wenn sich etwas geändert hat.</li>
|
|
53
|
+
</ul>
|
|
54
|
+
<ul>
|
|
55
|
+
<li><b>Value cache write (min)</b>: Der letzte Wert jedes Datenpunkts liegt in einer Datei im Node-RED-Verzeichnis, damit Nodes mit <i>cache</i> gleich nach dem nächsten Start einen Wert haben. Die Datei wird geschrieben, wenn Node-RED beendet oder die Verbindung neu deployt wird, und während es läuft höchstens so oft (nach dem Lesen aller Werte beim Start, nach einem Resync); Voreinstellung 60. 0 schreibt sie nur beim Beenden - die wenigsten Schreibzugriffe auf die SD-Karte, aber nach einem Stromausfall oder Absturz enthält die Datei die Werte vom letzten Beenden. So oder so kommen die aktuellen Werte nach einem Start wieder von der CCU. Auf einem großen System hat die Datei mehrere Megabyte, und jeder Schreibvorgang schreibt die ganze Datei.</li>
|
|
56
|
+
</ul>
|
|
51
57
|
<ul>
|
|
52
58
|
<li><b>Context-Store</b>: Hier wird der Node-RED Context-Store festgelegt in dem RedMatic die Zustände aller Geräte/Variablen vorhält.
|
|
53
59
|
|
|
54
|
-
Weiteres unter <a target="_blank" href="https://nodered.org/docs/user-guide/context">Working</a> with context in der Node-RED Dokumentation.</li>
|
|
60
|
+
Weiteres unter <a target="_blank" href="https://nodered.org/docs/user-guide/context">Working</a> with context in der Node-RED Dokumentation. Am besten ein Speicher-Store (memory): ein Datei-Store (<code>localfilesystem</code>) schreibt den ganzen globalen Kontext - mit allen Werten dieser Verbindung - jedes Mal neu, wenn irgendetwas darin gesetzt wird, und nutzt so die SD-Karte ab; das Log warnt dann.</li>
|
|
55
61
|
</ul>
|
|
56
62
|
<ul>
|
|
57
63
|
<li><b>openccu-lite Token</b>: Nur für <a href="https://github.com/hobbyquaker/openccu-lite" target="_blank">openccu-lite</a>,
|
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
</li>
|
|
24
24
|
<li><b>RPC ping</b> and <b>RPC ping timeout (s)</b>: How often the connection to the interface processes is checked with a ping, and after how many seconds without an answer it subscribes again. Off means no pings and no timeout-triggered re-init for this connection.</li>
|
|
25
25
|
<li><b>Rega poll</b>: Changes of system variables are not pushed by the CCU. With polling on, the variables and their values are read every <i>Rega poll interval</i> seconds.</li>
|
|
26
|
-
<li><b>Names/rooms refresh (min)</b>: How often channel names, rooms and functions are re-read; 0 never.</li>
|
|
26
|
+
<li><b>Names/rooms refresh (min)</b>: How often channel names, rooms and functions are re-read; 0 never. The names file is only written when something changed.</li>
|
|
27
|
+
<li><b>Value cache write (min)</b>: The last value of every datapoint is kept in a file in Node-RED's directory, so nodes with <i>cache</i> have a value right after the next start. The file is written when Node-RED stops or the connection is redeployed, and while it runs at most this often (after reading all values at the start, after a resync); 60 by default. 0 writes it only when stopping - the fewest writes to the SD card, but after a power cut or a crash the file holds the values of the last stop. Either way the live values come from the CCU again after a start. On a big system the file has several megabytes, and each write is the whole file.</li>
|
|
27
28
|
<li><b>Queue timeout (ms)</b>, <b>Queue pause (ms)</b>: The write queue's timeout per write and the pause between two writes.</li>
|
|
28
|
-
<li><b>Context Store</b>: The Node-RED context store the states of all devices and variables are kept in. See <a target="_blank" href="https://nodered.org/docs/user-guide/context">Working with context</a> in the Node-RED documentation.</li>
|
|
29
|
+
<li><b>Context Store</b>: The Node-RED context store the states of all devices and variables are kept in. See <a target="_blank" href="https://nodered.org/docs/user-guide/context">Working with context</a> in the Node-RED documentation. Use a memory store: a file store (<code>localfilesystem</code>) rewrites the whole global context - all values of this connection with it - every time anything in the global context is set, which wears an SD card; the log warns about it.</li>
|
|
29
30
|
<li><b>openccu-lite token</b>: Only for <a href="https://github.com/hobbyquaker/openccu-lite" target="_blank">openccu-lite</a>, a CCU firmware without ReGaHSS. Names, rooms and functions come from the system's metadata API there, which needs a token made under <i>Users</i> on the system. When Node-RED runs on the system itself (RedMatic) the field stays empty: the local token is read automatically. The token is kept, like the password, in Node-RED's credentials (encrypted in <code>flows_cred.json</code>, never in the flow, never in an export). A CCU, RaspberryMatic or OpenCCU ignores the field. openccu-lite has no system variables, programs or HM-Script; those nodes stay in the flow and report an error per message.</li>
|
|
30
31
|
<li><b>openccu-lite port</b>: Only needed when the system's web server is not on port 80 (443 with TLS).</li>
|
|
31
32
|
<li><b>openccu-lite interfaces</b>: How the interface processes are reached on an openccu-lite system. <i>auto</i> (the default) goes through the system's <b>lite-rpc</b> there - the requests over its web port, the events from a stream this node opens, one subscriber at the processes for every program on the system, the events replayed after a break, no callback server and no <code>init</code> of its own - and the CCU way on a CCU, RaspberryMatic or OpenCCU. The credential is the openccu-lite token above, or on the system itself RedMatic's own token, which the system mints for it; without one, or with a token that lacks <code>rpc:read</code> (one made for the names alone), the direct connection is used and the log says so; lite-rpc needs <code>rpc:read</code> for events and <code>rpc:operate</code> for commands. <i>CCU</i> keeps the direct connection with callbacks on openccu-lite as well (CUxD always goes that way; lite-rpc does not carry it). A flow from before 4.7.0 is moved to lite-rpc once at its first start on openccu-lite - the log says so - and a choice made here is never changed by a later version. The sysvar, program, script and poll nodes stay unavailable on openccu-lite either way.</li>
|