homematic-manager 3.4.0 → 3.4.1

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.
@@ -506,7 +506,7 @@ export class Backend {
506
506
  case 'paramset.valueStates':
507
507
  return this.#manager instanceof LiteInterfaces ? this.#manager.valueStates(p[0], p[1]) : {};
508
508
  case 'paramset.id':
509
- return this.#paramsetId(p[0], p[1]);
509
+ return this.#paramsetId(p[0], p[1], p[2]);
510
510
  case 'channel.mode':
511
511
  return this.#channelMode(p[0], p[1]);
512
512
  case 'paramset.description':
@@ -1365,17 +1365,18 @@ export class Backend {
1365
1365
  /**
1366
1366
  * Task 64: `getParamsetId(address, MASTER)`, once per address and connection. An interface
1367
1367
  * without the method (CUxD, a custom one) or a refusal is `''`, remembered as well, so the
1368
- * dialog falls back to the channel type without asking again.
1368
+ * dialog falls back to the channel type without asking again. Task 108: the same for `LINK`.
1369
1369
  */
1370
- async #paramsetId(interfaceName, address) {
1371
- const key = `${interfaceName}|${address}`;
1370
+ async #paramsetId(interfaceName, address, paramsetType) {
1371
+ const type = paramsetType === 'LINK' ? 'LINK' : 'MASTER';
1372
+ const key = `${interfaceName}|${address}|${type}`;
1372
1373
  const known = this.#paramsetIds.get(key);
1373
1374
  if (known !== undefined) {
1374
1375
  return known;
1375
1376
  }
1376
1377
  let id;
1377
1378
  try {
1378
- const answer = await this.#read(interfaceName, 'getParamsetId', [address, 'MASTER']);
1379
+ const answer = await this.#read(interfaceName, 'getParamsetId', [address, type]);
1379
1380
  id = typeof answer === 'string' ? answer : '';
1380
1381
  }
1381
1382
  catch (error) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homematic-manager/backend",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "type": "module",
5
5
  "description": "Homematic Manager backend: XML-RPC/BIN-RPC clients and callback servers, caches, optional ReGa",
6
6
  "license": "AGPL-3.0-or-later",
@@ -1246,10 +1246,12 @@ export interface ApiMethods {
1246
1246
  };
1247
1247
  /**
1248
1248
  * Task 64: what `getParamsetId(address, MASTER)` answers - the key the WebUI picks a MASTER form
1249
- * by. `''` where the interface has no such method or refuses it; cached per address.
1249
+ * by. `''` where the interface has no such method or refuses it; cached per address. Task 108:
1250
+ * `paramsetType` `LINK` asks for the link easy mode's key instead (a BidCos receiver's
1251
+ * `<paramid>.tcl`); `MASTER` when left out.
1250
1252
  */
1251
1253
  'paramset.id': {
1252
- params: [interfaceName: string, address: string];
1254
+ params: [interfaceName: string, address: string, paramsetType?: 'MASTER' | 'LINK'];
1253
1255
  result: string;
1254
1256
  };
1255
1257
  /**
@@ -153,12 +153,12 @@ export declare class EasyModeEngine {
153
153
  * "Schalter ein" and "Schalter ein / aus" differ in the jump table (`*_JT_ON` 1/3 or 4/6) -
154
154
  * so a toggle link was shown as "switch on", which has more fixed parameters.
155
155
  *
156
- * Order: `UI_HINT` when its profile fits (`0`, the expert view, is taken as it is); otherwise
157
- * the fitting profile the link has the most named parameters of, then the one with more fixed
158
- * parameters (a staircase light is a "switch on" with a fixed time: the more specific one), then
159
- * the one that lacks fewer, then the lower id - the WebUI takes the first fitting one by id, and
160
- * where only one fits, as for B-77's pair, the two agree; last a `UI_HINT` whose profile no
161
- * longer fits, as before.
156
+ * Order: `UI_HINT` when its profile fits (`0`, the expert view, is taken as it is) - the CCU writes
157
+ * it on BidCos, and it names the profile the user chose where two fit; otherwise the first fitting
158
+ * profile by number, as `get_cur_profile2` takes it (task 108: B-77 preferred the profile with the
159
+ * most named, then fixed parameters, which showed a CCU-made "auf / zu & hoch / herunter" link of a
160
+ * wired shutter as "Toggle", where the WebUI shows the former); last a `UI_HINT` whose profile no longer
161
+ * fits, as before.
162
162
  *
163
163
  * `undefined` means "none of them"; the caller then shows the expert view.
164
164
  */
@@ -163,12 +163,12 @@ export class EasyModeEngine {
163
163
  * "Schalter ein" and "Schalter ein / aus" differ in the jump table (`*_JT_ON` 1/3 or 4/6) -
164
164
  * so a toggle link was shown as "switch on", which has more fixed parameters.
165
165
  *
166
- * Order: `UI_HINT` when its profile fits (`0`, the expert view, is taken as it is); otherwise
167
- * the fitting profile the link has the most named parameters of, then the one with more fixed
168
- * parameters (a staircase light is a "switch on" with a fixed time: the more specific one), then
169
- * the one that lacks fewer, then the lower id - the WebUI takes the first fitting one by id, and
170
- * where only one fits, as for B-77's pair, the two agree; last a `UI_HINT` whose profile no
171
- * longer fits, as before.
166
+ * Order: `UI_HINT` when its profile fits (`0`, the expert view, is taken as it is) - the CCU writes
167
+ * it on BidCos, and it names the profile the user chose where two fit; otherwise the first fitting
168
+ * profile by number, as `get_cur_profile2` takes it (task 108: B-77 preferred the profile with the
169
+ * most named, then fixed parameters, which showed a CCU-made "auf / zu & hoch / herunter" link of a
170
+ * wired shutter as "Toggle", where the WebUI shows the former); last a `UI_HINT` whose profile no longer
171
+ * fits, as before.
172
172
  *
173
173
  * `undefined` means "none of them"; the caller then shows the expert view.
174
174
  */
@@ -180,16 +180,11 @@ export class EasyModeEngine {
180
180
  if (byHint && (byHint.id === EXPERT_PROFILE_ID || profileFits(byHint, linkParamset) !== undefined)) {
181
181
  return byHint;
182
182
  }
183
- let best;
184
- let bestFit;
185
- for (const profile of [...profiles].sort((a, b) => a.id - b.id)) {
186
- const fit = profileFits(profile, linkParamset);
187
- if (fit !== undefined && betterFit(fit, bestFit)) {
188
- bestFit = fit;
189
- best = profile;
190
- }
191
- }
192
- return best ?? byHint;
183
+ // task 108: the first fitting profile by number, as `get_cur_profile2` breaks on its first match
184
+ const first = [...profiles]
185
+ .sort((a, b) => a.id - b.id)
186
+ .find((profile) => profile.id !== EXPERT_PROFILE_ID && profileFits(profile, linkParamset) !== undefined);
187
+ return first ?? byHint;
193
188
  }
194
189
  /**
195
190
  * The MASTER paramset of a channel type as the dialog should show it: ordered, with the
@@ -274,16 +269,6 @@ function profileFits(profile, linkParamset) {
274
269
  }
275
270
  return present === 0 ? undefined : { present, fixed, missing };
276
271
  }
277
- /** Whether a fit is the better one: more named parameters, then more fixed ones, then fewer lacking. */
278
- function betterFit(fit, best) {
279
- if (best === undefined)
280
- return true;
281
- if (fit.present !== best.present)
282
- return fit.present > best.present;
283
- if (fit.fixed !== best.fixed)
284
- return fit.fixed > best.fixed;
285
- return fit.missing < best.missing;
286
- }
287
272
  function constraintHolds(constraint, value) {
288
273
  switch (constraint.kind) {
289
274
  case 'fixed':
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Task 108: which receiver folder and sender file of the easy-mode data a link's profiles come
3
+ * from - the step the CCU's WebUI takes before it shows a single profile.
4
+ *
5
+ * `ic_setprofiles.cgi` does not open `<RECEIVER_TYPE>/<SENDER_TYPE>.tcl` directly. It opens
6
+ * `linkHmIP_<RECEIVER_TYPE>.tcl` for an HmIP receiver, or the `<paramid>.tcl` its LINK paramset id
7
+ * names for a BidCos one, and that file chooses the folder and the sender file; inside the folder,
8
+ * a sender file may again be only a dispatcher that sources another by a value read at run time.
9
+ * Looking the profiles up by the raw channel types, as hmm did up to 3.4.0, gave every link whose
10
+ * WebUI file is chosen that way the expert profile only - HmIPW-DRI16/DRI32 inputs above all,
11
+ * whose channels are `MULTI_MODE_INPUT_TRANSMITTER` - or another device's profiles (a wired blind
12
+ * actuator run as a shutter got the blind profiles).
13
+ *
14
+ * The rules below are those of the WebUI's easymode tree (OpenCCU-Base `www/config/easymodes`);
15
+ * `data/extracted/easymode_links.json` is extracted from it by `data/scripts/easymode-links.mjs`,
16
+ * and `linkTypes.test.ts` fails for every rule of it this module does not follow.
17
+ *
18
+ * Pure: whatever has to be read from the interface (a MASTER paramset, the `channelMode`
19
+ * metadata, a LINK paramset id, whether a link exists) is asked through {@link LinkTypeQueries},
20
+ * and only when a rule needs it.
21
+ */
22
+ import type { ParamsetDescription } from '../paramset/description.js';
23
+ import type { Paramset, ParamsetValue } from '../rpc/values.js';
24
+ /** What the device list says about one end of a link. */
25
+ export interface LinkEnd {
26
+ /** The channel address, `<device>:<n>`. */
27
+ readonly address: string;
28
+ /** The channel type (`TYPE`). */
29
+ readonly type: string;
30
+ /** The device type (`PARENT_TYPE`). */
31
+ readonly parentType: string;
32
+ /** The device's firmware (`FIRMWARE` of the parent). */
33
+ readonly firmware?: string;
34
+ /** The channel's key-pair partner (`GROUP`), BidCos only. */
35
+ readonly group?: string;
36
+ }
37
+ /** A MASTER paramset with its description, so an enum read as a name can be turned into its index. */
38
+ export interface MasterRead {
39
+ readonly values: Paramset;
40
+ readonly description?: ParamsetDescription;
41
+ }
42
+ /** The reads a rule may need; each is asked at most once per resolution, and only where a rule needs it. */
43
+ export interface LinkTypeQueries {
44
+ /** `getParamset(address, MASTER)`. */
45
+ readonly master?: (address: string) => Promise<MasterRead | undefined>;
46
+ /** `getMetadata(address, 'channelMode')`; `''` where unset. */
47
+ readonly channelMode?: (address: string) => Promise<string>;
48
+ /** `getParamsetId(address, LINK)`; `''` where the interface does not answer. */
49
+ readonly linkParamsetId?: (address: string) => Promise<string>;
50
+ /** Whether a link `sender → receiver` exists (`getLinkInfo` answers). */
51
+ readonly linked?: (sender: string, receiver: string) => Promise<boolean>;
52
+ }
53
+ /** The receiver folder and sender file of the profile data, where the WebUI takes them from. */
54
+ export interface LinkProfileTypes {
55
+ readonly receiverType: string;
56
+ readonly senderType: string;
57
+ }
58
+ /**
59
+ * The sender files a `MULTI_MODE_INPUT_TRANSMITTER` / `ROTARY_CONTROL_TRANSCEIVER` dispatcher of a
60
+ * receiver folder sources from, and from which folder (the WebUI's `UNIVERSAL_ACTOR` and
61
+ * `UNIVERSAL_LIGHT_RECEIVER_PWM` take `DIMMER_VIRTUAL_RECEIVER`'s files).
62
+ */
63
+ export interface LinkDispatcher {
64
+ readonly by: 'CHANNEL_OPERATION_MODE' | 'channel';
65
+ readonly folder: string;
66
+ /** HmIP-FDC's key mode has a file of its own (`MULTI_MODE_INPUT_TRANSMITTER_1_FDC`). */
67
+ readonly variant?: {
68
+ readonly deviceType: string;
69
+ readonly mode: number;
70
+ readonly suffix: string;
71
+ };
72
+ }
73
+ /** The dispatcher files of the WebUI's receiver folders, by folder and sender type. */
74
+ export declare const LINK_DISPATCHERS: Readonly<Record<string, Readonly<Record<string, LinkDispatcher>>>>;
75
+ /** What a `linkHmIP_<RECEIVER_TYPE>.tcl` does to the sender type. */
76
+ export interface HmipLinkFile {
77
+ /** It reads an HmIP-MOD-RC8 key channel's `CHANNEL_OPERATION_MODE` (2: switch, 3: shutter contact). */
78
+ readonly modRc8: boolean;
79
+ /** `LEVEL_COMMAND_TRANSMITTER_*` senders it opens another sender file for. */
80
+ readonly levelCommand: Readonly<Record<string, string>>;
81
+ }
82
+ /**
83
+ * The WebUI's `linkHmIP_<RECEIVER_TYPE>.tcl` files. An HmIP receiver type without one has no easy
84
+ * mode in the WebUI (`receiver_paramid` stays empty); hmm still offers what the data has for it.
85
+ */
86
+ export declare const HMIP_LINK_FILES: Readonly<Record<string, HmipLinkFile>>;
87
+ /** What a BidCos `<paramid>.tcl` link dispatcher does beyond `<TYPE>/<SENDER_TYPE>.tcl`. */
88
+ export interface BidcosLinkFile {
89
+ /** `HMW_` + type (wired actors), type + `M` (the MP3 chime/LED), or a fixed folder. */
90
+ readonly receiver?: 'HMW_' | 'M' | 'DIMMER';
91
+ /** `VIRTUAL_DIMMER` channels use the `DIMMER` folder. */
92
+ readonly virtualDimmer?: 'DIMMER';
93
+ /** The sender file is `<TYPE>_<INPUT_TYPE>` (the sender's MASTER; `1` where it has none). */
94
+ readonly inputType?: boolean;
95
+ /** The sender file is `<TYPE>_PAIR` when the sender's key-pair partner is linked to the receiver too. */
96
+ readonly pair?: boolean;
97
+ /** A sender of this device type uses `<TYPE><suffix>`. */
98
+ readonly senderSuffix?: {
99
+ readonly deviceType: string;
100
+ readonly suffix: string;
101
+ };
102
+ }
103
+ /** The BidCos link dispatchers that do more than open `<TYPE>/<SENDER_TYPE>.tcl`, by paramset id. */
104
+ export declare const BIDCOS_LINK_FILES: Readonly<Record<string, BidcosLinkFile>>;
105
+ /** Whether an interface is served by hmipserver, where the WebUI takes the `linkHmIP_*` route. */
106
+ export declare function isHmipInterface(interfaceName: string): boolean;
107
+ /**
108
+ * An enum read from a MASTER paramset as the number the WebUI's Tcl compares: HmIP answers the
109
+ * index, a name is looked up in the description's `VALUE_LIST`. `undefined` when neither works.
110
+ */
111
+ export declare function enumValueIndex(value: ParamsetValue | undefined, values: readonly string[] | undefined): number | undefined;
112
+ /**
113
+ * The receiver folder and sender file the WebUI takes a link's profiles from. Without the reads a
114
+ * rule needs (a query missing, failing or answering nothing), the rule leaves the type as it is,
115
+ * which is what hmm did before.
116
+ */
117
+ export declare function linkProfileTypes(interfaceName: string, receiver: LinkEnd, sender: LinkEnd, queries?: LinkTypeQueries): Promise<LinkProfileTypes>;
118
+ //# sourceMappingURL=linkTypes.d.ts.map
@@ -0,0 +1,325 @@
1
+ /**
2
+ * Task 108: which receiver folder and sender file of the easy-mode data a link's profiles come
3
+ * from - the step the CCU's WebUI takes before it shows a single profile.
4
+ *
5
+ * `ic_setprofiles.cgi` does not open `<RECEIVER_TYPE>/<SENDER_TYPE>.tcl` directly. It opens
6
+ * `linkHmIP_<RECEIVER_TYPE>.tcl` for an HmIP receiver, or the `<paramid>.tcl` its LINK paramset id
7
+ * names for a BidCos one, and that file chooses the folder and the sender file; inside the folder,
8
+ * a sender file may again be only a dispatcher that sources another by a value read at run time.
9
+ * Looking the profiles up by the raw channel types, as hmm did up to 3.4.0, gave every link whose
10
+ * WebUI file is chosen that way the expert profile only - HmIPW-DRI16/DRI32 inputs above all,
11
+ * whose channels are `MULTI_MODE_INPUT_TRANSMITTER` - or another device's profiles (a wired blind
12
+ * actuator run as a shutter got the blind profiles).
13
+ *
14
+ * The rules below are those of the WebUI's easymode tree (OpenCCU-Base `www/config/easymodes`);
15
+ * `data/extracted/easymode_links.json` is extracted from it by `data/scripts/easymode-links.mjs`,
16
+ * and `linkTypes.test.ts` fails for every rule of it this module does not follow.
17
+ *
18
+ * Pure: whatever has to be read from the interface (a MASTER paramset, the `channelMode`
19
+ * metadata, a LINK paramset id, whether a link exists) is asked through {@link LinkTypeQueries},
20
+ * and only when a rule needs it.
21
+ */
22
+ const MULTI = 'MULTI_MODE_INPUT_TRANSMITTER';
23
+ const ROTARY = 'ROTARY_CONTROL_TRANSCEIVER';
24
+ const FDC = { deviceType: 'HmIP-FDC', mode: 1, suffix: '_FDC' };
25
+ function multi(folder, variant) {
26
+ return variant ? { by: 'CHANNEL_OPERATION_MODE', folder, variant } : { by: 'CHANNEL_OPERATION_MODE', folder };
27
+ }
28
+ function rotary(folder) {
29
+ return { by: 'channel', folder };
30
+ }
31
+ /** The dispatcher files of the WebUI's receiver folders, by folder and sender type. */
32
+ export const LINK_DISPATCHERS = {
33
+ ACCESS_RECEIVER: { [MULTI]: multi('ACCESS_RECEIVER') },
34
+ ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER: { [MULTI]: multi('ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER') },
35
+ ALARM_SWITCH_VIRTUAL_RECEIVER: { [MULTI]: multi('ALARM_SWITCH_VIRTUAL_RECEIVER') },
36
+ AUTO_RELOCK_TRANSCEIVER: { [MULTI]: multi('AUTO_RELOCK_TRANSCEIVER') },
37
+ BLIND_VIRTUAL_RECEIVER: { [MULTI]: multi('BLIND_VIRTUAL_RECEIVER'), [ROTARY]: rotary('BLIND_VIRTUAL_RECEIVER') },
38
+ DIMMER_VIRTUAL_RECEIVER: { [MULTI]: multi('DIMMER_VIRTUAL_RECEIVER'), [ROTARY]: rotary('DIMMER_VIRTUAL_RECEIVER') },
39
+ DOOR_LOCK_TRANSCEIVER: { [MULTI]: multi('DOOR_LOCK_TRANSCEIVER') },
40
+ DOOR_RECEIVER: { [MULTI]: multi('DOOR_RECEIVER') },
41
+ HEATING_KEY_RECEIVER: { [MULTI]: multi('HEATING_KEY_RECEIVER') },
42
+ SHUTTER_VIRTUAL_RECEIVER: {
43
+ [MULTI]: multi('SHUTTER_VIRTUAL_RECEIVER'),
44
+ [ROTARY]: rotary('SHUTTER_VIRTUAL_RECEIVER'),
45
+ },
46
+ SIMPLE_SWITCH_RECEIVER: { [MULTI]: multi('SIMPLE_SWITCH_RECEIVER') },
47
+ STATE_RESET_RECEIVER: { [MULTI]: multi('STATE_RESET_RECEIVER') },
48
+ SWITCH_VIRTUAL_RECEIVER: {
49
+ [MULTI]: multi('SWITCH_VIRTUAL_RECEIVER', FDC),
50
+ [ROTARY]: rotary('SWITCH_VIRTUAL_RECEIVER'),
51
+ },
52
+ UNIVERSAL_ACTOR: { [MULTI]: multi('DIMMER_VIRTUAL_RECEIVER'), [ROTARY]: rotary('DIMMER_VIRTUAL_RECEIVER') },
53
+ UNIVERSAL_LIGHT_RECEIVER_LSC: {
54
+ [MULTI]: multi('UNIVERSAL_LIGHT_RECEIVER_LSC'),
55
+ [ROTARY]: rotary('UNIVERSAL_LIGHT_RECEIVER_LSC'),
56
+ },
57
+ UNIVERSAL_LIGHT_RECEIVER_PWM: {
58
+ [MULTI]: multi('DIMMER_VIRTUAL_RECEIVER'),
59
+ [ROTARY]: rotary('DIMMER_VIRTUAL_RECEIVER'),
60
+ },
61
+ 'UNIVERSAL_LIGHT_RECEIVER_RGB(W)': { [MULTI]: multi('UNIVERSAL_LIGHT_RECEIVER_RGB(W)') },
62
+ UNIVERSAL_LIGHT_RECEIVER_RGBW_DALI: { [MULTI]: multi('UNIVERSAL_LIGHT_RECEIVER_RGBW_DALI') },
63
+ UNIVERSAL_LIGHT_RECEIVER_TW: { [MULTI]: multi('UNIVERSAL_LIGHT_RECEIVER_TW') },
64
+ WATER_SWITCH_VIRTUAL_RECEIVER: {
65
+ [MULTI]: multi('SWITCH_VIRTUAL_RECEIVER', FDC),
66
+ [ROTARY]: rotary('SWITCH_VIRTUAL_RECEIVER'),
67
+ },
68
+ };
69
+ const LEVEL_COMMAND = {
70
+ LEVEL_COMMAND_TRANSMITTER_CO2: 'COND_SWITCH_TRANSMITTER',
71
+ LEVEL_COMMAND_TRANSMITTER_HUMIDITY: 'COND_SWITCH_TRANSMITTER_HUMIDITY',
72
+ LEVEL_COMMAND_TRANSMITTER_TEMPERATURE: 'COND_SWITCH_TRANSMITTER_TEMPERATURE',
73
+ };
74
+ const file = (modRc8, levelCommand = {}) => ({
75
+ modRc8,
76
+ levelCommand,
77
+ });
78
+ /**
79
+ * The WebUI's `linkHmIP_<RECEIVER_TYPE>.tcl` files. An HmIP receiver type without one has no easy
80
+ * mode in the WebUI (`receiver_paramid` stays empty); hmm still offers what the data has for it.
81
+ */
82
+ export const HMIP_LINK_FILES = {
83
+ ACCESS_RECEIVER: file(true),
84
+ ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER: file(true, LEVEL_COMMAND),
85
+ ALARM_COND_SWITCH_RECEIVER: file(false),
86
+ ALARM_SWITCH_VIRTUAL_RECEIVER: file(true, LEVEL_COMMAND),
87
+ AUTO_RELOCK_TRANSCEIVER: file(true),
88
+ BLIND_VIRTUAL_RECEIVER: file(true, LEVEL_COMMAND),
89
+ CLIMATECONTROL_FLOOR_PUMP_TRANSCEIVER: file(false),
90
+ CLIMATECONTROL_FLOOR_TRANSCEIVER: file(false),
91
+ CLIMATECONTROL_INPUT_RECEIVER: file(false),
92
+ DIMMER_VIRTUAL_RECEIVER: file(true, LEVEL_COMMAND),
93
+ DOOR_LOCK_TRANSCEIVER: file(true),
94
+ DOOR_RECEIVER: file(true),
95
+ HEATING_CLIMATECONTROL_CL_RECEIVER: file(false),
96
+ HEATING_CLIMATECONTROL_RECEIVER: file(false),
97
+ HEATING_KEY_RECEIVER: file(false),
98
+ HEATING_ROOM_TH_RECEIVER: file(false),
99
+ HEATING_SHUTTER_CONTACT_RECEIVER: file(false),
100
+ OPTICAL_SIGNAL_RECEIVER: file(true),
101
+ SERVO_VIRTUAL_RECEIVER: file(true),
102
+ SHUTTER_VIRTUAL_RECEIVER: file(true, LEVEL_COMMAND),
103
+ SIMPLE_SWITCH_RECEIVER: file(true),
104
+ STATE_RESET_RECEIVER: file(false),
105
+ SWITCH_TRANSCEIVER: file(true, LEVEL_COMMAND),
106
+ // the only one that keeps the CO2 sender apart
107
+ SWITCH_VIRTUAL_RECEIVER: file(true, {
108
+ ...LEVEL_COMMAND,
109
+ LEVEL_COMMAND_TRANSMITTER_CO2: 'COND_SWITCH_TRANSMITTER_CO2',
110
+ }),
111
+ UNIVERSAL_LIGHT_RECEIVER: file(true, LEVEL_COMMAND),
112
+ WATER_SWITCH_VIRTUAL_RECEIVER: file(true, LEVEL_COMMAND),
113
+ WINDOW_DRIVE_RECEIVER: file(false, LEVEL_COMMAND),
114
+ };
115
+ const WDS100 = { senderSuffix: { deviceType: 'HM-WDS100-C6-O-2', suffix: '_2' } };
116
+ /** The BidCos link dispatchers that do more than open `<TYPE>/<SENDER_TYPE>.tcl`, by paramset id. */
117
+ export const BIDCOS_LINK_FILES = {
118
+ alarmactuator_ch_link: WDS100,
119
+ blind_ch_link: WDS100,
120
+ dimmer_ch_link: { virtualDimmer: 'DIMMER' },
121
+ dw_controller_brightness_ch_link: { receiver: 'DIMMER' },
122
+ hmw_blind_ch_link: { receiver: 'HMW_', inputType: true },
123
+ hmw_dimmer_ch_link: { receiver: 'HMW_', inputType: true },
124
+ hmw_switch_ch_link: { receiver: 'HMW_', inputType: true },
125
+ jalousie_ch_link: WDS100,
126
+ signal_chime_ch_link: { pair: true },
127
+ signal_led_ch_link: { pair: true },
128
+ signal_mchime_ch_link: { receiver: 'M', pair: true },
129
+ signal_mled_ch_link: { receiver: 'M', pair: true },
130
+ statusindicator_ch_link: WDS100,
131
+ switch_ch_link: WDS100,
132
+ };
133
+ /** Whether an interface is served by hmipserver, where the WebUI takes the `linkHmIP_*` route. */
134
+ export function isHmipInterface(interfaceName) {
135
+ return interfaceName.startsWith('HmIP');
136
+ }
137
+ /**
138
+ * An enum read from a MASTER paramset as the number the WebUI's Tcl compares: HmIP answers the
139
+ * index, a name is looked up in the description's `VALUE_LIST`. `undefined` when neither works.
140
+ */
141
+ export function enumValueIndex(value, values) {
142
+ if (typeof value === 'number')
143
+ return value;
144
+ if (typeof value === 'boolean')
145
+ return value ? 1 : 0;
146
+ if (typeof value !== 'string' || value === '')
147
+ return undefined;
148
+ if (/^\d+$/u.test(value))
149
+ return Number(value);
150
+ const at = values?.indexOf(value) ?? -1;
151
+ return at >= 0 ? at : undefined;
152
+ }
153
+ /** `x.y.z` >= `major.minor`, as `linkHmIP_BLIND_VIRTUAL_RECEIVER.tcl` compares a firmware. */
154
+ function firmwareAtLeast(firmware, major, minor) {
155
+ const [a = 'x', b = 'x'] = (firmware ?? '').split('.');
156
+ const fwMajor = Number.parseInt(a, 10);
157
+ const fwMinor = Number.parseInt(b, 10);
158
+ if (Number.isNaN(fwMajor) || Number.isNaN(fwMinor))
159
+ return false;
160
+ return fwMajor > major || (fwMajor === major && fwMinor >= minor);
161
+ }
162
+ function channelNumber(address) {
163
+ return address.slice(address.lastIndexOf(':') + 1);
164
+ }
165
+ function deviceAddress(address) {
166
+ const at = address.lastIndexOf(':');
167
+ return at < 0 ? address : address.slice(0, at);
168
+ }
169
+ /** One MASTER read per address within one resolution. */
170
+ function cachedMaster(queries) {
171
+ const cache = new Map();
172
+ return (address) => {
173
+ let entry = cache.get(address);
174
+ if (!entry) {
175
+ entry = (queries.master?.(address) ?? Promise.resolve(undefined)).catch(() => undefined);
176
+ cache.set(address, entry);
177
+ }
178
+ return entry;
179
+ };
180
+ }
181
+ async function masterEnum(master, address, param) {
182
+ const read = await master(address);
183
+ return enumValueIndex(read?.values[param], read?.description?.[param]?.VALUE_LIST);
184
+ }
185
+ async function ask(question, fallback) {
186
+ if (!question)
187
+ return fallback;
188
+ try {
189
+ return await question();
190
+ }
191
+ catch {
192
+ return fallback;
193
+ }
194
+ }
195
+ /** `linkHmIP_<TYPE>.tcl`'s receiver part: the folder its profiles come from. */
196
+ async function hmipReceiver(receiver, queries, master) {
197
+ const { type, parentType } = receiver;
198
+ if (type === 'BLIND_VIRTUAL_RECEIVER') {
199
+ const wired = parentType.split('-')[0] === 'HmIPW' || parentType === 'HmIP-DRBLI4' || parentType === 'HmIP-FBL';
200
+ if (wired && firmwareAtLeast(receiver.firmware, 1, 6)) {
201
+ const mode = await ask(() => queries.channelMode?.(receiver.address) ?? Promise.resolve(''), '');
202
+ return mode === '' || mode === 'shutter' ? 'SHUTTER_VIRTUAL_RECEIVER' : 'BLIND_VIRTUAL_RECEIVER';
203
+ }
204
+ return type;
205
+ }
206
+ if (type === 'DIMMER_VIRTUAL_RECEIVER' && (parentType === 'HmIP-WUA' || parentType === 'ELV-SH-WUA')) {
207
+ return 'UNIVERSAL_ACTOR';
208
+ }
209
+ if (type === 'UNIVERSAL_LIGHT_RECEIVER') {
210
+ if (parentType === 'HmIP-RGBW') {
211
+ // 0 = RGBW, 1 = RGB, 2 = tunable white, 3 = PWM
212
+ const mode = await masterEnum(master, `${deviceAddress(receiver.address)}:0`, 'DEVICE_OPERATION_MODE');
213
+ if (mode === 0 || mode === 1)
214
+ return 'UNIVERSAL_LIGHT_RECEIVER_RGB(W)';
215
+ if (mode === 2)
216
+ return 'UNIVERSAL_LIGHT_RECEIVER_TW';
217
+ if (mode === 3)
218
+ return 'UNIVERSAL_LIGHT_RECEIVER_PWM';
219
+ return type;
220
+ }
221
+ if (parentType === 'HmIP-DRG-DALI') {
222
+ // 0 = switch, 1 = dimmer (PWM), 2 = tunable white, 3/4 = RGB + tunable white
223
+ const mode = await masterEnum(master, receiver.address, 'UNIVERSAL_LIGHT_MAX_CAPABILITIES');
224
+ if (mode === 0)
225
+ return 'SWITCH_VIRTUAL_RECEIVER';
226
+ if (mode === 1)
227
+ return 'UNIVERSAL_LIGHT_RECEIVER_PWM';
228
+ if (mode === 2)
229
+ return 'UNIVERSAL_LIGHT_RECEIVER_TW';
230
+ if (mode === 3 || mode === 4)
231
+ return 'UNIVERSAL_LIGHT_RECEIVER_RGBW_DALI';
232
+ return type;
233
+ }
234
+ if (parentType === 'HmIP-LSC')
235
+ return 'UNIVERSAL_LIGHT_RECEIVER_LSC';
236
+ return type;
237
+ }
238
+ if (type === 'OPTICAL_SIGNAL_RECEIVER')
239
+ return 'DIMMER_VIRTUAL_RECEIVER';
240
+ if (type === 'SWITCH_TRANSCEIVER')
241
+ return 'SWITCH_VIRTUAL_RECEIVER';
242
+ return type;
243
+ }
244
+ /** `linkHmIP_<TYPE>.tcl`'s sender part. */
245
+ async function hmipSender(receiver, sender, master) {
246
+ const rules = HMIP_LINK_FILES[receiver.type];
247
+ if (!rules)
248
+ return sender.type;
249
+ if (rules.modRc8 && sender.type === 'KEY_TRANSCEIVER' && sender.parentType === 'HmIP-MOD-RC8') {
250
+ const mode = await masterEnum(master, sender.address, 'CHANNEL_OPERATION_MODE');
251
+ if (mode === 2)
252
+ return 'SWITCH_TRANSCEIVER';
253
+ if (mode === 3)
254
+ return 'SHUTTER_CONTACT';
255
+ return sender.type;
256
+ }
257
+ return rules.levelCommand[sender.type] ?? sender.type;
258
+ }
259
+ /** A dispatcher file inside the receiver folder: the folder and sender file it sources. */
260
+ async function dispatch(folder, senderType, receiver, sender, master) {
261
+ const dispatcher = LINK_DISPATCHERS[folder]?.[senderType];
262
+ if (!dispatcher)
263
+ return { receiverType: folder, senderType };
264
+ if (dispatcher.by === 'channel') {
265
+ return { receiverType: dispatcher.folder, senderType: `${senderType}_${channelNumber(sender.address)}` };
266
+ }
267
+ const mode = await masterEnum(master, sender.address, 'CHANNEL_OPERATION_MODE');
268
+ if (mode === undefined)
269
+ return { receiverType: folder, senderType };
270
+ const variant = dispatcher.variant && receiver.parentType === dispatcher.variant.deviceType && mode === dispatcher.variant.mode
271
+ ? dispatcher.variant.suffix
272
+ : '';
273
+ return { receiverType: dispatcher.folder, senderType: `${senderType}_${String(mode)}${variant}` };
274
+ }
275
+ async function bidcosTypes(receiver, sender, queries, master) {
276
+ const answer = await ask(() => queries.linkParamsetId?.(receiver.address) ?? Promise.resolve(''), '');
277
+ // the WebUI's getExistingParamId: the first id of the (Tcl) list it has a file for
278
+ const paramid = answer
279
+ .trim()
280
+ .split(/\s+/u)
281
+ .map((word) => (word.includes('=') ? (word.split('=')[1] ?? '') : word))
282
+ .find((id) => Object.prototype.hasOwnProperty.call(BIDCOS_LINK_FILES, id));
283
+ const rules = paramid === undefined ? undefined : BIDCOS_LINK_FILES[paramid];
284
+ if (!rules)
285
+ return { receiverType: receiver.type, senderType: sender.type };
286
+ let receiverType = receiver.type;
287
+ if (rules.receiver === 'HMW_')
288
+ receiverType = `HMW_${receiver.type}`;
289
+ else if (rules.receiver === 'M')
290
+ receiverType = `${receiver.type}M`;
291
+ else if (rules.receiver === 'DIMMER')
292
+ receiverType = 'DIMMER';
293
+ if (rules.virtualDimmer && receiver.type === 'VIRTUAL_DIMMER')
294
+ receiverType = rules.virtualDimmer;
295
+ let senderType = sender.type;
296
+ if (rules.senderSuffix && sender.parentType === rules.senderSuffix.deviceType) {
297
+ senderType += rules.senderSuffix.suffix;
298
+ }
299
+ if (rules.inputType) {
300
+ // `set IO "_1"` for a virtual key, `_$hmw(INPUT_TYPE)` where the sender has it
301
+ senderType += `_${String((await masterEnum(master, sender.address, 'INPUT_TYPE')) ?? 1)}`;
302
+ }
303
+ if (rules.pair && sender.group !== undefined && sender.group !== '') {
304
+ const group = sender.group;
305
+ const linked = await ask(() => queries.linked?.(group, receiver.address) ?? Promise.resolve(false), false);
306
+ if (linked)
307
+ senderType += '_PAIR';
308
+ }
309
+ return { receiverType, senderType };
310
+ }
311
+ /**
312
+ * The receiver folder and sender file the WebUI takes a link's profiles from. Without the reads a
313
+ * rule needs (a query missing, failing or answering nothing), the rule leaves the type as it is,
314
+ * which is what hmm did before.
315
+ */
316
+ export async function linkProfileTypes(interfaceName, receiver, sender, queries = {}) {
317
+ const master = cachedMaster(queries);
318
+ if (!isHmipInterface(interfaceName)) {
319
+ return bidcosTypes(receiver, sender, queries, master);
320
+ }
321
+ const folder = await hmipReceiver(receiver, queries, master);
322
+ const senderType = await hmipSender(receiver, sender, master);
323
+ return dispatch(folder, senderType, receiver, sender, master);
324
+ }
325
+ //# sourceMappingURL=linkTypes.js.map
@@ -30,6 +30,7 @@ export * from './paramset/diff.js';
30
30
  export * from './paramset/multiApply.js';
31
31
  export * from './easymodes/engine.js';
32
32
  export * from './easymodes/form.js';
33
+ export * from './easymodes/linkTypes.js';
33
34
  export * from './serviceMessages/index.js';
34
35
  export * from './rssi/index.js';
35
36
  export * from './events/ringBuffer.js';
@@ -34,6 +34,7 @@ export * from './paramset/multiApply.js';
34
34
  // Easy modes and the MASTER metadata layer
35
35
  export * from './easymodes/engine.js';
36
36
  export * from './easymodes/form.js';
37
+ export * from './easymodes/linkTypes.js';
37
38
  // State the tabs show
38
39
  export * from './serviceMessages/index.js';
39
40
  export * from './rssi/index.js';
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homematic-manager/core",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "type": "module",
5
5
  "description": "Pure domain logic of the Homematic Manager: no I/O, no DOM",
6
6
  "license": "AGPL-3.0-or-later",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homematic-manager",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "type": "module",
5
5
  "description": "Configure and administer Homematic and HomematicIP devices - devices and channels, direct links, paramsets, RSSI, service messages, events and an RPC console - from a local HTTP/WebSocket server that also serves the web UI",
6
6
  "keywords": [
@@ -67,8 +67,8 @@
67
67
  "hm-simulator": "^1.4.0"
68
68
  },
69
69
  "dependencies": {
70
- "@homematic-manager/backend": "3.4.0",
71
- "@homematic-manager/core": "3.4.0",
70
+ "@homematic-manager/backend": "3.4.1",
71
+ "@homematic-manager/core": "3.4.1",
72
72
  "binrpc": "^4.2.0",
73
73
  "homematic-rega": "^2.0.0",
74
74
  "homematic-xmlrpc": "^2.0.0",