matterbridge 3.2.7 → 3.2.8-dev-20250915-e9a5660
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/CHANGELOG.md +21 -2
- package/dist/cli.js +2 -91
- package/dist/cliEmitter.js +0 -30
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -24
- package/dist/deviceManager.js +1 -94
- package/dist/devices/airConditioner.js +0 -57
- package/dist/devices/batteryStorage.js +1 -48
- package/dist/devices/cooktop.js +0 -55
- package/dist/devices/dishwasher.js +0 -57
- package/dist/devices/evse.js +10 -74
- package/dist/devices/export.js +0 -5
- package/dist/devices/extractorHood.js +0 -42
- package/dist/devices/heatPump.js +2 -50
- package/dist/devices/laundryDryer.js +3 -62
- package/dist/devices/laundryWasher.js +4 -70
- package/dist/devices/microwaveOven.js +5 -88
- package/dist/devices/oven.js +0 -85
- package/dist/devices/refrigerator.js +0 -102
- package/dist/devices/roboticVacuumCleaner.js +9 -100
- package/dist/devices/solarPower.js +0 -38
- package/dist/devices/speaker.js +0 -84
- package/dist/devices/temperatureControl.js +3 -25
- package/dist/devices/waterHeater.js +2 -82
- package/dist/dgram/coap.js +13 -126
- package/dist/dgram/dgram.js +2 -114
- package/dist/dgram/mb_coap.js +3 -41
- package/dist/dgram/mb_mdns.js +15 -80
- package/dist/dgram/mdns.js +137 -299
- package/dist/dgram/multicast.js +1 -62
- package/dist/dgram/unicast.js +0 -54
- package/dist/frontend.js +33 -458
- package/dist/globalMatterbridge.js +0 -47
- package/dist/helpers.js +0 -53
- package/dist/index.js +1 -30
- package/dist/logger/export.js +0 -1
- package/dist/matter/behaviors.js +0 -2
- package/dist/matter/clusters.js +0 -2
- package/dist/matter/devices.js +0 -2
- package/dist/matter/endpoints.js +0 -2
- package/dist/matter/export.js +0 -3
- package/dist/matter/types.js +0 -3
- package/dist/matterbridge.js +53 -789
- package/dist/matterbridgeAccessoryPlatform.js +0 -36
- package/dist/matterbridgeBehaviors.js +5 -65
- package/dist/matterbridgeDeviceTypes.js +17 -630
- package/dist/matterbridgeDynamicPlatform.js +0 -36
- package/dist/matterbridgeEndpoint.js +55 -1373
- package/dist/matterbridgeEndpointHelpers.js +12 -345
- package/dist/matterbridgePlatform.js +0 -304
- package/dist/matterbridgeTypes.js +0 -25
- package/dist/pluginManager.js +3 -249
- package/dist/shelly.js +7 -168
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -69
- package/dist/utils/colorUtils.js +2 -97
- package/dist/utils/commandLine.js +0 -54
- package/dist/utils/copyDirectory.js +1 -38
- package/dist/utils/createDirectory.js +0 -33
- package/dist/utils/createZip.js +2 -47
- package/dist/utils/deepCopy.js +0 -39
- package/dist/utils/deepEqual.js +1 -72
- package/dist/utils/error.js +0 -41
- package/dist/utils/export.js +0 -1
- package/dist/utils/hex.js +0 -124
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/jestHelpers.js +3 -153
- package/dist/utils/network.js +5 -91
- package/dist/utils/spawn.js +0 -40
- package/dist/utils/wait.js +8 -60
- package/frontend/build/asset-manifest.json +6 -6
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/css/{main.a2f4846a.css → main.56c16a87.css} +2 -2
- package/frontend/build/static/css/main.56c16a87.css.map +1 -0
- package/frontend/build/static/js/{main.ee68a4ae.js → main.25c57952.js} +3 -3
- package/frontend/build/static/js/{main.ee68a4ae.js.map → main.25c57952.js.map} +1 -1
- package/frontend/package.json +1 -1
- package/npm-shrinkwrap.json +5 -5
- package/package.json +1 -2
- package/dist/cli.d.ts +0 -26
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cliEmitter.d.ts +0 -34
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.js.map +0 -1
- package/dist/clusters/export.d.ts +0 -2
- package/dist/clusters/export.d.ts.map +0 -1
- package/dist/clusters/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -28
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -112
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/devices/airConditioner.d.ts +0 -98
- package/dist/devices/airConditioner.d.ts.map +0 -1
- package/dist/devices/airConditioner.js.map +0 -1
- package/dist/devices/batteryStorage.d.ts +0 -48
- package/dist/devices/batteryStorage.d.ts.map +0 -1
- package/dist/devices/batteryStorage.js.map +0 -1
- package/dist/devices/cooktop.d.ts +0 -60
- package/dist/devices/cooktop.d.ts.map +0 -1
- package/dist/devices/cooktop.js.map +0 -1
- package/dist/devices/dishwasher.d.ts +0 -71
- package/dist/devices/dishwasher.d.ts.map +0 -1
- package/dist/devices/dishwasher.js.map +0 -1
- package/dist/devices/evse.d.ts +0 -75
- package/dist/devices/evse.d.ts.map +0 -1
- package/dist/devices/evse.js.map +0 -1
- package/dist/devices/export.d.ts +0 -17
- package/dist/devices/export.d.ts.map +0 -1
- package/dist/devices/export.js.map +0 -1
- package/dist/devices/extractorHood.d.ts +0 -46
- package/dist/devices/extractorHood.d.ts.map +0 -1
- package/dist/devices/extractorHood.js.map +0 -1
- package/dist/devices/heatPump.d.ts +0 -47
- package/dist/devices/heatPump.d.ts.map +0 -1
- package/dist/devices/heatPump.js.map +0 -1
- package/dist/devices/laundryDryer.d.ts +0 -67
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -81
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.js.map +0 -1
- package/dist/devices/microwaveOven.d.ts +0 -168
- package/dist/devices/microwaveOven.d.ts.map +0 -1
- package/dist/devices/microwaveOven.js.map +0 -1
- package/dist/devices/oven.d.ts +0 -105
- package/dist/devices/oven.d.ts.map +0 -1
- package/dist/devices/oven.js.map +0 -1
- package/dist/devices/refrigerator.d.ts +0 -118
- package/dist/devices/refrigerator.d.ts.map +0 -1
- package/dist/devices/refrigerator.js.map +0 -1
- package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
- package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/devices/roboticVacuumCleaner.js.map +0 -1
- package/dist/devices/solarPower.d.ts +0 -40
- package/dist/devices/solarPower.d.ts.map +0 -1
- package/dist/devices/solarPower.js.map +0 -1
- package/dist/devices/speaker.d.ts +0 -87
- package/dist/devices/speaker.d.ts.map +0 -1
- package/dist/devices/speaker.js.map +0 -1
- package/dist/devices/temperatureControl.d.ts +0 -166
- package/dist/devices/temperatureControl.d.ts.map +0 -1
- package/dist/devices/temperatureControl.js.map +0 -1
- package/dist/devices/waterHeater.d.ts +0 -111
- package/dist/devices/waterHeater.d.ts.map +0 -1
- package/dist/devices/waterHeater.js.map +0 -1
- package/dist/dgram/coap.d.ts +0 -205
- package/dist/dgram/coap.d.ts.map +0 -1
- package/dist/dgram/coap.js.map +0 -1
- package/dist/dgram/dgram.d.ts +0 -141
- package/dist/dgram/dgram.d.ts.map +0 -1
- package/dist/dgram/dgram.js.map +0 -1
- package/dist/dgram/mb_coap.d.ts +0 -24
- package/dist/dgram/mb_coap.d.ts.map +0 -1
- package/dist/dgram/mb_coap.js.map +0 -1
- package/dist/dgram/mb_mdns.d.ts +0 -24
- package/dist/dgram/mb_mdns.d.ts.map +0 -1
- package/dist/dgram/mb_mdns.js.map +0 -1
- package/dist/dgram/mdns.d.ts +0 -290
- package/dist/dgram/mdns.d.ts.map +0 -1
- package/dist/dgram/mdns.js.map +0 -1
- package/dist/dgram/multicast.d.ts +0 -67
- package/dist/dgram/multicast.d.ts.map +0 -1
- package/dist/dgram/multicast.js.map +0 -1
- package/dist/dgram/unicast.d.ts +0 -56
- package/dist/dgram/unicast.d.ts.map +0 -1
- package/dist/dgram/unicast.js.map +0 -1
- package/dist/frontend.d.ts +0 -315
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/globalMatterbridge.d.ts +0 -59
- package/dist/globalMatterbridge.d.ts.map +0 -1
- package/dist/globalMatterbridge.js.map +0 -1
- package/dist/helpers.d.ts +0 -48
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js.map +0 -1
- package/dist/index.d.ts +0 -33
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger/export.d.ts +0 -2
- package/dist/logger/export.d.ts.map +0 -1
- package/dist/logger/export.js.map +0 -1
- package/dist/matter/behaviors.d.ts +0 -2
- package/dist/matter/behaviors.d.ts.map +0 -1
- package/dist/matter/behaviors.js.map +0 -1
- package/dist/matter/clusters.d.ts +0 -2
- package/dist/matter/clusters.d.ts.map +0 -1
- package/dist/matter/clusters.js.map +0 -1
- package/dist/matter/devices.d.ts +0 -2
- package/dist/matter/devices.d.ts.map +0 -1
- package/dist/matter/devices.js.map +0 -1
- package/dist/matter/endpoints.d.ts +0 -2
- package/dist/matter/endpoints.d.ts.map +0 -1
- package/dist/matter/endpoints.js.map +0 -1
- package/dist/matter/export.d.ts +0 -5
- package/dist/matter/export.d.ts.map +0 -1
- package/dist/matter/export.js.map +0 -1
- package/dist/matter/types.d.ts +0 -3
- package/dist/matter/types.d.ts.map +0 -1
- package/dist/matter/types.js.map +0 -1
- package/dist/matterbridge.d.ts +0 -465
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1747
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -761
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1515
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -407
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -380
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -204
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -270
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -174
- package/dist/shelly.d.ts.map +0 -1
- package/dist/shelly.js.map +0 -1
- package/dist/storage/export.d.ts +0 -2
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/update.d.ts +0 -75
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -99
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/commandLine.d.ts +0 -59
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -33
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createDirectory.d.ts +0 -34
- package/dist/utils/createDirectory.d.ts.map +0 -1
- package/dist/utils/createDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -39
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -32
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -54
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/error.d.ts +0 -44
- package/dist/utils/error.d.ts.map +0 -1
- package/dist/utils/error.js.map +0 -1
- package/dist/utils/export.d.ts +0 -13
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/hex.d.ts +0 -89
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -103
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/jestHelpers.d.ts +0 -137
- package/dist/utils/jestHelpers.d.ts.map +0 -1
- package/dist/utils/jestHelpers.js.map +0 -1
- package/dist/utils/network.d.ts +0 -84
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/spawn.d.ts +0 -33
- package/dist/utils/spawn.d.ts.map +0 -1
- package/dist/utils/spawn.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -54
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
- package/frontend/build/static/css/main.a2f4846a.css.map +0 -1
- /package/frontend/build/static/js/{main.ee68a4ae.js.LICENSE.txt → main.25c57952.js.LICENSE.txt} +0 -0
package/dist/matterbridge.js
CHANGED
|
@@ -1,43 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the class Matterbridge.
|
|
3
|
-
*
|
|
4
|
-
* @file matterbridge.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @created 2023-12-29
|
|
7
|
-
* @version 1.6.0
|
|
8
|
-
* @license Apache-2.0
|
|
9
|
-
*
|
|
10
|
-
* Copyright 2023, 2024, 2025 Luca Liguori.
|
|
11
|
-
*
|
|
12
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License.
|
|
14
|
-
* You may obtain a copy of the License at
|
|
15
|
-
*
|
|
16
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
-
* See the License for the specific language governing permissions and
|
|
22
|
-
* limitations under the License.
|
|
23
|
-
*/
|
|
24
|
-
// Node.js modules
|
|
25
1
|
import os from 'node:os';
|
|
26
2
|
import path from 'node:path';
|
|
27
3
|
import { promises as fs } from 'node:fs';
|
|
28
4
|
import EventEmitter from 'node:events';
|
|
29
5
|
import { inspect } from 'node:util';
|
|
30
|
-
// AnsiLogger module
|
|
31
6
|
import { AnsiLogger, UNDERLINE, UNDERLINEOFF, db, debugStringify, BRIGHT, RESET, er, nf, rs, wr, RED, GREEN, zb, CYAN, nt, BLUE } from 'node-ansi-logger';
|
|
32
|
-
// NodeStorage module
|
|
33
7
|
import { NodeStorageManager } from 'node-persist-manager';
|
|
34
|
-
// @matter
|
|
35
8
|
import { DeviceTypeId, Endpoint, Logger, LogLevel as MatterLogLevel, LogFormat as MatterLogFormat, VendorId, StorageService, Environment, ServerNode, UINT32_MAX, UINT16_MAX, Crypto, } from '@matter/main';
|
|
36
9
|
import { DeviceCommissioner, FabricAction, MdnsService, PaseClient } from '@matter/main/protocol';
|
|
37
10
|
import { AggregatorEndpoint } from '@matter/main/endpoints';
|
|
38
11
|
import { BasicInformationServer } from '@matter/main/behaviors/basic-information';
|
|
39
12
|
import { BridgedDeviceBasicInformationServer } from '@matter/main/behaviors/bridged-device-basic-information';
|
|
40
|
-
// Matterbridge
|
|
41
13
|
import { getParameter, getIntParameter, hasParameter, copyDirectory, isValidString, parseVersionString, isValidNumber, createDirectory } from './utils/export.js';
|
|
42
14
|
import { withTimeout, waiter, wait } from './utils/wait.js';
|
|
43
15
|
import { dev, plg, typ } from './matterbridgeTypes.js';
|
|
@@ -47,9 +19,6 @@ import { MatterbridgeEndpoint } from './matterbridgeEndpoint.js';
|
|
|
47
19
|
import { bridge } from './matterbridgeDeviceTypes.js';
|
|
48
20
|
import { Frontend } from './frontend.js';
|
|
49
21
|
import { addVirtualDevices } from './helpers.js';
|
|
50
|
-
/**
|
|
51
|
-
* Represents the Matterbridge application.
|
|
52
|
-
*/
|
|
53
22
|
export class Matterbridge extends EventEmitter {
|
|
54
23
|
systemInformation = {
|
|
55
24
|
interfaceName: '',
|
|
@@ -98,7 +67,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
98
67
|
shellySysUpdate: false,
|
|
99
68
|
shellyMainUpdate: false,
|
|
100
69
|
profile: getParameter('profile'),
|
|
101
|
-
loggerLevel: "info"
|
|
70
|
+
loggerLevel: "info",
|
|
102
71
|
fileLogger: false,
|
|
103
72
|
matterLoggerLevel: MatterLogLevel.INFO,
|
|
104
73
|
matterFileLogger: false,
|
|
@@ -126,18 +95,15 @@ export class Matterbridge extends EventEmitter {
|
|
|
126
95
|
profile = getParameter('profile');
|
|
127
96
|
shutdown = false;
|
|
128
97
|
failCountLimit = hasParameter('shelly') ? 600 : 120;
|
|
129
|
-
|
|
130
|
-
log = new AnsiLogger({ logName: 'Matterbridge', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: hasParameter('debug') ? "debug" /* LogLevel.DEBUG */ : "info" /* LogLevel.INFO */ });
|
|
98
|
+
log = new AnsiLogger({ logName: 'Matterbridge', logTimestampFormat: 4, logLevel: hasParameter('debug') ? "debug" : "info" });
|
|
131
99
|
matterbridgeLoggerFile = 'matterbridge' + (getParameter('profile') ? '.' + getParameter('profile') : '') + '.log';
|
|
132
100
|
matterLoggerFile = 'matter' + (getParameter('profile') ? '.' + getParameter('profile') : '') + '.log';
|
|
133
101
|
plugins = new PluginManager(this);
|
|
134
102
|
devices = new DeviceManager(this);
|
|
135
103
|
frontend = new Frontend(this);
|
|
136
|
-
// Matterbridge storage
|
|
137
104
|
nodeStorageName = 'storage' + (getParameter('profile') ? '.' + getParameter('profile') : '');
|
|
138
105
|
nodeStorage;
|
|
139
106
|
nodeContext;
|
|
140
|
-
// Cleanup
|
|
141
107
|
hasCleanupStarted = false;
|
|
142
108
|
initialized = false;
|
|
143
109
|
startMatterInterval;
|
|
@@ -151,25 +117,20 @@ export class Matterbridge extends EventEmitter {
|
|
|
151
117
|
sigtermHandler;
|
|
152
118
|
exceptionHandler;
|
|
153
119
|
rejectionHandler;
|
|
154
|
-
|
|
155
|
-
matterLog = new AnsiLogger({ logName: 'Matter', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: "debug" /* LogLevel.DEBUG */ });
|
|
156
|
-
// Matter environment
|
|
120
|
+
matterLog = new AnsiLogger({ logName: 'Matter', logTimestampFormat: 4, logLevel: "debug" });
|
|
157
121
|
environment = Environment.default;
|
|
158
|
-
// Matter storage
|
|
159
122
|
matterStorageName = 'matterstorage' + (getParameter('profile') ? '.' + getParameter('profile') : '');
|
|
160
123
|
matterStorageService;
|
|
161
124
|
matterStorageManager;
|
|
162
125
|
matterbridgeContext;
|
|
163
126
|
controllerContext;
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
certification; // device certification
|
|
172
|
-
// Matter nodes
|
|
127
|
+
mdnsInterface;
|
|
128
|
+
ipv4address;
|
|
129
|
+
ipv6address;
|
|
130
|
+
port;
|
|
131
|
+
passcode;
|
|
132
|
+
discriminator;
|
|
133
|
+
certification;
|
|
173
134
|
serverNode;
|
|
174
135
|
aggregatorNode;
|
|
175
136
|
aggregatorVendorId = VendorId(getIntParameter('vendorId') ?? 0xfff1);
|
|
@@ -181,31 +142,16 @@ export class Matterbridge extends EventEmitter {
|
|
|
181
142
|
aggregatorUniqueId = getParameter('uniqueId');
|
|
182
143
|
advertisingNodes = new Map();
|
|
183
144
|
static instance;
|
|
184
|
-
// We load asyncronously so is private
|
|
185
145
|
constructor() {
|
|
186
146
|
super();
|
|
147
|
+
this.log.logNameColor = '\x1b[38;5;115m';
|
|
187
148
|
}
|
|
188
|
-
/**
|
|
189
|
-
* Retrieves the list of Matterbridge devices.
|
|
190
|
-
*
|
|
191
|
-
* @returns {MatterbridgeEndpoint[]} An array of MatterbridgeDevice objects.
|
|
192
|
-
*/
|
|
193
149
|
getDevices() {
|
|
194
150
|
return this.devices.array();
|
|
195
151
|
}
|
|
196
|
-
/**
|
|
197
|
-
* Retrieves the list of registered plugins.
|
|
198
|
-
*
|
|
199
|
-
* @returns {RegisteredPlugin[]} An array of RegisteredPlugin objects.
|
|
200
|
-
*/
|
|
201
152
|
getPlugins() {
|
|
202
153
|
return this.plugins.array();
|
|
203
154
|
}
|
|
204
|
-
/**
|
|
205
|
-
* Set the logger logLevel for the Matterbridge classes and call onChangeLoggerLevel() for each plugin.
|
|
206
|
-
*
|
|
207
|
-
* @param {LogLevel} logLevel The logger logLevel to set.
|
|
208
|
-
*/
|
|
209
155
|
async setLogLevel(logLevel) {
|
|
210
156
|
if (this.log)
|
|
211
157
|
this.log.logLevel = logLevel;
|
|
@@ -219,31 +165,19 @@ export class Matterbridge extends EventEmitter {
|
|
|
219
165
|
for (const plugin of this.plugins) {
|
|
220
166
|
if (!plugin.platform || !plugin.platform.log || !plugin.platform.config)
|
|
221
167
|
continue;
|
|
222
|
-
plugin.platform.log.logLevel = plugin.platform.config.debug === true ? "debug"
|
|
223
|
-
await plugin.platform.onChangeLoggerLevel(plugin.platform.config.debug === true ? "debug"
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
callbackLogLevel = "debug" /* LogLevel.DEBUG */;
|
|
168
|
+
plugin.platform.log.logLevel = plugin.platform.config.debug === true ? "debug" : this.log.logLevel;
|
|
169
|
+
await plugin.platform.onChangeLoggerLevel(plugin.platform.config.debug === true ? "debug" : this.log.logLevel);
|
|
170
|
+
}
|
|
171
|
+
let callbackLogLevel = "notice";
|
|
172
|
+
if (this.matterbridgeInformation.loggerLevel === "info" || this.matterbridgeInformation.matterLoggerLevel === MatterLogLevel.INFO)
|
|
173
|
+
callbackLogLevel = "info";
|
|
174
|
+
if (this.matterbridgeInformation.loggerLevel === "debug" || this.matterbridgeInformation.matterLoggerLevel === MatterLogLevel.DEBUG)
|
|
175
|
+
callbackLogLevel = "debug";
|
|
231
176
|
AnsiLogger.setGlobalCallback(this.frontend.wssSendMessage.bind(this.frontend), callbackLogLevel);
|
|
232
177
|
this.log.debug(`WebSocketServer logger global callback set to ${callbackLogLevel}`);
|
|
233
178
|
}
|
|
234
|
-
//* ************************************************************************************************************************************ */
|
|
235
|
-
// loadInstance() and cleanup() methods */
|
|
236
|
-
//* ************************************************************************************************************************************ */
|
|
237
|
-
/**
|
|
238
|
-
* Loads an instance of the Matterbridge class.
|
|
239
|
-
* If an instance already exists, return that instance.
|
|
240
|
-
*
|
|
241
|
-
* @param {boolean} initialize - Whether to initialize the Matterbridge instance after loading. Defaults to false.
|
|
242
|
-
* @returns {Matterbridge} A promise that resolves to the Matterbridge instance.
|
|
243
|
-
*/
|
|
244
179
|
static async loadInstance(initialize = false) {
|
|
245
180
|
if (!Matterbridge.instance) {
|
|
246
|
-
// eslint-disable-next-line no-console
|
|
247
181
|
if (hasParameter('debug'))
|
|
248
182
|
console.log(GREEN + 'Creating a new instance of Matterbridge.', initialize ? 'Initializing...' : 'Not initializing...', rs);
|
|
249
183
|
Matterbridge.instance = new Matterbridge();
|
|
@@ -252,17 +186,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
252
186
|
}
|
|
253
187
|
return Matterbridge.instance;
|
|
254
188
|
}
|
|
255
|
-
/**
|
|
256
|
-
* Call cleanup() and dispose MdnsService.
|
|
257
|
-
*
|
|
258
|
-
* @param {number} [timeout] - The timeout duration to wait for the cleanup to complete in milliseconds. Default is 1000.
|
|
259
|
-
* @param {number} [pause] - The pause duration after the cleanup in milliseconds. Default is 250.
|
|
260
|
-
*
|
|
261
|
-
* @deprecated This method is deprecated and is ONLY used for jest tests.
|
|
262
|
-
*/
|
|
263
189
|
async destroyInstance(timeout = 1000, pause = 250) {
|
|
264
190
|
this.log.info(`Destroy instance...`);
|
|
265
|
-
// Save server nodes to close
|
|
266
191
|
const servers = [];
|
|
267
192
|
if (this.bridgeMode === 'bridge') {
|
|
268
193
|
if (this.serverNode)
|
|
@@ -280,105 +205,72 @@ export class Matterbridge extends EventEmitter {
|
|
|
280
205
|
servers.push(device.serverNode);
|
|
281
206
|
}
|
|
282
207
|
}
|
|
283
|
-
// Let any already‐queued microtasks run first
|
|
284
208
|
await Promise.resolve();
|
|
285
|
-
// Wait for the cleanup to finish
|
|
286
209
|
await wait(pause, 'destroyInstance start', true);
|
|
287
|
-
// Cleanup
|
|
288
210
|
await this.cleanup('destroying instance...', false, timeout);
|
|
289
|
-
// Close servers mdns service
|
|
290
211
|
this.log.info(`Dispose ${servers.length} MdnsService...`);
|
|
291
212
|
for (const server of servers) {
|
|
292
213
|
await server.env.get(MdnsService)[Symbol.asyncDispose]();
|
|
293
214
|
this.log.info(`Closed ${server.id} MdnsService`);
|
|
294
215
|
}
|
|
295
|
-
// Let any already‐queued microtasks run first
|
|
296
216
|
await Promise.resolve();
|
|
297
|
-
// Wait for the cleanup to finish
|
|
298
217
|
await wait(pause, 'destroyInstance stop', true);
|
|
299
218
|
}
|
|
300
|
-
/**
|
|
301
|
-
* Initializes the Matterbridge application.
|
|
302
|
-
*
|
|
303
|
-
* @remarks
|
|
304
|
-
* This method performs the necessary setup and initialization steps for the Matterbridge application.
|
|
305
|
-
* It displays the help information if the 'help' parameter is provided, sets up the logger, checks the
|
|
306
|
-
* node version, registers signal handlers, initializes storage, and parses the command line.
|
|
307
|
-
*
|
|
308
|
-
* @returns {Promise<void>} A Promise that resolves when the initialization is complete.
|
|
309
|
-
*/
|
|
310
219
|
async initialize() {
|
|
311
|
-
// Emit the initialize_started event
|
|
312
220
|
this.emit('initialize_started');
|
|
313
|
-
// Set the restart mode
|
|
314
221
|
if (hasParameter('service'))
|
|
315
222
|
this.restartMode = 'service';
|
|
316
223
|
if (hasParameter('docker'))
|
|
317
224
|
this.restartMode = 'docker';
|
|
318
|
-
// Set the matterbridge home directory
|
|
319
225
|
this.homeDirectory = getParameter('homedir') ?? os.homedir();
|
|
320
226
|
this.matterbridgeInformation.homeDirectory = this.homeDirectory;
|
|
321
227
|
await createDirectory(this.homeDirectory, 'Matterbridge Home Directory', this.log);
|
|
322
|
-
// Set the matterbridge directory
|
|
323
228
|
this.matterbridgeDirectory = path.join(this.homeDirectory, '.matterbridge');
|
|
324
229
|
this.matterbridgeInformation.matterbridgeDirectory = this.matterbridgeDirectory;
|
|
325
230
|
await createDirectory(this.matterbridgeDirectory, 'Matterbridge Directory', this.log);
|
|
326
231
|
await createDirectory(path.join(this.matterbridgeDirectory, 'certs'), 'Matterbridge Frontend Certificate Directory', this.log);
|
|
327
232
|
await createDirectory(path.join(this.matterbridgeDirectory, 'uploads'), 'Matterbridge Frontend Uploads Directory', this.log);
|
|
328
|
-
// Set the matterbridge plugin directory
|
|
329
233
|
this.matterbridgePluginDirectory = path.join(this.homeDirectory, 'Matterbridge');
|
|
330
234
|
this.matterbridgeInformation.matterbridgePluginDirectory = this.matterbridgePluginDirectory;
|
|
331
235
|
await createDirectory(this.matterbridgePluginDirectory, 'Matterbridge Plugin Directory', this.log);
|
|
332
|
-
// Set the matterbridge cert directory
|
|
333
236
|
this.matterbridgeCertDirectory = path.join(this.homeDirectory, '.mattercert');
|
|
334
237
|
this.matterbridgeInformation.matterbridgeCertDirectory = this.matterbridgeCertDirectory;
|
|
335
238
|
await createDirectory(this.matterbridgeCertDirectory, 'Matterbridge Matter Certificate Directory', this.log);
|
|
336
|
-
// Set the matterbridge root directory
|
|
337
239
|
const { fileURLToPath } = await import('node:url');
|
|
338
240
|
const currentFileDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
339
241
|
this.rootDirectory = path.resolve(currentFileDirectory, '../');
|
|
340
242
|
this.matterbridgeInformation.rootDirectory = this.rootDirectory;
|
|
341
|
-
// Setup the matter environment
|
|
342
243
|
this.environment.vars.set('log.level', MatterLogLevel.INFO);
|
|
343
244
|
this.environment.vars.set('log.format', MatterLogFormat.ANSI);
|
|
344
245
|
this.environment.vars.set('path.root', path.join(this.matterbridgeDirectory, this.matterStorageName));
|
|
345
246
|
this.environment.vars.set('runtime.signals', false);
|
|
346
247
|
this.environment.vars.set('runtime.exitcode', false);
|
|
347
|
-
// Register process handlers
|
|
348
248
|
this.registerProcessHandlers();
|
|
349
|
-
// Initialize nodeStorage and nodeContext
|
|
350
249
|
try {
|
|
351
250
|
this.log.debug(`Creating node storage manager: ${CYAN}${this.nodeStorageName}${db}`);
|
|
352
251
|
this.nodeStorage = new NodeStorageManager({ dir: path.join(this.matterbridgeDirectory, this.nodeStorageName), writeQueue: false, expiredInterval: undefined, logging: false });
|
|
353
252
|
this.log.debug('Creating node storage context for matterbridge');
|
|
354
253
|
this.nodeContext = await this.nodeStorage.createStorage('matterbridge');
|
|
355
|
-
// TODO: Remove this code when node-persist-manager is updated
|
|
356
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
357
254
|
const keys = (await this.nodeStorage?.storage.keys());
|
|
358
255
|
for (const key of keys) {
|
|
359
256
|
this.log.debug(`Checking node storage manager key: ${CYAN}${key}${db}`);
|
|
360
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
361
257
|
await this.nodeStorage?.storage.get(key);
|
|
362
258
|
}
|
|
363
259
|
const storages = await this.nodeStorage.getStorageNames();
|
|
364
260
|
for (const storage of storages) {
|
|
365
261
|
this.log.debug(`Checking storage: ${CYAN}${storage}${db}`);
|
|
366
262
|
const nodeContext = await this.nodeStorage?.createStorage(storage);
|
|
367
|
-
// TODO: Remove this code when node-persist-manager is updated
|
|
368
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
369
263
|
const keys = (await nodeContext?.storage.keys());
|
|
370
264
|
keys.forEach(async (key) => {
|
|
371
265
|
this.log.debug(`Checking key: ${CYAN}${storage}:${key}${db}`);
|
|
372
266
|
await nodeContext?.get(key);
|
|
373
267
|
});
|
|
374
268
|
}
|
|
375
|
-
// Creating a backup of the node storage since it is not corrupted
|
|
376
269
|
this.log.debug('Creating node storage backup...');
|
|
377
270
|
await copyDirectory(path.join(this.matterbridgeDirectory, this.nodeStorageName), path.join(this.matterbridgeDirectory, this.nodeStorageName + '.backup'));
|
|
378
271
|
this.log.debug('Created node storage backup');
|
|
379
272
|
}
|
|
380
273
|
catch (error) {
|
|
381
|
-
// Restoring the backup of the node storage since it is corrupted
|
|
382
274
|
this.log.error(`Error creating node storage manager and context: ${error instanceof Error ? error.message : error}`);
|
|
383
275
|
if (hasParameter('norestore')) {
|
|
384
276
|
this.log.fatal(`The matterbridge storage is corrupted. Found -norestore parameter: exiting...`);
|
|
@@ -392,19 +284,14 @@ export class Matterbridge extends EventEmitter {
|
|
|
392
284
|
if (!this.nodeStorage || !this.nodeContext) {
|
|
393
285
|
throw new Error('Fatal error creating node storage manager and context for matterbridge');
|
|
394
286
|
}
|
|
395
|
-
// Set the first port to use for the commissioning server (will be incremented in childbridge mode)
|
|
396
287
|
this.port = getIntParameter('port') ?? (await this.nodeContext.get('matterport', 5540)) ?? 5540;
|
|
397
|
-
// Set the first passcode to use for the commissioning server (will be incremented in childbridge mode)
|
|
398
288
|
this.passcode = getIntParameter('passcode') ?? (await this.nodeContext.get('matterpasscode')) ?? PaseClient.generateRandomPasscode(this.environment.get(Crypto));
|
|
399
|
-
// Set the first discriminator to use for the commissioning server (will be incremented in childbridge mode)
|
|
400
289
|
this.discriminator = getIntParameter('discriminator') ?? (await this.nodeContext.get('matterdiscriminator')) ?? PaseClient.generateRandomDiscriminator(this.environment.get(Crypto));
|
|
401
|
-
// Certificate management
|
|
402
290
|
const pairingFilePath = path.join(this.matterbridgeCertDirectory, 'pairing.json');
|
|
403
291
|
try {
|
|
404
292
|
await fs.access(pairingFilePath, fs.constants.R_OK);
|
|
405
293
|
const pairingFileContent = await fs.readFile(pairingFilePath, 'utf8');
|
|
406
294
|
const pairingFileJson = JSON.parse(pairingFileContent);
|
|
407
|
-
// Set the vendorId, vendorName, productId, productName, deviceType, serialNumber, uniqueId if they are present in the pairing file
|
|
408
295
|
if (isValidNumber(pairingFileJson.vendorId)) {
|
|
409
296
|
this.aggregatorVendorId = VendorId(pairingFileJson.vendorId);
|
|
410
297
|
this.log.info(`Pairing file ${CYAN}${pairingFilePath}${nf} found. Using vendorId ${CYAN}${this.aggregatorVendorId}${nf} from pairing file.`);
|
|
@@ -433,13 +320,11 @@ export class Matterbridge extends EventEmitter {
|
|
|
433
320
|
this.aggregatorUniqueId = pairingFileJson.uniqueId;
|
|
434
321
|
this.log.info(`Pairing file ${CYAN}${pairingFilePath}${nf} found. Using uniqueId ${CYAN}${this.aggregatorUniqueId}${nf} from pairing file.`);
|
|
435
322
|
}
|
|
436
|
-
// Override the passcode and discriminator if they are present in the pairing file
|
|
437
323
|
if (isValidNumber(pairingFileJson.passcode) && isValidNumber(pairingFileJson.discriminator)) {
|
|
438
324
|
this.passcode = pairingFileJson.passcode;
|
|
439
325
|
this.discriminator = pairingFileJson.discriminator;
|
|
440
326
|
this.log.info(`Pairing file ${CYAN}${pairingFilePath}${nf} found. Using passcode ${CYAN}${this.passcode}${nf} and discriminator ${CYAN}${this.discriminator}${nf} from pairing file.`);
|
|
441
327
|
}
|
|
442
|
-
// Set the certification for matter.js if it is present in the pairing file
|
|
443
328
|
if (pairingFileJson.privateKey && pairingFileJson.certificate && pairingFileJson.intermediateCertificate && pairingFileJson.declaration) {
|
|
444
329
|
const { hexToBuffer } = await import('./utils/hex.js');
|
|
445
330
|
this.certification = {
|
|
@@ -454,44 +339,41 @@ export class Matterbridge extends EventEmitter {
|
|
|
454
339
|
catch (error) {
|
|
455
340
|
this.log.debug(`Pairing file ${CYAN}${pairingFilePath}${db} not found: ${error instanceof Error ? error.message : error}`);
|
|
456
341
|
}
|
|
457
|
-
// Store the passcode, discriminator and port in the node context
|
|
458
342
|
await this.nodeContext.set('matterport', this.port);
|
|
459
343
|
await this.nodeContext.set('matterpasscode', this.passcode);
|
|
460
344
|
await this.nodeContext.set('matterdiscriminator', this.discriminator);
|
|
461
345
|
this.log.debug(`Initializing server node for Matterbridge on port ${this.port} with passcode ${this.passcode} and discriminator ${this.discriminator}`);
|
|
462
|
-
// Set matterbridge logger level (context: matterbridgeLogLevel)
|
|
463
346
|
if (hasParameter('logger')) {
|
|
464
347
|
const level = getParameter('logger');
|
|
465
348
|
if (level === 'debug') {
|
|
466
|
-
this.log.logLevel = "debug"
|
|
349
|
+
this.log.logLevel = "debug";
|
|
467
350
|
}
|
|
468
351
|
else if (level === 'info') {
|
|
469
|
-
this.log.logLevel = "info"
|
|
352
|
+
this.log.logLevel = "info";
|
|
470
353
|
}
|
|
471
354
|
else if (level === 'notice') {
|
|
472
|
-
this.log.logLevel = "notice"
|
|
355
|
+
this.log.logLevel = "notice";
|
|
473
356
|
}
|
|
474
357
|
else if (level === 'warn') {
|
|
475
|
-
this.log.logLevel = "warn"
|
|
358
|
+
this.log.logLevel = "warn";
|
|
476
359
|
}
|
|
477
360
|
else if (level === 'error') {
|
|
478
|
-
this.log.logLevel = "error"
|
|
361
|
+
this.log.logLevel = "error";
|
|
479
362
|
}
|
|
480
363
|
else if (level === 'fatal') {
|
|
481
|
-
this.log.logLevel = "fatal"
|
|
364
|
+
this.log.logLevel = "fatal";
|
|
482
365
|
}
|
|
483
366
|
else {
|
|
484
367
|
this.log.warn(`Invalid matterbridge logger level: ${level}. Using default level "info".`);
|
|
485
|
-
this.log.logLevel = "info"
|
|
368
|
+
this.log.logLevel = "info";
|
|
486
369
|
}
|
|
487
370
|
}
|
|
488
371
|
else {
|
|
489
|
-
this.log.logLevel = await this.nodeContext.get('matterbridgeLogLevel', this.matterbridgeInformation.shellyBoard ? "notice"
|
|
372
|
+
this.log.logLevel = await this.nodeContext.get('matterbridgeLogLevel', this.matterbridgeInformation.shellyBoard ? "notice" : "info");
|
|
490
373
|
}
|
|
491
374
|
this.frontend.logLevel = this.log.logLevel;
|
|
492
375
|
MatterbridgeEndpoint.logLevel = this.log.logLevel;
|
|
493
376
|
this.matterbridgeInformation.loggerLevel = this.log.logLevel;
|
|
494
|
-
// Create the file logger for matterbridge (context: matterbridgeFileLog)
|
|
495
377
|
if (hasParameter('filelogger') || (await this.nodeContext.get('matterbridgeFileLog', false))) {
|
|
496
378
|
AnsiLogger.setGlobalLogfile(path.join(this.matterbridgeDirectory, this.matterbridgeLoggerFile), this.log.logLevel, true);
|
|
497
379
|
this.matterbridgeInformation.fileLogger = true;
|
|
@@ -500,7 +382,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
500
382
|
this.log.debug(`Matterbridge logLevel: ${this.log.logLevel} fileLoger: ${this.matterbridgeInformation.fileLogger}.`);
|
|
501
383
|
if (this.profile !== undefined)
|
|
502
384
|
this.log.debug(`Matterbridge profile: ${this.profile}.`);
|
|
503
|
-
// Set matter.js logger level, format and logger (context: matterLogLevel)
|
|
504
385
|
if (hasParameter('matterlogger')) {
|
|
505
386
|
const level = getParameter('matterlogger');
|
|
506
387
|
if (level === 'debug') {
|
|
@@ -530,14 +411,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
530
411
|
Logger.level = (await this.nodeContext.get('matterLogLevel', this.matterbridgeInformation.shellyBoard ? MatterLogLevel.NOTICE : MatterLogLevel.INFO));
|
|
531
412
|
}
|
|
532
413
|
Logger.format = MatterLogFormat.ANSI;
|
|
533
|
-
// Create the logger for matter.js with file logging (context: matterFileLog)
|
|
534
414
|
if (hasParameter('matterfilelogger') || (await this.nodeContext.get('matterFileLog', false))) {
|
|
535
415
|
this.matterbridgeInformation.matterFileLogger = true;
|
|
536
416
|
}
|
|
537
417
|
Logger.destinations.default.write = this.createDestinationMatterLogger(this.matterbridgeInformation.matterFileLogger);
|
|
538
418
|
this.matterbridgeInformation.matterLoggerLevel = Logger.level;
|
|
539
419
|
this.log.debug(`Matter logLevel: ${Logger.level} fileLoger: ${this.matterbridgeInformation.matterFileLogger}.`);
|
|
540
|
-
// Log network interfaces
|
|
541
420
|
const networkInterfaces = os.networkInterfaces();
|
|
542
421
|
const availableAddresses = Object.entries(networkInterfaces);
|
|
543
422
|
const availableInterfaces = Object.keys(networkInterfaces);
|
|
@@ -550,7 +429,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
550
429
|
});
|
|
551
430
|
}
|
|
552
431
|
}
|
|
553
|
-
// Set the interface to use for matter server node mdnsInterface
|
|
554
432
|
if (hasParameter('mdnsinterface')) {
|
|
555
433
|
this.mdnsInterface = getParameter('mdnsinterface');
|
|
556
434
|
}
|
|
@@ -559,7 +437,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
559
437
|
if (this.mdnsInterface === '')
|
|
560
438
|
this.mdnsInterface = undefined;
|
|
561
439
|
}
|
|
562
|
-
// Validate mdnsInterface
|
|
563
440
|
if (this.mdnsInterface) {
|
|
564
441
|
if (!availableInterfaces.includes(this.mdnsInterface)) {
|
|
565
442
|
this.log.error(`Invalid mdnsinterface: ${this.mdnsInterface}. Available interfaces are: ${availableInterfaces.join(', ')}. Using all available interfaces.`);
|
|
@@ -572,7 +449,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
572
449
|
}
|
|
573
450
|
if (this.mdnsInterface)
|
|
574
451
|
this.environment.vars.set('mdns.networkInterface', this.mdnsInterface);
|
|
575
|
-
// Set the listeningAddressIpv4 for the matter commissioning server
|
|
576
452
|
if (hasParameter('ipv4address')) {
|
|
577
453
|
this.ipv4address = getParameter('ipv4address');
|
|
578
454
|
}
|
|
@@ -581,7 +457,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
581
457
|
if (this.ipv4address === '')
|
|
582
458
|
this.ipv4address = undefined;
|
|
583
459
|
}
|
|
584
|
-
// Validate ipv4address
|
|
585
460
|
if (this.ipv4address) {
|
|
586
461
|
let isValid = false;
|
|
587
462
|
for (const [ifaceName, ifaces] of availableAddresses) {
|
|
@@ -597,7 +472,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
597
472
|
await this.nodeContext.remove('matteripv4address');
|
|
598
473
|
}
|
|
599
474
|
}
|
|
600
|
-
// Set the listeningAddressIpv6 for the matter commissioning server
|
|
601
475
|
if (hasParameter('ipv6address')) {
|
|
602
476
|
this.ipv6address = getParameter('ipv6address');
|
|
603
477
|
}
|
|
@@ -606,7 +480,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
606
480
|
if (this.ipv6address === '')
|
|
607
481
|
this.ipv6address = undefined;
|
|
608
482
|
}
|
|
609
|
-
// Validate ipv6address
|
|
610
483
|
if (this.ipv6address) {
|
|
611
484
|
let isValid = false;
|
|
612
485
|
for (const [ifaceName, ifaces] of availableAddresses) {
|
|
@@ -615,7 +488,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
615
488
|
isValid = true;
|
|
616
489
|
break;
|
|
617
490
|
}
|
|
618
|
-
/* istanbul ignore next */
|
|
619
491
|
if (ifaces && ifaces.find((iface) => iface.scopeid && iface.scopeid > 0 && iface.address + '%' + (process.platform === 'win32' ? iface.scopeid : ifaceName) === this.ipv6address)) {
|
|
620
492
|
this.log.info(`Using ipv6address ${CYAN}${this.ipv6address}${nf} on interface ${CYAN}${ifaceName}${nf} for the Matter server node.`);
|
|
621
493
|
isValid = true;
|
|
@@ -628,7 +500,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
628
500
|
await this.nodeContext.remove('matteripv6address');
|
|
629
501
|
}
|
|
630
502
|
}
|
|
631
|
-
// Initialize the virtual mode
|
|
632
503
|
if (hasParameter('novirtual')) {
|
|
633
504
|
this.matterbridgeInformation.virtualMode = 'disabled';
|
|
634
505
|
await this.nodeContext.set('virtualmode', 'disabled');
|
|
@@ -637,17 +508,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
637
508
|
this.matterbridgeInformation.virtualMode = (await this.nodeContext.get('virtualmode', 'outlet'));
|
|
638
509
|
}
|
|
639
510
|
this.log.debug(`Virtual mode ${this.matterbridgeInformation.virtualMode}.`);
|
|
640
|
-
// Initialize PluginManager
|
|
641
511
|
this.plugins.logLevel = this.log.logLevel;
|
|
642
512
|
await this.plugins.loadFromStorage();
|
|
643
|
-
// Initialize DeviceManager
|
|
644
513
|
this.devices.logLevel = this.log.logLevel;
|
|
645
|
-
// Get the plugins from node storage and create the plugins node storage contexts
|
|
646
514
|
for (const plugin of this.plugins) {
|
|
647
515
|
const packageJson = await this.plugins.parse(plugin);
|
|
648
516
|
if (packageJson === null && !hasParameter('add') && !hasParameter('remove') && !hasParameter('enable') && !hasParameter('disable') && !hasParameter('reset') && !hasParameter('factoryreset')) {
|
|
649
|
-
// Try to reinstall the plugin from npm (for Docker pull and external plugins)
|
|
650
|
-
// We don't do this when the add and other parameters are set because we shut down the process after adding the plugin
|
|
651
517
|
this.log.info(`Error parsing plugin ${plg}${plugin.name}${nf}. Trying to reinstall it from npm.`);
|
|
652
518
|
try {
|
|
653
519
|
const { spawnCommand } = await import('./utils/spawn.js');
|
|
@@ -670,7 +536,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
670
536
|
await plugin.nodeContext.set('description', plugin.description);
|
|
671
537
|
await plugin.nodeContext.set('author', plugin.author);
|
|
672
538
|
}
|
|
673
|
-
// Log system info and create .matterbridge directory
|
|
674
539
|
await this.logNodeAndSystemInfo();
|
|
675
540
|
this.log.notice(`Matterbridge version ${this.matterbridgeVersion} ` +
|
|
676
541
|
`${hasParameter('bridge') || (!hasParameter('childbridge') && (await this.nodeContext?.get('bridgeMode', '')) === 'bridge') ? 'mode bridge ' : ''}` +
|
|
@@ -678,7 +543,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
678
543
|
`${hasParameter('controller') ? 'mode controller ' : ''}` +
|
|
679
544
|
`${this.restartMode !== '' ? 'restart mode ' + this.restartMode + ' ' : ''}` +
|
|
680
545
|
`running on ${this.systemInformation.osType} (v.${this.systemInformation.osRelease}) platform ${this.systemInformation.osPlatform} arch ${this.systemInformation.osArch}`);
|
|
681
|
-
// Check node version and throw error
|
|
682
546
|
const minNodeVersion = 18;
|
|
683
547
|
const nodeVersion = process.versions.node;
|
|
684
548
|
const versionMajor = parseInt(nodeVersion.split('.')[0]);
|
|
@@ -686,18 +550,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
686
550
|
this.log.error(`Node version ${versionMajor} is not supported. Please upgrade to ${minNodeVersion} or above.`);
|
|
687
551
|
throw new Error(`Node version ${versionMajor} is not supported. Please upgrade to ${minNodeVersion} or above.`);
|
|
688
552
|
}
|
|
689
|
-
// Parse command line
|
|
690
553
|
await this.parseCommandLine();
|
|
691
|
-
// Emit the initialize_completed event
|
|
692
554
|
this.emit('initialize_completed');
|
|
693
555
|
this.initialized = true;
|
|
694
556
|
}
|
|
695
|
-
/**
|
|
696
|
-
* Parses the command line arguments and performs the corresponding actions.
|
|
697
|
-
*
|
|
698
|
-
* @private
|
|
699
|
-
* @returns {Promise<void>} A promise that resolves when the command line arguments have been processed, or the process exits.
|
|
700
|
-
*/
|
|
701
557
|
async parseCommandLine() {
|
|
702
558
|
if (hasParameter('help')) {
|
|
703
559
|
this.log.info(`\nUsage: matterbridge [options]\n
|
|
@@ -759,19 +615,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
759
615
|
}
|
|
760
616
|
index++;
|
|
761
617
|
}
|
|
762
|
-
/*
|
|
763
|
-
const serializedRegisteredDevices = await this.nodeContext?.get<SerializedMatterbridgeEndpoint[]>('devices', []);
|
|
764
|
-
this.log.info(`│ Registered devices (${serializedRegisteredDevices?.length})`);
|
|
765
|
-
serializedRegisteredDevices?.forEach((device, index) => {
|
|
766
|
-
if (index !== serializedRegisteredDevices.length - 1) {
|
|
767
|
-
this.log.info(`├─┬─ plugin ${plg}${device.pluginName}${nf} device: ${dev}${device.deviceName}${nf} uniqueId: ${YELLOW}${device.uniqueId}${nf}`);
|
|
768
|
-
this.log.info(`│ └─ endpoint ${RED}${device.endpoint}${nf} ${typ}${device.endpointName}${nf} ${debugStringify(device.clusterServersId)}`);
|
|
769
|
-
} else {
|
|
770
|
-
this.log.info(`└─┬─ plugin ${plg}${device.pluginName}${nf} device: ${dev}${device.deviceName}${nf} uniqueId: ${YELLOW}${device.uniqueId}${nf}`);
|
|
771
|
-
this.log.info(` └─ endpoint ${RED}${device.endpoint}${nf} ${typ}${device.endpointName}${nf} ${debugStringify(device.clusterServersId)}`);
|
|
772
|
-
}
|
|
773
|
-
});
|
|
774
|
-
*/
|
|
775
618
|
this.shutdown = true;
|
|
776
619
|
return;
|
|
777
620
|
}
|
|
@@ -821,7 +664,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
821
664
|
this.shutdown = true;
|
|
822
665
|
return;
|
|
823
666
|
}
|
|
824
|
-
// Start the matter storage and create the matterbridge context
|
|
825
667
|
try {
|
|
826
668
|
await this.startMatterStorage();
|
|
827
669
|
if (this.aggregatorSerialNumber && this.aggregatorUniqueId && this.matterStorageService) {
|
|
@@ -838,21 +680,18 @@ export class Matterbridge extends EventEmitter {
|
|
|
838
680
|
this.log.fatal(`Fatal error creating matter storage: ${error instanceof Error ? error.message : error}`);
|
|
839
681
|
throw new Error(`Fatal error creating matter storage: ${error instanceof Error ? error.message : error}`);
|
|
840
682
|
}
|
|
841
|
-
// Clear the matterbridge context if the reset parameter is set
|
|
842
683
|
if (hasParameter('reset') && getParameter('reset') === undefined) {
|
|
843
684
|
this.initialized = true;
|
|
844
685
|
await this.shutdownProcessAndReset();
|
|
845
686
|
this.shutdown = true;
|
|
846
687
|
return;
|
|
847
688
|
}
|
|
848
|
-
// Clear matterbridge plugin context if the reset parameter is set
|
|
849
689
|
if (hasParameter('reset') && getParameter('reset') !== undefined) {
|
|
850
690
|
this.log.debug(`Reset plugin ${getParameter('reset')}`);
|
|
851
691
|
const plugin = this.plugins.get(getParameter('reset'));
|
|
852
692
|
if (plugin) {
|
|
853
693
|
const matterStorageManager = await this.matterStorageService?.open(plugin.name);
|
|
854
694
|
if (!matterStorageManager) {
|
|
855
|
-
/* istanbul ignore next */
|
|
856
695
|
this.log.error(`Plugin ${plg}${plugin.name}${er} storageManager not found`);
|
|
857
696
|
}
|
|
858
697
|
else {
|
|
@@ -871,45 +710,37 @@ export class Matterbridge extends EventEmitter {
|
|
|
871
710
|
this.shutdown = true;
|
|
872
711
|
return;
|
|
873
712
|
}
|
|
874
|
-
// Initialize frontend
|
|
875
713
|
if (getIntParameter('frontend') !== 0 || getIntParameter('frontend') === undefined)
|
|
876
714
|
await this.frontend.start(getIntParameter('frontend'));
|
|
877
|
-
// Check in 30 seconds the latest and dev versions of matterbridge and the plugins
|
|
878
715
|
clearTimeout(this.checkUpdateTimeout);
|
|
879
716
|
this.checkUpdateTimeout = setTimeout(async () => {
|
|
880
717
|
const { checkUpdates } = await import('./update.js');
|
|
881
718
|
checkUpdates(this);
|
|
882
719
|
}, 30 * 1000).unref();
|
|
883
|
-
// Check each 12 hours the latest and dev versions of matterbridge and the plugins
|
|
884
720
|
clearInterval(this.checkUpdateInterval);
|
|
885
721
|
this.checkUpdateInterval = setInterval(async () => {
|
|
886
722
|
const { checkUpdates } = await import('./update.js');
|
|
887
723
|
checkUpdates(this);
|
|
888
724
|
}, 12 * 60 * 60 * 1000).unref();
|
|
889
|
-
// Start the matterbridge in mode test
|
|
890
725
|
if (hasParameter('test')) {
|
|
891
726
|
this.bridgeMode = 'bridge';
|
|
892
727
|
return;
|
|
893
728
|
}
|
|
894
|
-
// Start the matterbridge in mode controller
|
|
895
729
|
if (hasParameter('controller')) {
|
|
896
730
|
this.bridgeMode = 'controller';
|
|
897
731
|
await this.startController();
|
|
898
732
|
return;
|
|
899
733
|
}
|
|
900
|
-
// Check if the bridge mode is set and start matterbridge in bridge mode if not set
|
|
901
734
|
if (!hasParameter('bridge') && !hasParameter('childbridge') && (await this.nodeContext?.get('bridgeMode', '')) === '') {
|
|
902
735
|
this.log.info('Setting default matterbridge start mode to bridge');
|
|
903
736
|
await this.nodeContext?.set('bridgeMode', 'bridge');
|
|
904
737
|
}
|
|
905
|
-
// Start matterbridge in bridge mode
|
|
906
738
|
if (hasParameter('bridge') || (!hasParameter('childbridge') && (await this.nodeContext?.get('bridgeMode', '')) === 'bridge')) {
|
|
907
739
|
this.bridgeMode = 'bridge';
|
|
908
740
|
this.log.debug(`Starting matterbridge in mode ${this.bridgeMode}`);
|
|
909
741
|
await this.startBridge();
|
|
910
742
|
return;
|
|
911
743
|
}
|
|
912
|
-
// Start matterbridge in childbridge mode
|
|
913
744
|
if (hasParameter('childbridge') || (!hasParameter('bridge') && (await this.nodeContext?.get('bridgeMode', '')) === 'childbridge')) {
|
|
914
745
|
this.bridgeMode = 'childbridge';
|
|
915
746
|
this.log.debug(`Starting matterbridge in mode ${this.bridgeMode}`);
|
|
@@ -917,20 +748,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
917
748
|
return;
|
|
918
749
|
}
|
|
919
750
|
}
|
|
920
|
-
/**
|
|
921
|
-
* Asynchronously loads and starts the registered plugins.
|
|
922
|
-
*
|
|
923
|
-
* This method is responsible for initializing and starting all enabled plugins.
|
|
924
|
-
* It ensures that each plugin is properly loaded and started before the bridge starts.
|
|
925
|
-
*
|
|
926
|
-
* @returns {Promise<void>} A promise that resolves when all plugins have been loaded and started.
|
|
927
|
-
*/
|
|
928
751
|
async startPlugins() {
|
|
929
|
-
// Check, load and start the plugins
|
|
930
752
|
for (const plugin of this.plugins) {
|
|
931
753
|
plugin.configJson = await this.plugins.loadConfig(plugin);
|
|
932
754
|
plugin.schemaJson = await this.plugins.loadSchema(plugin);
|
|
933
|
-
// Check if the plugin is available
|
|
934
755
|
if (!(await this.plugins.resolve(plugin.path))) {
|
|
935
756
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not found or not validated. Disabling it.`);
|
|
936
757
|
plugin.enabled = false;
|
|
@@ -948,14 +769,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
948
769
|
plugin.configured = false;
|
|
949
770
|
plugin.registeredDevices = undefined;
|
|
950
771
|
plugin.addedDevices = undefined;
|
|
951
|
-
this.plugins.load(plugin, true, 'Matterbridge is starting');
|
|
772
|
+
this.plugins.load(plugin, true, 'Matterbridge is starting');
|
|
952
773
|
}
|
|
953
774
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
954
775
|
}
|
|
955
|
-
/**
|
|
956
|
-
* Registers the process handlers for uncaughtException, unhandledRejection, SIGINT and SIGTERM.
|
|
957
|
-
* When either of these signals are received, the cleanup method is called with an appropriate message.
|
|
958
|
-
*/
|
|
959
776
|
registerProcessHandlers() {
|
|
960
777
|
this.log.debug(`Registering uncaughtException and unhandledRejection handlers...`);
|
|
961
778
|
process.removeAllListeners('uncaughtException');
|
|
@@ -982,9 +799,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
982
799
|
};
|
|
983
800
|
process.on('SIGTERM', this.sigtermHandler);
|
|
984
801
|
}
|
|
985
|
-
/**
|
|
986
|
-
* Deregisters the process uncaughtException, unhandledRejection, SIGINT and SIGTERM signal handlers.
|
|
987
|
-
*/
|
|
988
802
|
deregisterProcessHandlers() {
|
|
989
803
|
this.log.debug(`Deregistering uncaughtException and unhandledRejection handlers...`);
|
|
990
804
|
if (this.exceptionHandler)
|
|
@@ -1001,17 +815,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
1001
815
|
process.off('SIGTERM', this.sigtermHandler);
|
|
1002
816
|
this.sigtermHandler = undefined;
|
|
1003
817
|
}
|
|
1004
|
-
/**
|
|
1005
|
-
* Logs the node and system information.
|
|
1006
|
-
*/
|
|
1007
818
|
async logNodeAndSystemInfo() {
|
|
1008
|
-
// IP address information
|
|
1009
819
|
const networkInterfaces = os.networkInterfaces();
|
|
1010
820
|
this.systemInformation.interfaceName = '';
|
|
1011
821
|
this.systemInformation.ipv4Address = '';
|
|
1012
822
|
this.systemInformation.ipv6Address = '';
|
|
1013
823
|
for (const [interfaceName, interfaceDetails] of Object.entries(networkInterfaces)) {
|
|
1014
|
-
// this.log.debug(`Checking interface: '${interfaceName}' for '${this.mdnsInterface}'`);
|
|
1015
824
|
if (this.mdnsInterface && interfaceName !== this.mdnsInterface)
|
|
1016
825
|
continue;
|
|
1017
826
|
if (!interfaceDetails) {
|
|
@@ -1037,22 +846,19 @@ export class Matterbridge extends EventEmitter {
|
|
|
1037
846
|
break;
|
|
1038
847
|
}
|
|
1039
848
|
}
|
|
1040
|
-
// Node information
|
|
1041
849
|
this.systemInformation.nodeVersion = process.versions.node;
|
|
1042
850
|
const versionMajor = parseInt(this.systemInformation.nodeVersion.split('.')[0]);
|
|
1043
851
|
const versionMinor = parseInt(this.systemInformation.nodeVersion.split('.')[1]);
|
|
1044
852
|
const versionPatch = parseInt(this.systemInformation.nodeVersion.split('.')[2]);
|
|
1045
|
-
// Host system information
|
|
1046
853
|
this.systemInformation.hostname = os.hostname();
|
|
1047
854
|
this.systemInformation.user = os.userInfo().username;
|
|
1048
|
-
this.systemInformation.osType = os.type();
|
|
1049
|
-
this.systemInformation.osRelease = os.release();
|
|
1050
|
-
this.systemInformation.osPlatform = os.platform();
|
|
1051
|
-
this.systemInformation.osArch = os.arch();
|
|
1052
|
-
this.systemInformation.totalMemory = (os.totalmem() / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
|
1053
|
-
this.systemInformation.freeMemory = (os.freemem() / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
|
1054
|
-
this.systemInformation.systemUptime = (os.uptime() / 60 / 60).toFixed(2) + ' hours';
|
|
1055
|
-
// Log the system information
|
|
855
|
+
this.systemInformation.osType = os.type();
|
|
856
|
+
this.systemInformation.osRelease = os.release();
|
|
857
|
+
this.systemInformation.osPlatform = os.platform();
|
|
858
|
+
this.systemInformation.osArch = os.arch();
|
|
859
|
+
this.systemInformation.totalMemory = (os.totalmem() / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
|
860
|
+
this.systemInformation.freeMemory = (os.freemem() / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
|
861
|
+
this.systemInformation.systemUptime = (os.uptime() / 60 / 60).toFixed(2) + ' hours';
|
|
1056
862
|
this.log.debug('Host System Information:');
|
|
1057
863
|
this.log.debug(`- Hostname: ${this.systemInformation.hostname}`);
|
|
1058
864
|
this.log.debug(`- User: ${this.systemInformation.user}`);
|
|
@@ -1068,17 +874,14 @@ export class Matterbridge extends EventEmitter {
|
|
|
1068
874
|
this.log.debug(`- Total Memory: ${this.systemInformation.totalMemory}`);
|
|
1069
875
|
this.log.debug(`- Free Memory: ${this.systemInformation.freeMemory}`);
|
|
1070
876
|
this.log.debug(`- System Uptime: ${this.systemInformation.systemUptime}`);
|
|
1071
|
-
// Log directories
|
|
1072
877
|
this.log.debug(`Root Directory: ${this.rootDirectory}`);
|
|
1073
878
|
this.log.debug(`Home Directory: ${this.homeDirectory}`);
|
|
1074
879
|
this.log.debug(`Matterbridge Directory: ${this.matterbridgeDirectory}`);
|
|
1075
880
|
this.log.debug(`Matterbridge Plugin Directory: ${this.matterbridgePluginDirectory}`);
|
|
1076
881
|
this.log.debug(`Matterbridge Matter Certificate Directory: ${this.matterbridgeCertDirectory}`);
|
|
1077
|
-
// Global node_modules directory
|
|
1078
882
|
if (this.nodeContext)
|
|
1079
883
|
this.globalModulesDirectory = this.matterbridgeInformation.globalModulesDirectory = await this.nodeContext.get('globalModulesDirectory', '');
|
|
1080
884
|
if (this.globalModulesDirectory === '') {
|
|
1081
|
-
// First run of Matterbridge so the node storage is empty
|
|
1082
885
|
this.log.debug(`Getting global node_modules directory...`);
|
|
1083
886
|
try {
|
|
1084
887
|
const { getGlobalNodeModules } = await import('./utils/network.js');
|
|
@@ -1091,7 +894,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1091
894
|
}
|
|
1092
895
|
}
|
|
1093
896
|
else {
|
|
1094
|
-
// The global node_modules directory is already set in the node storage and we check if it is still valid
|
|
1095
897
|
this.log.debug(`Checking global node_modules directory: ${this.globalModulesDirectory}`);
|
|
1096
898
|
try {
|
|
1097
899
|
const { getGlobalNodeModules } = await import('./utils/network.js');
|
|
@@ -1103,85 +905,58 @@ export class Matterbridge extends EventEmitter {
|
|
|
1103
905
|
this.log.error(`Error checking global node_modules directory: ${error}`);
|
|
1104
906
|
}
|
|
1105
907
|
}
|
|
1106
|
-
// Matterbridge version
|
|
1107
908
|
const packageJson = JSON.parse(await fs.readFile(path.join(this.rootDirectory, 'package.json'), 'utf-8'));
|
|
1108
909
|
this.matterbridgeVersion = this.matterbridgeLatestVersion = this.matterbridgeDevVersion = packageJson.version;
|
|
1109
910
|
this.matterbridgeInformation.matterbridgeVersion = this.matterbridgeInformation.matterbridgeLatestVersion = this.matterbridgeInformation.matterbridgeDevVersion = packageJson.version;
|
|
1110
911
|
this.log.debug(`Matterbridge Version: ${this.matterbridgeVersion}`);
|
|
1111
|
-
// Matterbridge latest version (will be set in the checkUpdate function)
|
|
1112
912
|
if (this.nodeContext)
|
|
1113
913
|
this.matterbridgeLatestVersion = this.matterbridgeInformation.matterbridgeLatestVersion = await this.nodeContext.get('matterbridgeLatestVersion', this.matterbridgeVersion);
|
|
1114
914
|
this.log.debug(`Matterbridge Latest Version: ${this.matterbridgeLatestVersion}`);
|
|
1115
|
-
// Matterbridge dev version (will be set in the checkUpdate function)
|
|
1116
915
|
if (this.nodeContext)
|
|
1117
916
|
this.matterbridgeDevVersion = this.matterbridgeInformation.matterbridgeDevVersion = await this.nodeContext.get('matterbridgeDevVersion', this.matterbridgeVersion);
|
|
1118
917
|
this.log.debug(`Matterbridge Dev Version: ${this.matterbridgeDevVersion}`);
|
|
1119
|
-
// Current working directory
|
|
1120
918
|
const currentDir = process.cwd();
|
|
1121
919
|
this.log.debug(`Current Working Directory: ${currentDir}`);
|
|
1122
|
-
// Command line arguments (excluding 'node' and the script name)
|
|
1123
920
|
const cmdArgs = process.argv.slice(2).join(' ');
|
|
1124
921
|
this.log.debug(`Command Line Arguments: ${cmdArgs}`);
|
|
1125
922
|
}
|
|
1126
|
-
/**
|
|
1127
|
-
* Creates a MatterLogger function to show the matter.js log messages in AnsiLogger (for the frontend).
|
|
1128
|
-
* It also logs to file (matter.log) if fileLogger is true.
|
|
1129
|
-
*
|
|
1130
|
-
* @param {boolean} fileLogger - Whether to log to file or not.
|
|
1131
|
-
* @returns {Function} The MatterLogger function.
|
|
1132
|
-
*/
|
|
1133
923
|
createDestinationMatterLogger(fileLogger) {
|
|
924
|
+
this.matterLog.logNameColor = '\x1b[34m';
|
|
1134
925
|
if (fileLogger) {
|
|
1135
926
|
this.matterLog.logFilePath = path.join(this.matterbridgeDirectory, this.matterLoggerFile);
|
|
1136
927
|
}
|
|
1137
928
|
return (text, message) => {
|
|
1138
|
-
// 2024-08-21 08:55:19.488 DEBUG InteractionMessenger Sending DataReport chunk with 28 attributes and 0 events: 1004 bytes
|
|
1139
929
|
const logger = text.slice(44, 44 + 20).trim();
|
|
1140
930
|
const msg = text.slice(65);
|
|
1141
931
|
this.matterLog.logName = logger;
|
|
1142
932
|
switch (message.level) {
|
|
1143
933
|
case MatterLogLevel.DEBUG:
|
|
1144
|
-
this.matterLog.log("debug"
|
|
934
|
+
this.matterLog.log("debug", msg);
|
|
1145
935
|
break;
|
|
1146
936
|
case MatterLogLevel.INFO:
|
|
1147
|
-
this.matterLog.log("info"
|
|
937
|
+
this.matterLog.log("info", msg);
|
|
1148
938
|
break;
|
|
1149
939
|
case MatterLogLevel.NOTICE:
|
|
1150
|
-
this.matterLog.log("notice"
|
|
940
|
+
this.matterLog.log("notice", msg);
|
|
1151
941
|
break;
|
|
1152
942
|
case MatterLogLevel.WARN:
|
|
1153
|
-
this.matterLog.log("warn"
|
|
943
|
+
this.matterLog.log("warn", msg);
|
|
1154
944
|
break;
|
|
1155
945
|
case MatterLogLevel.ERROR:
|
|
1156
|
-
this.matterLog.log("error"
|
|
946
|
+
this.matterLog.log("error", msg);
|
|
1157
947
|
break;
|
|
1158
948
|
case MatterLogLevel.FATAL:
|
|
1159
|
-
this.matterLog.log("fatal"
|
|
949
|
+
this.matterLog.log("fatal", msg);
|
|
1160
950
|
break;
|
|
1161
951
|
}
|
|
1162
952
|
};
|
|
1163
953
|
}
|
|
1164
|
-
/**
|
|
1165
|
-
* Restarts the process by exiting the current instance and loading a new instance (/api/restart).
|
|
1166
|
-
*
|
|
1167
|
-
* @returns {Promise<void>} A promise that resolves when the restart is completed.
|
|
1168
|
-
*/
|
|
1169
954
|
async restartProcess() {
|
|
1170
955
|
await this.cleanup('restarting...', true);
|
|
1171
956
|
}
|
|
1172
|
-
/**
|
|
1173
|
-
* Shut down the process (/api/shutdown).
|
|
1174
|
-
*
|
|
1175
|
-
* @returns {Promise<void>} A promise that resolves when the shutdown is completed.
|
|
1176
|
-
*/
|
|
1177
957
|
async shutdownProcess() {
|
|
1178
958
|
await this.cleanup('shutting down...', false);
|
|
1179
959
|
}
|
|
1180
|
-
/**
|
|
1181
|
-
* Update matterbridge and shut down the process (virtual device 'Update Matterbridge').
|
|
1182
|
-
*
|
|
1183
|
-
* @returns {Promise<void>} A promise that resolves when the update is completed.
|
|
1184
|
-
*/
|
|
1185
960
|
async updateProcess() {
|
|
1186
961
|
this.log.info('Updating matterbridge...');
|
|
1187
962
|
try {
|
|
@@ -1195,13 +970,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1195
970
|
this.frontend.wssSendRestartRequired();
|
|
1196
971
|
await this.cleanup('updating...', false);
|
|
1197
972
|
}
|
|
1198
|
-
/**
|
|
1199
|
-
* Unregister all devices and shut down the process (/api/unregister).
|
|
1200
|
-
*
|
|
1201
|
-
* @param {number} [timeout] - The timeout duration to wait for the message exchange to complete in milliseconds. Default is 1000.
|
|
1202
|
-
*
|
|
1203
|
-
* @returns {Promise<void>} A promise that resolves when the cleanup is completed.
|
|
1204
|
-
*/
|
|
1205
973
|
async unregisterAndShutdownProcess(timeout = 1000) {
|
|
1206
974
|
this.log.info('Unregistering all devices and shutting down...');
|
|
1207
975
|
for (const plugin of this.plugins.array()) {
|
|
@@ -1215,71 +983,46 @@ export class Matterbridge extends EventEmitter {
|
|
|
1215
983
|
await this.removeAllBridgedEndpoints(plugin.name, 100);
|
|
1216
984
|
}
|
|
1217
985
|
this.log.debug('Waiting for the MessageExchange to finish...');
|
|
1218
|
-
await wait(timeout);
|
|
986
|
+
await wait(timeout);
|
|
1219
987
|
this.log.debug('Cleaning up and shutting down...');
|
|
1220
988
|
await this.cleanup('unregistered all devices and shutting down...', false, timeout);
|
|
1221
989
|
}
|
|
1222
|
-
/**
|
|
1223
|
-
* Reset commissioning and shut down the process (/api/reset).
|
|
1224
|
-
*
|
|
1225
|
-
* @returns {Promise<void>} A promise that resolves when the cleanup is completed.
|
|
1226
|
-
*/
|
|
1227
990
|
async shutdownProcessAndReset() {
|
|
1228
991
|
await this.cleanup('shutting down with reset...', false);
|
|
1229
992
|
}
|
|
1230
|
-
/**
|
|
1231
|
-
* Factory reset and shut down the process (/api/factory-reset).
|
|
1232
|
-
*
|
|
1233
|
-
* @returns {Promise<void>} A promise that resolves when the cleanup is completed.
|
|
1234
|
-
*/
|
|
1235
993
|
async shutdownProcessAndFactoryReset() {
|
|
1236
994
|
await this.cleanup('shutting down with factory reset...', false);
|
|
1237
995
|
}
|
|
1238
|
-
/**
|
|
1239
|
-
* Cleans up the Matterbridge instance.
|
|
1240
|
-
*
|
|
1241
|
-
* @param {string} message - The cleanup message.
|
|
1242
|
-
* @param {boolean} [restart] - Indicates whether to restart the instance after cleanup. Default is `false`.
|
|
1243
|
-
* @param {number} [timeout] - The timeout duration to wait for the message exchange to complete in milliseconds. Default is 1000.
|
|
1244
|
-
*
|
|
1245
|
-
* @returns {Promise<void>} A promise that resolves when the cleanup is completed.
|
|
1246
|
-
*/
|
|
1247
996
|
async cleanup(message, restart = false, timeout = 1000) {
|
|
1248
997
|
if (this.initialized && !this.hasCleanupStarted) {
|
|
1249
998
|
this.emit('cleanup_started');
|
|
1250
999
|
this.hasCleanupStarted = true;
|
|
1251
1000
|
this.log.info(message);
|
|
1252
|
-
// Clear the start matter interval
|
|
1253
1001
|
if (this.startMatterInterval) {
|
|
1254
1002
|
clearInterval(this.startMatterInterval);
|
|
1255
1003
|
this.startMatterInterval = undefined;
|
|
1256
1004
|
this.log.debug('Start matter interval cleared');
|
|
1257
1005
|
}
|
|
1258
|
-
// Clear the check update timeout
|
|
1259
1006
|
if (this.checkUpdateTimeout) {
|
|
1260
1007
|
clearTimeout(this.checkUpdateTimeout);
|
|
1261
1008
|
this.checkUpdateTimeout = undefined;
|
|
1262
1009
|
this.log.debug('Check update timeout cleared');
|
|
1263
1010
|
}
|
|
1264
|
-
// Clear the check update interval
|
|
1265
1011
|
if (this.checkUpdateInterval) {
|
|
1266
1012
|
clearInterval(this.checkUpdateInterval);
|
|
1267
1013
|
this.checkUpdateInterval = undefined;
|
|
1268
1014
|
this.log.debug('Check update interval cleared');
|
|
1269
1015
|
}
|
|
1270
|
-
// Clear the configure timeout
|
|
1271
1016
|
if (this.configureTimeout) {
|
|
1272
1017
|
clearTimeout(this.configureTimeout);
|
|
1273
1018
|
this.configureTimeout = undefined;
|
|
1274
1019
|
this.log.debug('Matterbridge configure timeout cleared');
|
|
1275
1020
|
}
|
|
1276
|
-
// Clear the reachability timeout
|
|
1277
1021
|
if (this.reachabilityTimeout) {
|
|
1278
1022
|
clearTimeout(this.reachabilityTimeout);
|
|
1279
1023
|
this.reachabilityTimeout = undefined;
|
|
1280
1024
|
this.log.debug('Matterbridge reachability timeout cleared');
|
|
1281
1025
|
}
|
|
1282
|
-
// Call the shutdown method of each plugin and clear the plugins reachability timeout
|
|
1283
1026
|
for (const plugin of this.plugins) {
|
|
1284
1027
|
if (!plugin.enabled || plugin.error)
|
|
1285
1028
|
continue;
|
|
@@ -1290,7 +1033,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1290
1033
|
this.log.debug(`Plugin ${plg}${plugin.name}${db} reachability timeout cleared`);
|
|
1291
1034
|
}
|
|
1292
1035
|
}
|
|
1293
|
-
// Stop matter server nodes
|
|
1294
1036
|
this.log.notice(`Stopping matter server nodes in ${this.bridgeMode} mode...`);
|
|
1295
1037
|
this.log.debug('Waiting for the MessageExchange to finish...');
|
|
1296
1038
|
await wait(timeout, 'Waiting for the MessageExchange to finish...', true);
|
|
@@ -1315,7 +1057,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1315
1057
|
}
|
|
1316
1058
|
}
|
|
1317
1059
|
this.log.notice('Stopped matter server nodes');
|
|
1318
|
-
// Matter commisioning reset
|
|
1319
1060
|
if (message === 'shutting down with reset...') {
|
|
1320
1061
|
this.log.info('Resetting Matterbridge commissioning information...');
|
|
1321
1062
|
await this.matterStorageManager?.createContext('events')?.clearAll();
|
|
@@ -1325,7 +1066,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1325
1066
|
await this.matterbridgeContext?.clearAll();
|
|
1326
1067
|
this.log.info('Matter storage reset done! Remove the bridge from the controller.');
|
|
1327
1068
|
}
|
|
1328
|
-
// Unregister all devices
|
|
1329
1069
|
if (message === 'unregistered all devices and shutting down...') {
|
|
1330
1070
|
if (this.bridgeMode === 'bridge') {
|
|
1331
1071
|
await this.matterStorageManager?.createContext('root')?.createContext('parts')?.createContext('Matterbridge')?.createContext('parts')?.clearAll();
|
|
@@ -1343,36 +1083,18 @@ export class Matterbridge extends EventEmitter {
|
|
|
1343
1083
|
}
|
|
1344
1084
|
this.log.info('Matter storage reset done!');
|
|
1345
1085
|
}
|
|
1346
|
-
// Stop matter storage
|
|
1347
1086
|
await this.stopMatterStorage();
|
|
1348
|
-
// Stop the frontend
|
|
1349
1087
|
await this.frontend.stop();
|
|
1350
|
-
// Remove the matterfilelogger
|
|
1351
1088
|
try {
|
|
1352
1089
|
Logger.removeLogger('matterfilelogger');
|
|
1353
1090
|
}
|
|
1354
1091
|
catch (error) {
|
|
1355
1092
|
this.log.debug(`Error removing the matterfilelogger for file ${CYAN}${path.join(this.matterbridgeDirectory, this.matterLoggerFile)}${db}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1356
1093
|
}
|
|
1357
|
-
// Close the matterbridge node storage and context
|
|
1358
1094
|
if (this.nodeStorage && this.nodeContext) {
|
|
1359
|
-
/*
|
|
1360
|
-
TODO: Implement serialization of registered devices in edge mode
|
|
1361
|
-
this.log.info('Saving registered devices...');
|
|
1362
|
-
const serializedRegisteredDevices: SerializedMatterbridgeEndpoint[] = [];
|
|
1363
|
-
this.devices.forEach(async (device) => {
|
|
1364
|
-
const serializedMatterbridgeDevice = MatterbridgeEndpoint.serialize(device);
|
|
1365
|
-
// this.log.info(`- ${serializedMatterbridgeDevice.deviceName}${rs}\n`, serializedMatterbridgeDevice);
|
|
1366
|
-
if (serializedMatterbridgeDevice) serializedRegisteredDevices.push(serializedMatterbridgeDevice);
|
|
1367
|
-
});
|
|
1368
|
-
await this.nodeContext.set<SerializedMatterbridgeEndpoint[]>('devices', serializedRegisteredDevices);
|
|
1369
|
-
this.log.info(`Saved registered devices (${serializedRegisteredDevices?.length})`);
|
|
1370
|
-
*/
|
|
1371
|
-
// Clear nodeContext and nodeStorage (they just need 1000ms to write the data to disk)
|
|
1372
1095
|
this.log.debug(`Closing node storage context for ${plg}Matterbridge${db}...`);
|
|
1373
1096
|
await this.nodeContext.close();
|
|
1374
1097
|
this.nodeContext = undefined;
|
|
1375
|
-
// Clear nodeContext for each plugin (they just need 1000ms to write the data to disk)
|
|
1376
1098
|
for (const plugin of this.plugins) {
|
|
1377
1099
|
if (plugin.nodeContext) {
|
|
1378
1100
|
this.log.debug(`Closing node storage context for plugin ${plg}${plugin.name}${db}...`);
|
|
@@ -1389,10 +1111,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
1389
1111
|
}
|
|
1390
1112
|
this.plugins.clear();
|
|
1391
1113
|
this.devices.clear();
|
|
1392
|
-
// Factory reset
|
|
1393
1114
|
if (message === 'shutting down with factory reset...') {
|
|
1394
1115
|
try {
|
|
1395
|
-
// Delete matter storage directory with its subdirectories and backup
|
|
1396
1116
|
const dir = path.join(this.matterbridgeDirectory, this.matterStorageName);
|
|
1397
1117
|
this.log.info(`Removing matter storage directory: ${dir}`);
|
|
1398
1118
|
await fs.rm(dir, { recursive: true });
|
|
@@ -1401,13 +1121,11 @@ export class Matterbridge extends EventEmitter {
|
|
|
1401
1121
|
await fs.rm(backup, { recursive: true });
|
|
1402
1122
|
}
|
|
1403
1123
|
catch (error) {
|
|
1404
|
-
// istanbul ignore next if
|
|
1405
1124
|
if (error instanceof Error && error.code !== 'ENOENT') {
|
|
1406
1125
|
this.log.error(`Error removing matter storage directory: ${error}`);
|
|
1407
1126
|
}
|
|
1408
1127
|
}
|
|
1409
1128
|
try {
|
|
1410
|
-
// Delete matterbridge storage directory with its subdirectories and backup
|
|
1411
1129
|
const dir = path.join(this.matterbridgeDirectory, this.nodeStorageName);
|
|
1412
1130
|
this.log.info(`Removing matterbridge storage directory: ${dir}`);
|
|
1413
1131
|
await fs.rm(dir, { recursive: true });
|
|
@@ -1416,20 +1134,18 @@ export class Matterbridge extends EventEmitter {
|
|
|
1416
1134
|
await fs.rm(backup, { recursive: true });
|
|
1417
1135
|
}
|
|
1418
1136
|
catch (error) {
|
|
1419
|
-
// istanbul ignore next if
|
|
1420
1137
|
if (error instanceof Error && error.code !== 'ENOENT') {
|
|
1421
1138
|
this.log.error(`Error removing matterbridge storage directory: ${error}`);
|
|
1422
1139
|
}
|
|
1423
1140
|
}
|
|
1424
1141
|
this.log.info('Factory reset done! Remove all paired fabrics from the controllers.');
|
|
1425
1142
|
}
|
|
1426
|
-
// Deregisters the process handlers
|
|
1427
1143
|
this.deregisterProcessHandlers();
|
|
1428
1144
|
if (restart) {
|
|
1429
1145
|
if (message === 'updating...') {
|
|
1430
1146
|
this.log.info('Cleanup completed. Updating...');
|
|
1431
1147
|
Matterbridge.instance = undefined;
|
|
1432
|
-
this.emit('update');
|
|
1148
|
+
this.emit('update');
|
|
1433
1149
|
}
|
|
1434
1150
|
else if (message === 'restarting...') {
|
|
1435
1151
|
this.log.info('Cleanup completed. Restarting...');
|
|
@@ -1450,13 +1166,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1450
1166
|
this.log.debug('Cleanup already started...');
|
|
1451
1167
|
}
|
|
1452
1168
|
}
|
|
1453
|
-
/**
|
|
1454
|
-
* Creates and configures the server node for a single not bridged device.
|
|
1455
|
-
*
|
|
1456
|
-
* @param {RegisteredPlugin} plugin - The plugin to configure.
|
|
1457
|
-
* @param {MatterbridgeEndpoint} device - The device to associate with the plugin.
|
|
1458
|
-
* @returns {Promise<void>} A promise that resolves when the server node for the accessory plugin is created and configured.
|
|
1459
|
-
*/
|
|
1460
1169
|
async createDeviceServerNode(plugin, device) {
|
|
1461
1170
|
if (device.mode === 'server' && !device.serverNode && device.deviceType && device.deviceName && device.vendorId && device.vendorName && device.productId && device.productName) {
|
|
1462
1171
|
this.log.debug(`Creating device ${plg}${plugin.name}${db}:${dev}${device.deviceName}${db} server node...`);
|
|
@@ -1467,13 +1176,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1467
1176
|
this.log.debug(`Added ${plg}${plugin.name}${db}:${dev}${device.deviceName}${db} to server node`);
|
|
1468
1177
|
}
|
|
1469
1178
|
}
|
|
1470
|
-
/**
|
|
1471
|
-
* Creates and configures the server node for an accessory plugin for a given device.
|
|
1472
|
-
*
|
|
1473
|
-
* @param {RegisteredPlugin} plugin - The plugin to configure.
|
|
1474
|
-
* @param {MatterbridgeEndpoint} device - The device to associate with the plugin.
|
|
1475
|
-
* @returns {Promise<void>} A promise that resolves when the server node for the accessory plugin is created and configured.
|
|
1476
|
-
*/
|
|
1477
1179
|
async createAccessoryPlugin(plugin, device) {
|
|
1478
1180
|
if (!plugin.locked && device.deviceType && device.deviceName && device.vendorId && device.productId && device.vendorName && device.productName) {
|
|
1479
1181
|
plugin.locked = true;
|
|
@@ -1485,12 +1187,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1485
1187
|
await plugin.serverNode.add(device);
|
|
1486
1188
|
}
|
|
1487
1189
|
}
|
|
1488
|
-
/**
|
|
1489
|
-
* Creates and configures the server node and the aggregator node for a dynamic plugin.
|
|
1490
|
-
*
|
|
1491
|
-
* @param {RegisteredPlugin} plugin - The plugin to configure.
|
|
1492
|
-
* @returns {Promise<void>} A promise that resolves when the server node and the aggregator node for the dynamic plugin is created and configured.
|
|
1493
|
-
*/
|
|
1494
1190
|
async createDynamicPlugin(plugin) {
|
|
1495
1191
|
if (!plugin.locked) {
|
|
1496
1192
|
plugin.locked = true;
|
|
@@ -1501,14 +1197,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
1501
1197
|
await plugin.serverNode.add(plugin.aggregatorNode);
|
|
1502
1198
|
}
|
|
1503
1199
|
}
|
|
1504
|
-
/**
|
|
1505
|
-
* Starts the Matterbridge in bridge mode.
|
|
1506
|
-
*
|
|
1507
|
-
* @private
|
|
1508
|
-
* @returns {Promise<void>} A promise that resolves when the Matterbridge is started.
|
|
1509
|
-
*/
|
|
1510
1200
|
async startBridge() {
|
|
1511
|
-
// Plugins are configured by a timer when matter server is started and plugin.configured is set to true
|
|
1512
1201
|
if (!this.matterStorageManager)
|
|
1513
1202
|
throw new Error('No storage manager initialized');
|
|
1514
1203
|
if (!this.matterbridgeContext)
|
|
@@ -1547,16 +1236,13 @@ export class Matterbridge extends EventEmitter {
|
|
|
1547
1236
|
clearInterval(this.startMatterInterval);
|
|
1548
1237
|
this.startMatterInterval = undefined;
|
|
1549
1238
|
this.log.debug('Cleared startMatterInterval interval for Matterbridge');
|
|
1550
|
-
|
|
1551
|
-
this.startServerNode(this.serverNode); // We don't await this, because the server node is started in the background
|
|
1552
|
-
// Start the Matter server node of single devices in mode 'server'
|
|
1239
|
+
this.startServerNode(this.serverNode);
|
|
1553
1240
|
for (const device of this.devices.array()) {
|
|
1554
1241
|
if (device.mode === 'server' && device.serverNode) {
|
|
1555
1242
|
this.log.debug(`Starting server node for device ${dev}${device.deviceName}${db} in server mode...`);
|
|
1556
|
-
this.startServerNode(device.serverNode);
|
|
1243
|
+
this.startServerNode(device.serverNode);
|
|
1557
1244
|
}
|
|
1558
1245
|
}
|
|
1559
|
-
// Configure the plugins
|
|
1560
1246
|
this.configureTimeout = setTimeout(async () => {
|
|
1561
1247
|
for (const plugin of this.plugins.array()) {
|
|
1562
1248
|
if (!plugin.enabled || !plugin.loaded || !plugin.started || plugin.error)
|
|
@@ -1574,25 +1260,16 @@ export class Matterbridge extends EventEmitter {
|
|
|
1574
1260
|
}
|
|
1575
1261
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
1576
1262
|
}, 30 * 1000).unref();
|
|
1577
|
-
// Setting reachability to true
|
|
1578
1263
|
this.reachabilityTimeout = setTimeout(() => {
|
|
1579
1264
|
this.log.info(`Setting reachability to true for ${plg}Matterbridge${db}`);
|
|
1580
1265
|
if (this.aggregatorNode)
|
|
1581
1266
|
this.setAggregatorReachability(this.aggregatorNode, true);
|
|
1582
1267
|
this.frontend.wssSendRefreshRequired('reachability');
|
|
1583
1268
|
}, 60 * 1000).unref();
|
|
1584
|
-
// Logger.get('LogServerNode').info(this.serverNode);
|
|
1585
1269
|
this.emit('bridge_started');
|
|
1586
1270
|
this.log.notice('Matterbridge bridge started successfully');
|
|
1587
1271
|
}, this.startMatterIntervalMs);
|
|
1588
1272
|
}
|
|
1589
|
-
/**
|
|
1590
|
-
* Starts the Matterbridge in childbridge mode.
|
|
1591
|
-
*
|
|
1592
|
-
* @param {number} [delay] - The delay before starting the childbridge. Default is 1000 milliseconds.
|
|
1593
|
-
*
|
|
1594
|
-
* @returns {Promise<void>} A promise that resolves when the Matterbridge is started.
|
|
1595
|
-
*/
|
|
1596
1273
|
async startChildbridge(delay = 1000) {
|
|
1597
1274
|
if (!this.matterStorageManager)
|
|
1598
1275
|
throw new Error('No storage manager initialized');
|
|
@@ -1633,9 +1310,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
1633
1310
|
clearInterval(this.startMatterInterval);
|
|
1634
1311
|
this.startMatterInterval = undefined;
|
|
1635
1312
|
if (delay > 0)
|
|
1636
|
-
await wait(delay);
|
|
1313
|
+
await wait(delay);
|
|
1637
1314
|
this.log.debug('Cleared startMatterInterval interval in childbridge mode');
|
|
1638
|
-
// Configure the plugins
|
|
1639
1315
|
this.configureTimeout = setTimeout(async () => {
|
|
1640
1316
|
for (const plugin of this.plugins.array()) {
|
|
1641
1317
|
if (!plugin.enabled || !plugin.loaded || !plugin.started || plugin.error)
|
|
@@ -1672,9 +1348,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
1672
1348
|
this.log.error(`Node storage context not found for plugin ${plg}${plugin.name}${er}`);
|
|
1673
1349
|
continue;
|
|
1674
1350
|
}
|
|
1675
|
-
|
|
1676
|
-
this.startServerNode(plugin.serverNode); // We don't await this, because the server node is started in the background
|
|
1677
|
-
// Setting reachability to true
|
|
1351
|
+
this.startServerNode(plugin.serverNode);
|
|
1678
1352
|
plugin.reachabilityTimeout = setTimeout(() => {
|
|
1679
1353
|
this.log.info(`Setting reachability to true for ${plg}${plugin.name}${nf} type ${plugin.type} server node ${plugin.serverNode !== undefined} aggregator node ${plugin.aggregatorNode !== undefined} device ${plugin.device !== undefined}`);
|
|
1680
1354
|
if (plugin.type === 'DynamicPlatform' && plugin.aggregatorNode)
|
|
@@ -1682,241 +1356,19 @@ export class Matterbridge extends EventEmitter {
|
|
|
1682
1356
|
this.frontend.wssSendRefreshRequired('reachability');
|
|
1683
1357
|
}, 60 * 1000).unref();
|
|
1684
1358
|
}
|
|
1685
|
-
// Start the Matter server node of single devices in mode 'server'
|
|
1686
1359
|
for (const device of this.devices.array()) {
|
|
1687
1360
|
if (device.mode === 'server' && device.serverNode) {
|
|
1688
1361
|
this.log.debug(`Starting server node for device ${dev}${device.deviceName}${db} in server mode...`);
|
|
1689
|
-
this.startServerNode(device.serverNode);
|
|
1362
|
+
this.startServerNode(device.serverNode);
|
|
1690
1363
|
}
|
|
1691
1364
|
}
|
|
1692
|
-
// Logger.get('LogServerNode').info(this.serverNode);
|
|
1693
1365
|
this.emit('childbridge_started');
|
|
1694
1366
|
this.log.notice('Matterbridge childbridge started successfully');
|
|
1695
1367
|
}, this.startMatterIntervalMs);
|
|
1696
1368
|
}
|
|
1697
|
-
/**
|
|
1698
|
-
* Starts the Matterbridge controller.
|
|
1699
|
-
*
|
|
1700
|
-
* @private
|
|
1701
|
-
* @returns {Promise<void>} A promise that resolves when the Matterbridge is started.
|
|
1702
|
-
*/
|
|
1703
1369
|
async startController() {
|
|
1704
|
-
/*
|
|
1705
|
-
if (!this.matterStorageManager) {
|
|
1706
|
-
this.log.error('No storage manager initialized');
|
|
1707
|
-
await this.cleanup('No storage manager initialized');
|
|
1708
|
-
return;
|
|
1709
|
-
}
|
|
1710
|
-
this.log.info('Creating context: mattercontrollerContext');
|
|
1711
|
-
this.controllerContext = this.matterStorageManager.createContext('mattercontrollerContext');
|
|
1712
|
-
if (!this.controllerContext) {
|
|
1713
|
-
this.log.error('No storage context mattercontrollerContext initialized');
|
|
1714
|
-
await this.cleanup('No storage context mattercontrollerContext initialized');
|
|
1715
|
-
return;
|
|
1716
|
-
}
|
|
1717
|
-
|
|
1718
|
-
this.log.debug('Starting matterbridge in mode', this.bridgeMode);
|
|
1719
|
-
this.matterServer = await this.createMatterServer(this.storageManager);
|
|
1720
|
-
this.log.info('Creating matter commissioning controller');
|
|
1721
|
-
this.commissioningController = new CommissioningController({
|
|
1722
|
-
autoConnect: false,
|
|
1723
|
-
});
|
|
1724
|
-
this.log.info('Adding matter commissioning controller to matter server');
|
|
1725
|
-
await this.matterServer.addCommissioningController(this.commissioningController);
|
|
1726
|
-
|
|
1727
|
-
this.log.info('Starting matter server');
|
|
1728
|
-
await this.matterServer.start();
|
|
1729
|
-
this.log.info('Matter server started');
|
|
1730
|
-
const commissioningOptions: ControllerCommissioningFlowOptions = {
|
|
1731
|
-
regulatoryLocation: GeneralCommissioning.RegulatoryLocationType.IndoorOutdoor,
|
|
1732
|
-
regulatoryCountryCode: 'XX',
|
|
1733
|
-
};
|
|
1734
|
-
const commissioningController = new CommissioningController({
|
|
1735
|
-
environment: {
|
|
1736
|
-
environment,
|
|
1737
|
-
id: uniqueId,
|
|
1738
|
-
},
|
|
1739
|
-
autoConnect: false, // Do not auto connect to the commissioned nodes
|
|
1740
|
-
adminFabricLabel,
|
|
1741
|
-
});
|
|
1742
|
-
|
|
1743
|
-
if (hasParameter('pairingcode')) {
|
|
1744
|
-
this.log.info('Pairing device with pairingcode:', getParameter('pairingcode'));
|
|
1745
|
-
const pairingCode = getParameter('pairingcode');
|
|
1746
|
-
const ip = this.controllerContext.has('ip') ? this.controllerContext.get<string>('ip') : undefined;
|
|
1747
|
-
const port = this.controllerContext.has('port') ? this.controllerContext.get<number>('port') : undefined;
|
|
1748
|
-
|
|
1749
|
-
let longDiscriminator, setupPin, shortDiscriminator;
|
|
1750
|
-
if (pairingCode !== undefined) {
|
|
1751
|
-
const pairingCodeCodec = ManualPairingCodeCodec.decode(pairingCode);
|
|
1752
|
-
shortDiscriminator = pairingCodeCodec.shortDiscriminator;
|
|
1753
|
-
longDiscriminator = undefined;
|
|
1754
|
-
setupPin = pairingCodeCodec.passcode;
|
|
1755
|
-
this.log.info(`Data extracted from pairing code: ${Logger.toJSON(pairingCodeCodec)}`);
|
|
1756
|
-
} else {
|
|
1757
|
-
longDiscriminator = await this.controllerContext.get('longDiscriminator', 3840);
|
|
1758
|
-
if (longDiscriminator > 4095) throw new Error('Discriminator value must be less than 4096');
|
|
1759
|
-
setupPin = this.controllerContext.get('pin', 20202021);
|
|
1760
|
-
}
|
|
1761
|
-
if ((shortDiscriminator === undefined && longDiscriminator === undefined) || setupPin === undefined) {
|
|
1762
|
-
throw new Error('Please specify the longDiscriminator of the device to commission with -longDiscriminator or provide a valid passcode with -passcode');
|
|
1763
|
-
}
|
|
1764
|
-
|
|
1765
|
-
const options = {
|
|
1766
|
-
commissioning: commissioningOptions,
|
|
1767
|
-
discovery: {
|
|
1768
|
-
knownAddress: ip !== undefined && port !== undefined ? { ip, port, type: 'udp' } : undefined,
|
|
1769
|
-
identifierData: longDiscriminator !== undefined ? { longDiscriminator } : shortDiscriminator !== undefined ? { shortDiscriminator } : {},
|
|
1770
|
-
},
|
|
1771
|
-
passcode: setupPin,
|
|
1772
|
-
} as NodeCommissioningOptions;
|
|
1773
|
-
this.log.info('Commissioning with options:', options);
|
|
1774
|
-
const nodeId = await this.commissioningController.commissionNode(options);
|
|
1775
|
-
this.log.info(`Commissioning successfully done with nodeId: ${nodeId}`);
|
|
1776
|
-
this.log.info('ActiveSessionInformation:', this.commissioningController.getActiveSessionInformation());
|
|
1777
|
-
} // (hasParameter('pairingcode'))
|
|
1778
|
-
|
|
1779
|
-
if (hasParameter('unpairall')) {
|
|
1780
|
-
this.log.info('***Commissioning controller unpairing all nodes...');
|
|
1781
|
-
const nodeIds = this.commissioningController.getCommissionedNodes();
|
|
1782
|
-
for (const nodeId of nodeIds) {
|
|
1783
|
-
this.log.info('***Commissioning controller unpairing node:', nodeId);
|
|
1784
|
-
await this.commissioningController.removeNode(nodeId);
|
|
1785
|
-
}
|
|
1786
|
-
return;
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
|
-
if (hasParameter('discover')) {
|
|
1790
|
-
// const discover = await this.commissioningController.discoverCommissionableDevices({ productId: 0x8000, deviceType: 0xfff1 });
|
|
1791
|
-
// console.log(discover);
|
|
1792
|
-
}
|
|
1793
|
-
|
|
1794
|
-
if (!this.commissioningController.isCommissioned()) {
|
|
1795
|
-
this.log.info('***Commissioning controller is not commissioned: use matterbridge -controller -pairingcode [pairingcode] to commission a device');
|
|
1796
|
-
return;
|
|
1797
|
-
}
|
|
1798
|
-
|
|
1799
|
-
const nodeIds = this.commissioningController.getCommissionedNodes();
|
|
1800
|
-
this.log.info(`***Commissioning controller is commissioned ${this.commissioningController.isCommissioned()} and has ${nodeIds.length} nodes commisioned: `);
|
|
1801
|
-
for (const nodeId of nodeIds) {
|
|
1802
|
-
this.log.info(`***Connecting to commissioned node: ${nodeId}`);
|
|
1803
|
-
|
|
1804
|
-
const node = await this.commissioningController.connectNode(nodeId, {
|
|
1805
|
-
autoSubscribe: false,
|
|
1806
|
-
attributeChangedCallback: (peerNodeId, { path: { nodeId, clusterId, endpointId, attributeName }, value }) =>
|
|
1807
|
-
this.log.info(`***Commissioning controller attributeChangedCallback ${peerNodeId}: attribute ${nodeId}/${endpointId}/${clusterId}/${attributeName} changed to ${Logger.toJSON(value)}`),
|
|
1808
|
-
eventTriggeredCallback: (peerNodeId, { path: { nodeId, clusterId, endpointId, eventName }, events }) =>
|
|
1809
|
-
this.log.info(`***Commissioning controller eventTriggeredCallback ${peerNodeId}: Event ${nodeId}/${endpointId}/${clusterId}/${eventName} triggered with ${Logger.toJSON(events)}`),
|
|
1810
|
-
stateInformationCallback: (peerNodeId, info) => {
|
|
1811
|
-
switch (info) {
|
|
1812
|
-
case NodeStateInformation.Connected:
|
|
1813
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} connected`);
|
|
1814
|
-
break;
|
|
1815
|
-
case NodeStateInformation.Disconnected:
|
|
1816
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} disconnected`);
|
|
1817
|
-
break;
|
|
1818
|
-
case NodeStateInformation.Reconnecting:
|
|
1819
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} reconnecting`);
|
|
1820
|
-
break;
|
|
1821
|
-
case NodeStateInformation.WaitingForDeviceDiscovery:
|
|
1822
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} waiting for device discovery`);
|
|
1823
|
-
break;
|
|
1824
|
-
case NodeStateInformation.StructureChanged:
|
|
1825
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} structure changed`);
|
|
1826
|
-
break;
|
|
1827
|
-
case NodeStateInformation.Decommissioned:
|
|
1828
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} decommissioned`);
|
|
1829
|
-
break;
|
|
1830
|
-
default:
|
|
1831
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} NodeStateInformation.${info}`);
|
|
1832
|
-
break;
|
|
1833
|
-
}
|
|
1834
|
-
},
|
|
1835
|
-
});
|
|
1836
|
-
|
|
1837
|
-
node.logStructure();
|
|
1838
|
-
|
|
1839
|
-
// Get the interaction client
|
|
1840
|
-
this.log.info('Getting the interaction client');
|
|
1841
|
-
const interactionClient = await node.getInteractionClient();
|
|
1842
|
-
let cluster;
|
|
1843
|
-
let attributes;
|
|
1844
|
-
|
|
1845
|
-
// Log BasicInformationCluster
|
|
1846
|
-
cluster = BasicInformationCluster;
|
|
1847
|
-
attributes = await interactionClient.getMultipleAttributes({
|
|
1848
|
-
attributes: [{ clusterId: cluster.id }],
|
|
1849
|
-
});
|
|
1850
|
-
if (attributes.length > 0) this.log.info(`Cluster: ${idn}${cluster.name}${rs}${nf} attributes:`);
|
|
1851
|
-
attributes.forEach((attribute) => {
|
|
1852
|
-
this.log.info(
|
|
1853
|
-
`- endpoint ${or}${attribute.path.endpointId}${nf} cluster ${hk}${getClusterNameById(attribute.path.clusterId)}${nf} (${hk}0x${attribute.path.clusterId.toString(16)}${nf}) attribute ${zb}${attribute.path.attributeName}${nf} (${zb}0x${attribute.path.attributeId.toString(16)}${nf}): ${typeof attribute.value === 'object' ? stringify(attribute.value) : attribute.value}`,
|
|
1854
|
-
);
|
|
1855
|
-
});
|
|
1856
|
-
|
|
1857
|
-
// Log PowerSourceCluster
|
|
1858
|
-
cluster = PowerSourceCluster;
|
|
1859
|
-
attributes = await interactionClient.getMultipleAttributes({
|
|
1860
|
-
attributes: [{ clusterId: cluster.id }],
|
|
1861
|
-
});
|
|
1862
|
-
if (attributes.length > 0) this.log.info(`Cluster: ${idn}${cluster.name}${rs}${nf} attributes:`);
|
|
1863
|
-
attributes.forEach((attribute) => {
|
|
1864
|
-
this.log.info(
|
|
1865
|
-
`- endpoint ${or}${attribute.path.endpointId}${nf} cluster ${hk}${getClusterNameById(attribute.path.clusterId)}${nf} (${hk}0x${attribute.path.clusterId.toString(16)}${nf}) attribute ${zb}${attribute.path.attributeName}${nf} (${zb}0x${attribute.path.attributeId.toString(16)}${nf}): ${typeof attribute.value === 'object' ? stringify(attribute.value) : attribute.value}`,
|
|
1866
|
-
);
|
|
1867
|
-
});
|
|
1868
|
-
|
|
1869
|
-
// Log ThreadNetworkDiagnostics
|
|
1870
|
-
cluster = ThreadNetworkDiagnosticsCluster;
|
|
1871
|
-
attributes = await interactionClient.getMultipleAttributes({
|
|
1872
|
-
attributes: [{ clusterId: cluster.id }],
|
|
1873
|
-
});
|
|
1874
|
-
if (attributes.length > 0) this.log.info(`Cluster: ${idn}${cluster.name}${rs}${nf} attributes:`);
|
|
1875
|
-
attributes.forEach((attribute) => {
|
|
1876
|
-
this.log.info(
|
|
1877
|
-
`- endpoint ${or}${attribute.path.endpointId}${nf} cluster ${hk}${getClusterNameById(attribute.path.clusterId)}${nf} (${hk}0x${attribute.path.clusterId.toString(16)}${nf}) attribute ${zb}${attribute.path.attributeName}${nf} (${zb}0x${attribute.path.attributeId.toString(16)}${nf}): ${typeof attribute.value === 'object' ? stringify(attribute.value) : attribute.value}`,
|
|
1878
|
-
);
|
|
1879
|
-
});
|
|
1880
|
-
|
|
1881
|
-
// Log SwitchCluster
|
|
1882
|
-
cluster = SwitchCluster;
|
|
1883
|
-
attributes = await interactionClient.getMultipleAttributes({
|
|
1884
|
-
attributes: [{ clusterId: cluster.id }],
|
|
1885
|
-
});
|
|
1886
|
-
if (attributes.length > 0) this.log.info(`Cluster: ${idn}${cluster.name}${rs}${nf} attributes:`);
|
|
1887
|
-
attributes.forEach((attribute) => {
|
|
1888
|
-
this.log.info(
|
|
1889
|
-
`- endpoint ${or}${attribute.path.endpointId}${nf} cluster ${hk}${getClusterNameById(attribute.path.clusterId)}${nf} (${hk}0x${attribute.path.clusterId.toString(16)}${nf}) attribute ${zb}${attribute.path.attributeName}${nf} (${zb}0x${attribute.path.attributeId.toString(16)}${nf}): ${typeof attribute.value === 'object' ? stringify(attribute.value) : attribute.value}`,
|
|
1890
|
-
);
|
|
1891
|
-
});
|
|
1892
|
-
|
|
1893
|
-
this.log.info('Subscribing to all attributes and events');
|
|
1894
|
-
await node.subscribeAllAttributesAndEvents({
|
|
1895
|
-
ignoreInitialTriggers: false,
|
|
1896
|
-
attributeChangedCallback: ({ path: { nodeId, clusterId, endpointId, attributeName }, version, value }) =>
|
|
1897
|
-
this.log.info(
|
|
1898
|
-
`***${db}Commissioning controller attributeChangedCallback version ${version}: attribute ${BLUE}${nodeId}${db}/${or}${endpointId}${db}/${hk}${getClusterNameById(clusterId)}${db}/${zb}${attributeName}${db} changed to ${typeof value === 'object' ? debugStringify(value ?? { none: true }) : value}`,
|
|
1899
|
-
),
|
|
1900
|
-
eventTriggeredCallback: ({ path: { nodeId, clusterId, endpointId, eventName }, events }) => {
|
|
1901
|
-
this.log.info(
|
|
1902
|
-
`***${db}Commissioning controller eventTriggeredCallback: event ${BLUE}${nodeId}${db}/${or}${endpointId}${db}/${hk}${getClusterNameById(clusterId)}${db}/${zb}${eventName}${db} triggered with ${debugStringify(events ?? { none: true })}`,
|
|
1903
|
-
);
|
|
1904
|
-
},
|
|
1905
|
-
});
|
|
1906
|
-
this.log.info('Subscribed to all attributes and events');
|
|
1907
|
-
}
|
|
1908
|
-
*/
|
|
1909
1370
|
}
|
|
1910
|
-
/** */
|
|
1911
|
-
/** Matter.js methods */
|
|
1912
|
-
/** */
|
|
1913
|
-
/**
|
|
1914
|
-
* Starts the matter storage with name Matterbridge, create the matterbridge context and performs a backup.
|
|
1915
|
-
*
|
|
1916
|
-
* @returns {Promise<void>} - A promise that resolves when the storage is started.
|
|
1917
|
-
*/
|
|
1918
1371
|
async startMatterStorage() {
|
|
1919
|
-
// Setup Matter storage
|
|
1920
1372
|
this.log.info(`Starting matter node storage...`);
|
|
1921
1373
|
this.matterStorageService = this.environment.get(StorageService);
|
|
1922
1374
|
this.log.info(`Matter node storage service created: ${this.matterStorageService.location}`);
|
|
@@ -1925,17 +1377,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
1925
1377
|
this.matterbridgeContext = await this.createServerNodeContext('Matterbridge', 'Matterbridge', this.aggregatorDeviceType, this.aggregatorVendorId, this.aggregatorVendorName, this.aggregatorProductId, this.aggregatorProductName, this.aggregatorSerialNumber, this.aggregatorUniqueId);
|
|
1926
1378
|
this.matterbridgeInformation.matterbridgeSerialNumber = await this.matterbridgeContext.get('serialNumber', '');
|
|
1927
1379
|
this.log.info('Matter node storage started');
|
|
1928
|
-
// Backup matter storage since it is created/opened correctly
|
|
1929
1380
|
await this.backupMatterStorage(path.join(this.matterbridgeDirectory, this.matterStorageName), path.join(this.matterbridgeDirectory, this.matterStorageName + '.backup'));
|
|
1930
1381
|
}
|
|
1931
|
-
/**
|
|
1932
|
-
* Makes a backup copy of the specified matter storage directory.
|
|
1933
|
-
*
|
|
1934
|
-
* @param {string} storageName - The name of the storage directory to be backed up.
|
|
1935
|
-
* @param {string} backupName - The name of the backup directory to be created.
|
|
1936
|
-
* @private
|
|
1937
|
-
* @returns {Promise<void>} A promise that resolves when the has been done.
|
|
1938
|
-
*/
|
|
1939
1382
|
async backupMatterStorage(storageName, backupName) {
|
|
1940
1383
|
this.log.info('Creating matter node storage backup...');
|
|
1941
1384
|
try {
|
|
@@ -1946,11 +1389,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1946
1389
|
this.log.error(`Error creating matter node storage backup from ${storageName} to ${backupName}:`, error);
|
|
1947
1390
|
}
|
|
1948
1391
|
}
|
|
1949
|
-
/**
|
|
1950
|
-
* Stops the matter storage.
|
|
1951
|
-
*
|
|
1952
|
-
* @returns {Promise<void>} A promise that resolves when the storage is stopped.
|
|
1953
|
-
*/
|
|
1954
1392
|
async stopMatterStorage() {
|
|
1955
1393
|
this.log.info('Closing matter node storage...');
|
|
1956
1394
|
await this.matterStorageManager?.close();
|
|
@@ -1959,20 +1397,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1959
1397
|
this.matterbridgeContext = undefined;
|
|
1960
1398
|
this.log.info('Matter node storage closed');
|
|
1961
1399
|
}
|
|
1962
|
-
/**
|
|
1963
|
-
* Creates a server node storage context.
|
|
1964
|
-
*
|
|
1965
|
-
* @param {string} storeId - The storeId.
|
|
1966
|
-
* @param {string} deviceName - The name of the device.
|
|
1967
|
-
* @param {DeviceTypeId} deviceType - The device type of the device.
|
|
1968
|
-
* @param {number} vendorId - The vendor ID.
|
|
1969
|
-
* @param {string} vendorName - The vendor name.
|
|
1970
|
-
* @param {number} productId - The product ID.
|
|
1971
|
-
* @param {string} productName - The product name.
|
|
1972
|
-
* @param {string} [serialNumber] - The serial number of the device (optional).
|
|
1973
|
-
* @param {string} [uniqueId] - The unique ID of the device (optional).
|
|
1974
|
-
* @returns {Promise<StorageContext>} The storage context for the commissioning server.
|
|
1975
|
-
*/
|
|
1976
1400
|
async createServerNodeContext(storeId, deviceName, deviceType, vendorId, vendorName, productId, productName, serialNumber, uniqueId) {
|
|
1977
1401
|
const { randomBytes } = await import('node:crypto');
|
|
1978
1402
|
if (!this.matterStorageService)
|
|
@@ -2012,15 +1436,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2012
1436
|
this.log.debug(`- hardwareVersion: ${await storageContext.get('hardwareVersion')} hardwareVersionString: ${await storageContext.get('hardwareVersionString')}`);
|
|
2013
1437
|
return storageContext;
|
|
2014
1438
|
}
|
|
2015
|
-
/**
|
|
2016
|
-
* Creates a server node.
|
|
2017
|
-
*
|
|
2018
|
-
* @param {StorageContext} storageContext - The storage context for the server node.
|
|
2019
|
-
* @param {number} [port] - The port number for the server node. Defaults to 5540.
|
|
2020
|
-
* @param {number} [passcode] - The passcode for the server node. Defaults to 20242025.
|
|
2021
|
-
* @param {number} [discriminator] - The discriminator for the server node. Defaults to 3850.
|
|
2022
|
-
* @returns {Promise<ServerNode<ServerNode.RootEndpoint>>} A promise that resolves to the created server node.
|
|
2023
|
-
*/
|
|
2024
1439
|
async createServerNode(storageContext, port = 5540, passcode = 20242025, discriminator = 3850) {
|
|
2025
1440
|
const storeId = await storageContext.get('storeId');
|
|
2026
1441
|
this.log.notice(`Creating server node for ${storeId} on port ${port} with passcode ${passcode} and discriminator ${discriminator}...`);
|
|
@@ -2030,37 +1445,24 @@ export class Matterbridge extends EventEmitter {
|
|
|
2030
1445
|
this.log.debug(`- uniqueId: ${await storageContext.get('uniqueId')}`);
|
|
2031
1446
|
this.log.debug(`- softwareVersion: ${await storageContext.get('softwareVersion')} softwareVersionString: ${await storageContext.get('softwareVersionString')}`);
|
|
2032
1447
|
this.log.debug(`- hardwareVersion: ${await storageContext.get('hardwareVersion')} hardwareVersionString: ${await storageContext.get('hardwareVersionString')}`);
|
|
2033
|
-
/**
|
|
2034
|
-
* Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration
|
|
2035
|
-
*/
|
|
2036
1448
|
const serverNode = await ServerNode.create({
|
|
2037
|
-
// Required: Give the Node a unique ID which is used to store the state of this node
|
|
2038
1449
|
id: storeId,
|
|
2039
|
-
// Provide Network relevant configuration like the port
|
|
2040
|
-
// Optional when operating only one device on a host, Default port is 5540
|
|
2041
1450
|
network: {
|
|
2042
1451
|
listeningAddressIpv4: this.ipv4address,
|
|
2043
1452
|
listeningAddressIpv6: this.ipv6address,
|
|
2044
1453
|
port,
|
|
2045
1454
|
},
|
|
2046
|
-
// Provide the certificate for the device
|
|
2047
1455
|
operationalCredentials: {
|
|
2048
1456
|
certification: this.certification,
|
|
2049
1457
|
},
|
|
2050
|
-
// Provide Commissioning relevant settings
|
|
2051
|
-
// Optional for development/testing purposes
|
|
2052
1458
|
commissioning: {
|
|
2053
1459
|
passcode,
|
|
2054
1460
|
discriminator,
|
|
2055
1461
|
},
|
|
2056
|
-
// Provide Node announcement settings
|
|
2057
|
-
// Optional: If Ommitted some development defaults are used
|
|
2058
1462
|
productDescription: {
|
|
2059
1463
|
name: await storageContext.get('deviceName'),
|
|
2060
1464
|
deviceType: DeviceTypeId(await storageContext.get('deviceType')),
|
|
2061
1465
|
},
|
|
2062
|
-
// Provide defaults for the BasicInformation cluster on the Root endpoint
|
|
2063
|
-
// Optional: If Omitted some development defaults are used
|
|
2064
1466
|
basicInformation: {
|
|
2065
1467
|
vendorId: VendorId(await storageContext.get('vendorId')),
|
|
2066
1468
|
vendorName: await storageContext.get('vendorName'),
|
|
@@ -2077,20 +1479,14 @@ export class Matterbridge extends EventEmitter {
|
|
|
2077
1479
|
reachable: true,
|
|
2078
1480
|
},
|
|
2079
1481
|
});
|
|
2080
|
-
/**
|
|
2081
|
-
* This event is triggered when the device is initially commissioned successfully.
|
|
2082
|
-
* This means: It is added to the first fabric.
|
|
2083
|
-
*/
|
|
2084
1482
|
serverNode.lifecycle.commissioned.on(() => {
|
|
2085
1483
|
this.log.notice(`Server node for ${storeId} was initially commissioned successfully!`);
|
|
2086
1484
|
clearTimeout(this.endAdvertiseTimeout);
|
|
2087
1485
|
});
|
|
2088
|
-
/** This event is triggered when all fabrics are removed from the device, usually it also does a factory reset then. */
|
|
2089
1486
|
serverNode.lifecycle.decommissioned.on(() => {
|
|
2090
1487
|
this.log.notice(`Server node for ${storeId} was fully decommissioned successfully!`);
|
|
2091
1488
|
clearTimeout(this.endAdvertiseTimeout);
|
|
2092
1489
|
});
|
|
2093
|
-
/** This event is triggered when the device went online. This means that it is discoverable in the network. */
|
|
2094
1490
|
serverNode.lifecycle.online.on(async () => {
|
|
2095
1491
|
this.log.notice(`Server node for ${storeId} is online`);
|
|
2096
1492
|
if (!serverNode.lifecycle.isCommissioned) {
|
|
@@ -2098,14 +1494,11 @@ export class Matterbridge extends EventEmitter {
|
|
|
2098
1494
|
const { qrPairingCode, manualPairingCode } = serverNode.state.commissioning.pairingCodes;
|
|
2099
1495
|
this.log.notice(`QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`);
|
|
2100
1496
|
this.log.notice(`Manual pairing code: ${manualPairingCode}`);
|
|
2101
|
-
// Set a timeout to show that advertising stops after 15 minutes if not commissioned
|
|
2102
1497
|
this.startEndAdvertiseTimer(serverNode);
|
|
2103
1498
|
this.advertisingNodes.set(storeId, Date.now());
|
|
2104
1499
|
}
|
|
2105
1500
|
else {
|
|
2106
|
-
// istanbul ignore next
|
|
2107
1501
|
this.log.notice(`Server node for ${storeId} is already commissioned. Waiting for controllers to connect ...`);
|
|
2108
|
-
// istanbul ignore next
|
|
2109
1502
|
this.advertisingNodes.delete(storeId);
|
|
2110
1503
|
}
|
|
2111
1504
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
@@ -2114,28 +1507,23 @@ export class Matterbridge extends EventEmitter {
|
|
|
2114
1507
|
this.frontend.wssSendSnackbarMessage(`${storeId} is online`, 5, 'success');
|
|
2115
1508
|
this.emit('online', storeId);
|
|
2116
1509
|
});
|
|
2117
|
-
/** This event is triggered when the device went offline. it is not longer discoverable or connectable in the network. */
|
|
2118
1510
|
serverNode.lifecycle.offline.on(() => {
|
|
2119
1511
|
this.log.notice(`Server node for ${storeId} is offline`);
|
|
2120
|
-
this.matterbridgeInformation.matterbridgeEndAdvertise = true;
|
|
1512
|
+
this.matterbridgeInformation.matterbridgeEndAdvertise = true;
|
|
2121
1513
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
2122
1514
|
this.frontend.wssSendRefreshRequired('settings');
|
|
2123
1515
|
this.frontend.wssSendRefreshRequired('matter', { matter: { ...this.getServerNodeData(serverNode) } });
|
|
2124
1516
|
this.frontend.wssSendSnackbarMessage(`${storeId} is offline`, 5, 'warning');
|
|
2125
1517
|
this.emit('offline', storeId);
|
|
2126
1518
|
});
|
|
2127
|
-
/**
|
|
2128
|
-
* This event is triggered when a fabric is added, removed or updated on the device. Use this if more granular
|
|
2129
|
-
* information is needed.
|
|
2130
|
-
*/
|
|
2131
1519
|
serverNode.events.commissioning.fabricsChanged.on((fabricIndex, fabricAction) => {
|
|
2132
1520
|
let action = '';
|
|
2133
1521
|
switch (fabricAction) {
|
|
2134
1522
|
case FabricAction.Added:
|
|
2135
|
-
this.advertisingNodes.delete(storeId);
|
|
1523
|
+
this.advertisingNodes.delete(storeId);
|
|
2136
1524
|
clearTimeout(this.endAdvertiseTimeout);
|
|
2137
1525
|
this.endAdvertiseTimeout = undefined;
|
|
2138
|
-
this.matterbridgeInformation.matterbridgeEndAdvertise = true;
|
|
1526
|
+
this.matterbridgeInformation.matterbridgeEndAdvertise = true;
|
|
2139
1527
|
action = 'added';
|
|
2140
1528
|
break;
|
|
2141
1529
|
case FabricAction.Removed:
|
|
@@ -2149,24 +1537,16 @@ export class Matterbridge extends EventEmitter {
|
|
|
2149
1537
|
this.frontend.wssSendRefreshRequired('fabrics');
|
|
2150
1538
|
this.frontend.wssSendRefreshRequired('matter', { matter: { ...this.getServerNodeData(serverNode) } });
|
|
2151
1539
|
});
|
|
2152
|
-
/**
|
|
2153
|
-
* This event is triggered when an operative new session was opened by a Controller.
|
|
2154
|
-
* It is not triggered for the initial commissioning process, just afterwards for real connections.
|
|
2155
|
-
*/
|
|
2156
1540
|
serverNode.events.sessions.opened.on((session) => {
|
|
2157
1541
|
this.log.notice(`Session opened on server node for ${storeId}: ${debugStringify(session)}`);
|
|
2158
1542
|
this.frontend.wssSendRefreshRequired('sessions');
|
|
2159
1543
|
this.frontend.wssSendRefreshRequired('matter', { matter: { ...this.getServerNodeData(serverNode) } });
|
|
2160
1544
|
});
|
|
2161
|
-
/**
|
|
2162
|
-
* This event is triggered when an operative session is closed by a Controller or because the Device goes offline.
|
|
2163
|
-
*/
|
|
2164
1545
|
serverNode.events.sessions.closed.on((session) => {
|
|
2165
1546
|
this.log.notice(`Session closed on server node for ${storeId}: ${debugStringify(session)}`);
|
|
2166
1547
|
this.frontend.wssSendRefreshRequired('sessions');
|
|
2167
1548
|
this.frontend.wssSendRefreshRequired('matter', { matter: { ...this.getServerNodeData(serverNode) } });
|
|
2168
1549
|
});
|
|
2169
|
-
/** This event is triggered when a subscription gets added or removed on an operative session. */
|
|
2170
1550
|
serverNode.events.sessions.subscriptionsChanged.on((session) => {
|
|
2171
1551
|
this.log.notice(`Session subscriptions changed on server node for ${storeId}: ${debugStringify(session)}`);
|
|
2172
1552
|
this.frontend.wssSendRefreshRequired('sessions');
|
|
@@ -2175,11 +1555,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2175
1555
|
this.log.info(`Created server node for ${storeId}`);
|
|
2176
1556
|
return serverNode;
|
|
2177
1557
|
}
|
|
2178
|
-
/**
|
|
2179
|
-
* Starts the 15 minutes timer to advice that advertising for the specified server node is ended.
|
|
2180
|
-
*
|
|
2181
|
-
* @param {ServerNode} [matterServerNode] - The server node to start.
|
|
2182
|
-
*/
|
|
2183
1558
|
startEndAdvertiseTimer(matterServerNode) {
|
|
2184
1559
|
if (this.endAdvertiseTimeout) {
|
|
2185
1560
|
this.log.debug(`Clear ${matterServerNode.id} server node end advertise timer`);
|
|
@@ -2199,12 +1574,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2199
1574
|
this.log.notice(`Advertising stopped.`);
|
|
2200
1575
|
}, 15 * 60 * 1000).unref();
|
|
2201
1576
|
}
|
|
2202
|
-
/**
|
|
2203
|
-
* Starts the 15 minutes timer to advice that advertising for the specified server node is ended.
|
|
2204
|
-
*
|
|
2205
|
-
* @param {ServerNode} [serverNode] - The server node to start.
|
|
2206
|
-
* @returns {ApiDevicesMatter} The sanitized data of the server node.
|
|
2207
|
-
*/
|
|
2208
1577
|
getServerNodeData(serverNode) {
|
|
2209
1578
|
const advertiseTime = this.advertisingNodes.get(serverNode.id) || 0;
|
|
2210
1579
|
return {
|
|
@@ -2220,25 +1589,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
2220
1589
|
serialNumber: serverNode.state.basicInformation.serialNumber,
|
|
2221
1590
|
};
|
|
2222
1591
|
}
|
|
2223
|
-
/**
|
|
2224
|
-
* Starts the specified server node.
|
|
2225
|
-
*
|
|
2226
|
-
* @param {ServerNode} [matterServerNode] - The server node to start.
|
|
2227
|
-
* @returns {Promise<void>} A promise that resolves when the server node has started.
|
|
2228
|
-
*/
|
|
2229
1592
|
async startServerNode(matterServerNode) {
|
|
2230
1593
|
if (!matterServerNode)
|
|
2231
1594
|
return;
|
|
2232
1595
|
this.log.notice(`Starting ${matterServerNode.id} server node`);
|
|
2233
1596
|
await matterServerNode.start();
|
|
2234
1597
|
}
|
|
2235
|
-
/**
|
|
2236
|
-
* Stops the specified server node.
|
|
2237
|
-
*
|
|
2238
|
-
* @param {ServerNode} matterServerNode - The server node to stop.
|
|
2239
|
-
* @param {number} [timeout] - The timeout in milliseconds for stopping the server node. Defaults to 30 seconds.
|
|
2240
|
-
* @returns {Promise<void>} A promise that resolves when the server node has stopped.
|
|
2241
|
-
*/
|
|
2242
1598
|
async stopServerNode(matterServerNode, timeout = 30000) {
|
|
2243
1599
|
if (!matterServerNode)
|
|
2244
1600
|
return;
|
|
@@ -2251,12 +1607,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2251
1607
|
this.log.error(`Failed to close ${matterServerNode.id} server node: ${error instanceof Error ? error.message : error}`);
|
|
2252
1608
|
}
|
|
2253
1609
|
}
|
|
2254
|
-
/**
|
|
2255
|
-
* Advertises the specified server node.
|
|
2256
|
-
*
|
|
2257
|
-
* @param {ServerNode} [matterServerNode] - The server node to advertise.
|
|
2258
|
-
* @returns {Promise<{ qrPairingCode: string, manualPairingCode: string } | undefined>} A promise that resolves to the pairing codes if the server node is advertised, or undefined if not.
|
|
2259
|
-
*/
|
|
2260
1610
|
async advertiseServerNode(matterServerNode) {
|
|
2261
1611
|
if (matterServerNode) {
|
|
2262
1612
|
await matterServerNode.env.get(DeviceCommissioner)?.allowBasicCommissioning();
|
|
@@ -2266,12 +1616,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2266
1616
|
return { qrPairingCode, manualPairingCode };
|
|
2267
1617
|
}
|
|
2268
1618
|
}
|
|
2269
|
-
/**
|
|
2270
|
-
* Stop advertise the specified server node.
|
|
2271
|
-
*
|
|
2272
|
-
* @param {ServerNode} [matterServerNode] - The server node to advertise.
|
|
2273
|
-
* @returns {Promise<void>} A promise that resolves when the server node has stopped advertising.
|
|
2274
|
-
*/
|
|
2275
1619
|
async stopAdvertiseServerNode(matterServerNode) {
|
|
2276
1620
|
if (matterServerNode && matterServerNode.lifecycle.isOnline) {
|
|
2277
1621
|
await matterServerNode.env.get(DeviceCommissioner)?.endCommissioning();
|
|
@@ -2279,27 +1623,13 @@ export class Matterbridge extends EventEmitter {
|
|
|
2279
1623
|
this.log.notice(`Stopped advertising for ${matterServerNode.id}`);
|
|
2280
1624
|
}
|
|
2281
1625
|
}
|
|
2282
|
-
/**
|
|
2283
|
-
* Creates an aggregator node with the specified storage context.
|
|
2284
|
-
*
|
|
2285
|
-
* @param {StorageContext} storageContext - The storage context for the aggregator node.
|
|
2286
|
-
* @returns {Promise<Endpoint<AggregatorEndpoint>>} A promise that resolves to the created aggregator node.
|
|
2287
|
-
*/
|
|
2288
1626
|
async createAggregatorNode(storageContext) {
|
|
2289
1627
|
this.log.notice(`Creating ${await storageContext.get('storeId')} aggregator...`);
|
|
2290
1628
|
const aggregatorNode = new Endpoint(AggregatorEndpoint, { id: `${await storageContext.get('storeId')}` });
|
|
2291
1629
|
this.log.info(`Created ${await storageContext.get('storeId')} aggregator`);
|
|
2292
1630
|
return aggregatorNode;
|
|
2293
1631
|
}
|
|
2294
|
-
/**
|
|
2295
|
-
* Adds a MatterbridgeEndpoint to the specified plugin.
|
|
2296
|
-
*
|
|
2297
|
-
* @param {string} pluginName - The name of the plugin.
|
|
2298
|
-
* @param {MatterbridgeEndpoint} device - The device to add as a bridged endpoint.
|
|
2299
|
-
* @returns {Promise<void>} A promise that resolves when the bridged endpoint has been added.
|
|
2300
|
-
*/
|
|
2301
1632
|
async addBridgedEndpoint(pluginName, device) {
|
|
2302
|
-
// Check if the plugin is registered
|
|
2303
1633
|
const plugin = this.plugins.get(pluginName);
|
|
2304
1634
|
if (!plugin) {
|
|
2305
1635
|
this.log.error(`Error adding bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.id}${er}) plugin ${plg}${pluginName}${er} not found`);
|
|
@@ -2319,7 +1649,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2319
1649
|
}
|
|
2320
1650
|
else if (this.bridgeMode === 'bridge') {
|
|
2321
1651
|
if (device.mode === 'matter') {
|
|
2322
|
-
// Register and add the device to the matterbridge server node
|
|
2323
1652
|
this.log.debug(`Adding matter endpoint ${plg}${pluginName}${db}:${dev}${device.deviceName}${db} to Matterbridge server node...`);
|
|
2324
1653
|
if (!this.serverNode) {
|
|
2325
1654
|
this.log.error('Server node not found for Matterbridge');
|
|
@@ -2336,7 +1665,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2336
1665
|
}
|
|
2337
1666
|
}
|
|
2338
1667
|
else {
|
|
2339
|
-
// Register and add the device to the matterbridge aggregator node
|
|
2340
1668
|
this.log.debug(`Adding bridged endpoint ${plg}${pluginName}${db}:${dev}${device.deviceName}${db} to Matterbridge aggregator node`);
|
|
2341
1669
|
if (!this.aggregatorNode) {
|
|
2342
1670
|
this.log.error('Aggregator node not found for Matterbridge');
|
|
@@ -2354,7 +1682,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2354
1682
|
}
|
|
2355
1683
|
}
|
|
2356
1684
|
else if (this.bridgeMode === 'childbridge') {
|
|
2357
|
-
// Register and add the device to the plugin server node
|
|
2358
1685
|
if (plugin.type === 'AccessoryPlatform') {
|
|
2359
1686
|
try {
|
|
2360
1687
|
this.log.debug(`Creating endpoint ${dev}${device.deviceName}${db} for AccessoryPlatform plugin ${plg}${plugin.name}${db} server node`);
|
|
@@ -2378,12 +1705,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
2378
1705
|
return;
|
|
2379
1706
|
}
|
|
2380
1707
|
}
|
|
2381
|
-
// Register and add the device to the plugin aggregator node
|
|
2382
1708
|
if (plugin.type === 'DynamicPlatform') {
|
|
2383
1709
|
try {
|
|
2384
1710
|
this.log.debug(`Adding bridged endpoint ${dev}${device.deviceName}${db} for DynamicPlatform plugin ${plg}${plugin.name}${db} aggregator node`);
|
|
2385
1711
|
await this.createDynamicPlugin(plugin);
|
|
2386
|
-
// Fast plugins can add another device before the server node is ready, so we wait for the server node to be ready
|
|
2387
1712
|
await waiter(`createDynamicPlugin(${plugin.name})`, () => plugin.serverNode?.hasParts === true);
|
|
2388
1713
|
if (!plugin.aggregatorNode) {
|
|
2389
1714
|
this.log.error(`Aggregator node not found for plugin ${plg}${plugin.name}${er}`);
|
|
@@ -2406,28 +1731,17 @@ export class Matterbridge extends EventEmitter {
|
|
|
2406
1731
|
plugin.registeredDevices++;
|
|
2407
1732
|
if (plugin.addedDevices !== undefined)
|
|
2408
1733
|
plugin.addedDevices++;
|
|
2409
|
-
// Add the device to the DeviceManager
|
|
2410
1734
|
this.devices.set(device);
|
|
2411
|
-
// Subscribe to the reachable$Changed event
|
|
2412
1735
|
await this.subscribeAttributeChanged(plugin, device);
|
|
2413
1736
|
this.log.info(`Added and registered bridged endpoint (${plugin.registeredDevices}/${plugin.addedDevices}) ${dev}${device.deviceName}${nf} (${dev}${device.id}${nf}) for plugin ${plg}${pluginName}${nf}`);
|
|
2414
1737
|
}
|
|
2415
|
-
/**
|
|
2416
|
-
* Removes a MatterbridgeEndpoint from the specified plugin.
|
|
2417
|
-
*
|
|
2418
|
-
* @param {string} pluginName - The name of the plugin.
|
|
2419
|
-
* @param {MatterbridgeEndpoint} device - The device to remove as a bridged endpoint.
|
|
2420
|
-
* @returns {Promise<void>} A promise that resolves when the bridged endpoint has been removed.
|
|
2421
|
-
*/
|
|
2422
1738
|
async removeBridgedEndpoint(pluginName, device) {
|
|
2423
1739
|
this.log.debug(`Removing bridged endpoint ${plg}${pluginName}${db}:${dev}${device.deviceName}${db} (${zb}${device.name}${db}) for plugin ${plg}${pluginName}${db}`);
|
|
2424
|
-
// Check if the plugin is registered
|
|
2425
1740
|
const plugin = this.plugins.get(pluginName);
|
|
2426
1741
|
if (!plugin) {
|
|
2427
1742
|
this.log.error(`Error removing bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.name}${er}) for plugin ${plg}${pluginName}${er}: plugin not found`);
|
|
2428
1743
|
return;
|
|
2429
1744
|
}
|
|
2430
|
-
// Register and add the device to the matterbridge aggregator node
|
|
2431
1745
|
if (this.bridgeMode === 'bridge') {
|
|
2432
1746
|
if (!this.aggregatorNode) {
|
|
2433
1747
|
this.log.error(`Error removing bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.name}${er}) for plugin ${plg}${pluginName}${er}: aggregator node not found`);
|
|
@@ -2442,7 +1756,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2442
1756
|
}
|
|
2443
1757
|
else if (this.bridgeMode === 'childbridge') {
|
|
2444
1758
|
if (plugin.type === 'AccessoryPlatform') {
|
|
2445
|
-
// Nothing to do here since the server node has no aggregator node but only the device itself
|
|
2446
1759
|
}
|
|
2447
1760
|
else if (plugin.type === 'DynamicPlatform') {
|
|
2448
1761
|
if (!plugin.aggregatorNode) {
|
|
@@ -2457,21 +1770,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
2457
1770
|
if (plugin.addedDevices !== undefined)
|
|
2458
1771
|
plugin.addedDevices--;
|
|
2459
1772
|
}
|
|
2460
|
-
// Remove the device from the DeviceManager
|
|
2461
1773
|
this.devices.remove(device);
|
|
2462
1774
|
}
|
|
2463
|
-
/**
|
|
2464
|
-
* Removes all bridged endpoints from the specified plugin.
|
|
2465
|
-
*
|
|
2466
|
-
* @param {string} pluginName - The name of the plugin.
|
|
2467
|
-
* @param {number} [delay] - The delay in milliseconds between removing each bridged endpoint (default: 0).
|
|
2468
|
-
* @returns {Promise<void>} A promise that resolves when all bridged endpoints have been removed.
|
|
2469
|
-
*
|
|
2470
|
-
* @remarks
|
|
2471
|
-
* This method iterates through all devices in the DeviceManager and removes each bridged endpoint associated with the specified plugin.
|
|
2472
|
-
* It also applies a delay between each removal if specified.
|
|
2473
|
-
* The delay is useful to allow the controllers to receive a single subscription for each device removed.
|
|
2474
|
-
*/
|
|
2475
1775
|
async removeAllBridgedEndpoints(pluginName, delay = 0) {
|
|
2476
1776
|
this.log.debug(`Removing all bridged endpoints for plugin ${plg}${pluginName}${db}${delay > 0 ? ` with delay ${delay} ms` : ''}`);
|
|
2477
1777
|
for (const device of this.devices.array().filter((device) => device.plugin === pluginName)) {
|
|
@@ -2482,15 +1782,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2482
1782
|
if (delay > 0)
|
|
2483
1783
|
await wait(2000);
|
|
2484
1784
|
}
|
|
2485
|
-
/**
|
|
2486
|
-
* Subscribes to the attribute change event for the given device and plugin.
|
|
2487
|
-
* Specifically, it listens for changes in the 'reachable' attribute of the
|
|
2488
|
-
* BridgedDeviceBasicInformationServer cluster server of the bridged device or BasicInformationServer cluster server of server node.
|
|
2489
|
-
*
|
|
2490
|
-
* @param {RegisteredPlugin} plugin - The plugin associated with the device.
|
|
2491
|
-
* @param {MatterbridgeEndpoint} device - The device to subscribe to attribute changes for.
|
|
2492
|
-
* @returns {Promise<void>} A promise that resolves when the subscription is set up.
|
|
2493
|
-
*/
|
|
2494
1785
|
async subscribeAttributeChanged(plugin, device) {
|
|
2495
1786
|
this.log.info(`Subscribing attributes for endpoint ${dev}${device.deviceName}${nf} (${dev}${device.id}${nf}) plugin ${plg}${plugin.name}${nf}`);
|
|
2496
1787
|
if (this.bridgeMode === 'childbridge' && plugin.type === 'AccessoryPlatform' && plugin.serverNode) {
|
|
@@ -2506,12 +1797,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2506
1797
|
});
|
|
2507
1798
|
}
|
|
2508
1799
|
}
|
|
2509
|
-
/**
|
|
2510
|
-
* Sanitizes the fabric information by converting bigint properties to strings because `res.json` doesn't support bigint.
|
|
2511
|
-
*
|
|
2512
|
-
* @param {ExposedFabricInformation[]} fabricInfo - The array of exposed fabric information objects.
|
|
2513
|
-
* @returns {SanitizedExposedFabricInformation[]} An array of sanitized exposed fabric information objects.
|
|
2514
|
-
*/
|
|
2515
1800
|
sanitizeFabricInformations(fabricInfo) {
|
|
2516
1801
|
return fabricInfo.map((info) => {
|
|
2517
1802
|
return {
|
|
@@ -2525,12 +1810,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2525
1810
|
};
|
|
2526
1811
|
});
|
|
2527
1812
|
}
|
|
2528
|
-
/**
|
|
2529
|
-
* Sanitizes the session information by converting bigint properties to strings because `res.json` doesn't support bigint.
|
|
2530
|
-
*
|
|
2531
|
-
* @param {SessionsBehavior.Session[]} sessions - The array of session information objects.
|
|
2532
|
-
* @returns {SanitizedSession[]} An array of sanitized session information objects.
|
|
2533
|
-
*/
|
|
2534
1813
|
sanitizeSessionInformation(sessions) {
|
|
2535
1814
|
return sessions
|
|
2536
1815
|
.filter((session) => session.isPeerActive)
|
|
@@ -2557,21 +1836,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
2557
1836
|
};
|
|
2558
1837
|
});
|
|
2559
1838
|
}
|
|
2560
|
-
/**
|
|
2561
|
-
* Sets the reachability of the specified aggregator node bridged devices and trigger.
|
|
2562
|
-
*
|
|
2563
|
-
* @param {Endpoint<AggregatorEndpoint>} aggregatorNode - The aggregator node to set the reachability for.
|
|
2564
|
-
* @param {boolean} reachable - A boolean indicating the reachability status to set.
|
|
2565
|
-
*/
|
|
2566
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2567
1839
|
async setAggregatorReachability(aggregatorNode, reachable) {
|
|
2568
|
-
/*
|
|
2569
|
-
for (const child of aggregatorNode.parts) {
|
|
2570
|
-
this.log.debug(`Setting reachability of ${(child as unknown as MatterbridgeEndpoint)?.deviceName} to ${reachable}`);
|
|
2571
|
-
await child.setStateOf(BridgedDeviceBasicInformationServer, { reachable });
|
|
2572
|
-
child.act((agent) => child.eventsOf(BridgedDeviceBasicInformationServer).reachableChanged.emit({ reachableNewValue: true }, agent.context));
|
|
2573
|
-
}
|
|
2574
|
-
*/
|
|
2575
1840
|
}
|
|
2576
1841
|
getVendorIdName = (vendorId) => {
|
|
2577
1842
|
if (!vendorId)
|
|
@@ -2611,11 +1876,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
2611
1876
|
case 0x1488:
|
|
2612
1877
|
vendorName = '(ShortcutLabsFlic)';
|
|
2613
1878
|
break;
|
|
2614
|
-
case 65521:
|
|
1879
|
+
case 65521:
|
|
2615
1880
|
vendorName = '(MatterTest)';
|
|
2616
1881
|
break;
|
|
2617
1882
|
}
|
|
2618
1883
|
return vendorName;
|
|
2619
1884
|
};
|
|
2620
1885
|
}
|
|
2621
|
-
//# sourceMappingURL=matterbridge.js.map
|