node-red-contrib-ccu 4.12.0 → 4.14.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.
@@ -2,7 +2,8 @@ const path = require('path');
2
2
 
3
3
  const statusHelper = require(path.join(__dirname, '/lib/status.js'));
4
4
  const {topicReplace} = require('./lib/topic.js');
5
- const {discoveryMessages, removalMessage} = require('./lib/hadiscovery.js');
5
+ const {discoveryMessages, removalMessage, usesChildDevices} = require('./lib/hadiscovery.js');
6
+ const {readText, writeJsonIfChanged} = require('./lib/cachefile.js');
6
7
 
7
8
  const pkg = require(path.join(__dirname, '..', 'package.json'));
8
9
 
@@ -38,6 +39,12 @@ module.exports = function (RED) {
38
39
  this.prefix = String(config.prefix || 'homeassistant').replace(/\/+$/, '');
39
40
  this.generic = config.generic !== false;
40
41
  this.area = config.area !== false;
42
+ // task 33: Homematic channels as Home Assistant devices - `off` (one device per
43
+ // Homematic device, as before), `children` (child devices) or `devices` (devices of
44
+ // their own); a device's `split` and a channel's `device` override it
45
+ this.channelDevices = ['children', 'devices'].includes(config.channelDevices)
46
+ ? config.channelDevices
47
+ : 'off';
41
48
  this.devices = config.devices || {};
42
49
  this.selected = Object.keys(this.devices).filter(
43
50
  (a) => this.devices[a] && this.devices[a].enabled === true,
@@ -47,6 +54,19 @@ module.exports = function (RED) {
47
54
  );
48
55
  this.selectedSet = new Set(this.selected);
49
56
 
57
+ // what the last run published, per device and topic (component key → platform): a
58
+ // component missing now is removed from Home Assistant with a stub, a topic missing
59
+ // now is cleared - kept across restarts beside the connection's cache files
60
+ const userDir = RED.settings && RED.settings.userDir;
61
+ this.publishedFile = userDir
62
+ ? path.join(userDir, 'ccu_homeassistant_' + String(this.id).replace(/[^\w.-]/g, '_') + '.json')
63
+ : null;
64
+ this.published = this.loadPublished();
65
+
66
+ if (usesChildDevices(this.channelDevices, this.devices)) {
67
+ this.log('Homematic channels as child devices need Home Assistant 2026.11 or newer');
68
+ }
69
+
50
70
  this.ccu.register(this);
51
71
 
52
72
  /** datapointName → {iface, channel, datapoint, topic} of the published availability topics */
@@ -110,6 +130,32 @@ module.exports = function (RED) {
110
130
  this.status(status);
111
131
  }
112
132
 
133
+ /** the record of the last run, or an empty one */
134
+ loadPublished() {
135
+ if (!this.publishedFile) {
136
+ return {};
137
+ }
138
+
139
+ try {
140
+ const data = JSON.parse(readText(this.publishedFile));
141
+ return data && typeof data.devices === 'object' && data.devices ? data.devices : {};
142
+ } catch {
143
+ return {};
144
+ }
145
+ }
146
+
147
+ savePublished() {
148
+ if (!this.publishedFile) {
149
+ return;
150
+ }
151
+
152
+ try {
153
+ writeJsonIfChanged(this.publishedFile, {devices: this.published});
154
+ } catch (error) {
155
+ this.warn('could not write ' + this.publishedFile + ': ' + error.message);
156
+ }
157
+ }
158
+
113
159
  /** the referenced ccu-mqtt node, or null with a red status */
114
160
  mqtt() {
115
161
  const node = this.mqttNodeId && RED.nodes.getNode(this.mqttNodeId);
@@ -231,9 +277,32 @@ module.exports = function (RED) {
231
277
  area: this.area,
232
278
  devices: ccu.metadata.devices,
233
279
  selected: this.selected,
280
+ channelDevices: this.channelDevices,
281
+ overrides: this.devices,
282
+ previous: this.published,
234
283
  description: (iface, address) => {
235
284
  const device = ccu.metadata.devices[iface] && ccu.metadata.devices[iface][address];
236
- return device && ccu.getParamsetDescription(iface, device, 'VALUES');
285
+ if (!device) {
286
+ return undefined;
287
+ }
288
+
289
+ // undefined while the description is not there yet (the call queues its fetch):
290
+ // the components of such a channel are neither published nor removed. A
291
+ // description that will never come (no VALUES paramset, a refused fetch) is
292
+ // an empty one, as in ready()
293
+ const key = ccu.paramsetName(iface, device, 'VALUES');
294
+ const known = ccu.paramsetDescriptions[key] !== undefined;
295
+ if (
296
+ !known &&
297
+ (!key ||
298
+ !(device.PARAMSETS || []).includes('VALUES') ||
299
+ (ccu.paramsetFailed && ccu.paramsetFailed.has(iface + '/' + device.ADDRESS + '/VALUES')))
300
+ ) {
301
+ return {};
302
+ }
303
+
304
+ const description = ccu.getParamsetDescription(iface, device, 'VALUES');
305
+ return known ? description : undefined;
237
306
  },
238
307
  channelName: (address) => ccu.channelNames[address],
239
308
  rooms: (address) => ccu.channelRooms && ccu.channelRooms[address],
@@ -243,10 +312,22 @@ module.exports = function (RED) {
243
312
  topicReplace(mqtt.topicInputSetValue, this.topicMessage(iface, address, dp)),
244
313
  };
245
314
 
246
- const {messages, availability, missing, empty} = discoveryMessages(ctx);
315
+ const {messages, clear, published, availability, missing, empty} = discoveryMessages(ctx);
247
316
 
317
+ // removals first: an entity that moves to another topic must be gone from the old one
318
+ // before Home Assistant reads the new one
248
319
  for (const address of this.removed) {
249
- const {topic, payload} = removalMessage(this.prefix, address);
320
+ const topics = new Set([removalMessage(this.prefix, address).topic]);
321
+ for (const topic of Object.keys(this.published[address] || {})) {
322
+ topics.add(topic);
323
+ }
324
+
325
+ for (const topic of topics) {
326
+ this.send({topic, payload: '', retain: true});
327
+ }
328
+ }
329
+
330
+ for (const {topic, payload} of clear) {
250
331
  this.send({topic, payload, retain: true});
251
332
  }
252
333
 
@@ -254,6 +335,17 @@ module.exports = function (RED) {
254
335
  this.send({topic, payload, retain: true});
255
336
  }
256
337
 
338
+ // devices neither ticked nor unticked keep their record
339
+ const record = {};
340
+ for (const [address, topics] of Object.entries(this.published)) {
341
+ if (!this.selectedSet.has(address) && !this.removed.includes(address)) {
342
+ record[address] = topics;
343
+ }
344
+ }
345
+
346
+ this.published = {...record, ...published};
347
+ this.savePublished();
348
+
257
349
  this.publishAvailability(availability);
258
350
 
259
351
  if (missing.length > 0) {
package/nodes/ccu-poll.js CHANGED
@@ -18,8 +18,9 @@ module.exports = function (RED) {
18
18
 
19
19
  this.on('input', (message, send, done) => {
20
20
  if (this.ccu.metaMode) {
21
- // openccu-lite has no ReGaHSS - nothing to poll (B-17)
22
- done(this.ccu.regaMissingError('system variables and programs'));
21
+ // openccu-lite has no ReGaHSS (B-17); the Logic addon's variables and programs
22
+ // arrive as events, there is nothing to poll (task 32)
23
+ done(this.ccu.logicUnavailable('system variables and programs') || undefined);
23
24
  return;
24
25
  }
25
26
 
@@ -30,7 +31,7 @@ module.exports = function (RED) {
30
31
  }
31
32
 
32
33
  setStatus(data) {
33
- statusHelper(this, data);
34
+ statusHelper.sysvar(this, data);
34
35
  }
35
36
  }
36
37
 
@@ -71,7 +71,7 @@ module.exports = function (RED) {
71
71
  }
72
72
 
73
73
  setStatus(data) {
74
- statusHelper(this, data);
74
+ statusHelper.sysvar(this, data);
75
75
  }
76
76
  }
77
77
 
@@ -137,7 +137,7 @@ module.exports = function (RED) {
137
137
  }
138
138
 
139
139
  setStatus(data) {
140
- statusHelper(this, data);
140
+ statusHelper.sysvar(this, data);
141
141
  }
142
142
  }
143
143