homematic-manager 3.8.0 → 3.9.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.
@@ -14,7 +14,7 @@
14
14
  * main process with it, issue #127).
15
15
  */
16
16
  import path from 'node:path';
17
- import { RPC_METHOD_NAMES, RSSI_UNKNOWN, countsAsServiceMessage, isAcknowledgeable, isKnownInterface, offersConfigMaintenance, maintenanceAddress, mergeMethodHelp, methodsFor, callbackPinOption, normaliseDescription, repairMisdecodedUtf8, } from '@homematic-manager/core';
17
+ import { RPC_METHOD_NAMES, RSSI_UNKNOWN, countsAsServiceMessage, isAcknowledgeable, isKnownInterface, offersConfigMaintenance, offersMethod, maintenanceAddress, mergeMethodHelp, methodsFor, callbackPinOption, normaliseDescription, repairMisdecodedUtf8, } from '@homematic-manager/core';
18
18
  import { CacheStore } from '../cache/store.js';
19
19
  import { ConfigStore } from '../config/store.js';
20
20
  import { LinkTemplateStore } from '../config/linkTemplates.js';
@@ -538,6 +538,10 @@ export class Backend {
538
538
  case 'value.get':
539
539
  return this.#read(p[0], 'getValue', [p[1], p[2]]);
540
540
  case 'links.list':
541
+ // B-107: an interface without links (Logic's) is not asked for them
542
+ if (!(await this.#offersMethod(p[0], 'getLinks'))) {
543
+ return [];
544
+ }
541
545
  return asLinks(await this.#read(p[0], 'getLinks', []));
542
546
  case 'links.add':
543
547
  await this.#write(p[0], 'addLink', [
@@ -706,6 +710,9 @@ export class Backend {
706
710
  const manager = useLite
707
711
  ? (this.#options.createLiteInterfaces ?? ((options) => new LiteInterfaces(options)))({
708
712
  ...shared,
713
+ onRemoved: (interfaceName) => {
714
+ this.#onInterfaceRemoved(interfaceName);
715
+ },
709
716
  // on the system: the loopback lighttpd (or `metaUrl`, the integration tests' door)
710
717
  baseUrl: localLite ? metaBaseUrl(connection) : (liteProbe?.baseUrl ?? hostBaseUrl(connection)),
711
718
  token,
@@ -1000,6 +1007,20 @@ export class Backend {
1000
1007
  await this.#refreshServiceMessages(interfaceName);
1001
1008
  }
1002
1009
  }
1010
+ /**
1011
+ * B-107: an interface the openccu-lite system offered and no longer does (an addon removed). Its
1012
+ * devices and service messages go, so no grid keeps a device nobody can reach any more.
1013
+ */
1014
+ #onInterfaceRemoved(interfaceName) {
1015
+ this.#listedMethods.delete(interfaceName);
1016
+ this.#noListMethods.delete(interfaceName);
1017
+ const addresses = this.#caches.devices.list(interfaceName).map((entry) => entry.ADDRESS);
1018
+ this.#caches.devices.clear(interfaceName);
1019
+ this.#caches.saveDevices();
1020
+ this.events.emit('devices.changed', { interfaceName, kind: 'deleted', addresses });
1021
+ this.#caches.serviceMessages.replaceInterface(interfaceName, []);
1022
+ this.events.emit('serviceMessages.changed', this.#serviceMessages());
1023
+ }
1003
1024
  /** Issue #93: an answer that is not a list of interfaces must not take the connection down. */
1004
1025
  async #findCentralAddress(interfaceName) {
1005
1026
  try {
@@ -1840,6 +1861,17 @@ export class Backend {
1840
1861
  const type = this.#manager?.states().find((state) => state.name === interfaceName)?.type ?? '';
1841
1862
  return offersConfigMaintenance(interfaceName, type, method, listed);
1842
1863
  }
1864
+ /**
1865
+ * B-107: may `method` be called on this interface? For an interface the table does not know (an
1866
+ * addon's own, a user-defined one) its `system.listMethods` decides; see `offersMethod`.
1867
+ */
1868
+ async #offersMethod(interfaceName, method) {
1869
+ const type = this.#manager?.states().find((state) => state.name === interfaceName)?.type ?? '';
1870
+ if (isKnownInterface(type)) {
1871
+ return true;
1872
+ }
1873
+ return offersMethod(type, method, await this.#methodList(interfaceName));
1874
+ }
1843
1875
  /** `devices.restoreConfig` and `devices.clearConfigCache`: refused where the interface lacks the method. */
1844
1876
  async #configMaintenance(interfaceName, method, address) {
1845
1877
  if (!(await this.#offersConfigMaintenance(interfaceName, method))) {
@@ -17,6 +17,15 @@
17
17
  * - the errors as the backend knows them: a fault of the interface process stays a fault, a
18
18
  * scope the token lacks is said as such and never taken for a lost connection (task 78's tiers).
19
19
  *
20
+ * B-107: the interfaces are the system's. The profile's list (`connection.interfaces`) is where a
21
+ * CCU's interfaces are chosen; an openccu-lite system says itself which interfaces it offers, and
22
+ * every one of them is followed - BidCos-Wired where the system has a wired gateway, and an addon's
23
+ * own interface process such as lite-addon-logic's `Logic` (its variables and programs as devices).
24
+ * The client follows the system's whole list, so an interface that appears later (an addon installed
25
+ * or switched on) arrives as `interface {state: 'added'}` and is connected at once, and one that
26
+ * goes (an addon removed) is dropped with its devices. A listed interface the system lacks stays, as
27
+ * before, "not on this system".
28
+ *
20
29
  * The CCU path is untouched: on the system itself the addon keeps its loopback callbacks
21
30
  * (maintainer, 2026-09-27: "remote only"), and a CCU never gets here at all.
22
31
  */
@@ -48,6 +57,11 @@ export interface LiteInterfacesOptions {
48
57
  readonly onNotice: (level: 'debug' | 'info' | 'warn' | 'error', message: string, interfaceName?: string) => void;
49
58
  /** Called once an interface is reachable - the backend fills its caches there. */
50
59
  readonly onConnected?: (interfaceName: string) => void | Promise<void>;
60
+ /**
61
+ * B-107: an interface the system offered and the profile does not list is gone from the system
62
+ * (an addon uninstalled): its entry is dropped, and the backend forgets its devices here.
63
+ */
64
+ readonly onRemoved?: (interfaceName: string) => void;
51
65
  readonly onCall?: (record: RpcCallRecord) => void;
52
66
  /** Task 48: the origin of a call that names none (the backend's request context). */
53
67
  readonly originOf?: () => RpcOrigin;
@@ -17,11 +17,20 @@
17
17
  * - the errors as the backend knows them: a fault of the interface process stays a fault, a
18
18
  * scope the token lacks is said as such and never taken for a lost connection (task 78's tiers).
19
19
  *
20
+ * B-107: the interfaces are the system's. The profile's list (`connection.interfaces`) is where a
21
+ * CCU's interfaces are chosen; an openccu-lite system says itself which interfaces it offers, and
22
+ * every one of them is followed - BidCos-Wired where the system has a wired gateway, and an addon's
23
+ * own interface process such as lite-addon-logic's `Logic` (its variables and programs as devices).
24
+ * The client follows the system's whole list, so an interface that appears later (an addon installed
25
+ * or switched on) arrives as `interface {state: 'added'}` and is connected at once, and one that
26
+ * goes (an addon removed) is dropped with its devices. A listed interface the system lacks stays, as
27
+ * before, "not on this system".
28
+ *
20
29
  * The CCU path is untouched: on the system itself the addon keeps its loopback callbacks
21
30
  * (maintainer, 2026-09-27: "remote only"), and a CCU never gets here at all.
22
31
  */
23
32
  import { OccuLite, OccuLiteError, datapointRef, parseRef, } from 'occulite-client';
24
- import { isExplicitDouble, isKnownInterface, normaliseDescription, } from '@homematic-manager/core';
33
+ import { isExplicitDouble, isKnownInterface, normaliseDescription, resolveInterface, resolveUserDefinedInterface, } from '@homematic-manager/core';
25
34
  import { interfaceTargets } from '../config/defaults.js';
26
35
  import { BackendError, configError, connectionError, errorMessage, rpcFaultError } from '../errors.js';
27
36
  import { tierAwareTransport } from '../meta/system.js';
@@ -159,28 +168,132 @@ export class LiteInterfaces {
159
168
  if (targets.length === 0) {
160
169
  throw configError('no interface selected');
161
170
  }
162
- const port = Number(this.#url.port) || (this.#url.protocol === 'https:' ? 443 : 80);
163
171
  for (const target of targets) {
164
- const { name } = target.resolved;
165
- this.#entries.set(name, {
172
+ this.#addEntry(target, false);
173
+ }
174
+ this.#changed();
175
+ await this.#open();
176
+ }
177
+ /** The system's web port, which every interface's state names. */
178
+ get #port() {
179
+ return Number(this.#url.port) || (this.#url.protocol === 'https:' ? 443 : 80);
180
+ }
181
+ /** One interface into the list, waiting for the system's answer. */
182
+ #addEntry(target, discovered, addon) {
183
+ const { name } = target.resolved;
184
+ const entry = {
185
+ name,
186
+ target,
187
+ discovered,
188
+ lastEvent: 0,
189
+ state: {
166
190
  name,
167
- target,
168
- lastEvent: 0,
169
- state: {
170
- name,
171
- type: isKnownInterface(name) ? name : 'custom',
172
- protocol: target.resolved.protocol,
173
- host: this.#url.hostname,
174
- port,
175
- ...(this.#url.protocol === 'https:' ? { tls: true } : {}),
176
- lite: true,
177
- connected: false,
178
- waiting: true,
179
- },
191
+ type: isKnownInterface(name) ? name : 'custom',
192
+ protocol: target.resolved.protocol,
193
+ host: this.#url.hostname,
194
+ port: this.#port,
195
+ ...(this.#url.protocol === 'https:' ? { tls: true } : {}),
196
+ lite: true,
197
+ ...(addon === undefined || addon === '' ? {} : { addon }),
198
+ ...(discovered ? { discovered: true } : {}),
199
+ connected: false,
200
+ waiting: true,
201
+ },
202
+ };
203
+ this.#entries.set(name, entry);
204
+ return entry;
205
+ }
206
+ /**
207
+ * B-107: an interface the system offers that the profile does not list. A built-in name keeps
208
+ * its table entry (BidCos-Wired, VirtualDevices); any other name - an addon's interface process -
209
+ * is spoken to like a user-defined interface at the path the system names.
210
+ */
211
+ #discover(info) {
212
+ const connection = this.#options.connection;
213
+ const resolved = isKnownInterface(info.name)
214
+ ? resolveInterface(info.name, { tls: connection.tls, local: connection.local === true })
215
+ : resolveUserDefinedInterface({
216
+ name: info.name,
217
+ host: this.#url.hostname,
218
+ port: this.#port,
219
+ protocol: 'xmlrpc',
220
+ ...(info.url_path === undefined ? {} : { path: info.url_path }),
221
+ ...(this.#url.protocol === 'https:' ? { tls: true } : {}),
180
222
  });
223
+ return this.#addEntry({ resolved, host: this.#url.hostname, auth: undefined }, true, addonOf(info));
224
+ }
225
+ /** B-107: a discovered interface the system no longer offers - the entry goes, and its devices with it. */
226
+ #drop(entry) {
227
+ this.#entries.delete(entry.name);
228
+ this.#options.onNotice('info', `${entry.name}: the system no longer offers this interface`, entry.name);
229
+ this.#options.onRemoved?.(entry.name);
230
+ }
231
+ /**
232
+ * B-107: the entries follow the system's list - every interface it offers is in, a discovered
233
+ * one it no longer offers is out, and the providing addon is taken from where it is named.
234
+ */
235
+ #syncEntries() {
236
+ const box = this.#box;
237
+ if (box === undefined) {
238
+ return;
239
+ }
240
+ for (const info of box.interfaces) {
241
+ const entry = this.#entries.get(info.name);
242
+ if (entry === undefined) {
243
+ this.#discover(info);
244
+ continue;
245
+ }
246
+ const addon = addonOf(info);
247
+ if (addon !== undefined && entry.state.addon !== addon) {
248
+ entry.state = { ...entry.state, addon };
249
+ }
250
+ }
251
+ for (const entry of [...this.#entries.values()]) {
252
+ if (entry.discovered && !box.interfaces.some((info) => info.name === entry.name)) {
253
+ this.#drop(entry);
254
+ }
255
+ }
256
+ }
257
+ /**
258
+ * B-107: the interface event names no addon, and the stream's hello neither; the interface list
259
+ * does. Asked once for an interface that appeared after the connect, best effort - the name of
260
+ * the addon is a label in the popup, and the interface works without it.
261
+ */
262
+ async #learnAddon(box, interfaceName) {
263
+ let list;
264
+ try {
265
+ list = await box.listInterfaces();
266
+ }
267
+ catch {
268
+ return;
181
269
  }
270
+ const addon = addonOf(list.find((info) => info.name === interfaceName));
271
+ const entry = this.#entries.get(interfaceName);
272
+ if (this.#box !== box || entry === undefined || addon === undefined || entry.state.addon === addon) {
273
+ return;
274
+ }
275
+ entry.state = { ...entry.state, addon };
182
276
  this.#changed();
183
- await this.#open();
277
+ }
278
+ /**
279
+ * B-107: after a gap - another boot of the system, a stream that lost events - the interface
280
+ * list is read again, because the client re-reads only the values: an addon installed or removed
281
+ * meanwhile is in the list or out of it, and the stream's hello names no interface the first
282
+ * list lacked. Best effort: a list that cannot be read leaves the one there is.
283
+ */
284
+ async #relist(box) {
285
+ let list;
286
+ try {
287
+ list = await box.listInterfaces();
288
+ }
289
+ catch {
290
+ return;
291
+ }
292
+ if (this.#box !== box) {
293
+ return;
294
+ }
295
+ box.interfaces = list;
296
+ this.#applyInterfaces();
184
297
  }
185
298
  /** D-31: closes the stream and forgets nothing; {@link subscribe} opens it again. */
186
299
  async unsubscribe() {
@@ -287,7 +400,8 @@ export class LiteInterfaces {
287
400
  // occulite-client B-3: a paired token names its tier (rpc:admin), and the client would
288
401
  // take it for names-only; the transport spells the tier's rpc:read out for it
289
402
  transport: tierAwareTransport(this.#options.transport),
290
- interfaces: [...this.#entries.keys()],
403
+ // B-107: no `interfaces` - the client follows every interface the system offers, and a
404
+ // filter would hide the `interface added` of one that appears later (an addon installed)
291
405
  // the state store at connect (task 68's timestamps); no sweep of every channel - the
292
406
  // grids read a paramset when they need it, as on a CCU, and rfd asks a BidCos device on
293
407
  // the air for each such call. No metadata: the provider follows that stream itself, and
@@ -327,7 +441,7 @@ export class LiteInterfaces {
327
441
  box.on('resync', (event) => {
328
442
  if (current()) {
329
443
  this.#options.onNotice('info', `the system's event stream was resynchronised (${event.reason}); the devices are read again`);
330
- void this.#connectAll();
444
+ void this.#relist(box).then(() => (current() ? this.#connectAll() : undefined));
331
445
  }
332
446
  });
333
447
  box.on('error', (error) => {
@@ -372,6 +486,7 @@ export class LiteInterfaces {
372
486
  if (box === undefined) {
373
487
  return;
374
488
  }
489
+ this.#syncEntries();
375
490
  for (const entry of this.#entries.values()) {
376
491
  const info = box.interfaces.find((candidate) => candidate.name === entry.name);
377
492
  if (info === undefined) {
@@ -533,9 +648,24 @@ export class LiteInterfaces {
533
648
  }
534
649
  /** An interface process came up, went down, or the system gained or lost an interface. */
535
650
  #onInterface(interfaceName, state) {
536
- const entry = this.#entries.get(interfaceName);
651
+ let entry = this.#entries.get(interfaceName);
652
+ const box = this.#box;
537
653
  if (entry === undefined) {
538
- return;
654
+ // B-107: an interface the system gained after the connect - an addon installed or
655
+ // switched on. The client has put it into its list; it is followed from now on.
656
+ const info = box?.interfaces.find((candidate) => candidate.name === interfaceName);
657
+ if (!this.#ready || box === undefined || info === undefined || state === 'removed') {
658
+ return;
659
+ }
660
+ entry = this.#discover(info);
661
+ this.#changed();
662
+ if (addonOf(info) === undefined) {
663
+ void this.#learnAddon(box, interfaceName);
664
+ }
665
+ if (state === 'down') {
666
+ this.#applyInterfaces();
667
+ return;
668
+ }
539
669
  }
540
670
  switch (state) {
541
671
  case 'up':
@@ -557,6 +687,11 @@ export class LiteInterfaces {
557
687
  this.#options.onNotice('warn', `${interfaceName}: the interface process is down`, interfaceName);
558
688
  break;
559
689
  case 'removed':
690
+ if (entry.discovered) {
691
+ this.#drop(entry);
692
+ this.#changed();
693
+ break;
694
+ }
560
695
  this.#update(entry, {
561
696
  connected: false,
562
697
  error: `${interfaceName}: the system runs no such interface`,
@@ -709,6 +844,14 @@ export class LiteInterfaces {
709
844
  entry.state = state;
710
845
  }
711
846
  }
847
+ /**
848
+ * B-107: the addon that provides an interface, from the system's interface list (occulited task
849
+ * 169). occulite-client passes the field through without naming it in its type.
850
+ */
851
+ function addonOf(info) {
852
+ const addon = info?.addon;
853
+ return typeof addon === 'string' && addon !== '' ? addon : undefined;
854
+ }
712
855
  /** The client's view of a stored value, without the value: what the grids show beside it (task 82). */
713
856
  function toValueState(value) {
714
857
  return {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homematic-manager/backend",
3
- "version": "3.8.0",
3
+ "version": "3.9.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",
@@ -383,6 +383,17 @@ export interface InterfaceState {
383
383
  * Only present when it is true.
384
384
  */
385
385
  lite?: boolean;
386
+ /**
387
+ * B-107: the openccu-lite addon that provides this interface - lite-addon-logic's `Logic`, say -
388
+ * as the system's interface list names it (`addon` in `GET /api/rpc/v1/interfaces`). Only
389
+ * present for such an interface.
390
+ */
391
+ addon?: string;
392
+ /**
393
+ * B-107: the interface is not in the profile's list; it was found on the openccu-lite system,
394
+ * which offers it, and is followed for as long as the system does. Only present when true.
395
+ */
396
+ discovered?: boolean;
386
397
  /** `init` succeeded and the ping/event watchdog is satisfied. */
387
398
  connected: boolean;
388
399
  /** Milliseconds since epoch of the last event or ping answer, if any. */
@@ -220,11 +220,23 @@ export declare function isKnownInterface(name: string): name is InterfaceName;
220
220
  /** The built-in definition, or `undefined` for a name the table does not know. */
221
221
  export declare function interfaceDefinition(name: string): InterfaceDefinition | undefined;
222
222
  /**
223
- * Whether devices can be paired to an interface of this type (task 28). Only a built-in interface
224
- * that says it has no install mode is refused; a user-defined one - Homegear, a bare rfd - and a
225
- * type that is not known yet get the pairing dialog, and the process behind them has the last word.
223
+ * Whether devices can be paired to an interface of this type (task 28). A built-in interface that
224
+ * says it has no install mode is refused; a user-defined one - Homegear, a bare rfd - and a type
225
+ * that is not known yet get the pairing dialog, and the process behind them has the last word -
226
+ * unless its `system.listMethods` (`listed`) lacks `setInstallMode` (B-107: Logic's interface).
226
227
  */
227
- export declare function canPairDevices(type: string): boolean;
228
+ export declare function canPairDevices(type: string, listed?: readonly string[] | ReadonlySet<string>): boolean;
229
+ /**
230
+ * B-107: may a feature that needs `method` be offered for an interface of this type?
231
+ *
232
+ * An interface the table does not know - an openccu-lite addon's own interface process such as
233
+ * Logic's, a user-defined one - is asked: its `system.listMethods` decides, so a process that has
234
+ * no `setInstallMode` gets no pairing dialog and one without `getLinks` no links, whatever its name.
235
+ * The built-in processes keep their measured rules (the table and the views' own checks), and so
236
+ * does a process without a usable list (`undefined`): there the process has the last word, as
237
+ * before.
238
+ */
239
+ export declare function offersMethod(type: string, method: string, listed: readonly string[] | ReadonlySet<string> | undefined): boolean;
228
240
  /** The two BidCos maintenance calls of the device menu and the repair dialog (task 115). */
229
241
  export type ConfigMaintenanceMethod = 'restoreConfigToDevice' | 'clearConfigCache';
230
242
  /**
@@ -106,12 +106,29 @@ export function interfaceDefinition(name) {
106
106
  return isKnownInterface(name) ? INTERFACES[name] : undefined;
107
107
  }
108
108
  /**
109
- * Whether devices can be paired to an interface of this type (task 28). Only a built-in interface
110
- * that says it has no install mode is refused; a user-defined one - Homegear, a bare rfd - and a
111
- * type that is not known yet get the pairing dialog, and the process behind them has the last word.
109
+ * Whether devices can be paired to an interface of this type (task 28). A built-in interface that
110
+ * says it has no install mode is refused; a user-defined one - Homegear, a bare rfd - and a type
111
+ * that is not known yet get the pairing dialog, and the process behind them has the last word -
112
+ * unless its `system.listMethods` (`listed`) lacks `setInstallMode` (B-107: Logic's interface).
112
113
  */
113
- export function canPairDevices(type) {
114
- return interfaceDefinition(type)?.installMode !== false;
114
+ export function canPairDevices(type, listed) {
115
+ return interfaceDefinition(type)?.installMode !== false && offersMethod(type, 'setInstallMode', listed);
116
+ }
117
+ /**
118
+ * B-107: may a feature that needs `method` be offered for an interface of this type?
119
+ *
120
+ * An interface the table does not know - an openccu-lite addon's own interface process such as
121
+ * Logic's, a user-defined one - is asked: its `system.listMethods` decides, so a process that has
122
+ * no `setInstallMode` gets no pairing dialog and one without `getLinks` no links, whatever its name.
123
+ * The built-in processes keep their measured rules (the table and the views' own checks), and so
124
+ * does a process without a usable list (`undefined`): there the process has the last word, as
125
+ * before.
126
+ */
127
+ export function offersMethod(type, method, listed) {
128
+ if (listed === undefined || isKnownInterface(type)) {
129
+ return true;
130
+ }
131
+ return 'has' in listed ? listed.has(method) : listed.includes(method);
115
132
  }
116
133
  /**
117
134
  * Task 115: may `restoreConfigToDevice` or `clearConfigCache` be offered for this interface?
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homematic-manager/core",
3
- "version": "3.8.0",
3
+ "version": "3.9.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.8.0",
3
+ "version": "3.9.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.5.0"
68
68
  },
69
69
  "dependencies": {
70
- "@homematic-manager/backend": "3.8.0",
71
- "@homematic-manager/core": "3.8.0",
70
+ "@homematic-manager/backend": "3.9.1",
71
+ "@homematic-manager/core": "3.9.1",
72
72
  "binrpc": "^4.2.0",
73
73
  "homematic-rega": "^2.0.0",
74
74
  "homematic-xmlrpc": "^2.0.0",