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.
- package/CHANGELOG.md +50 -0
- package/README.md +38 -2
- package/nodes/ccu-connection.js +626 -48
- package/nodes/ccu-homeassistant.html +482 -48
- package/nodes/ccu-homeassistant.js +96 -4
- package/nodes/ccu-poll.js +4 -3
- package/nodes/ccu-program.js +1 -1
- package/nodes/ccu-sysvar.js +1 -1
- package/nodes/lib/hadiscovery.js +397 -16
- package/nodes/lib/lite.js +15 -2
- package/nodes/lib/logic.js +178 -0
- package/nodes/lib/status.js +31 -0
- package/nodes/locales/de/ccu-homeassistant.html +31 -3
- package/nodes/locales/de/ccu-poll.html +2 -0
- package/nodes/locales/de/ccu-program.html +5 -0
- package/nodes/locales/de/ccu-sysvar.html +7 -0
- package/nodes/locales/en-US/ccu-homeassistant.html +30 -3
- package/nodes/locales/en-US/ccu-poll.html +2 -0
- package/nodes/locales/en-US/ccu-program.html +5 -0
- package/nodes/locales/en-US/ccu-sysvar.html +7 -0
- package/package.json +1 -1
|
@@ -1,4 +1,179 @@
|
|
|
1
1
|
<script type="text/javascript">
|
|
2
|
+
/* task 33: the per-device and per-channel Home Assistant settings of the editor. Pure functions
|
|
3
|
+
on the stored `devices` entries, kept apart from the DOM so the unit tests can run them:
|
|
4
|
+
a value equal to the default is not stored, so an untouched channel inherits (the device's
|
|
5
|
+
split, then the node's model). */
|
|
6
|
+
const haModel = {
|
|
7
|
+
/** the node option and a device's split */
|
|
8
|
+
MODELS: ['off', 'children', 'devices'],
|
|
9
|
+
/** where a channel goes */
|
|
10
|
+
PLACES: ['parent', 'child', 'own'],
|
|
11
|
+
|
|
12
|
+
/** a deep copy of the stored entries the editor works on */
|
|
13
|
+
copy(devices) {
|
|
14
|
+
return JSON.parse(JSON.stringify(devices || {}));
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
/** the entry of a device in the working copy, created on demand */
|
|
18
|
+
entry(model, address) {
|
|
19
|
+
if (!model[address]) {
|
|
20
|
+
model[address] = {enabled: false};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return model[address];
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
/** sets (or with '' clears) a device's split */
|
|
27
|
+
setSplit(model, address, split) {
|
|
28
|
+
const entry = haModel.entry(model, address);
|
|
29
|
+
if (haModel.MODELS.includes(split)) {
|
|
30
|
+
entry.split = split;
|
|
31
|
+
} else {
|
|
32
|
+
delete entry.split;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
/** changes a channel's settings; `publish: true` and `device: ''` are the defaults and go */
|
|
37
|
+
setChannel(model, address, index, patch) {
|
|
38
|
+
const entry = haModel.entry(model, address);
|
|
39
|
+
const channels = entry.channels || {};
|
|
40
|
+
const channel = {...channels[index], ...patch};
|
|
41
|
+
if (channel.publish !== false) {
|
|
42
|
+
delete channel.publish;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!haModel.PLACES.includes(channel.device)) {
|
|
46
|
+
delete channel.device;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (Object.keys(channel).length > 0) {
|
|
50
|
+
channels[index] = channel;
|
|
51
|
+
} else {
|
|
52
|
+
delete channels[index];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (Object.keys(channels).length > 0) {
|
|
56
|
+
entry.channels = channels;
|
|
57
|
+
} else {
|
|
58
|
+
delete entry.channels;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
/** a channel's settings as the editor shows them */
|
|
63
|
+
channel(model, address, index) {
|
|
64
|
+
const channels = (model[address] && model[address].channels) || {};
|
|
65
|
+
return {publish: (channels[index] || {}).publish !== false, device: (channels[index] || {}).device || ''};
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
/** whether the filter text matches a device (name, address, type, interface) */
|
|
69
|
+
matchesDevice(needle, address, device) {
|
|
70
|
+
return (
|
|
71
|
+
!needle || [device.name, address, device.type, device.iface].join(' ').toLowerCase().includes(needle)
|
|
72
|
+
);
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
/** whether the filter text matches a unit's channels (names, addresses, types, rooms, functions) */
|
|
76
|
+
matchesChannels(needle, channels) {
|
|
77
|
+
if (!needle) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return channels.some((ch) =>
|
|
82
|
+
[ch.name, ch.address, ch.type, ...(ch.rooms || []), ...(ch.functions || [])]
|
|
83
|
+
.join(' ')
|
|
84
|
+
.toLowerCase()
|
|
85
|
+
.includes(needle),
|
|
86
|
+
);
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The `devices` config to store: the ticked ones enabled, a device ticked before and not now
|
|
91
|
+
* `enabled: false` (Home Assistant forgets it), devices not listed this time as they were.
|
|
92
|
+
* Split and channel settings go with the entry either way.
|
|
93
|
+
*/
|
|
94
|
+
serialize(model, ticked, listed, previous) {
|
|
95
|
+
const devices = {};
|
|
96
|
+
for (const address of listed) {
|
|
97
|
+
const settings = {};
|
|
98
|
+
const entry = model[address] || {};
|
|
99
|
+
if (entry.split) {
|
|
100
|
+
settings.split = entry.split;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (entry.channels && Object.keys(entry.channels).length > 0) {
|
|
104
|
+
settings.channels = entry.channels;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (ticked.includes(address)) {
|
|
108
|
+
devices[address] = {enabled: true, ...settings};
|
|
109
|
+
} else if (previous[address]) {
|
|
110
|
+
devices[address] = {enabled: false, ...settings};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
for (const address of Object.keys(previous)) {
|
|
115
|
+
if (!(address in devices) && !listed.includes(address)) {
|
|
116
|
+
devices[address] = previous[address];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return devices;
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
/** what a unit publishes, e.g. "switch, 2 sensors, +5 disabled" */
|
|
124
|
+
preview(platforms) {
|
|
125
|
+
if (!platforms) {
|
|
126
|
+
return 'not known yet';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (platforms.length === 0) {
|
|
130
|
+
return 'nothing';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const counts = {};
|
|
134
|
+
let disabled = 0;
|
|
135
|
+
for (const {p, en} of platforms) {
|
|
136
|
+
if (en) {
|
|
137
|
+
counts[p] = (counts[p] || 0) + 1;
|
|
138
|
+
} else {
|
|
139
|
+
disabled += 1;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const parts = Object.keys(counts).map((p) => (counts[p] > 1 ? counts[p] + ' × ' + p : p));
|
|
144
|
+
if (disabled > 0) {
|
|
145
|
+
parts.push('+' + disabled + ' disabled');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return parts.join(', ');
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The rows of a device's channel table: one per unit (an HmIP transmitter with its virtual
|
|
153
|
+
* receivers is one), from the units the runtime reports; without them one per channel.
|
|
154
|
+
*/
|
|
155
|
+
units(device) {
|
|
156
|
+
const byIndex = {};
|
|
157
|
+
for (const ch of device.channels || []) {
|
|
158
|
+
byIndex[Number(String(ch.address).split(':')[1])] = ch;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (Array.isArray(device.units) && device.units.length > 0) {
|
|
162
|
+
return device.units.map((unit) => ({
|
|
163
|
+
index: unit.index,
|
|
164
|
+
function: unit.function,
|
|
165
|
+
platforms: unit.platforms,
|
|
166
|
+
channels: unit.channels.map((i) => byIndex[i]).filter(Boolean),
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return Object.keys(byIndex)
|
|
171
|
+
.map(Number)
|
|
172
|
+
.sort((a, b) => a - b)
|
|
173
|
+
.map((index) => ({index, function: false, platforms: undefined, channels: [byIndex[index]]}));
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
|
|
2
177
|
RED.nodes.registerType('ccu-homeassistant', {
|
|
3
178
|
category: 'ccu',
|
|
4
179
|
defaults: {
|
|
@@ -8,6 +183,7 @@
|
|
|
8
183
|
prefix: {value: 'homeassistant'},
|
|
9
184
|
generic: {value: true},
|
|
10
185
|
area: {value: true},
|
|
186
|
+
channelDevices: {value: 'off'},
|
|
11
187
|
devices: {value: {}},
|
|
12
188
|
},
|
|
13
189
|
inputs: 1,
|
|
@@ -16,6 +192,7 @@
|
|
|
16
192
|
color: '#c2d5e4',
|
|
17
193
|
paletteLabel: 'home assistant',
|
|
18
194
|
align: 'right',
|
|
195
|
+
haModel,
|
|
19
196
|
label() {
|
|
20
197
|
return this.name || 'home assistant';
|
|
21
198
|
},
|
|
@@ -28,6 +205,16 @@
|
|
|
28
205
|
this.devices = {};
|
|
29
206
|
}
|
|
30
207
|
|
|
208
|
+
if (!this.channelDevices) {
|
|
209
|
+
$('#node-input-channelDevices').val('off');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// the working copy of the device and channel settings, stored by oneditsave
|
|
213
|
+
this._haModel = haModel.copy(this.devices);
|
|
214
|
+
this._haListed = [];
|
|
215
|
+
const model = this._haModel;
|
|
216
|
+
let data = {};
|
|
217
|
+
|
|
31
218
|
const $ccuConfig = $('#node-input-ccuConfig');
|
|
32
219
|
const $mqttNode = $('#node-input-mqttNode');
|
|
33
220
|
const $devices = $('#ha-devices');
|
|
@@ -41,6 +228,42 @@
|
|
|
41
228
|
.html();
|
|
42
229
|
}
|
|
43
230
|
|
|
231
|
+
function select(cls, options, value, title) {
|
|
232
|
+
return (
|
|
233
|
+
'<select class="' +
|
|
234
|
+
cls +
|
|
235
|
+
'" title="' +
|
|
236
|
+
escape(title) +
|
|
237
|
+
'">' +
|
|
238
|
+
options
|
|
239
|
+
.map(
|
|
240
|
+
([v, text]) =>
|
|
241
|
+
'<option value="' +
|
|
242
|
+
v +
|
|
243
|
+
'"' +
|
|
244
|
+
(v === value ? ' selected' : '') +
|
|
245
|
+
'>' +
|
|
246
|
+
escape(text) +
|
|
247
|
+
'</option>',
|
|
248
|
+
)
|
|
249
|
+
.join('') +
|
|
250
|
+
'</select>'
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const SPLIT = [
|
|
255
|
+
['', 'as the node'],
|
|
256
|
+
['off', 'one device'],
|
|
257
|
+
['children', 'child devices'],
|
|
258
|
+
['devices', 'own devices'],
|
|
259
|
+
];
|
|
260
|
+
const PLACE = [
|
|
261
|
+
['', 'as the device'],
|
|
262
|
+
['parent', 'on the device'],
|
|
263
|
+
['child', 'child device'],
|
|
264
|
+
['own', 'own device'],
|
|
265
|
+
];
|
|
266
|
+
|
|
44
267
|
// the ccu-mqtt nodes of the flows whose topics this node reuses
|
|
45
268
|
function loadMqttNodes() {
|
|
46
269
|
const config = $ccuConfig.val();
|
|
@@ -67,22 +290,107 @@
|
|
|
67
290
|
}
|
|
68
291
|
}
|
|
69
292
|
|
|
293
|
+
function needle() {
|
|
294
|
+
return String($filter.val() || '')
|
|
295
|
+
.trim()
|
|
296
|
+
.toLowerCase();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** the channel rows of a device, built when it is opened */
|
|
300
|
+
function channelRows(addr) {
|
|
301
|
+
const dev = data[addr];
|
|
302
|
+
return haModel.units(dev).map((unit) => {
|
|
303
|
+
const head = unit.channels[0] || {address: addr + ':' + unit.index};
|
|
304
|
+
const settings = haModel.channel(model, addr, unit.index);
|
|
305
|
+
const others = unit.channels.slice(1).map((ch) => String(ch.address).split(':')[1]);
|
|
306
|
+
const rooms = [...new Set(unit.channels.flatMap((ch) => ch.rooms || []))];
|
|
307
|
+
const maintenance = unit.index === 0;
|
|
308
|
+
const $row = $(
|
|
309
|
+
'<tr class="ha-channel-row" data-addr="' +
|
|
310
|
+
escape(addr) +
|
|
311
|
+
'" data-index="' +
|
|
312
|
+
unit.index +
|
|
313
|
+
'">' +
|
|
314
|
+
'<td></td>' +
|
|
315
|
+
'<td class="ha-small ha-right">' +
|
|
316
|
+
unit.index +
|
|
317
|
+
(others.length > 0 ? '<br>+' + escape(others.join(',')) : '') +
|
|
318
|
+
'</td>' +
|
|
319
|
+
'<td class="ha-text" title="' +
|
|
320
|
+
escape([head.name || head.address, head.type, ...rooms].join(' · ')) +
|
|
321
|
+
'">' +
|
|
322
|
+
escape(head.name || head.address) +
|
|
323
|
+
'<div class="ha-small">' +
|
|
324
|
+
escape([head.type, ...rooms].join(' · ')) +
|
|
325
|
+
'</div>' +
|
|
326
|
+
'</td>' +
|
|
327
|
+
'<td class="ha-text ha-small" title="' +
|
|
328
|
+
escape(haModel.preview(unit.platforms)) +
|
|
329
|
+
'">' +
|
|
330
|
+
escape(haModel.preview(unit.platforms)) +
|
|
331
|
+
'</td>' +
|
|
332
|
+
'<td class="ha-enabled"><input type="checkbox" class="ha-publish" title="publish to Home Assistant"' +
|
|
333
|
+
(settings.publish ? ' checked' : '') +
|
|
334
|
+
'></td>' +
|
|
335
|
+
'<td>' +
|
|
336
|
+
(maintenance
|
|
337
|
+
? '<span class="ha-small" title="the maintenance channel stays on the device">—</span>'
|
|
338
|
+
: select('ha-place', PLACE, settings.device, 'where the channel goes')) +
|
|
339
|
+
'</td>' +
|
|
340
|
+
'</tr>',
|
|
341
|
+
);
|
|
342
|
+
$row.data('unit', unit);
|
|
343
|
+
return $row;
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
70
347
|
function applyFilter() {
|
|
71
|
-
const
|
|
348
|
+
const text = needle();
|
|
72
349
|
$devices.find('tr.ha-device-row').each(function () {
|
|
73
350
|
const $row = $(this);
|
|
74
|
-
const
|
|
75
|
-
|
|
351
|
+
const addr = $row.data('addr');
|
|
352
|
+
const dev = data[addr];
|
|
353
|
+
const deviceHit = haModel.matchesDevice(text, addr, dev);
|
|
354
|
+
let channelHit = false;
|
|
355
|
+
$devices.find('tr.ha-channel-row[data-addr="' + addr + '"]').each(function () {
|
|
356
|
+
const unit = $(this).data('unit');
|
|
357
|
+
const hit = deviceHit || haModel.matchesChannels(text, unit.channels);
|
|
358
|
+
channelHit = channelHit || hit;
|
|
359
|
+
$(this).toggle(hit && $row.hasClass('ha-open'));
|
|
360
|
+
});
|
|
361
|
+
if (!channelHit && !deviceHit) {
|
|
362
|
+
channelHit = haModel.units(dev).some((unit) => haModel.matchesChannels(text, unit.channels));
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
$row.toggle(deviceHit || channelHit);
|
|
76
366
|
});
|
|
77
367
|
}
|
|
78
368
|
|
|
79
|
-
function
|
|
80
|
-
$
|
|
369
|
+
function toggleDevice($row) {
|
|
370
|
+
const addr = $row.data('addr');
|
|
371
|
+
const open = !$row.hasClass('ha-open');
|
|
372
|
+
$row.toggleClass('ha-open', open);
|
|
373
|
+
$row.find('.ha-toggle').text(open ? '▾' : '▸');
|
|
374
|
+
if (open && !$row.data('built')) {
|
|
375
|
+
$row.after(channelRows(addr));
|
|
376
|
+
$row.data('built', true);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
applyFilter();
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const COLUMNS =
|
|
383
|
+
'<colgroup><col class="ha-col-check"><col class="ha-col-index"><col><col class="ha-col-preview">' +
|
|
384
|
+
'<col class="ha-col-check"><col class="ha-col-select"></colgroup>';
|
|
385
|
+
|
|
386
|
+
function renderDevices() {
|
|
387
|
+
$devices.empty().append(COLUMNS);
|
|
81
388
|
const addresses = Object.keys(data).sort((a, b) => {
|
|
82
389
|
const na = data[a].name || a;
|
|
83
390
|
const nb = data[b].name || b;
|
|
84
391
|
return na.localeCompare(nb);
|
|
85
392
|
});
|
|
393
|
+
that._haListed = addresses;
|
|
86
394
|
if (addresses.length === 0) {
|
|
87
395
|
$message.text('No devices known yet — is the CCU connection deployed and initialized?').show();
|
|
88
396
|
return;
|
|
@@ -90,33 +398,29 @@
|
|
|
90
398
|
|
|
91
399
|
addresses.forEach((addr) => {
|
|
92
400
|
const dev = data[addr];
|
|
93
|
-
const entry =
|
|
401
|
+
const entry = model[addr];
|
|
94
402
|
const checked = Boolean(entry && entry.enabled === true);
|
|
95
|
-
const search = [dev.name, addr, dev.type, dev.iface].join(' ').toLowerCase();
|
|
96
403
|
const $row = $(
|
|
97
404
|
'<tr class="ha-device-row">' +
|
|
98
|
-
'<td class="ha-enabled"><input type="checkbox" class="ha-device"
|
|
99
|
-
escape(addr) +
|
|
100
|
-
'"' +
|
|
405
|
+
'<td class="ha-enabled"><input type="checkbox" class="ha-device"' +
|
|
101
406
|
(checked ? ' checked' : '') +
|
|
102
407
|
'></td>' +
|
|
103
|
-
'<td class="ha-
|
|
104
|
-
|
|
408
|
+
'<td class="ha-toggle" title="channels">▸</td>' +
|
|
409
|
+
'<td class="ha-text" colspan="3" title="' +
|
|
410
|
+
escape([dev.name || addr, addr, dev.type, dev.iface].join(' · ')) +
|
|
105
411
|
'">' +
|
|
106
412
|
escape(dev.name || addr) +
|
|
413
|
+
'<div class="ha-small">' +
|
|
414
|
+
escape([addr, dev.type, dev.iface].join(' · ')) +
|
|
415
|
+
'</div>' +
|
|
107
416
|
'</td>' +
|
|
108
|
-
'<td
|
|
109
|
-
|
|
110
|
-
'</td>' +
|
|
111
|
-
'<td class="ha-text ha-small">' +
|
|
112
|
-
escape(dev.type) +
|
|
113
|
-
'</td>' +
|
|
114
|
-
'<td class="ha-text ha-small">' +
|
|
115
|
-
escape(dev.iface) +
|
|
417
|
+
'<td>' +
|
|
418
|
+
select('ha-split', SPLIT, (entry && entry.split) || '', 'channels as devices') +
|
|
116
419
|
'</td>' +
|
|
117
420
|
'</tr>',
|
|
118
421
|
);
|
|
119
|
-
$row.
|
|
422
|
+
$row.attr('data-addr', addr);
|
|
423
|
+
$row.data('addr', addr);
|
|
120
424
|
$devices.append($row);
|
|
121
425
|
});
|
|
122
426
|
applyFilter();
|
|
@@ -138,9 +442,11 @@
|
|
|
138
442
|
|
|
139
443
|
loading = true;
|
|
140
444
|
$spinner.show();
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
445
|
+
const generic = $('#node-input-generic').is(':checked');
|
|
446
|
+
$.getJSON('ccu?config=' + config + '&type=devices&generic=' + generic)
|
|
447
|
+
.done((answer) => {
|
|
448
|
+
data = answer || {};
|
|
449
|
+
renderDevices();
|
|
144
450
|
})
|
|
145
451
|
.fail(() => {
|
|
146
452
|
$devices.empty();
|
|
@@ -152,16 +458,78 @@
|
|
|
152
458
|
});
|
|
153
459
|
}
|
|
154
460
|
|
|
461
|
+
$devices.on('click', 'td.ha-toggle', function () {
|
|
462
|
+
toggleDevice($(this).closest('tr'));
|
|
463
|
+
});
|
|
464
|
+
$devices.on('change', 'input.ha-device', function () {
|
|
465
|
+
haModel.entry(model, $(this).closest('tr').data('addr')).enabled = $(this).is(':checked');
|
|
466
|
+
});
|
|
467
|
+
$devices.on('change', 'select.ha-split', function () {
|
|
468
|
+
haModel.setSplit(model, $(this).closest('tr').data('addr'), $(this).val());
|
|
469
|
+
});
|
|
470
|
+
$devices.on('change', 'input.ha-publish', function () {
|
|
471
|
+
const $row = $(this).closest('tr');
|
|
472
|
+
haModel.setChannel(model, $row.attr('data-addr'), Number($row.attr('data-index')), {publish: $(this).is(':checked')});
|
|
473
|
+
});
|
|
474
|
+
$devices.on('change', 'select.ha-place', function () {
|
|
475
|
+
const $row = $(this).closest('tr');
|
|
476
|
+
haModel.setChannel(model, $row.attr('data-addr'), Number($row.attr('data-index')), {device: $(this).val()});
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
// bulk actions on what the filter lists: the ticked devices, their matching channels
|
|
480
|
+
$('#ha-bulk-apply').on('click', () => {
|
|
481
|
+
const [kind, value] = String($('#ha-bulk').val() || '').split(':');
|
|
482
|
+
if (!kind) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
const text = needle();
|
|
487
|
+
$devices.find('tr.ha-device-row:visible').each(function () {
|
|
488
|
+
const $row = $(this);
|
|
489
|
+
const addr = $row.data('addr');
|
|
490
|
+
if (!$row.find('input.ha-device').is(':checked')) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if (kind === 'split') {
|
|
495
|
+
haModel.setSplit(model, addr, value);
|
|
496
|
+
$row.find('select.ha-split').val(value);
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const deviceHit = haModel.matchesDevice(text, addr, data[addr]);
|
|
501
|
+
for (const unit of haModel.units(data[addr])) {
|
|
502
|
+
if (unit.index === 0 && kind === 'place') {
|
|
503
|
+
continue;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
if (deviceHit || haModel.matchesChannels(text, unit.channels)) {
|
|
507
|
+
haModel.setChannel(
|
|
508
|
+
model,
|
|
509
|
+
addr,
|
|
510
|
+
unit.index,
|
|
511
|
+
kind === 'publish' ? {publish: value === 'yes'} : {device: value},
|
|
512
|
+
);
|
|
513
|
+
const $channel = $devices.find(
|
|
514
|
+
'tr.ha-channel-row[data-addr="' + addr + '"][data-index="' + unit.index + '"]',
|
|
515
|
+
);
|
|
516
|
+
$channel.find('input.ha-publish').prop('checked', haModel.channel(model, addr, unit.index).publish);
|
|
517
|
+
$channel.find('select.ha-place').val(haModel.channel(model, addr, unit.index).device);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
|
|
155
523
|
$ccuConfig.on('change', () => {
|
|
156
524
|
loadMqttNodes();
|
|
157
525
|
loadDevices();
|
|
158
526
|
});
|
|
159
527
|
$filter.on('input keyup', applyFilter);
|
|
160
528
|
$('#ha-enable-all').on('click', () => {
|
|
161
|
-
$devices.find('tr.ha-device-row:visible input.ha-device').prop('checked', true);
|
|
529
|
+
$devices.find('tr.ha-device-row:visible input.ha-device').prop('checked', true).trigger('change');
|
|
162
530
|
});
|
|
163
531
|
$('#ha-disable-all').on('click', () => {
|
|
164
|
-
$devices.find('tr.ha-device-row:visible input.ha-device').prop('checked', false);
|
|
532
|
+
$devices.find('tr.ha-device-row:visible input.ha-device').prop('checked', false).trigger('change');
|
|
165
533
|
});
|
|
166
534
|
|
|
167
535
|
loadMqttNodes();
|
|
@@ -169,24 +537,10 @@
|
|
|
169
537
|
},
|
|
170
538
|
oneditsave() {
|
|
171
539
|
const previous = this.devices || {};
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
devices[addr] = {enabled: true};
|
|
177
|
-
} else if (previous[addr]) {
|
|
178
|
-
// was known before → publish a removal so Home Assistant forgets it
|
|
179
|
-
devices[addr] = {enabled: false};
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
// keep entries of devices that were not listed this time (interface
|
|
183
|
-
// temporarily down) instead of dropping them
|
|
184
|
-
Object.keys(previous).forEach((addr) => {
|
|
185
|
-
if (!(addr in devices)) {
|
|
186
|
-
devices[addr] = previous[addr];
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
this.devices = devices;
|
|
540
|
+
const model = this._haModel || haModel.copy(previous);
|
|
541
|
+
const listed = this._haListed || [];
|
|
542
|
+
const ticked = listed.filter((addr) => model[addr] && model[addr].enabled === true);
|
|
543
|
+
this.devices = haModel.serialize(model, ticked, listed, previous);
|
|
190
544
|
},
|
|
191
545
|
});
|
|
192
546
|
</script>
|
|
@@ -209,21 +563,40 @@
|
|
|
209
563
|
padding: 1px 4px;
|
|
210
564
|
border-bottom: 1px solid #eee;
|
|
211
565
|
}
|
|
566
|
+
#ha-devices {
|
|
567
|
+
table-layout: fixed;
|
|
568
|
+
}
|
|
212
569
|
#ha-devices td.ha-text {
|
|
213
570
|
white-space: nowrap;
|
|
214
571
|
overflow: hidden;
|
|
215
572
|
text-overflow: ellipsis;
|
|
216
|
-
|
|
573
|
+
}
|
|
574
|
+
#ha-devices td.ha-text div.ha-small {
|
|
575
|
+
overflow: hidden;
|
|
576
|
+
text-overflow: ellipsis;
|
|
577
|
+
}
|
|
578
|
+
#ha-devices col.ha-col-check {
|
|
579
|
+
width: 22px;
|
|
580
|
+
}
|
|
581
|
+
#ha-devices col.ha-col-index {
|
|
582
|
+
width: 34px;
|
|
583
|
+
}
|
|
584
|
+
#ha-devices col.ha-col-preview {
|
|
585
|
+
width: 28%;
|
|
586
|
+
}
|
|
587
|
+
#ha-devices col.ha-col-select {
|
|
588
|
+
width: 118px;
|
|
217
589
|
}
|
|
218
590
|
#ha-devices td.ha-small {
|
|
219
591
|
font-size: 10px;
|
|
220
|
-
color: #666;
|
|
592
|
+
color: var(--red-ui-secondary-text-color, #666);
|
|
221
593
|
max-width: 120px;
|
|
222
594
|
}
|
|
223
595
|
#ha-devices td.ha-enabled {
|
|
224
596
|
width: 20px;
|
|
225
597
|
}
|
|
226
|
-
#ha-devices input.ha-device
|
|
598
|
+
#ha-devices input.ha-device,
|
|
599
|
+
#ha-devices input.ha-publish {
|
|
227
600
|
width: auto !important;
|
|
228
601
|
margin: 0 !important;
|
|
229
602
|
}
|
|
@@ -237,6 +610,38 @@
|
|
|
237
610
|
flex: 1;
|
|
238
611
|
width: auto !important;
|
|
239
612
|
}
|
|
613
|
+
#ha-devices td.ha-toggle {
|
|
614
|
+
width: 14px;
|
|
615
|
+
cursor: pointer;
|
|
616
|
+
user-select: none;
|
|
617
|
+
}
|
|
618
|
+
#ha-devices td.ha-right {
|
|
619
|
+
text-align: right;
|
|
620
|
+
vertical-align: top;
|
|
621
|
+
}
|
|
622
|
+
#ha-devices tr.ha-channel-row td {
|
|
623
|
+
background: var(--red-ui-secondary-background, #f7f7f7);
|
|
624
|
+
}
|
|
625
|
+
#ha-devices select {
|
|
626
|
+
width: 112px !important;
|
|
627
|
+
height: 22px;
|
|
628
|
+
padding: 0 2px;
|
|
629
|
+
font-size: 11px;
|
|
630
|
+
}
|
|
631
|
+
#ha-devices div.ha-small {
|
|
632
|
+
font-size: 10px;
|
|
633
|
+
color: var(--red-ui-secondary-text-color, #666);
|
|
634
|
+
}
|
|
635
|
+
#ha-bulk-bar {
|
|
636
|
+
display: flex;
|
|
637
|
+
gap: 8px;
|
|
638
|
+
align-items: center;
|
|
639
|
+
margin-bottom: 6px;
|
|
640
|
+
font-size: 12px;
|
|
641
|
+
}
|
|
642
|
+
#ha-bulk-bar select {
|
|
643
|
+
width: auto !important;
|
|
644
|
+
}
|
|
240
645
|
#ha-message {
|
|
241
646
|
display: none;
|
|
242
647
|
color: #888;
|
|
@@ -278,16 +683,45 @@
|
|
|
278
683
|
</div>
|
|
279
684
|
</div>
|
|
280
685
|
|
|
686
|
+
<div class="form-row">
|
|
687
|
+
<label for="node-input-channelDevices"><i class="fa fa-sitemap"></i> Channels</label>
|
|
688
|
+
<select id="node-input-channelDevices" style="width: 70%">
|
|
689
|
+
<option value="off">one Home Assistant device per Homematic device</option>
|
|
690
|
+
<option value="children">child devices of the device (Home Assistant 2026.11 or newer)</option>
|
|
691
|
+
<option value="devices">devices of their own, each in its channel's room</option>
|
|
692
|
+
</select>
|
|
693
|
+
</div>
|
|
281
694
|
<div class="form-row">
|
|
282
695
|
<b>Devices published to Home Assistant</b>
|
|
283
696
|
</div>
|
|
284
697
|
<div class="form-row">
|
|
285
698
|
<div id="ha-toolbar">
|
|
286
|
-
<input type="text" id="ha-filter" placeholder="filter by name, address, type">
|
|
699
|
+
<input type="text" id="ha-filter" placeholder="filter by name, address, type, room, function">
|
|
287
700
|
<button type="button" class="red-ui-button red-ui-button-small" id="ha-enable-all">check all</button>
|
|
288
701
|
<button type="button" class="red-ui-button red-ui-button-small" id="ha-disable-all">uncheck all</button>
|
|
289
702
|
<img id="ha-spinner" src="red/images/spin.svg" style="display: none; height: 16px;">
|
|
290
703
|
</div>
|
|
704
|
+
<div id="ha-bulk-bar">
|
|
705
|
+
<span>Listed and ticked:</span>
|
|
706
|
+
<select id="ha-bulk">
|
|
707
|
+
<option value="">…</option>
|
|
708
|
+
<optgroup label="devices">
|
|
709
|
+
<option value="split:">channels as the node says</option>
|
|
710
|
+
<option value="split:off">one device</option>
|
|
711
|
+
<option value="split:children">channels as child devices</option>
|
|
712
|
+
<option value="split:devices">channels as own devices</option>
|
|
713
|
+
</optgroup>
|
|
714
|
+
<optgroup label="matching channels">
|
|
715
|
+
<option value="publish:yes">publish</option>
|
|
716
|
+
<option value="publish:no">do not publish</option>
|
|
717
|
+
<option value="place:">as the device says</option>
|
|
718
|
+
<option value="place:parent">on the device</option>
|
|
719
|
+
<option value="place:child">child device</option>
|
|
720
|
+
<option value="place:own">own device</option>
|
|
721
|
+
</optgroup>
|
|
722
|
+
</select>
|
|
723
|
+
<button type="button" class="red-ui-button red-ui-button-small" id="ha-bulk-apply">apply</button>
|
|
724
|
+
</div>
|
|
291
725
|
<div id="ha-message"></div>
|
|
292
726
|
<div style="max-height: 320px; overflow-y: auto;">
|
|
293
727
|
<table id="ha-devices"></table>
|