homematic-manager 3.3.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.
@@ -35,6 +35,8 @@ export declare const SERVICE_MESSAGE_POLL_MS = 300000;
35
35
  export declare const REGA_CONNECT_WAIT_MS = 3000;
36
36
  /** How long the HmIP `getParamset(:0, VALUES)` sweep waits for the device list to settle. */
37
37
  export declare const HMIP_SWEEP_DELAY_MS = 1000;
38
+ /** Task 107: the addon's id on openccu-lite (`files/openccu-lite.json`), whose token the system mints. */
39
+ export declare const ADDON_ID = "hmm";
38
40
  export interface BackendOptions extends Omit<ConfigStoreOptions, 'version'> {
39
41
  /** `AppConfig.version`; the host passes its package version. */
40
42
  readonly version?: string;
@@ -92,6 +94,14 @@ export interface BackendOptions extends Omit<ConfigStoreOptions, 'version'> {
92
94
  /** Task 72: the same for the openccu-lite path of a remote connection. */
93
95
  readonly createLiteInterfaces?: (options: LiteInterfacesOptions) => LiteInterfaces;
94
96
  readonly liteOptions?: Partial<LiteInterfacesOptions>;
97
+ /**
98
+ * Task 107: the addon's id on openccu-lite, whose own API token the system mints from the
99
+ * manifest's `api_scopes` into `<addonTokenDir>/<id>.api`. Read when the connection is `local`:
100
+ * the token found there is what makes the interfaces go through lite-rpc on the system itself.
101
+ * `hmm` unless a test says otherwise; the directory is occulite-client's default.
102
+ */
103
+ readonly addonId?: string;
104
+ readonly addonTokenDir?: string;
95
105
  /** Task 72: occulite-client's `pair()`, replaced by the tests. */
96
106
  readonly pair?: PairWithSystemOptions['pair'];
97
107
  readonly createRega?: (options: RegaServiceOptions) => RegaService;
@@ -26,8 +26,9 @@ import { BackendError, configError, connectionError, errorMessage, internalError
26
26
  import { DEFAULT_IDLE_UNSUBSCRIBE_MS, InterfaceManager, LOOPBACK_IP, callbackBindHost, firstBidcosInterfaceAddress, } from '../interfaces/manager.js';
27
27
  import { LiteInterfaces } from '../interfaces/lite.js';
28
28
  import { HeatingGroupsClient } from '../groups/client.js';
29
- import { MetaService, hostBaseUrl } from '../meta/service.js';
29
+ import { MetaService, hostBaseUrl, metaBaseUrl } from '../meta/service.js';
30
30
  import { DETECT_TIMEOUT_MS, detectSystem, pairWithSystem, testSystem, transportFor, } from '../meta/system.js';
31
+ import { nodeAuth } from 'occulite-client/node';
31
32
  import { RegaService } from '../rega/client.js';
32
33
  import { listDevicesAnswer } from '../rpc/server.js';
33
34
  import { ApiEventEmitter } from '../util/emitter.js';
@@ -51,6 +52,8 @@ export const REGA_CONNECT_WAIT_MS = 3000;
51
52
  const OWN_PARAMSETS = new Set(['MASTER', 'VALUES', 'SERVICE', 'ROUTING_TABLE']);
52
53
  /** How long the HmIP `getParamset(:0, VALUES)` sweep waits for the device list to settle. */
53
54
  export const HMIP_SWEEP_DELAY_MS = 1000;
55
+ /** Task 107: the addon's id on openccu-lite (`files/openccu-lite.json`), whose token the system mints. */
56
+ export const ADDON_ID = 'hmm';
54
57
  /**
55
58
  * An HmIP interface, by name or by interface type - the same rule the UI's settings dialog uses to
56
59
  * count the messages it asks about (task 34), so the question and the writes agree.
@@ -88,6 +91,12 @@ export class Backend {
88
91
  #manager;
89
92
  /** Task 72: counts the connects, so a connect that waited for the probe knows it is still the current one. */
90
93
  #connectSeq = 0;
94
+ /**
95
+ * Task 107: the addon's own API token, read at every connect of a `local` connection. Found,
96
+ * the host is an openccu-lite system that minted it (nothing else writes that directory), and
97
+ * the settings dialog may offer the choice between lite-rpc and the direct connection.
98
+ */
99
+ #addonToken;
91
100
  /** Task 72: the pairing with an openccu-lite system that is running, if any. */
92
101
  #pairing;
93
102
  #rega;
@@ -497,7 +506,7 @@ export class Backend {
497
506
  case 'paramset.valueStates':
498
507
  return this.#manager instanceof LiteInterfaces ? this.#manager.valueStates(p[0], p[1]) : {};
499
508
  case 'paramset.id':
500
- return this.#paramsetId(p[0], p[1]);
509
+ return this.#paramsetId(p[0], p[1], p[2]);
501
510
  case 'channel.mode':
502
511
  return this.#channelMode(p[0], p[1]);
503
512
  case 'paramset.description':
@@ -611,7 +620,7 @@ export class Backend {
611
620
  return runWithOrigin('background', () => this.#connectNow());
612
621
  }
613
622
  async #connectNow() {
614
- const connection = this.#config.connection;
623
+ const configured = this.#config.connection;
615
624
  const seq = ++this.#connectSeq;
616
625
  this.#paramsetIds.clear();
617
626
  this.#noServiceMessages.clear();
@@ -624,7 +633,29 @@ export class Backend {
624
633
  // the probe waited for - for everybody else (the addon on the system, a profile without a
625
634
  // token, every CCU) it runs alongside the interface start as before (D-40's rule: a host
626
635
  // that swallows the packet holds up the names, never the interfaces).
627
- const token = (connection.metaToken ?? '').trim();
636
+ // Task 107: on the system itself the addon's own token decides. The system mints it from
637
+ // the manifest's scopes at every start, so finding it means "this is openccu-lite, and
638
+ // lite-rpc is open to us": the profile is moved to lite-rpc once (the marker says whether
639
+ // that happened before), and then its choice holds - `direct` keeps the callbacks.
640
+ let localLite = false;
641
+ if (configured.local === true) {
642
+ this.#addonToken = await this.#readAddonToken();
643
+ if (this.#superseded(seq)) {
644
+ return;
645
+ }
646
+ if (this.#addonToken !== undefined) {
647
+ await this.#migrateLocalRpc();
648
+ if (this.#superseded(seq)) {
649
+ return;
650
+ }
651
+ localLite = this.#config.connection.localRpc !== 'direct';
652
+ }
653
+ else if (configured.localRpc === 'lite') {
654
+ this.#notice('info', 'the profile asks for lite-rpc, but the system minted no API token for this addon (an openccu-lite before task 107, or a CCU): the interfaces are reached directly, with callbacks');
655
+ }
656
+ }
657
+ const connection = this.#config.connection;
658
+ const token = localLite ? this.#addonToken : (connection.metaToken ?? '').trim();
628
659
  const mayBeRemoteLite = connection.local !== true && token !== '';
629
660
  let hostProbe;
630
661
  let liteProbe;
@@ -639,6 +670,7 @@ export class Backend {
639
670
  else {
640
671
  hostProbe = this.#probeHost(connection);
641
672
  }
673
+ const useLite = localLite || liteProbe?.answer !== undefined;
642
674
  const shared = {
643
675
  connection,
644
676
  handler: this.#callbackHandler(),
@@ -654,10 +686,11 @@ export class Backend {
654
686
  },
655
687
  originOf: currentOrigin,
656
688
  };
657
- const manager = liteProbe?.answer !== undefined
689
+ const manager = useLite
658
690
  ? (this.#options.createLiteInterfaces ?? ((options) => new LiteInterfaces(options)))({
659
691
  ...shared,
660
- baseUrl: liteProbe.baseUrl ?? hostBaseUrl(connection),
692
+ // on the system: the loopback lighttpd (or `metaUrl`, the integration tests' door)
693
+ baseUrl: localLite ? metaBaseUrl(connection) : (liteProbe?.baseUrl ?? hostBaseUrl(connection)),
661
694
  token,
662
695
  transport: transportFor({
663
696
  fetch: this.#options.metaOptions?.fetch,
@@ -680,16 +713,17 @@ export class Backend {
680
713
  ...(this.#options.watchdogIntervalMs === undefined
681
714
  ? {}
682
715
  : { watchdogIntervalMs: this.#options.watchdogIntervalMs }),
683
- ...(this.#options.localAddresses === undefined
684
- ? {}
685
- : { localAddresses: this.#options.localAddresses }),
716
+ ...(this.#options.localAddresses === undefined ? {} : { localAddresses: this.#options.localAddresses }),
686
717
  ...(this.#options.network === undefined ? {} : { network: this.#options.network }),
687
718
  ...(this.#keepsConfiguredCallbackIp() ? { keepConfiguredCallbackIp: true } : {}),
688
719
  ...(this.#options.now === undefined ? {} : { now: this.#options.now }),
689
720
  ...this.#options.interfaceManagerOptions,
690
721
  });
691
722
  this.#manager = manager;
692
- if (liteProbe?.answer !== undefined) {
723
+ if (localLite) {
724
+ this.#notice('info', "this openccu-lite system: the interfaces are reached through its lite-rpc with the addon's own token, without callbacks (the direct connection is selectable in the settings)");
725
+ }
726
+ else if (liteProbe?.answer !== undefined) {
693
727
  this.#notice('info', `${connection.host}: an openccu-lite system - the interfaces are reached through its lite-rpc with the API token, without callbacks`);
694
728
  }
695
729
  try {
@@ -756,6 +790,39 @@ export class Backend {
756
790
  // B-70: counted from the start (or the reconnect of a save) when no page is open
757
791
  this.#armIdleTimer();
758
792
  }
793
+ /** Disconnected, or another connect started, while this one was waiting (read through a call, so an `await` cannot narrow it away). */
794
+ #superseded(seq) {
795
+ return this.#stopped || seq !== this.#connectSeq;
796
+ }
797
+ /** Task 107: the addon's own API token on openccu-lite, or `undefined` everywhere else. */
798
+ async #readAddonToken() {
799
+ const found = await nodeAuth({ addon: this.#options.addonId ?? ADDON_ID }, this.#options.addonTokenDir === undefined ? {} : { addonTokenDir: this.#options.addonTokenDir }).resolve('start');
800
+ const token = found.token?.trim() ?? '';
801
+ return token === '' ? undefined : token;
802
+ }
803
+ /**
804
+ * Task 107: the one-time move of a `local` profile to lite-rpc, on the first connect on
805
+ * openccu-lite that found the addon's token. A profile that was never moved - every one of an
806
+ * earlier version, which connected directly, and a fresh one - gets `localRpc: 'lite'` and the
807
+ * marker; a profile that carries the marker is left exactly as it is, whatever it says, so a
808
+ * `direct` the user chose afterwards survives every restart and update.
809
+ */
810
+ async #migrateLocalRpc() {
811
+ const connection = this.#config.connection;
812
+ if (connection.connectionMigrated === 1) {
813
+ return;
814
+ }
815
+ const moved = connection.localRpc === undefined;
816
+ const config = this.#withHostFacts(await this.#config.setConnection({
817
+ ...connection,
818
+ ...(moved ? { localRpc: 'lite' } : {}),
819
+ connectionMigrated: 1,
820
+ }));
821
+ this.events.emit('config.changed', config);
822
+ if (moved) {
823
+ this.#notice('info', 'connection: moved to lite-rpc, the default on openccu-lite - once; the direct connection with callbacks stays selectable in the settings and is never changed again');
824
+ }
825
+ }
759
826
  /**
760
827
  * B-62: whether the connection's own host is an openccu-lite system - decided from what exists,
761
828
  * openccu-lite's own rule (D-40): `GET /api/meta/v1/version` on the host itself answers
@@ -1167,6 +1234,9 @@ export class Backend {
1167
1234
  ...(ports === undefined ? {} : { callbackDefaultPorts: { xmlrpc: ports.xmlrpc, binrpc: ports.binrpc } }),
1168
1235
  ...(pins === undefined ? {} : { callbackPinned: { ...pins } }),
1169
1236
  ...(publish ? { publishCallbackPorts: true } : {}),
1237
+ // task 107: the addon's token was found, so the host is an openccu-lite system and the
1238
+ // settings dialog may offer lite-rpc or the direct connection
1239
+ ...(this.#addonToken === undefined ? {} : { liteSystem: true }),
1170
1240
  // B-70: only a host that goes idle offers the time; the default of an unpinned host is
1171
1241
  // D-31's default (never, since B-95), whatever it was started with, so "the default" means one thing
1172
1242
  ...(idle === undefined
@@ -1295,17 +1365,18 @@ export class Backend {
1295
1365
  /**
1296
1366
  * Task 64: `getParamsetId(address, MASTER)`, once per address and connection. An interface
1297
1367
  * without the method (CUxD, a custom one) or a refusal is `''`, remembered as well, so the
1298
- * 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`.
1299
1369
  */
1300
- async #paramsetId(interfaceName, address) {
1301
- const key = `${interfaceName}|${address}`;
1370
+ async #paramsetId(interfaceName, address, paramsetType) {
1371
+ const type = paramsetType === 'LINK' ? 'LINK' : 'MASTER';
1372
+ const key = `${interfaceName}|${address}|${type}`;
1302
1373
  const known = this.#paramsetIds.get(key);
1303
1374
  if (known !== undefined) {
1304
1375
  return known;
1305
1376
  }
1306
1377
  let id;
1307
1378
  try {
1308
- const answer = await this.#read(interfaceName, 'getParamsetId', [address, 'MASTER']);
1379
+ const answer = await this.#read(interfaceName, 'getParamsetId', [address, type]);
1309
1380
  id = typeof answer === 'string' ? answer : '';
1310
1381
  }
1311
1382
  catch (error) {
@@ -6,7 +6,7 @@
6
6
  * have - is caught here rather than at the first `init` call, where the error would arrive as a
7
7
  * socket timeout twenty seconds later.
8
8
  */
9
- import { DEFAULT_INTERFACES, INTERFACE_NAMES, META_PROVIDERS, isKnownInterface, resolveInterface, resolveUserDefinedInterface, validateUserDefinedInterface, } from '@homematic-manager/core';
9
+ import { DEFAULT_INTERFACES, INTERFACE_NAMES, LOCAL_RPC_CHOICES, META_PROVIDERS, isKnownInterface, resolveInterface, resolveUserDefinedInterface, validateUserDefinedInterface, } from '@homematic-manager/core';
10
10
  /**
11
11
  * Minimum pause between two writes to one interface.
12
12
  *
@@ -85,6 +85,12 @@ export function normaliseConnection(input) {
85
85
  const metaProvider = META_PROVIDERS.find((candidate) => candidate === raw.metaProvider);
86
86
  const metaToken = stringOr(raw.metaToken, '').trim();
87
87
  const metaUrl = stringOr(raw.metaUrl, '').trim();
88
+ // Task 107: the addon's way to the interfaces on openccu-lite, and the marker that the
89
+ // one-time move to lite-rpc has run. A value that is neither choice is dropped (the backend
90
+ // then treats the profile as never migrated, which is the safe reading); the marker is kept
91
+ // only as the `1` this version writes.
92
+ const localRpc = LOCAL_RPC_CHOICES.find((candidate) => candidate === raw.localRpc);
93
+ const connectionMigrated = raw.connectionMigrated === 1 ? 1 : undefined;
88
94
  const connection = {
89
95
  host: stringOr(raw.host, defaults.host).trim(),
90
96
  interfaces: interfaces.length > 0 ? [...new Set(interfaces)] : defaults.interfaces,
@@ -92,6 +98,8 @@ export function normaliseConnection(input) {
92
98
  extraInterfaces,
93
99
  tls: typeof raw.tls === 'boolean' ? raw.tls : defaults.tls,
94
100
  ...(raw.local === true ? { local: true } : {}),
101
+ ...(localRpc === undefined ? {} : { localRpc }),
102
+ ...(connectionMigrated === undefined ? {} : { connectionMigrated }),
95
103
  rega: typeof raw.rega === 'boolean' ? raw.rega : defaults.rega,
96
104
  callback: {
97
105
  ip: stringOr(callback['ip'], defaults.callback.ip).trim(),
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homematic-manager/backend",
3
- "version": "3.3.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",
@@ -32,6 +32,23 @@ export interface ConnectionConfig {
32
32
  * and no CCU authentication. What the addon of task 13 sets; `local` wins over `tls`.
33
33
  */
34
34
  local?: boolean;
35
+ /**
36
+ * Task 107: how the addon on an openccu-lite system (`local`) reaches the interface processes.
37
+ *
38
+ * `lite` (the default) goes through the system's lite-rpc with the addon's own API token - one
39
+ * subscriber at the daemons for every client, the events replayed after a break, nothing
40
+ * registered with `init`; `direct` keeps the CCU way, XML-RPC/BIN-RPC on the processes' own
41
+ * ports with callback servers, for whoever wants it (CUxD, say, which lite-rpc does not carry).
42
+ * Read only on a system that minted the addon's token; a CCU connects directly whatever it says.
43
+ */
44
+ localRpc?: LocalRpcChoice;
45
+ /**
46
+ * Task 107: the one-time move to lite-rpc has run (`1`). A profile that connected directly to
47
+ * the interfaces is moved to `lite` once, at the first start on openccu-lite that finds the
48
+ * addon's token; from then on the choice is the user's, and a later version never moves it
49
+ * again - so `direct` chosen afterwards stays `direct` across restarts and updates.
50
+ */
51
+ connectionMigrated?: number;
35
52
  auth?: {
36
53
  user: string;
37
54
  password: string;
@@ -260,6 +277,12 @@ export interface AppConfig {
260
277
  defaultMs: number;
261
278
  pinnedMs?: number;
262
279
  };
280
+ /**
281
+ * Task 107: the host runs as the addon on an openccu-lite system that minted its API token, so
282
+ * the settings dialog offers {@link ConnectionConfig.localRpc}. A property of the host, learnt at
283
+ * the connect; absent everywhere else, where the choice means nothing.
284
+ */
285
+ liteSystem?: boolean;
263
286
  }
264
287
  /**
265
288
  * B-53 (#162, #165): why the automatic callback address is the one it is.
@@ -496,6 +519,10 @@ export type NameMap = Record<string, string>;
496
519
  export type MetaProviderChoice = 'auto' | 'local' | 'occulite' | 'rega';
497
520
  /** The values of {@link MetaProviderChoice} as a runtime list, for validation and a select. */
498
521
  export declare const META_PROVIDERS: readonly MetaProviderChoice[];
522
+ /** Task 107: {@link ConnectionConfig.localRpc} - the addon's way to the interfaces on openccu-lite. */
523
+ export type LocalRpcChoice = 'lite' | 'direct';
524
+ /** The values of {@link LocalRpcChoice} as a runtime list, for validation and a select. */
525
+ export declare const LOCAL_RPC_CHOICES: readonly LocalRpcChoice[];
499
526
  /**
500
527
  * D-40: which store the names, rooms and functions come from, and whether it can be written.
501
528
  *
@@ -1219,10 +1246,12 @@ export interface ApiMethods {
1219
1246
  };
1220
1247
  /**
1221
1248
  * Task 64: what `getParamsetId(address, MASTER)` answers - the key the WebUI picks a MASTER form
1222
- * 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.
1223
1252
  */
1224
1253
  'paramset.id': {
1225
- params: [interfaceName: string, address: string];
1254
+ params: [interfaceName: string, address: string, paramsetType?: 'MASTER' | 'LINK'];
1226
1255
  result: string;
1227
1256
  };
1228
1257
  /**
@@ -23,6 +23,8 @@ export function callbackPinOption(field) {
23
23
  }
24
24
  /** The values of {@link MetaProviderChoice} as a runtime list, for validation and a select. */
25
25
  export const META_PROVIDERS = Object.freeze(['auto', 'local', 'occulite', 'rega']);
26
+ /** The values of {@link LocalRpcChoice} as a runtime list, for validation and a select. */
27
+ export const LOCAL_RPC_CHOICES = Object.freeze(['lite', 'direct']);
26
28
  export const RPC_ORIGINS = Object.freeze(['console', 'ui', 'background']);
27
29
  /**
28
30
  * Every event of {@link ApiEvents} as a runtime value, because a type has none.
@@ -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