@matterbridge/core 3.11.2 → 3.11.3-dev-20261109-ca46ffb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backend.d.ts +4 -2
- package/dist/backend.js +13 -5
- package/dist/backendExpress.d.ts +0 -1
- package/dist/backendExpress.js +19 -9
- package/dist/backendWsServer.d.ts +2 -1
- package/dist/backendWsServer.js +124 -6
- package/dist/behaviors/export.d.ts +3 -0
- package/dist/behaviors/export.js +3 -0
- package/dist/behaviors/timeSynchronizationServer.d.ts +34 -0
- package/dist/behaviors/timeSynchronizationServer.js +202 -0
- package/dist/behaviors/tlsCertificateManagementServer.d.ts +58 -0
- package/dist/behaviors/tlsCertificateManagementServer.js +352 -0
- package/dist/behaviors/tlsClientManagementServer.d.ts +21 -0
- package/dist/behaviors/tlsClientManagementServer.js +110 -0
- package/dist/behaviors/windowCoveringServer.d.ts +63 -0
- package/dist/behaviors/windowCoveringServer.js +3 -0
- package/dist/cli.js +1 -1
- package/dist/deviceManager.d.ts +2 -4
- package/dist/deviceManager.js +7 -24
- package/dist/frontend.d.ts +2 -3
- package/dist/frontend.js +81 -90
- package/dist/matterNode.d.ts +4 -1
- package/dist/matterNode.js +62 -24
- package/dist/matterNodeHelpers.d.ts +104 -2
- package/dist/matterNodeHelpers.js +45 -1
- package/dist/matterbridge.js +15 -19
- package/dist/matterbridgeEndpoint.js +5 -63
- package/dist/matterbridgeEndpointCommandHandler.d.ts +0 -25
- package/dist/matterbridgeEndpointHelpers.d.ts +5 -0
- package/dist/matterbridgeEndpointHelpers.js +82 -3
- package/dist/matterbridgePlatform.js +52 -0
- package/dist/pluginManager.js +24 -1
- package/package.json +6 -6
package/dist/matterNode.js
CHANGED
|
@@ -7,11 +7,9 @@ import { Crypto, Environment, LogFormat as MatterLogFormat, LogLevel as MatterLo
|
|
|
7
7
|
import { Endpoint, ServerNode } from '@matter/node';
|
|
8
8
|
import { BasicInformationServer } from '@matter/node/behaviors/basic-information';
|
|
9
9
|
import { BridgedDeviceBasicInformationServer } from '@matter/node/behaviors/bridged-device-basic-information';
|
|
10
|
-
import { PowerSourceServer } from '@matter/node/behaviors/power-source';
|
|
11
10
|
import { AggregatorEndpoint } from '@matter/node/endpoints/aggregator';
|
|
12
11
|
import { PaseClient } from '@matter/protocol';
|
|
13
|
-
import {
|
|
14
|
-
import { DeviceTypeId, EndpointNumber, VendorId } from '@matter/types/datatype';
|
|
12
|
+
import { DeviceTypeId, VendorId } from '@matter/types/datatype';
|
|
15
13
|
import { BroadcastServer } from '@matterbridge/thread/server';
|
|
16
14
|
import { dev, MATTER_STORAGE_DIR, NODE_STORAGE_DIR, plg } from '@matterbridge/types';
|
|
17
15
|
import { getIntParameter, getParameter, hasAnyParameter, hasParameter } from '@matterbridge/utils/cli';
|
|
@@ -24,7 +22,7 @@ import { NodeStorageManager } from 'node-persist-manager';
|
|
|
24
22
|
import { addVirtualDevice } from './helpers.js';
|
|
25
23
|
import { bridge } from './matterbridgeDeviceTypes.js';
|
|
26
24
|
import { setupLoggers } from './matterLogger.js';
|
|
27
|
-
import { deleteAdvertisingNode, getServerNodeData, setAdvertisingNode,
|
|
25
|
+
import { deleteAdvertisingNode, getServerNodeData, rootCameraEndpoint, rootCameraOptions, setAdvertisingNode, toDevice } from './matterNodeHelpers.js';
|
|
28
26
|
import { startMatterStorage, stopMatterStorage } from './matterStorage.js';
|
|
29
27
|
import { PluginManager } from './pluginManager.js';
|
|
30
28
|
logModuleLoaded('MatterNode');
|
|
@@ -200,7 +198,12 @@ export class MatterNode extends EventEmitter {
|
|
|
200
198
|
this.log.debug(`Creating MatterNode instance for plugin ${CYAN}${this.pluginName}${db}...`);
|
|
201
199
|
this.log.debug(`Loading plugin ${CYAN}${this.pluginName}${db}...`);
|
|
202
200
|
await this.pluginManager.load(this.pluginName);
|
|
203
|
-
|
|
201
|
+
const plugin = this.pluginManager.get(this.pluginName);
|
|
202
|
+
this.pluginStatusUpdate(this.pluginName, { loaded: plugin?.loaded });
|
|
203
|
+
if (plugin?.configJson)
|
|
204
|
+
this.pluginSetConfig(plugin.name, plugin.configJson);
|
|
205
|
+
if (plugin?.schemaJson)
|
|
206
|
+
this.pluginSetSchema(plugin.name, plugin.schemaJson);
|
|
204
207
|
this.log.debug(`Loaded plugin ${CYAN}${this.pluginName}${db}`);
|
|
205
208
|
this.log.debug(`Created MatterNode instance for plugin ${CYAN}${this.pluginName}${db}`);
|
|
206
209
|
this.emit('ready', this.pluginName);
|
|
@@ -216,6 +219,10 @@ export class MatterNode extends EventEmitter {
|
|
|
216
219
|
await Promise.all(loadPromises);
|
|
217
220
|
for (const plugin of this.pluginManager.array().filter((p) => p.enabled)) {
|
|
218
221
|
this.pluginStatusUpdate(plugin.name, { loaded: plugin.loaded });
|
|
222
|
+
if (plugin.configJson)
|
|
223
|
+
this.pluginSetConfig(plugin.name, plugin.configJson);
|
|
224
|
+
if (plugin.schemaJson)
|
|
225
|
+
this.pluginSetSchema(plugin.name, plugin.schemaJson);
|
|
219
226
|
}
|
|
220
227
|
this.log.debug('Loaded all plugins');
|
|
221
228
|
this.log.debug('Created MatterNode instance for all plugins');
|
|
@@ -235,6 +242,7 @@ export class MatterNode extends EventEmitter {
|
|
|
235
242
|
return;
|
|
236
243
|
}
|
|
237
244
|
if (!this.pluginName) {
|
|
245
|
+
this.matterbridgeStatusUpdate('starting');
|
|
238
246
|
this.log.debug(`Starting all plugins for ${this.storeId}...`);
|
|
239
247
|
const startPromises = [];
|
|
240
248
|
for (const plugin of this.pluginManager.array().filter((p) => p.enabled && p.loaded)) {
|
|
@@ -243,6 +251,10 @@ export class MatterNode extends EventEmitter {
|
|
|
243
251
|
await Promise.all(startPromises);
|
|
244
252
|
for (const plugin of this.pluginManager.array().filter((p) => p.enabled)) {
|
|
245
253
|
this.pluginStatusUpdate(plugin.name, { started: plugin.started, registeredDevices: plugin.registeredDevices });
|
|
254
|
+
if (plugin.configJson)
|
|
255
|
+
this.pluginSetConfig(plugin.name, plugin.configJson);
|
|
256
|
+
if (plugin.schemaJson)
|
|
257
|
+
this.pluginSetSchema(plugin.name, plugin.schemaJson);
|
|
246
258
|
}
|
|
247
259
|
this.log.debug(`Started all plugins for ${this.storeId}`);
|
|
248
260
|
this.log.debug(`Starting MatterNode for ${this.storeId}...`);
|
|
@@ -264,6 +276,10 @@ export class MatterNode extends EventEmitter {
|
|
|
264
276
|
await this.pluginManager.start(this.pluginName, 'Starting MatterNode');
|
|
265
277
|
const plugin = this.pluginManager.get(this.pluginName);
|
|
266
278
|
this.pluginStatusUpdate(this.pluginName, { started: plugin?.started, registeredDevices: plugin?.registeredDevices });
|
|
279
|
+
if (plugin?.configJson)
|
|
280
|
+
this.pluginSetConfig(plugin.name, plugin.configJson);
|
|
281
|
+
if (plugin?.schemaJson)
|
|
282
|
+
this.pluginSetSchema(plugin.name, plugin.schemaJson);
|
|
267
283
|
this.log.debug(`Started plugin ${this.pluginName}...`);
|
|
268
284
|
this.log.debug(`Starting MatterNode for plugin ${this.storeId}...`);
|
|
269
285
|
await this.startServerNode();
|
|
@@ -278,6 +294,8 @@ export class MatterNode extends EventEmitter {
|
|
|
278
294
|
await dependantMatterNode.start();
|
|
279
295
|
}
|
|
280
296
|
this.log.debug(`Started dependant MatterNodes for ${this.storeId}`);
|
|
297
|
+
if (!this.pluginName)
|
|
298
|
+
this.matterbridgeStatusUpdate('started');
|
|
281
299
|
this.log.info(`Started MatterNode for ${this.storeId}`);
|
|
282
300
|
await this.yieldToNode();
|
|
283
301
|
}
|
|
@@ -298,10 +316,14 @@ export class MatterNode extends EventEmitter {
|
|
|
298
316
|
return;
|
|
299
317
|
}
|
|
300
318
|
if (!this.pluginName) {
|
|
319
|
+
this.matterbridgeStatusUpdate('stopping');
|
|
301
320
|
this.log.debug(`Stopping all plugins for ${this.storeId}...`);
|
|
302
321
|
const shutdownPromises = [];
|
|
303
322
|
for (const plugin of this.pluginManager.array().filter((p) => p.enabled && p.started)) {
|
|
304
|
-
shutdownPromises.push(this.pluginManager.shutdown(plugin, 'Stopping MatterNode'))
|
|
323
|
+
shutdownPromises.push(this.pluginManager.shutdown(plugin, 'Stopping MatterNode').then((result) => {
|
|
324
|
+
this.pluginStatusUpdate(plugin.name, { loaded: plugin.loaded, started: plugin.started, configured: plugin.configured, registeredDevices: plugin.registeredDevices });
|
|
325
|
+
return result;
|
|
326
|
+
}));
|
|
305
327
|
}
|
|
306
328
|
await Promise.all(shutdownPromises);
|
|
307
329
|
this.log.debug(`Stopped all plugins for ${this.storeId}`);
|
|
@@ -309,6 +331,8 @@ export class MatterNode extends EventEmitter {
|
|
|
309
331
|
else {
|
|
310
332
|
this.log.debug(`Stopping plugin ${this.pluginName}...`);
|
|
311
333
|
await this.pluginManager.shutdown(this.pluginName, 'Stopping MatterNode');
|
|
334
|
+
const plugin = this.pluginManager.get(this.pluginName);
|
|
335
|
+
this.pluginStatusUpdate(this.pluginName, { loaded: plugin?.loaded, started: plugin?.started, configured: plugin?.configured, registeredDevices: plugin?.registeredDevices });
|
|
312
336
|
this.log.debug(`Stopped plugin ${this.pluginName}`);
|
|
313
337
|
}
|
|
314
338
|
this.log.debug(`Stopping dependant MatterNodes for ${this.storeId}...`);
|
|
@@ -320,6 +344,8 @@ export class MatterNode extends EventEmitter {
|
|
|
320
344
|
this.serverNode = undefined;
|
|
321
345
|
this.aggregatorNode = undefined;
|
|
322
346
|
await this.stopMatterStorage();
|
|
347
|
+
if (!this.pluginName)
|
|
348
|
+
this.matterbridgeStatusUpdate('stopped');
|
|
323
349
|
this.log.info(`Stopped MatterNode for ${this.storeId}`);
|
|
324
350
|
await this.yieldToNode();
|
|
325
351
|
}
|
|
@@ -416,12 +442,14 @@ export class MatterNode extends EventEmitter {
|
|
|
416
442
|
this.log.warn(`Invalid discriminator ${discriminator} for server node ${storeId}. Discriminator must be between 0 and 4095 (0xFFF). Generating a random discriminator...`);
|
|
417
443
|
validDiscriminator = PaseClient.generateRandomDiscriminator(this.environment.get(Crypto));
|
|
418
444
|
}
|
|
445
|
+
const rootCamera = hasParameter('root-camera') || Boolean(process.env.MATTERBRIDGE_CHIP_TEST);
|
|
419
446
|
let rootEndpoint;
|
|
420
|
-
if (
|
|
447
|
+
if (rootCamera) {
|
|
421
448
|
this.log.warn(' ****************************************************************************************');
|
|
422
|
-
this.log.warn(' * Adding the PowerSource
|
|
449
|
+
this.log.warn(' * Adding the PowerSource, TimeSynchronization, TlsCertificateManagement and *');
|
|
450
|
+
this.log.warn(' * TlsClientManagement cluster servers to the root endpoint (root camera). *');
|
|
423
451
|
this.log.warn(' ****************************************************************************************');
|
|
424
|
-
rootEndpoint =
|
|
452
|
+
rootEndpoint = rootCameraEndpoint();
|
|
425
453
|
}
|
|
426
454
|
else {
|
|
427
455
|
rootEndpoint = ServerNode.RootEndpoint;
|
|
@@ -473,26 +501,18 @@ export class MatterNode extends EventEmitter {
|
|
|
473
501
|
configurationVersion: await this.matterStorageContext.get('configurationVersion'),
|
|
474
502
|
reachable: true,
|
|
475
503
|
},
|
|
476
|
-
...(
|
|
477
|
-
? {
|
|
478
|
-
powerSource: {
|
|
479
|
-
status: PowerSource.PowerSourceStatus.Active,
|
|
480
|
-
order: 0,
|
|
481
|
-
description: 'AC Power',
|
|
482
|
-
endpointList: [EndpointNumber(0)],
|
|
483
|
-
wiredCurrentType: PowerSource.WiredCurrentType.Ac,
|
|
484
|
-
},
|
|
485
|
-
}
|
|
486
|
-
: {}),
|
|
504
|
+
...(rootCamera ? rootCameraOptions() : {}),
|
|
487
505
|
});
|
|
488
506
|
serverNode.lifecycle.commissioned.on(() => {
|
|
489
507
|
this.log.notice(`Server node for ${storeId} was initially commissioned successfully!`);
|
|
490
508
|
deleteAdvertisingNode(storeId);
|
|
509
|
+
this.pluginMatterUpdate(serverNode);
|
|
491
510
|
this.server.request({ type: 'frontend_refreshrequired', src: 'matter', dst: 'frontend', params: { changed: 'matter', matter: { ...getServerNodeData(serverNode) } } });
|
|
492
511
|
});
|
|
493
512
|
serverNode.lifecycle.decommissioned.on(() => {
|
|
494
513
|
this.log.notice(`Server node for ${storeId} was fully decommissioned successfully!`);
|
|
495
514
|
deleteAdvertisingNode(storeId);
|
|
515
|
+
this.pluginMatterUpdate(serverNode);
|
|
496
516
|
this.server.request({ type: 'frontend_refreshrequired', src: 'matter', dst: 'frontend', params: { changed: 'matter', matter: { ...getServerNodeData(serverNode) } } });
|
|
497
517
|
this.server.request({ type: 'frontend_snackbarmessage', src: 'matter', dst: 'frontend', params: { message: `${storeId} is offline`, timeout: 5, severity: 'warning' } });
|
|
498
518
|
this.log.notice(`Server node for ${storeId} was reset to factory defaults: restart Matterbridge before pairing it again`);
|
|
@@ -524,6 +544,7 @@ export class MatterNode extends EventEmitter {
|
|
|
524
544
|
this.log.notice(`Server node for ${storeId} is already commissioned. Waiting for controllers to connect ...`);
|
|
525
545
|
deleteAdvertisingNode(storeId);
|
|
526
546
|
}
|
|
547
|
+
this.pluginMatterUpdate(serverNode);
|
|
527
548
|
this.server.request({ type: 'frontend_refreshrequired', src: 'matter', dst: 'frontend', params: { changed: 'matter', matter: { ...getServerNodeData(serverNode) } } });
|
|
528
549
|
this.server.request({ type: 'frontend_snackbarmessage', src: 'matter', dst: 'frontend', params: { message: `${storeId} is online`, timeout: 5, severity: 'success' } });
|
|
529
550
|
this.emit('online', storeId);
|
|
@@ -531,6 +552,7 @@ export class MatterNode extends EventEmitter {
|
|
|
531
552
|
serverNode.lifecycle.offline.on(() => {
|
|
532
553
|
this.log.notice(`Server node for ${storeId} is offline`);
|
|
533
554
|
deleteAdvertisingNode(storeId);
|
|
555
|
+
this.pluginMatterUpdate(serverNode);
|
|
534
556
|
this.server.request({ type: 'frontend_refreshrequired', src: 'matter', dst: 'frontend', params: { changed: 'matter', matter: { ...getServerNodeData(serverNode) } } });
|
|
535
557
|
this.server.request({ type: 'frontend_snackbarmessage', src: 'matter', dst: 'frontend', params: { message: `${storeId} is offline`, timeout: 5, severity: 'warning' } });
|
|
536
558
|
this.emit('offline', storeId);
|
|
@@ -550,18 +572,22 @@ export class MatterNode extends EventEmitter {
|
|
|
550
572
|
break;
|
|
551
573
|
}
|
|
552
574
|
this.log.notice(`Commissioned fabric index ${fabricIndex} ${action} on server node for ${storeId}: ${debugStringify(serverNode.state.commissioning.fabrics[fabricIndex])}`);
|
|
575
|
+
this.pluginMatterUpdate(serverNode);
|
|
553
576
|
this.server.request({ type: 'frontend_refreshrequired', src: 'matter', dst: 'frontend', params: { changed: 'matter', matter: { ...getServerNodeData(serverNode) } } });
|
|
554
577
|
});
|
|
555
578
|
serverNode.events.sessions.opened.on((session) => {
|
|
556
579
|
this.log.notice(`Session opened on server node for ${storeId}: ${debugStringify(session)}`);
|
|
580
|
+
this.pluginMatterUpdate(serverNode);
|
|
557
581
|
this.server.request({ type: 'frontend_refreshrequired', src: 'matter', dst: 'frontend', params: { changed: 'matter', matter: { ...getServerNodeData(serverNode) } } });
|
|
558
582
|
});
|
|
559
583
|
serverNode.events.sessions.closed.on((session) => {
|
|
560
584
|
this.log.notice(`Session closed on server node for ${storeId}: ${debugStringify(session)}`);
|
|
585
|
+
this.pluginMatterUpdate(serverNode);
|
|
561
586
|
this.server.request({ type: 'frontend_refreshrequired', src: 'matter', dst: 'frontend', params: { changed: 'matter', matter: { ...getServerNodeData(serverNode) } } });
|
|
562
587
|
});
|
|
563
588
|
serverNode.events.sessions.subscriptionsChanged.on((session) => {
|
|
564
589
|
this.log.notice(`Session subscriptions changed on server node for ${storeId}: ${debugStringify(session)}`);
|
|
590
|
+
this.pluginMatterUpdate(serverNode);
|
|
565
591
|
this.server.request({ type: 'frontend_refreshrequired', src: 'matter', dst: 'frontend', params: { changed: 'matter', matter: { ...getServerNodeData(serverNode) } } });
|
|
566
592
|
});
|
|
567
593
|
this.storeId = storeId;
|
|
@@ -751,7 +777,7 @@ export class MatterNode extends EventEmitter {
|
|
|
751
777
|
if (plugin.registeredDevices !== undefined)
|
|
752
778
|
plugin.registeredDevices++;
|
|
753
779
|
await device.construction.ready;
|
|
754
|
-
await this.server.fetch({ type: 'devices_set', src: this.server.name, dst: 'devices', params: { device:
|
|
780
|
+
await this.server.fetch({ type: 'devices_set', src: this.server.name, dst: 'devices', params: { device: toDevice(device) } });
|
|
755
781
|
await this.subscribeAttributeChanged(plugin, device);
|
|
756
782
|
this.log.info(`Added endpoint #${plugin.registeredDevices} ${plg}${pluginName}${nf}:${dev}${device.deviceName}${nf} (${zb}${device.name}${nf})`);
|
|
757
783
|
await this.yieldToNode(10);
|
|
@@ -792,7 +818,7 @@ export class MatterNode extends EventEmitter {
|
|
|
792
818
|
this.log.info(`Removed bridged endpoint #${plugin.registeredDevices} ${plg}${pluginName}${nf}:${dev}${device.deviceName}${nf} (${zb}${device.name}${nf})`);
|
|
793
819
|
if (plugin.registeredDevices !== undefined)
|
|
794
820
|
plugin.registeredDevices--;
|
|
795
|
-
await this.server.fetch({ type: 'devices_remove', src: this.server.name, dst: 'devices', params: { device:
|
|
821
|
+
await this.server.fetch({ type: 'devices_remove', src: this.server.name, dst: 'devices', params: { device: toDevice(device) } });
|
|
796
822
|
await this.yieldToNode(10);
|
|
797
823
|
return device;
|
|
798
824
|
}
|
|
@@ -801,7 +827,7 @@ export class MatterNode extends EventEmitter {
|
|
|
801
827
|
if (!plugin)
|
|
802
828
|
throw new Error(`Error removing all bridged endpoints for plugin ${plg}${pluginName}${er}: plugin not found`);
|
|
803
829
|
this.log.debug(`Removing all #${plugin.registeredDevices} bridged endpoints for plugin ${plg}${pluginName}${db}${delay > 0 ? ` with delay ${delay} ms` : ''}...`);
|
|
804
|
-
const devices = (await this.server.fetch({ type: '
|
|
830
|
+
const devices = (await this.server.fetch({ type: 'devices_array', src: this.server.name, dst: 'devices', params: { pluginName } })).result.devices;
|
|
805
831
|
for (const device of devices) {
|
|
806
832
|
const endpoint = (this.aggregatorNode?.parts.get(device.id || '') || this.serverNode?.parts.get(device.id || ''));
|
|
807
833
|
if (!endpoint)
|
|
@@ -811,7 +837,7 @@ export class MatterNode extends EventEmitter {
|
|
|
811
837
|
this.log.info(`Removed bridged endpoint #${plugin.registeredDevices} ${plg}${pluginName}${nf}:${dev}${device.deviceName}${nf} (${zb}${endpoint?.name}${nf})`);
|
|
812
838
|
if (plugin.registeredDevices !== undefined)
|
|
813
839
|
plugin.registeredDevices--;
|
|
814
|
-
await this.server.fetch({ type: 'devices_remove', src: this.server.name, dst: 'devices', params: { device:
|
|
840
|
+
await this.server.fetch({ type: 'devices_remove', src: this.server.name, dst: 'devices', params: { device: toDevice(device) } });
|
|
815
841
|
await this.yieldToNode(10);
|
|
816
842
|
if (delay > 0)
|
|
817
843
|
await wait(delay);
|
|
@@ -973,6 +999,17 @@ export class MatterNode extends EventEmitter {
|
|
|
973
999
|
child.act((agent) => child.eventsOf(BridgedDeviceBasicInformationServer).reachableChanged.emit({ reachableNewValue: true }, agent.context));
|
|
974
1000
|
}
|
|
975
1001
|
}
|
|
1002
|
+
pluginSetConfig(pluginName, config) {
|
|
1003
|
+
this.server.request({ type: 'plugins_setconfig', src: 'matter', dst: 'plugins', params: { name: pluginName, config } });
|
|
1004
|
+
}
|
|
1005
|
+
pluginSetSchema(pluginName, schema) {
|
|
1006
|
+
this.server.request({ type: 'plugins_setschema', src: 'matter', dst: 'plugins', params: { name: pluginName, schema } });
|
|
1007
|
+
}
|
|
1008
|
+
pluginMatterUpdate(serverNode) {
|
|
1009
|
+
if (!this.pluginName || this.device)
|
|
1010
|
+
return;
|
|
1011
|
+
this.server.request({ type: 'plugins_set', src: 'matter', dst: 'plugins', params: { plugin: { name: this.pluginName, matter: getServerNodeData(serverNode) } } });
|
|
1012
|
+
}
|
|
976
1013
|
pluginStatusUpdate(pluginName, status) {
|
|
977
1014
|
this.server.request({ type: 'plugins_set', src: 'matter', dst: 'plugins', params: { plugin: { name: pluginName, ...status } } });
|
|
978
1015
|
this.server.request({
|
|
@@ -983,6 +1020,7 @@ export class MatterNode extends EventEmitter {
|
|
|
983
1020
|
});
|
|
984
1021
|
}
|
|
985
1022
|
matterbridgeStatusUpdate(status) {
|
|
1023
|
+
this.server.request({ type: 'matterbridge_apisettings', src: 'matter', dst: 'matterbridge', params: { bridgeStatus: status } });
|
|
986
1024
|
this.server.request({
|
|
987
1025
|
type: 'frontend_broadcast_message',
|
|
988
1026
|
src: 'matter',
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { ServerNode, type SessionsBehavior } from '@matter/node';
|
|
2
|
+
import { PowerSourceServer } from '@matter/node/behaviors/power-source';
|
|
2
3
|
import type { ExposedFabricInformation } from '@matter/protocol';
|
|
3
|
-
import
|
|
4
|
+
import { PowerSource } from '@matter/types/clusters/power-source';
|
|
5
|
+
import { TimeSynchronization } from '@matter/types/clusters/time-synchronization';
|
|
6
|
+
import { EndpointNumber } from '@matter/types/datatype';
|
|
7
|
+
import type { ApiClusters, ApiDevice, ApiMatter, Device, SanitizedExposedFabricInformation, SanitizedSession } from '@matterbridge/types';
|
|
4
8
|
import { type AnsiLogger } from 'node-ansi-logger';
|
|
9
|
+
import { MatterbridgeTimeSynchronizationServer } from './behaviors/timeSynchronizationServer.js';
|
|
10
|
+
import { MatterbridgeTlsCertificateManagementServer } from './behaviors/tlsCertificateManagementServer.js';
|
|
11
|
+
import { MatterbridgeTlsClientManagementServer } from './behaviors/tlsClientManagementServer.js';
|
|
5
12
|
import type { MatterbridgeEndpoint } from './matterbridgeEndpoint.js';
|
|
6
13
|
export declare function toApiClusters(endpoint: MatterbridgeEndpoint, log: AnsiLogger): ApiClusters | undefined;
|
|
7
|
-
export declare function
|
|
14
|
+
export declare function toDevice(device: MatterbridgeEndpoint | Device): Device;
|
|
8
15
|
export declare function toApiDevice(device: MatterbridgeEndpoint, extended?: boolean): ApiDevice | undefined;
|
|
9
16
|
export declare function getReachability(device: MatterbridgeEndpoint): boolean;
|
|
10
17
|
export declare function getPowerSource(endpoint: MatterbridgeEndpoint): 'ac' | 'dc' | 'ok' | 'warning' | 'critical' | undefined;
|
|
@@ -17,3 +24,98 @@ export declare function getServerNodeData(serverNode: ServerNode): ApiMatter;
|
|
|
17
24
|
export declare function sanitizeFabricInformations(fabricInfo: ExposedFabricInformation[]): SanitizedExposedFabricInformation[];
|
|
18
25
|
export declare function sanitizeSessionInformation(sessions: SessionsBehavior.Session[]): SanitizedSession[];
|
|
19
26
|
export declare function getVendorIdName(vendorId: number | undefined): string;
|
|
27
|
+
export declare function rootCameraEndpoint(): import("@matter/node").MutableEndpoint.With<import("@matter/node").EndpointType.For<{
|
|
28
|
+
readonly name: "RootNode";
|
|
29
|
+
readonly deviceType: 22;
|
|
30
|
+
readonly deviceRevision: 5;
|
|
31
|
+
readonly deviceClass: import("@matter/model").DeviceClassification.Node;
|
|
32
|
+
readonly requirements: typeof import("@matter/node/endpoints").RootRequirements;
|
|
33
|
+
readonly behaviors: {
|
|
34
|
+
readonly parts: typeof import("@matter/node").PartsBehavior;
|
|
35
|
+
} & {
|
|
36
|
+
readonly index: typeof import("@matter/node").IndexBehavior;
|
|
37
|
+
} & {
|
|
38
|
+
readonly accessControl: typeof import("@matter/node/behaviors").AccessControlServer;
|
|
39
|
+
} & {
|
|
40
|
+
readonly basicInformation: typeof import("@matter/node/behaviors").BasicInformationServer;
|
|
41
|
+
} & {
|
|
42
|
+
readonly generalCommissioning: typeof import("@matter/node/behaviors").GeneralCommissioningServer;
|
|
43
|
+
} & {
|
|
44
|
+
readonly generalDiagnostics: typeof import("@matter/node/behaviors").GeneralDiagnosticsServer;
|
|
45
|
+
} & {
|
|
46
|
+
readonly administratorCommissioning: typeof import("@matter/node/behaviors").AdministratorCommissioningServer;
|
|
47
|
+
} & {
|
|
48
|
+
readonly operationalCredentials: typeof import("@matter/node/behaviors").OperationalCredentialsServer;
|
|
49
|
+
} & {
|
|
50
|
+
readonly groupKeyManagement: typeof import("@matter/node/behaviors").GroupKeyManagementServer;
|
|
51
|
+
};
|
|
52
|
+
}>, import("@matter/node").SupportedBehaviors.With<import("@matter/node").SupportedBehaviors.With<{
|
|
53
|
+
readonly parts: typeof import("@matter/node").PartsBehavior;
|
|
54
|
+
} & {
|
|
55
|
+
readonly index: typeof import("@matter/node").IndexBehavior;
|
|
56
|
+
} & {
|
|
57
|
+
readonly accessControl: typeof import("@matter/node/behaviors").AccessControlServer;
|
|
58
|
+
} & {
|
|
59
|
+
readonly basicInformation: typeof import("@matter/node/behaviors").BasicInformationServer;
|
|
60
|
+
} & {
|
|
61
|
+
readonly generalCommissioning: typeof import("@matter/node/behaviors").GeneralCommissioningServer;
|
|
62
|
+
} & {
|
|
63
|
+
readonly generalDiagnostics: typeof import("@matter/node/behaviors").GeneralDiagnosticsServer;
|
|
64
|
+
} & {
|
|
65
|
+
readonly administratorCommissioning: typeof import("@matter/node/behaviors").AdministratorCommissioningServer;
|
|
66
|
+
} & {
|
|
67
|
+
readonly operationalCredentials: typeof import("@matter/node/behaviors").OperationalCredentialsServer;
|
|
68
|
+
} & {
|
|
69
|
+
readonly groupKeyManagement: typeof import("@matter/node/behaviors").GroupKeyManagementServer;
|
|
70
|
+
}, readonly [typeof import("@matter/node").CommissioningServer, typeof import("@matter/node").NetworkServer, typeof import("@matter/node").ProductDescriptionServer, typeof import("@matter/node").SubscriptionsServer, typeof SessionsBehavior, typeof import("@matter/node").EventsBehavior]>, readonly [import("@matter/node").ClusterBehavior.Type<typeof PowerSourceServer, import("@matter/types/cluster").ClusterType.WithSupportedFeatures<import("@matter/types/cluster").ClusterType.WithSupportedFeatures<import("@matter/types/cluster").ClusterType.WithSupportedFeatures<PowerSource, {
|
|
71
|
+
battery: true;
|
|
72
|
+
rechargeable: true;
|
|
73
|
+
replaceable: false;
|
|
74
|
+
wired: true;
|
|
75
|
+
}>, {
|
|
76
|
+
battery: false;
|
|
77
|
+
rechargeable: false;
|
|
78
|
+
replaceable: false;
|
|
79
|
+
wired: false;
|
|
80
|
+
}>, {
|
|
81
|
+
battery: false;
|
|
82
|
+
rechargeable: false;
|
|
83
|
+
replaceable: false;
|
|
84
|
+
wired: true;
|
|
85
|
+
}>, import("@matter/types/cluster").ClusterType.Concrete, new () => {}, "powerSource">, typeof MatterbridgeTimeSynchronizationServer, typeof MatterbridgeTlsCertificateManagementServer, typeof MatterbridgeTlsClientManagementServer]>, {}>;
|
|
86
|
+
export declare function rootCameraOptions(): {
|
|
87
|
+
powerSource: {
|
|
88
|
+
status: PowerSource.PowerSourceStatus;
|
|
89
|
+
order: number;
|
|
90
|
+
description: string;
|
|
91
|
+
endpointList: EndpointNumber[];
|
|
92
|
+
wiredCurrentType: PowerSource.WiredCurrentType;
|
|
93
|
+
};
|
|
94
|
+
timeSynchronization: {
|
|
95
|
+
utcTime: null;
|
|
96
|
+
granularity: TimeSynchronization.Granularity;
|
|
97
|
+
timeSource: TimeSynchronization.TimeSource;
|
|
98
|
+
trustedTimeSource: null;
|
|
99
|
+
defaultNtp: null;
|
|
100
|
+
supportsDnsResolve: boolean;
|
|
101
|
+
timeZone: {
|
|
102
|
+
offset: number;
|
|
103
|
+
validAt: bigint;
|
|
104
|
+
}[];
|
|
105
|
+
dstOffset: never[];
|
|
106
|
+
localTime: null;
|
|
107
|
+
timeZoneDatabase: TimeSynchronization.TimeZoneDatabase;
|
|
108
|
+
timeZoneListMaxSize: number;
|
|
109
|
+
dstOffsetListMaxSize: number;
|
|
110
|
+
};
|
|
111
|
+
tlsCertificateManagement: {
|
|
112
|
+
maxRootCertificates: number;
|
|
113
|
+
provisionedRootCertificates: never[];
|
|
114
|
+
maxClientCertificates: number;
|
|
115
|
+
provisionedClientCertificates: never[];
|
|
116
|
+
};
|
|
117
|
+
tlsClientManagement: {
|
|
118
|
+
maxProvisioned: number;
|
|
119
|
+
provisionedEndpoints: never[];
|
|
120
|
+
};
|
|
121
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Lifecycle } from '@matter/general';
|
|
2
2
|
import { ServerNode } from '@matter/node';
|
|
3
|
+
import { PowerSourceServer } from '@matter/node/behaviors/power-source';
|
|
3
4
|
import { getClusterNameById } from '@matter/types/cluster';
|
|
4
5
|
import { AirQuality } from '@matter/types/clusters/air-quality';
|
|
5
6
|
import { BridgedDeviceBasicInformation } from '@matter/types/clusters/bridged-device-basic-information';
|
|
@@ -11,12 +12,17 @@ import { OperationalState } from '@matter/types/clusters/operational-state';
|
|
|
11
12
|
import { PowerSource } from '@matter/types/clusters/power-source';
|
|
12
13
|
import { RvcOperationalState } from '@matter/types/clusters/rvc-operational-state';
|
|
13
14
|
import { SmokeCoAlarm } from '@matter/types/clusters/smoke-co-alarm';
|
|
15
|
+
import { TimeSynchronization } from '@matter/types/clusters/time-synchronization';
|
|
14
16
|
import { UserLabel } from '@matter/types/clusters/user-label';
|
|
15
17
|
import { ValveConfigurationAndControl } from '@matter/types/clusters/valve-configuration-and-control';
|
|
18
|
+
import { EndpointNumber } from '@matter/types/datatype';
|
|
16
19
|
import { ThreeLevelAuto } from '@matter/types/globals';
|
|
17
20
|
import { getEnumDescription } from '@matterbridge/utils/enum';
|
|
18
21
|
import { isValidArray, isValidNumber, isValidObject } from '@matterbridge/utils/validate';
|
|
19
22
|
import { stringify } from 'node-ansi-logger';
|
|
23
|
+
import { MATTER_EPOCH_US, MatterbridgeTimeSynchronizationServer } from './behaviors/timeSynchronizationServer.js';
|
|
24
|
+
import { MatterbridgeTlsCertificateManagementServer } from './behaviors/tlsCertificateManagementServer.js';
|
|
25
|
+
import { MatterbridgeTlsClientManagementServer } from './behaviors/tlsClientManagementServer.js';
|
|
20
26
|
import { capitalizeFirstLetter, featuresFor, getAttribute, getSnapshot } from './matterbridgeEndpointHelpers.js';
|
|
21
27
|
const advertisingNodes = new Map();
|
|
22
28
|
export function toApiClusters(endpoint, log) {
|
|
@@ -60,7 +66,7 @@ export function toApiClusters(endpoint, log) {
|
|
|
60
66
|
clusters,
|
|
61
67
|
};
|
|
62
68
|
}
|
|
63
|
-
export function
|
|
69
|
+
export function toDevice(device) {
|
|
64
70
|
return {
|
|
65
71
|
mode: device.mode,
|
|
66
72
|
plugin: device.plugin,
|
|
@@ -483,3 +489,41 @@ export function getVendorIdName(vendorId) {
|
|
|
483
489
|
}
|
|
484
490
|
return vendorName;
|
|
485
491
|
}
|
|
492
|
+
export function rootCameraEndpoint() {
|
|
493
|
+
return ServerNode.RootEndpoint.with(PowerSourceServer.with(PowerSource.Feature.Wired), MatterbridgeTimeSynchronizationServer, MatterbridgeTlsCertificateManagementServer, MatterbridgeTlsClientManagementServer);
|
|
494
|
+
}
|
|
495
|
+
export function rootCameraOptions() {
|
|
496
|
+
return {
|
|
497
|
+
powerSource: {
|
|
498
|
+
status: PowerSource.PowerSourceStatus.Active,
|
|
499
|
+
order: 0,
|
|
500
|
+
description: 'AC Power',
|
|
501
|
+
endpointList: [EndpointNumber(0)],
|
|
502
|
+
wiredCurrentType: PowerSource.WiredCurrentType.Ac,
|
|
503
|
+
},
|
|
504
|
+
timeSynchronization: {
|
|
505
|
+
utcTime: null,
|
|
506
|
+
granularity: TimeSynchronization.Granularity.NoTimeGranularity,
|
|
507
|
+
timeSource: TimeSynchronization.TimeSource.None,
|
|
508
|
+
trustedTimeSource: null,
|
|
509
|
+
defaultNtp: null,
|
|
510
|
+
supportsDnsResolve: false,
|
|
511
|
+
timeZone: [{ offset: 0, validAt: MATTER_EPOCH_US }],
|
|
512
|
+
dstOffset: [],
|
|
513
|
+
localTime: null,
|
|
514
|
+
timeZoneDatabase: TimeSynchronization.TimeZoneDatabase.None,
|
|
515
|
+
timeZoneListMaxSize: 2,
|
|
516
|
+
dstOffsetListMaxSize: 2,
|
|
517
|
+
},
|
|
518
|
+
tlsCertificateManagement: {
|
|
519
|
+
maxRootCertificates: 5,
|
|
520
|
+
provisionedRootCertificates: [],
|
|
521
|
+
maxClientCertificates: 5,
|
|
522
|
+
provisionedClientCertificates: [],
|
|
523
|
+
},
|
|
524
|
+
tlsClientManagement: {
|
|
525
|
+
maxProvisioned: 5,
|
|
526
|
+
provisionedEndpoints: [],
|
|
527
|
+
},
|
|
528
|
+
};
|
|
529
|
+
}
|
package/dist/matterbridge.js
CHANGED
|
@@ -8,11 +8,9 @@ import { inspect } from 'node:util';
|
|
|
8
8
|
import { Crypto, Environment, LogFormat as MatterLogFormat, Logger, LogLevel as MatterLogLevel, StorageService, UINT16_MAX, UINT32_MAX, } from '@matter/general';
|
|
9
9
|
import { Endpoint, ServerNode } from '@matter/node';
|
|
10
10
|
import { BasicInformationServer } from '@matter/node/behaviors/basic-information';
|
|
11
|
-
import { PowerSourceServer } from '@matter/node/behaviors/power-source';
|
|
12
11
|
import { AggregatorEndpoint } from '@matter/node/endpoints/aggregator';
|
|
13
12
|
import { PaseClient } from '@matter/protocol';
|
|
14
|
-
import {
|
|
15
|
-
import { DeviceTypeId, EndpointNumber, VendorId } from '@matter/types/datatype';
|
|
13
|
+
import { DeviceTypeId, VendorId } from '@matter/types/datatype';
|
|
16
14
|
import { ManualPairingCodeCodec } from '@matter/types/schema';
|
|
17
15
|
import { BroadcastServer } from '@matterbridge/thread/server';
|
|
18
16
|
import { dev, MATTER_LOGGER_FILE, MATTER_STORAGE_DIR, MATTERBRIDGE_LOGGER_FILE, NODE_STORAGE_DIR, plg, typ } from '@matterbridge/types';
|
|
@@ -35,7 +33,7 @@ import { bridge } from './matterbridgeDeviceTypes.js';
|
|
|
35
33
|
import { MatterbridgeEndpoint } from './matterbridgeEndpoint.js';
|
|
36
34
|
import { startController } from './matterController.js';
|
|
37
35
|
import { matterToAnsiLogLevel } from './matterLogger.js';
|
|
38
|
-
import { clearAdvertisingNodes, deleteAdvertisingNode, getServerNodeData, setAdvertisingNode } from './matterNodeHelpers.js';
|
|
36
|
+
import { clearAdvertisingNodes, deleteAdvertisingNode, getServerNodeData, rootCameraEndpoint, rootCameraOptions, setAdvertisingNode } from './matterNodeHelpers.js';
|
|
39
37
|
import { PluginManager } from './pluginManager.js';
|
|
40
38
|
logModuleLoaded('Matterbridge');
|
|
41
39
|
export class Matterbridge extends EventEmitter {
|
|
@@ -373,6 +371,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
373
371
|
this.restartRequired = msg.params.restartRequired;
|
|
374
372
|
if (msg.params?.updateRequired !== undefined)
|
|
375
373
|
this.updateRequired = msg.params.updateRequired;
|
|
374
|
+
if (msg.params?.bridgeStatus !== undefined)
|
|
375
|
+
this.bridgeStatus = msg.params.bridgeStatus;
|
|
376
376
|
this.server.respond({ ...msg, result: { data: this.getApiSettings(), success: true } });
|
|
377
377
|
break;
|
|
378
378
|
case 'matterbridge_start_plugin_server':
|
|
@@ -1084,6 +1084,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
1084
1084
|
this.log.debug(`Starting matterbridge in mode ${this.bridgeMode}`);
|
|
1085
1085
|
if (hasParameter('experimental-node')) {
|
|
1086
1086
|
this.log.notice(`***Starting experimental MatterNode threads in ${this.bridgeMode} mode...`);
|
|
1087
|
+
this.server.request({ type: 'frontend_matterbridgestatusupdate', src: 'matterbridge', dst: 'frontend', params: { status: (this.bridgeStatus = 'starting') } });
|
|
1087
1088
|
for (const plugin of this.plugins.array().filter((p) => p.enabled)) {
|
|
1088
1089
|
this.server.request({
|
|
1089
1090
|
type: 'manager_run',
|
|
@@ -1092,6 +1093,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
1092
1093
|
params: { name: 'RootNode', workerData: { threadName: 'RootNode', sharedMatterbridge: this.getSharedMatterbridge(), pluginName: plugin.name } },
|
|
1093
1094
|
});
|
|
1094
1095
|
}
|
|
1096
|
+
this.server.request({ type: 'frontend_matterbridgestatusupdate', src: 'matterbridge', dst: 'frontend', params: { status: (this.bridgeStatus = 'started') } });
|
|
1095
1097
|
this.log.notice(`***Started experimental MatterNode threads in ${this.bridgeMode} mode`);
|
|
1096
1098
|
return;
|
|
1097
1099
|
}
|
|
@@ -1514,7 +1516,9 @@ export class Matterbridge extends EventEmitter {
|
|
|
1514
1516
|
}
|
|
1515
1517
|
this.log.info('Matter storage reset done!');
|
|
1516
1518
|
}
|
|
1517
|
-
|
|
1519
|
+
if (!hasParameter('experimental-node')) {
|
|
1520
|
+
await this.stopMatterStorage();
|
|
1521
|
+
}
|
|
1518
1522
|
clearAdvertisingNodes();
|
|
1519
1523
|
function unlinkSafe(path, log) {
|
|
1520
1524
|
try {
|
|
@@ -2009,12 +2013,14 @@ export class Matterbridge extends EventEmitter {
|
|
|
2009
2013
|
this.log.warn(`Invalid discriminator ${discriminator} for server node ${storeId}. Discriminator must be between 0 and 4095 (0xFFF). Generating a random discriminator...`);
|
|
2010
2014
|
discriminator = PaseClient.generateRandomDiscriminator(this.environment.get(Crypto));
|
|
2011
2015
|
}
|
|
2016
|
+
const rootCamera = hasParameter('root-camera') || Boolean(process.env.MATTERBRIDGE_CHIP_TEST);
|
|
2012
2017
|
let rootEndpoint;
|
|
2013
|
-
if (
|
|
2018
|
+
if (rootCamera) {
|
|
2014
2019
|
this.log.warn(' ****************************************************************************************');
|
|
2015
|
-
this.log.warn(' * Adding the PowerSource
|
|
2020
|
+
this.log.warn(' * Adding the PowerSource, TimeSynchronization, TlsCertificateManagement and *');
|
|
2021
|
+
this.log.warn(' * TlsClientManagement cluster servers to the root endpoint (root camera). *');
|
|
2016
2022
|
this.log.warn(' ****************************************************************************************');
|
|
2017
|
-
rootEndpoint =
|
|
2023
|
+
rootEndpoint = rootCameraEndpoint();
|
|
2018
2024
|
}
|
|
2019
2025
|
else {
|
|
2020
2026
|
rootEndpoint = ServerNode.RootEndpoint;
|
|
@@ -2064,17 +2070,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
2064
2070
|
configurationVersion: await storageContext.get('configurationVersion'),
|
|
2065
2071
|
reachable: true,
|
|
2066
2072
|
},
|
|
2067
|
-
...(
|
|
2068
|
-
? {
|
|
2069
|
-
powerSource: {
|
|
2070
|
-
status: PowerSource.PowerSourceStatus.Active,
|
|
2071
|
-
order: 0,
|
|
2072
|
-
description: 'AC Power',
|
|
2073
|
-
endpointList: [EndpointNumber(0)],
|
|
2074
|
-
wiredCurrentType: PowerSource.WiredCurrentType.Ac,
|
|
2075
|
-
},
|
|
2076
|
-
}
|
|
2077
|
-
: {}),
|
|
2073
|
+
...(rootCamera ? rootCameraOptions() : {}),
|
|
2078
2074
|
});
|
|
2079
2075
|
serverNode.lifecycle.commissioned.on(() => {
|
|
2080
2076
|
this.log.notice(`Server node for ${storeId} commissioned successfully!`);
|