node-red-contrib-ccu 4.14.1 → 4.16.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,6 +2,7 @@ const path = require('path');
2
2
 
3
3
  const statusHelper = require(path.join(__dirname, '/lib/status.js'));
4
4
  const {effectiveConfig} = require(path.join(__dirname, '/lib/dynconfig.js'));
5
+ const {signalCommand} = require(path.join(__dirname, '/lib/signal.js'));
5
6
 
6
7
  /** Fields that already carry a typed input (`<name>Type`) in the editor. */
7
8
  const TYPED_VALUES = ['rampTimeValue', 'durationValue', 'repeat', 'volume', 'soundLevel'];
@@ -21,27 +22,12 @@ const DYNAMIC_KEYS = [
21
22
  'repetitions',
22
23
  'dimmerLevel',
23
24
  'dimmerColor',
25
+ 'colorBehaviour',
24
26
  'dimmerList',
25
27
  'soundList',
26
28
  ...TYPED_VALUES,
27
29
  ];
28
30
 
29
- /**
30
- * Accept both the editor's list shape and a plain array of values, so a
31
- * flow can send `msg.config.soundList = [1, 2]` instead of building
32
- * `[{sound: 1}, {sound: 2}]` by hand (#148).
33
- * @param {*} list
34
- * @param {string} key 'sound' or 'color'
35
- * @returns {object[]}
36
- */
37
- function normalizeList(list, key) {
38
- if (!Array.isArray(list)) {
39
- return [];
40
- }
41
-
42
- return list.map((item) => (item !== null && typeof item === 'object' ? item : {[key]: item}));
43
- }
44
-
45
31
  module.exports = function (RED) {
46
32
  class CcuSignal {
47
33
  constructor(config) {
@@ -88,83 +74,34 @@ module.exports = function (RED) {
88
74
  });
89
75
  }
90
76
 
77
+ /**
78
+ * The channel's VALUES description as far as it is known, without asking the interface.
79
+ * @param {string} iface
80
+ * @param {string} channel
81
+ * @returns {object|undefined}
82
+ */
83
+ valuesDescription(iface, channel) {
84
+ const devices = this.ccu.metadata && this.ccu.metadata.devices && this.ccu.metadata.devices[iface];
85
+ const device = devices && devices[String(channel).split(' ')[0]];
86
+ const key = device && this.ccu.paramsetName(iface, device, 'VALUES');
87
+ return key ? this.ccu.paramsetDescriptions[key] : undefined;
88
+ }
89
+
91
90
  sendCommand(config) {
92
- let payload;
93
91
  this.debug(config.channelType);
94
92
 
95
- switch (config.channelType) {
96
- case 'SIGNAL_CHIME':
97
- payload = [config.volume / 100, config.repeat, 108000, ...String(config.chime).split(',')];
98
- return this.ccu.setValue(config.iface, config.channel, 'SUBMIT', payload);
99
- case 'SIGNAL_LED':
100
- payload = ['1', config.repeat, 108000, ...String(config.led).split(',')];
101
- return this.ccu.setValue(config.iface, config.channel, 'SUBMIT', payload);
102
- case 'ALARM_SWITCH_VIRTUAL_RECEIVER':
103
- return this.ccu.methodCall(config.iface, 'putParamset', [
104
- config.channel,
105
- 'VALUES',
106
- {
107
- ACOUSTIC_ALARM_SELECTION: config.acousticAlarmSelection,
108
- DURATION_UNIT: config.durationUnit,
109
- DURATION_VALUE: Number.parseInt(config.durationValue, 10) || 0,
110
- OPTICAL_ALARM_SELECTION: config.opticalAlarmSelection,
111
- },
112
- ]);
113
- case 'DIMMER_VIRTUAL_RECEIVER': {
114
- const dimmerList = normalizeList(config.dimmerList, 'color');
115
- const parameters = {
116
- LEVEL: config.dimmerLevel / 100,
117
- RAMP_TIME_UNIT: config.rampTimeUnit,
118
- RAMP_TIME_VALUE: Number(config.rampTimeValue),
119
- DURATION_UNIT: config.durationUnit,
120
- DURATION_VALUE: Number.parseInt(config.durationValue, 10) || 0,
121
- REPETITIONS: Number(config.repetitions),
122
- OUTPUT_SELECT_SIZE: dimmerList.length,
123
- };
124
- dimmerList.forEach((item, i) => {
125
- const index = i + 1;
126
- parameters['COLOR_LIST_' + index] = Number(item.color);
127
- parameters['ON_TIME_LIST_' + index] = Number(item.ontime);
128
- });
129
- return this.ccu.methodCall(config.iface, 'putParamset', [config.channel, 'VALUES', parameters]);
130
- }
131
-
132
- case 'BSL_DIMMER_VIRTUAL_RECEIVER': {
133
- return this.ccu.methodCall(config.iface, 'putParamset', [
134
- config.channel,
135
- 'VALUES',
136
- {
137
- LEVEL: config.dimmerLevel / 100,
138
- RAMP_TIME_UNIT: config.rampTimeUnit,
139
- RAMP_TIME_VALUE: Number(config.rampTimeValue),
140
- DURATION_UNIT: config.durationUnit,
141
- DURATION_VALUE: Number.parseInt(config.durationValue, 10) || 0,
142
- COLOR: Number(config.dimmerColor),
143
- },
144
- ]);
145
- }
146
-
147
- case 'ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER': {
148
- const soundList = normalizeList(config.soundList, 'sound');
149
- const parameters = {
150
- LEVEL: config.soundLevel / 100,
151
- RAMP_TIME_UNIT: config.rampTimeUnit,
152
- RAMP_TIME_VALUE: Number(config.rampTimeValue),
153
- DURATION_UNIT: config.durationUnit,
154
- DURATION_VALUE: Number.parseInt(config.durationValue, 10) || 0,
155
- REPETITIONS: Number(config.repetitions),
156
- OUTPUT_SELECT_SIZE: soundList.length,
157
- };
158
- soundList.forEach((item, i) => {
159
- const index = i + 1;
160
- parameters['SOUNDFILE_LIST_' + index] = Number(item.sound);
161
- });
162
- return this.ccu.methodCall(config.iface, 'putParamset', [config.channel, 'VALUES', parameters]);
163
- }
93
+ let command;
94
+ try {
95
+ command = signalCommand(config, this.valuesDescription(config.iface, config.channel));
96
+ } catch (error) {
97
+ return Promise.reject(error);
98
+ }
164
99
 
165
- default:
166
- return Promise.reject(new Error(`channelType ${config.channelType} unknown`));
100
+ if (command.paramset) {
101
+ return this.ccu.methodCall(config.iface, 'putParamset', [config.channel, 'VALUES', command.paramset]);
167
102
  }
103
+
104
+ return this.ccu.setValue(config.iface, config.channel, command.datapoint, command.value);
168
105
  }
169
106
 
170
107
  setStatus(data) {
@@ -106,4 +106,109 @@ function createMessage(ccu, iface, channel, datapoint, payload, additions) {
106
106
  return message;
107
107
  }
108
108
 
109
- module.exports = {createMessage};
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};
@@ -0,0 +1,175 @@
1
+ /* The signal node's commands, by channel type (pure: no connection, no Node-RED).
2
+
3
+ COLOR_BEHAVIOUR (#177): the HmIP-BSL with firmware 2.x and the channel type
4
+ OPTICAL_SIGNAL_RECEIVER (HmIPW-WRC6) have a datapoint beside COLOR and LEVEL that
5
+ says how the LED lights - on, blinking, flashing, billowing. Its default is OFF,
6
+ so a command without it leaves the LED dark. The channel's description decides
7
+ whether it is sent: a BSL 2.x keeps the channel type DIMMER_VIRTUAL_RECEIVER of
8
+ the 1.x, which does not have the datapoint. */
9
+
10
+ /** COLOR_BEHAVIOUR's entries, in the order of the devices' VALUE_LIST */
11
+ const COLOR_BEHAVIOURS = [
12
+ 'OFF',
13
+ 'ON',
14
+ 'BLINKING_SLOW',
15
+ 'BLINKING_MIDDLE',
16
+ 'BLINKING_FAST',
17
+ 'FLASH_SLOW',
18
+ 'FLASH_MIDDLE',
19
+ 'FLASH_FAST',
20
+ 'BILLOW_SLOW',
21
+ 'BILLOW_MIDDLE',
22
+ 'BILLOW_FAST',
23
+ 'OLD_VALUE',
24
+ 'DO_NOT_CARE',
25
+ ];
26
+
27
+ /** what a node without the setting sends: the LED lights steadily */
28
+ const DEFAULT_COLOR_BEHAVIOUR = 1;
29
+
30
+ /**
31
+ * Accept both the editor's list shape and a plain array of values, so a
32
+ * flow can send `msg.config.soundList = [1, 2]` instead of building
33
+ * `[{sound: 1}, {sound: 2}]` by hand (#148).
34
+ * @param {*} list
35
+ * @param {string} key 'sound' or 'color'
36
+ * @returns {object[]}
37
+ */
38
+ function normalizeList(list, key) {
39
+ if (!Array.isArray(list)) {
40
+ return [];
41
+ }
42
+
43
+ return list.map((item) => (item !== null && typeof item === 'object' ? item : {[key]: item}));
44
+ }
45
+
46
+ /**
47
+ * The COLOR_BEHAVIOUR to send, as the entry's number.
48
+ * @param {*} value the setting: a number, a number as text or an entry's name; empty = the default
49
+ * @param {string[]} [list] the channel's VALUE_LIST
50
+ * @returns {number}
51
+ * @throws {Error} a value the list does not have
52
+ */
53
+ function colorBehaviourValue(value, list) {
54
+ const entries = Array.isArray(list) && list.length > 0 ? list : COLOR_BEHAVIOURS;
55
+ if (value === undefined || value === null || value === '') {
56
+ return DEFAULT_COLOR_BEHAVIOUR;
57
+ }
58
+
59
+ const number = typeof value === 'number' ? value : /^\d+$/.test(String(value).trim()) ? Number(value) : -1;
60
+ const index = number === -1 ? entries.indexOf(String(value).trim().toUpperCase()) : number;
61
+ if (!Number.isInteger(index) || index < 0 || index >= entries.length) {
62
+ throw new Error(`colorBehaviour ${value} unknown`);
63
+ }
64
+
65
+ return index;
66
+ }
67
+
68
+ /**
69
+ * Whether a coloured-LED channel takes COLOR_BEHAVIOUR.
70
+ * @param {string} channelType
71
+ * @param {object} [description] the channel's VALUES description, if known
72
+ * @returns {boolean}
73
+ */
74
+ function hasColorBehaviour(channelType, description) {
75
+ if (description && Object.keys(description).length > 0) {
76
+ const dp = description.COLOR_BEHAVIOUR;
77
+ return Boolean(dp && dp.OPERATIONS & 2);
78
+ }
79
+
80
+ // no description at hand: the channel type OPTICAL_SIGNAL_RECEIVER always has it, a BSL only from 2.x
81
+ return channelType === 'OPTICAL_SIGNAL_RECEIVER';
82
+ }
83
+
84
+ /**
85
+ * The command for one message.
86
+ * @param {object} config the node's effective configuration
87
+ * @param {object} [description] the channel's VALUES description, if known
88
+ * @returns {{datapoint: string, value: *}|{paramset: object}} a setValue or a putParamset on VALUES
89
+ * @throws {Error} an unknown channel type or setting
90
+ */
91
+ function signalCommand(config, description) {
92
+ switch (config.channelType) {
93
+ case 'SIGNAL_CHIME':
94
+ return {
95
+ datapoint: 'SUBMIT',
96
+ value: [config.volume / 100, config.repeat, 108000, ...String(config.chime).split(',')],
97
+ };
98
+ case 'SIGNAL_LED':
99
+ return {datapoint: 'SUBMIT', value: ['1', config.repeat, 108000, ...String(config.led).split(',')]};
100
+ case 'ALARM_SWITCH_VIRTUAL_RECEIVER':
101
+ return {
102
+ paramset: {
103
+ ACOUSTIC_ALARM_SELECTION: config.acousticAlarmSelection,
104
+ DURATION_UNIT: config.durationUnit,
105
+ DURATION_VALUE: Number.parseInt(config.durationValue, 10) || 0,
106
+ OPTICAL_ALARM_SELECTION: config.opticalAlarmSelection,
107
+ },
108
+ };
109
+ case 'DIMMER_VIRTUAL_RECEIVER': {
110
+ const dimmerList = normalizeList(config.dimmerList, 'color');
111
+ const paramset = {
112
+ LEVEL: config.dimmerLevel / 100,
113
+ RAMP_TIME_UNIT: config.rampTimeUnit,
114
+ RAMP_TIME_VALUE: Number(config.rampTimeValue),
115
+ DURATION_UNIT: config.durationUnit,
116
+ DURATION_VALUE: Number.parseInt(config.durationValue, 10) || 0,
117
+ REPETITIONS: Number(config.repetitions),
118
+ OUTPUT_SELECT_SIZE: dimmerList.length,
119
+ };
120
+ dimmerList.forEach((item, i) => {
121
+ const index = i + 1;
122
+ paramset['COLOR_LIST_' + index] = Number(item.color);
123
+ paramset['ON_TIME_LIST_' + index] = Number(item.ontime);
124
+ });
125
+ return {paramset};
126
+ }
127
+
128
+ case 'BSL_DIMMER_VIRTUAL_RECEIVER':
129
+ case 'OPTICAL_SIGNAL_RECEIVER': {
130
+ const paramset = {
131
+ LEVEL: config.dimmerLevel / 100,
132
+ RAMP_TIME_UNIT: config.rampTimeUnit,
133
+ RAMP_TIME_VALUE: Number(config.rampTimeValue),
134
+ DURATION_UNIT: config.durationUnit,
135
+ DURATION_VALUE: Number.parseInt(config.durationValue, 10) || 0,
136
+ COLOR: Number(config.dimmerColor),
137
+ };
138
+ if (hasColorBehaviour(config.channelType, description)) {
139
+ const list = description && description.COLOR_BEHAVIOUR && description.COLOR_BEHAVIOUR.VALUE_LIST;
140
+ paramset.COLOR_BEHAVIOUR = colorBehaviourValue(config.colorBehaviour, list);
141
+ }
142
+
143
+ return {paramset};
144
+ }
145
+
146
+ case 'ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER': {
147
+ const soundList = normalizeList(config.soundList, 'sound');
148
+ const paramset = {
149
+ LEVEL: config.soundLevel / 100,
150
+ RAMP_TIME_UNIT: config.rampTimeUnit,
151
+ RAMP_TIME_VALUE: Number(config.rampTimeValue),
152
+ DURATION_UNIT: config.durationUnit,
153
+ DURATION_VALUE: Number.parseInt(config.durationValue, 10) || 0,
154
+ REPETITIONS: Number(config.repetitions),
155
+ OUTPUT_SELECT_SIZE: soundList.length,
156
+ };
157
+ soundList.forEach((item, i) => {
158
+ paramset['SOUNDFILE_LIST_' + (i + 1)] = Number(item.sound);
159
+ });
160
+ return {paramset};
161
+ }
162
+
163
+ default:
164
+ throw new Error(`channelType ${config.channelType} unknown`);
165
+ }
166
+ }
167
+
168
+ module.exports = {
169
+ COLOR_BEHAVIOURS,
170
+ DEFAULT_COLOR_BEHAVIOUR,
171
+ colorBehaviourValue,
172
+ hasColorBehaviour,
173
+ normalizeList,
174
+ signalCommand,
175
+ };
@@ -0,0 +1,197 @@
1
+ /* The HmIP-WRCD's display command (#144), pure: no connection, no Node-RED.
2
+
3
+ Channel 3 (ACOUSTIC_DISPLAY_RECEIVER) takes the five lines of the display and a
4
+ sound in one write of COMBINED_PARAMETER - a block in braces per line, the commit
5
+ in the last one, then a block for the sound:
6
+
7
+ {DDBC=WHITE,DDTC=BLACK,DDI=2,DDA=CENTER,DDS=Kitchen,DDID=1},
8
+ {DDBC=WHITE,DDTC=BLACK,DDI=0,DDA=LEFT,DDS=21.5 C,DDID=2,DDC=true},{R=1,IN=5,ANS=6}
9
+
10
+ DDBC/DDTC = background and text colour, DDI = the icon's number, DDA = alignment,
11
+ DDS = the text, DDID = the line, DDC = commit; R = repetitions, IN = seconds between
12
+ them, ANS = the sound's number. It is the text the CCU's own program dialog writes;
13
+ the entries are those of the channel's description (DISPLAY_DATA_ICON,
14
+ ACOUSTIC_NOTIFICATION_SELECTION). */
15
+
16
+ const LINES = 5;
17
+ const TEXT_LENGTH = 16;
18
+
19
+ /** DISPLAY_DATA_ICON's entries; the number sent is the index */
20
+ const ICONS = [
21
+ 'NO_ICON',
22
+ 'LAMP_OFF',
23
+ 'LAMP_ON',
24
+ 'PADLOCK_OPEN',
25
+ 'PADLOCK_CLOSED',
26
+ 'ERROR',
27
+ 'EVERYTHING_OKAY',
28
+ 'INFORMATION',
29
+ 'NEW_MESSAGE',
30
+ 'SERVICE_MESSAGE',
31
+ 'SUN',
32
+ 'MOON',
33
+ 'WIND',
34
+ 'CLOUD',
35
+ 'THUNDERSTORM',
36
+ 'DRIZZLE',
37
+ 'CLOUD_AND_MOOON',
38
+ 'RAIN',
39
+ 'SNOW',
40
+ 'CLOUD_AND_SUN',
41
+ 'CLOUD_SUN_AND_RAIN',
42
+ 'SNOWFLAKE',
43
+ 'RAINDROP',
44
+ 'FLAME',
45
+ 'WINDOW_OPEN',
46
+ 'SHUTTERS',
47
+ 'ECO',
48
+ 'PROTECTION_DEACTIVATED',
49
+ 'EXTERNAL_PROTECTION',
50
+ 'INTERNAL_PROTECTION',
51
+ 'BELL',
52
+ 'CLOCK',
53
+ ];
54
+
55
+ /** ACOUSTIC_NOTIFICATION_SELECTION's entries; the number sent is the index */
56
+ const SOUNDS = [
57
+ 'LOW_BATTERY',
58
+ 'DISARMED',
59
+ 'INTERNALLY_ARMED',
60
+ 'EXTERNALLY_ARMED',
61
+ 'DELAYED_INTERNALLY_ARMED',
62
+ 'DELAYED_EXTERNALLY_ARMED',
63
+ 'EVENT',
64
+ 'ERROR',
65
+ ];
66
+
67
+ const ALIGNMENTS = {
68
+ LEFT: 'LEFT',
69
+ LINKS: 'LEFT',
70
+ CENTER: 'CENTER',
71
+ CENTRE: 'CENTER',
72
+ MITTE: 'CENTER',
73
+ ZENTRIERT: 'CENTER',
74
+ RIGHT: 'RIGHT',
75
+ RECHTS: 'RIGHT',
76
+ };
77
+
78
+ const COLORS = {
79
+ WHITE: 'WHITE',
80
+ WEISS: 'WHITE',
81
+ WEIß: 'WHITE',
82
+ BLACK: 'BLACK',
83
+ SCHWARZ: 'BLACK',
84
+ };
85
+
86
+ /** the display's stand-ins for the characters its table has in other places */
87
+ const CHARACTERS = {
88
+ Ä: '[',
89
+ Ö: '#',
90
+ Ü: '$',
91
+ ä: '²',
92
+ ö: '|',
93
+ ü: '³',
94
+ ß: '_',
95
+ '&': ']',
96
+ "'": 'µ',
97
+ // the command's own punctuation cannot be part of a text
98
+ ',': '.',
99
+ '=': ':',
100
+ '{': '(',
101
+ '}': ')',
102
+ };
103
+
104
+ /** the stand-ins as text would otherwise show them: the characters they displace */
105
+ const DISPLACED = new Set(['[', ']', '#', '$', '|', '_']);
106
+
107
+ /**
108
+ * A line's text as the display takes it: sixteen characters of its table.
109
+ * @param {*} text
110
+ * @returns {string}
111
+ */
112
+ function wrcdText(text) {
113
+ let out = '';
114
+ for (const c of String(text === undefined || text === null ? '' : text)) {
115
+ if (CHARACTERS[c]) {
116
+ out += CHARACTERS[c];
117
+ } else if (c >= ' ' && c <= '~' && !DISPLACED.has(c)) {
118
+ out += c;
119
+ }
120
+ }
121
+
122
+ return out.slice(0, TEXT_LENGTH);
123
+ }
124
+
125
+ /**
126
+ * An entry's number from a number, a number as text or a name.
127
+ * @param {*} value
128
+ * @param {string[]} entries
129
+ * @returns {number} -1 = none of them
130
+ */
131
+ function entryIndex(value, entries) {
132
+ if (value === undefined || value === null || value === '') {
133
+ return -1;
134
+ }
135
+
136
+ const text = String(value).trim();
137
+ const index = /^\d+$/.test(text) ? Number(text) : entries.indexOf(text.toUpperCase().replace(/[\s-]+/g, '_'));
138
+ return index >= 0 && index < entries.length ? index : -1;
139
+ }
140
+
141
+ function clamp(value, min, max, fallback) {
142
+ const number = Number.parseInt(value, 10);
143
+ if (Number.isNaN(number)) {
144
+ return fallback;
145
+ }
146
+
147
+ return Math.min(max, Math.max(min, number));
148
+ }
149
+
150
+ /**
151
+ * The COMBINED_PARAMETER text of one message.
152
+ * @param {object} lines per line (1 to 5) what to show: `{text, icon, align, color, background}`;
153
+ * a line that is missing stays as it is on the display
154
+ * @param {object} [sound] `{sound, repeat, interval}`; without a sound nothing is played
155
+ * @returns {string} empty when there is neither a line nor a sound
156
+ */
157
+ function wrcdCommand(lines, sound) {
158
+ const blocks = [];
159
+ for (let i = 1; i <= LINES; i++) {
160
+ const line = lines && lines[i];
161
+ if (!line) {
162
+ continue;
163
+ }
164
+
165
+ const upper = (value) => String(value === undefined || value === null ? '' : value).toUpperCase();
166
+ blocks.push(
167
+ [
168
+ 'DDBC=' + (COLORS[upper(line.background).trim()] || 'WHITE'),
169
+ 'DDTC=' + (COLORS[upper(line.color).trim()] || 'BLACK'),
170
+ 'DDI=' + Math.max(0, entryIndex(line.icon, ICONS)),
171
+ 'DDA=' + (ALIGNMENTS[upper(line.align).trim()] || 'CENTER'),
172
+ 'DDS=' + wrcdText(line.text),
173
+ 'DDID=' + i,
174
+ ].join(','),
175
+ );
176
+ }
177
+
178
+ if (blocks.length > 0) {
179
+ blocks[blocks.length - 1] += ',DDC=true';
180
+ }
181
+
182
+ const number = sound ? entryIndex(sound.sound, SOUNDS) : -1;
183
+ if (number !== -1) {
184
+ blocks.push(
185
+ [
186
+ 'R=' + clamp(sound.repeat, 0, 15, 0),
187
+ // seconds, in the steps of five the CCU's dialog offers
188
+ 'IN=' + Math.round(clamp(sound.interval, 5, 80, 5) / 5) * 5,
189
+ 'ANS=' + number,
190
+ ].join(','),
191
+ );
192
+ }
193
+
194
+ return blocks.map((block) => '{' + block + '}').join(',');
195
+ }
196
+
197
+ module.exports = {ICONS, SOUNDS, LINES, TEXT_LENGTH, wrcdText, wrcdCommand};
@@ -5,6 +5,11 @@
5
5
  anstelle der Konfiguration genutzt.</p>
6
6
  <p>Mit <code>msg.disbleX</code> kann explizit gesetzt werden, dass keine Daten für die Zeile übertragen werden.</p>
7
7
 
8
+ <h3>HmIP-WRCD</h3>
9
+ <p>Der Wandtaster mit E-Paper-Display hat fünf Zeilen mit je 16 Zeichen, je Zeile ein Icon, die Ausrichtung, Textfarbe und Hintergrund (schwarz oder weiß), dazu einen Ton mit Wiederholungen und Abstand. Der Node schreibt alles in einem Befehl auf <code>COMBINED_PARAMETER</code> des Kanals 3. Eine Zeile mit „nicht verändern“ bleibt, wie sie ist.</p>
10
+ <p>Aus der Nachricht: <code>msg.lineX</code> (Text), <code>msg.iconX</code> (Nummer 0 bis 31 oder Name aus <code>DISPLAY_DATA_ICON</code>, z.B. <code>LAMP_ON</code>), <code>msg.colorX</code> und <code>msg.backgroundX</code> (<code>BLACK</code> oder <code>WHITE</code>), <code>msg.alignX</code> (<code>LEFT</code>, <code>CENTER</code>, <code>RIGHT</code>), <code>msg.disableX</code>.</p>
11
+ <p>Umlaute und ß werden für das Display umgesetzt. Komma, Gleichheitszeichen und geschweifte Klammern gehören zum Befehl selbst und werden als Punkt, Doppelpunkt und runde Klammern gesendet; Zeichen, die das Display nicht kennt, entfallen. Der HmIP-WRCD ist noch nicht an einem Gerät erprobt.</p>
12
+
8
13
  <h3>Dynamische Konfiguration</h3>
9
14
  <p><code>msg.config</code> ist ein Objekt, dessen Eigenschaften die Konfiguration dieses Nodes für genau diese Nachricht überschreiben. Die gespeicherte Konfiguration bleibt unverändert.</p>
10
15
  <ul>
@@ -19,6 +24,7 @@
19
24
  <li><code>color1 ... color6</code></li>
20
25
  <li><code>icon1 ... icon6</code></li>
21
26
  <li><code>disable1 ... disable6</code></li>
27
+ <li>HmIP-WRCD: <code>wrcdIcon1 ... wrcdIcon5</code>, <code>wrcdAlign1 ... wrcdAlign5</code>, <code>wrcdColor1 ... wrcdColor5</code>, <code>wrcdBackground1 ... wrcdBackground5</code>, <code>wrcdSound</code> (Nummer 0 bis 7 oder Name aus <code>ACOUSTIC_NOTIFICATION_SELECTION</code>), <code>wrcdRepeat</code> (0 bis 15), <code>wrcdInterval</code> (5 bis 80 Sekunden)</li>
22
28
  </ul>
23
29
  <p><code>msg.line1</code> usw. funktionieren unverändert weiter.</p>
24
30
  </script>