node-red-contrib-ccu 4.14.0 → 4.15.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 +28 -0
- package/nodes/ccu-connection.js +91 -9
- package/nodes/lib/message.js +106 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,34 @@ 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.15.0 (2026-11-27)
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **A much smaller values cache file.** `ccu_values_<host>.json` in the
|
|
13
|
+
Node-RED user directory kept the whole message of every datapoint (names,
|
|
14
|
+
types, rooms, functions, the description's limits), about 730 bytes each -
|
|
15
|
+
2.5 MB for 3500 datapoints on a large system. It now keeps only the value,
|
|
16
|
+
its timestamps and the previous value; the message around it is built from
|
|
17
|
+
the device, name and description caches at start, the same message as
|
|
18
|
+
before. The file shrinks to about a fifth, and a cached value carries the
|
|
19
|
+
current names, rooms and functions instead of those of its last event, so
|
|
20
|
+
a renamed channel no longer shows its old name in cached values. The file of
|
|
21
|
+
earlier versions is read, the next write is the short one. After going back
|
|
22
|
+
to an earlier version, the cached values of its first start carry no names
|
|
23
|
+
until it has read the values from the system again.
|
|
24
|
+
|
|
25
|
+
## 4.14.1 (2026-11-25)
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- **openccu-lite: a Logic system variable without its texts, list or unit
|
|
30
|
+
after the start.** At connect the values come before the descriptions of
|
|
31
|
+
the variables, so a variable's message and the editor's list had an empty
|
|
32
|
+
`enum`, no `valueEnum` and no `unit` until the variable was written the
|
|
33
|
+
next time. The variable now takes them as soon as its description is
|
|
34
|
+
there. Writing was not affected.
|
|
35
|
+
|
|
8
36
|
## 4.14.0 (2026-11-25)
|
|
9
37
|
|
|
10
38
|
### Added
|
package/nodes/ccu-connection.js
CHANGED
|
@@ -8,7 +8,7 @@ const base62 = require('./lib/base62.js').toBase62;
|
|
|
8
8
|
const {castValue, castSysvar} = require('./lib/cast.js');
|
|
9
9
|
const {combinedParameterValue} = require('./lib/combined.js');
|
|
10
10
|
const {isPartyWrite, mergePartyValues, PARTY_DATAPOINTS} = require('./lib/party.js');
|
|
11
|
-
const {createMessage} = require('./lib/message.js');
|
|
11
|
+
const {createMessage, savedValue, restoreMessage} = require('./lib/message.js');
|
|
12
12
|
const {topicReplace} = require('./lib/topic.js');
|
|
13
13
|
const {isLocalCcu} = require('./lib/localccu.js');
|
|
14
14
|
const {resolveTransport} = require('./lib/transport.js');
|
|
@@ -1302,6 +1302,19 @@ module.exports = function (RED) {
|
|
|
1302
1302
|
return Promise.resolve();
|
|
1303
1303
|
}
|
|
1304
1304
|
|
|
1305
|
+
/**
|
|
1306
|
+
* task 36: the values cache file now - per datapoint only what the restore needs
|
|
1307
|
+
* (savedValue), the rest is the metadata's
|
|
1308
|
+
*/
|
|
1309
|
+
writeValues() {
|
|
1310
|
+
const values = {};
|
|
1311
|
+
for (const datapointName of Object.keys(this.values)) {
|
|
1312
|
+
values[datapointName] = savedValue(this.values[datapointName]);
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
this.writeCache(this.valuesFile, 'values', {format: 2, values});
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1305
1318
|
/**
|
|
1306
1319
|
* The values cache file. At stop and after a prune (`now`: datapoints of deleted devices
|
|
1307
1320
|
* must leave the file) it is written at once; otherwise at most every `valuesSaveInterval`
|
|
@@ -1315,7 +1328,7 @@ module.exports = function (RED) {
|
|
|
1315
1328
|
clearTimeout(this.valuesSaveTimer);
|
|
1316
1329
|
this.valuesSaveTimer = null;
|
|
1317
1330
|
if (now) {
|
|
1318
|
-
this.
|
|
1331
|
+
this.writeValues();
|
|
1319
1332
|
return Promise.resolve();
|
|
1320
1333
|
}
|
|
1321
1334
|
|
|
@@ -1325,7 +1338,7 @@ module.exports = function (RED) {
|
|
|
1325
1338
|
|
|
1326
1339
|
const due = lastWritten(this.valuesFile) + this.valuesSaveInterval * 60000 - Date.now();
|
|
1327
1340
|
if (due <= 0) {
|
|
1328
|
-
this.
|
|
1341
|
+
this.writeValues();
|
|
1329
1342
|
} else {
|
|
1330
1343
|
this.valuesSaveTimer = setTimeout(() => this.saveValues(), Math.min(due, 2147483647));
|
|
1331
1344
|
if (typeof this.valuesSaveTimer.unref === 'function') {
|
|
@@ -1415,13 +1428,15 @@ module.exports = function (RED) {
|
|
|
1415
1428
|
const {values} = JSON.parse(fs.readFileSync(this.valuesFile));
|
|
1416
1429
|
this.logger.info('values loaded from', this.valuesFile);
|
|
1417
1430
|
|
|
1431
|
+
// task 36: the file keeps a value and its timestamps; the message around it
|
|
1432
|
+
// (names, types, rooms, functions) is built from the device table, the names
|
|
1433
|
+
// and the descriptions loaded before. An entry of the old format (the whole
|
|
1434
|
+
// message) is read too, the next write is the short one.
|
|
1418
1435
|
for (const datapointName in values) {
|
|
1419
|
-
this
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
uncertain: true,
|
|
1424
|
-
};
|
|
1436
|
+
const message = restoreMessage(this, datapointName, values[datapointName]);
|
|
1437
|
+
if (message) {
|
|
1438
|
+
this.values[datapointName] = message;
|
|
1439
|
+
}
|
|
1425
1440
|
}
|
|
1426
1441
|
|
|
1427
1442
|
resolve();
|
|
@@ -1572,6 +1587,10 @@ module.exports = function (RED) {
|
|
|
1572
1587
|
all ? Object.keys(all).length : 0,
|
|
1573
1588
|
'(' + Object.keys(this.paramsetDescriptions).length + ' in memory for the device types present)',
|
|
1574
1589
|
);
|
|
1590
|
+
if (loaded > 0) {
|
|
1591
|
+
this.refreshLogicShapesSoon();
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1575
1594
|
return loaded;
|
|
1576
1595
|
}
|
|
1577
1596
|
|
|
@@ -3318,6 +3337,47 @@ module.exports = function (RED) {
|
|
|
3318
3337
|
return paramset ? paramset[datapoint] : undefined;
|
|
3319
3338
|
}
|
|
3320
3339
|
|
|
3340
|
+
/**
|
|
3341
|
+
* task 32: a variable's shape (type, list, unit, limits) comes from its VALUE description,
|
|
3342
|
+
* which may be fetched after the value came in (the start's picture): once descriptions
|
|
3343
|
+
* arrive, the entries that were made without one take it. Once per burst.
|
|
3344
|
+
*/
|
|
3345
|
+
refreshLogicShapesSoon() {
|
|
3346
|
+
if (this.logicShapeTimer || !this.logicIface) {
|
|
3347
|
+
return;
|
|
3348
|
+
}
|
|
3349
|
+
|
|
3350
|
+
this.logicShapeTimer = setImmediate(() => {
|
|
3351
|
+
this.logicShapeTimer = null;
|
|
3352
|
+
Object.keys(this.logicObjects).forEach((channel) => {
|
|
3353
|
+
const entry = this.logicObjects[channel];
|
|
3354
|
+
if (entry.type !== 'SYSVAR') {
|
|
3355
|
+
return;
|
|
3356
|
+
}
|
|
3357
|
+
|
|
3358
|
+
const description = this.logicDescription(channel, 'VALUE');
|
|
3359
|
+
if (!description) {
|
|
3360
|
+
return;
|
|
3361
|
+
}
|
|
3362
|
+
|
|
3363
|
+
const shape = logic.variableShape(description, entry.value);
|
|
3364
|
+
Object.assign(entry, {
|
|
3365
|
+
valueType: shape.valueType,
|
|
3366
|
+
enum: shape.enum,
|
|
3367
|
+
unit: shape.unit,
|
|
3368
|
+
valueEnum: shape.enum[Number(entry.value)],
|
|
3369
|
+
});
|
|
3370
|
+
if (shape.min !== undefined) {
|
|
3371
|
+
entry.min = shape.min;
|
|
3372
|
+
}
|
|
3373
|
+
|
|
3374
|
+
if (shape.max !== undefined) {
|
|
3375
|
+
entry.max = shape.max;
|
|
3376
|
+
}
|
|
3377
|
+
});
|
|
3378
|
+
});
|
|
3379
|
+
}
|
|
3380
|
+
|
|
3321
3381
|
/**
|
|
3322
3382
|
* task 32: a datapoint of Logic's interface - a variable's VALUE, a program's ACTIVE or
|
|
3323
3383
|
* LAST_RUN - into the tables the sysvar and program nodes read (this.sysvar, this.program).
|
|
@@ -4413,6 +4473,10 @@ module.exports = function (RED) {
|
|
|
4413
4473
|
this.newParamsetDescription = true;
|
|
4414
4474
|
this.paramsetDescriptions[name] = res;
|
|
4415
4475
|
this.paramsetNew[name] = res;
|
|
4476
|
+
if (iface === this.logicIface) {
|
|
4477
|
+
this.refreshLogicShapesSoon();
|
|
4478
|
+
}
|
|
4479
|
+
|
|
4416
4480
|
this.paramsetFileMissing.delete(name);
|
|
4417
4481
|
// saved once the queue is through (or at stop): every save rewrites the
|
|
4418
4482
|
// whole file, 14 MB and more - one every 30 descriptions was a dozen
|
|
@@ -4463,6 +4527,24 @@ module.exports = function (RED) {
|
|
|
4463
4527
|
}
|
|
4464
4528
|
}
|
|
4465
4529
|
|
|
4530
|
+
/**
|
|
4531
|
+
* getParamsetDescription without asking the interface for a missing one (task 36: the
|
|
4532
|
+
* values cache's messages are built at start, before any interface is connected)
|
|
4533
|
+
* @param iface
|
|
4534
|
+
* @param device
|
|
4535
|
+
* @param paramset
|
|
4536
|
+
* @param parameter
|
|
4537
|
+
* @returns {*}
|
|
4538
|
+
*/
|
|
4539
|
+
peekParamsetDescription(iface, device, paramset, parameter) {
|
|
4540
|
+
const descriptions = this.paramsetDescriptions[this.paramsetName(iface, device, paramset)];
|
|
4541
|
+
if (!descriptions) {
|
|
4542
|
+
return {};
|
|
4543
|
+
}
|
|
4544
|
+
|
|
4545
|
+
return parameter ? descriptions[parameter] : descriptions;
|
|
4546
|
+
}
|
|
4547
|
+
|
|
4466
4548
|
/**
|
|
4467
4549
|
*
|
|
4468
4550
|
* @param iface
|
package/nodes/lib/message.js
CHANGED
|
@@ -106,4 +106,109 @@ function createMessage(ccu, iface, channel, datapoint, payload, additions) {
|
|
|
106
106
|
return message;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
/*
|
|
110
|
+
* The values cache file (task 36). An entry used to be the whole message (names, types, rooms,
|
|
111
|
+
* functions, the description's MIN/MAX/ENUM ...), about 730 bytes; all of that comes from the
|
|
112
|
+
* device table, the names and the paramset descriptions, which are loaded before the values. The
|
|
113
|
+
* file keeps only the message's own fields that nothing else knows - under their message names,
|
|
114
|
+
* so an entry is a subset of the message - and the load builds the message around them again.
|
|
115
|
+
*/
|
|
116
|
+
const SAVED_FIELDS = ['value', 'ts', 'lc', 'valuePrevious', 'tsPrevious', 'valueStable', 'working', 'direction'];
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The part of a cached message the values file keeps. `valueStable` only where it differs from
|
|
120
|
+
* the value (while a datapoint is working), `working`/`direction` only where the message has them.
|
|
121
|
+
* @param {object} message
|
|
122
|
+
* @returns {object} the entry
|
|
123
|
+
*/
|
|
124
|
+
function savedValue(message) {
|
|
125
|
+
const entry = {};
|
|
126
|
+
for (const key of SAVED_FIELDS) {
|
|
127
|
+
if (message[key] === undefined) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (key === 'valueStable' && message.valueStable === message.value) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
entry[key] = message[key];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return entry;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Whether an entry of the values file is a whole message (the format up to 4.14).
|
|
143
|
+
* @param {object} entry
|
|
144
|
+
* @returns {boolean}
|
|
145
|
+
*/
|
|
146
|
+
function isFullMessage(entry) {
|
|
147
|
+
return Boolean(entry) && (entry.datapointName !== undefined || entry.iface !== undefined);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Builds the cached message of a values file entry again: the metadata as createMessage puts it
|
|
152
|
+
* into a live event's message, the saved fields, and what a cached value is at start (cache, no
|
|
153
|
+
* change, uncertain). An entry in the old format (the whole message) is taken through its saved
|
|
154
|
+
* fields the same way; only when the device table does not know its channel (an interface whose
|
|
155
|
+
* table was not read yet) is the old entry kept as it is, as the old load did.
|
|
156
|
+
* @param {object} ccu connection-shaped (see createMessage); `peekParamsetDescription` (the same
|
|
157
|
+
* arguments as getParamsetDescription), if it has one, is asked instead: no fetch queued
|
|
158
|
+
* @param {string} datapointName iface.channel.datapoint
|
|
159
|
+
* @param {object} entry the file's entry
|
|
160
|
+
* @returns {object|null} the message, null for a key that is not a datapoint name
|
|
161
|
+
*/
|
|
162
|
+
function restoreMessage(ccu, datapointName, entry) {
|
|
163
|
+
const first = datapointName.indexOf('.');
|
|
164
|
+
const last = datapointName.lastIndexOf('.');
|
|
165
|
+
if (!entry || typeof entry !== 'object' || first < 1 || last <= first + 1 || last === datapointName.length - 1) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const iface = datapointName.slice(0, first);
|
|
170
|
+
const channel = datapointName.slice(first + 1, last);
|
|
171
|
+
const datapoint = datapointName.slice(last + 1);
|
|
172
|
+
const full = isFullMessage(entry);
|
|
173
|
+
const metadata = ccu.metadata && ccu.metadata.devices ? ccu.metadata : {devices: {}};
|
|
174
|
+
const devices = metadata.devices[iface];
|
|
175
|
+
if (full && !(devices && devices[channel])) {
|
|
176
|
+
return {...entry, cache: true, change: false, uncertain: true};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const saved = full ? savedValue(entry) : entry;
|
|
180
|
+
const additions = {};
|
|
181
|
+
for (const key of SAVED_FIELDS) {
|
|
182
|
+
if (saved[key] !== undefined) {
|
|
183
|
+
additions[key] = saved[key];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (additions.valueStable === undefined) {
|
|
188
|
+
additions.valueStable = saved.value;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// a view of the connection: createMessage reads the previous value from `values` and adds
|
|
192
|
+
// an empty entry there, and asks for the description - neither may touch the connection
|
|
193
|
+
const view = {
|
|
194
|
+
host: ccu.host,
|
|
195
|
+
metadata,
|
|
196
|
+
channelNames: ccu.channelNames || {},
|
|
197
|
+
channelRooms: ccu.channelRooms || {},
|
|
198
|
+
channelFunctions: ccu.channelFunctions || {},
|
|
199
|
+
values: {},
|
|
200
|
+
logger: {trace() {}},
|
|
201
|
+
getParamsetDescription: (i, device, paramset, parameter) =>
|
|
202
|
+
(ccu.peekParamsetDescription || ccu.getParamsetDescription).call(ccu, i, device, paramset, parameter),
|
|
203
|
+
};
|
|
204
|
+
const message = createMessage(view, iface, channel, datapoint, saved.value, {
|
|
205
|
+
...additions,
|
|
206
|
+
cache: true,
|
|
207
|
+
change: false,
|
|
208
|
+
uncertain: true,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
return message;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
module.exports = {createMessage, savedValue, restoreMessage, isFullMessage, SAVED_FIELDS};
|