matterbridge 3.1.8 → 3.2.0-dev-20250729-fcbf392
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 +24 -0
- package/README.md +1 -1
- 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/batteryStorage.js +1 -48
- package/dist/devices/dishwasher.js +3 -78
- package/dist/devices/evse.js +10 -74
- package/dist/devices/export.js +0 -2
- package/dist/devices/extractorHood.js +0 -42
- package/dist/devices/heatPump.js +2 -50
- package/dist/devices/laundryDryer.js +6 -83
- package/dist/devices/laundryWasher.js +7 -91
- package/dist/devices/roboticVacuumCleaner.js +7 -93
- package/dist/devices/solarPower.js +0 -38
- package/dist/devices/waterHeater.js +2 -82
- package/dist/dgram/coap.js +13 -126
- package/dist/dgram/dgram.js +2 -113
- package/dist/dgram/mb_coap.js +3 -41
- package/dist/dgram/mb_mdns.js +13 -51
- package/dist/dgram/mdns.js +137 -298
- package/dist/dgram/multicast.js +1 -60
- package/dist/dgram/unicast.js +0 -54
- package/dist/frontend.js +23 -449
- 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 +50 -803
- package/dist/matterbridgeAccessoryPlatform.js +0 -36
- package/dist/matterbridgeBehaviors.js +5 -65
- package/dist/matterbridgeDeviceTypes.js +15 -579
- package/dist/matterbridgeDynamicPlatform.js +0 -36
- package/dist/matterbridgeEndpoint.js +55 -1215
- package/dist/matterbridgeEndpointHelpers.js +12 -344
- package/dist/matterbridgePlatform.js +0 -233
- 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 +23 -65
- package/dist/utils/colorUtils.js +2 -263
- 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 -123
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/network.js +43 -81
- package/dist/utils/spawn.js +0 -40
- package/dist/utils/wait.js +9 -62
- package/npm-shrinkwrap.json +49 -49
- package/package.json +3 -4
- 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/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/dishwasher.d.ts +0 -91
- 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 -11
- 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 -87
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -242
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.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/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 -140
- 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 -288
- package/dist/dgram/mdns.d.ts.map +0 -1
- package/dist/dgram/mdns.js.map +0 -1
- package/dist/dgram/multicast.d.ts +0 -65
- 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 -313
- 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 -463
- 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 -1351
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -709
- 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 -1348
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -406
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -310
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -197
- 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 -68
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -117
- 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 -12
- 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/network.d.ts +0 -74
- 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 -56
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
- package/frontend/public/Shelly.svg +0 -1
- package/frontend/public/bmc-button.svg +0 -22
- package/frontend/public/discord.svg +0 -5
- package/frontend/public/favicon.ico +0 -0
- package/frontend/public/index.html +0 -19
- package/frontend/public/manifest.json +0 -15
- package/frontend/public/matter.png +0 -0
- package/frontend/public/matterbridge 1250x1250.png +0 -0
- package/frontend/public/matterbridge 32x32.png +0 -0
- package/frontend/public/matterbridge 624x624.png +0 -0
- package/frontend/public/matterbridge 64x64.png +0 -0
- package/frontend/public/matterbridge.svg +0 -50
- package/frontend/public/robots.txt +0 -3
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
|
execRunningCount = 0;
|
|
@@ -152,23 +118,19 @@ export class Matterbridge extends EventEmitter {
|
|
|
152
118
|
sigtermHandler;
|
|
153
119
|
exceptionHandler;
|
|
154
120
|
rejectionHandler;
|
|
155
|
-
// Matter environment
|
|
156
121
|
environment = Environment.default;
|
|
157
|
-
// Matter storage
|
|
158
122
|
matterStorageName = 'matterstorage' + (getParameter('profile') ? '.' + getParameter('profile') : '');
|
|
159
123
|
matterStorageService;
|
|
160
124
|
matterStorageManager;
|
|
161
125
|
matterbridgeContext;
|
|
162
126
|
controllerContext;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
certification; // device certification
|
|
171
|
-
// Matter nodes
|
|
127
|
+
mdnsInterface;
|
|
128
|
+
ipv4address;
|
|
129
|
+
ipv6address;
|
|
130
|
+
port;
|
|
131
|
+
passcode;
|
|
132
|
+
discriminator;
|
|
133
|
+
certification;
|
|
172
134
|
serverNode;
|
|
173
135
|
aggregatorNode;
|
|
174
136
|
aggregatorVendorId = VendorId(getIntParameter('vendorId') ?? 0xfff1);
|
|
@@ -179,31 +141,15 @@ export class Matterbridge extends EventEmitter {
|
|
|
179
141
|
aggregatorSerialNumber = getParameter('serialNumber');
|
|
180
142
|
aggregatorUniqueId = getParameter('uniqueId');
|
|
181
143
|
static instance;
|
|
182
|
-
// We load asyncronously so is private
|
|
183
144
|
constructor() {
|
|
184
145
|
super();
|
|
185
146
|
}
|
|
186
|
-
/**
|
|
187
|
-
* Retrieves the list of Matterbridge devices.
|
|
188
|
-
*
|
|
189
|
-
* @returns {MatterbridgeEndpoint[]} An array of MatterbridgeDevice objects.
|
|
190
|
-
*/
|
|
191
147
|
getDevices() {
|
|
192
148
|
return this.devices.array();
|
|
193
149
|
}
|
|
194
|
-
/**
|
|
195
|
-
* Retrieves the list of registered plugins.
|
|
196
|
-
*
|
|
197
|
-
* @returns {RegisteredPlugin[]} An array of RegisteredPlugin objects.
|
|
198
|
-
*/
|
|
199
150
|
getPlugins() {
|
|
200
151
|
return this.plugins.array();
|
|
201
152
|
}
|
|
202
|
-
/**
|
|
203
|
-
* Set the logger logLevel for the Matterbridge classes and call onChangeLoggerLevel() for each plugin.
|
|
204
|
-
*
|
|
205
|
-
* @param {LogLevel} logLevel The logger logLevel to set.
|
|
206
|
-
*/
|
|
207
153
|
async setLogLevel(logLevel) {
|
|
208
154
|
if (this.log)
|
|
209
155
|
this.log.logLevel = logLevel;
|
|
@@ -217,31 +163,19 @@ export class Matterbridge extends EventEmitter {
|
|
|
217
163
|
for (const plugin of this.plugins) {
|
|
218
164
|
if (!plugin.platform || !plugin.platform.log || !plugin.platform.config)
|
|
219
165
|
continue;
|
|
220
|
-
plugin.platform.log.logLevel = plugin.platform.config.debug === true ? "debug"
|
|
221
|
-
await plugin.platform.onChangeLoggerLevel(plugin.platform.config.debug === true ? "debug"
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
callbackLogLevel = "debug" /* LogLevel.DEBUG */;
|
|
166
|
+
plugin.platform.log.logLevel = plugin.platform.config.debug === true ? "debug" : this.log.logLevel;
|
|
167
|
+
await plugin.platform.onChangeLoggerLevel(plugin.platform.config.debug === true ? "debug" : this.log.logLevel);
|
|
168
|
+
}
|
|
169
|
+
let callbackLogLevel = "notice";
|
|
170
|
+
if (this.matterbridgeInformation.loggerLevel === "info" || this.matterbridgeInformation.matterLoggerLevel === MatterLogLevel.INFO)
|
|
171
|
+
callbackLogLevel = "info";
|
|
172
|
+
if (this.matterbridgeInformation.loggerLevel === "debug" || this.matterbridgeInformation.matterLoggerLevel === MatterLogLevel.DEBUG)
|
|
173
|
+
callbackLogLevel = "debug";
|
|
229
174
|
AnsiLogger.setGlobalCallback(this.frontend.wssSendMessage.bind(this.frontend), callbackLogLevel);
|
|
230
175
|
this.log.debug(`WebSocketServer logger global callback set to ${callbackLogLevel}`);
|
|
231
176
|
}
|
|
232
|
-
//* ************************************************************************************************************************************ */
|
|
233
|
-
// loadInstance() and cleanup() methods */
|
|
234
|
-
//* ************************************************************************************************************************************ */
|
|
235
|
-
/**
|
|
236
|
-
* Loads an instance of the Matterbridge class.
|
|
237
|
-
* If an instance already exists, return that instance.
|
|
238
|
-
*
|
|
239
|
-
* @param {boolean} initialize - Whether to initialize the Matterbridge instance after loading. Defaults to false.
|
|
240
|
-
* @returns {Matterbridge} A promise that resolves to the Matterbridge instance.
|
|
241
|
-
*/
|
|
242
177
|
static async loadInstance(initialize = false) {
|
|
243
178
|
if (!Matterbridge.instance) {
|
|
244
|
-
// eslint-disable-next-line no-console
|
|
245
179
|
if (hasParameter('debug'))
|
|
246
180
|
console.log(GREEN + 'Creating a new instance of Matterbridge.', initialize ? 'Initializing...' : 'Not initializing...', rs);
|
|
247
181
|
Matterbridge.instance = new Matterbridge();
|
|
@@ -250,17 +184,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
250
184
|
}
|
|
251
185
|
return Matterbridge.instance;
|
|
252
186
|
}
|
|
253
|
-
/**
|
|
254
|
-
* Call cleanup() and dispose MdnsService.
|
|
255
|
-
*
|
|
256
|
-
* @param {number} [timeout] - The timeout duration to wait for the cleanup to complete in milliseconds. Default is 1000.
|
|
257
|
-
* @param {number} [pause] - The pause duration after the cleanup in milliseconds. Default is 250.
|
|
258
|
-
*
|
|
259
|
-
* @deprecated This method is deprecated and is ONLY used for jest tests.
|
|
260
|
-
*/
|
|
261
187
|
async destroyInstance(timeout = 1000, pause = 250) {
|
|
262
188
|
this.log.info(`Destroy instance...`);
|
|
263
|
-
// Save server nodes to close
|
|
264
189
|
const servers = [];
|
|
265
190
|
if (this.bridgeMode === 'bridge') {
|
|
266
191
|
if (this.serverNode)
|
|
@@ -278,105 +203,72 @@ export class Matterbridge extends EventEmitter {
|
|
|
278
203
|
servers.push(device.serverNode);
|
|
279
204
|
}
|
|
280
205
|
}
|
|
281
|
-
// Let any already‐queued microtasks run first
|
|
282
206
|
await Promise.resolve();
|
|
283
|
-
// Wait for the cleanup to finish
|
|
284
207
|
await wait(pause, 'destroyInstance start', true);
|
|
285
|
-
// Cleanup
|
|
286
208
|
await this.cleanup('destroying instance...', false, timeout);
|
|
287
|
-
// Close servers mdns service
|
|
288
209
|
this.log.info(`Dispose ${servers.length} MdnsService...`);
|
|
289
210
|
for (const server of servers) {
|
|
290
211
|
await server.env.get(MdnsService)[Symbol.asyncDispose]();
|
|
291
212
|
this.log.info(`Closed ${server.id} MdnsService`);
|
|
292
213
|
}
|
|
293
|
-
// Let any already‐queued microtasks run first
|
|
294
214
|
await Promise.resolve();
|
|
295
|
-
// Wait for the cleanup to finish
|
|
296
215
|
await wait(pause, 'destroyInstance stop', true);
|
|
297
216
|
}
|
|
298
|
-
/**
|
|
299
|
-
* Initializes the Matterbridge application.
|
|
300
|
-
*
|
|
301
|
-
* @remarks
|
|
302
|
-
* This method performs the necessary setup and initialization steps for the Matterbridge application.
|
|
303
|
-
* It displays the help information if the 'help' parameter is provided, sets up the logger, checks the
|
|
304
|
-
* node version, registers signal handlers, initializes storage, and parses the command line.
|
|
305
|
-
*
|
|
306
|
-
* @returns {Promise<void>} A Promise that resolves when the initialization is complete.
|
|
307
|
-
*/
|
|
308
217
|
async initialize() {
|
|
309
|
-
// Emit the initialize_started event
|
|
310
218
|
this.emit('initialize_started');
|
|
311
|
-
// Set the restart mode
|
|
312
219
|
if (hasParameter('service'))
|
|
313
220
|
this.restartMode = 'service';
|
|
314
221
|
if (hasParameter('docker'))
|
|
315
222
|
this.restartMode = 'docker';
|
|
316
|
-
// Set the matterbridge home directory
|
|
317
223
|
this.homeDirectory = getParameter('homedir') ?? os.homedir();
|
|
318
224
|
this.matterbridgeInformation.homeDirectory = this.homeDirectory;
|
|
319
225
|
await createDirectory(this.homeDirectory, 'Matterbridge Home Directory', this.log);
|
|
320
|
-
// Set the matterbridge directory
|
|
321
226
|
this.matterbridgeDirectory = path.join(this.homeDirectory, '.matterbridge');
|
|
322
227
|
this.matterbridgeInformation.matterbridgeDirectory = this.matterbridgeDirectory;
|
|
323
228
|
await createDirectory(this.matterbridgeDirectory, 'Matterbridge Directory', this.log);
|
|
324
229
|
await createDirectory(path.join(this.matterbridgeDirectory, 'certs'), 'Matterbridge Frontend Certificate Directory', this.log);
|
|
325
230
|
await createDirectory(path.join(this.matterbridgeDirectory, 'uploads'), 'Matterbridge Frontend Uploads Directory', this.log);
|
|
326
|
-
// Set the matterbridge plugin directory
|
|
327
231
|
this.matterbridgePluginDirectory = path.join(this.homeDirectory, 'Matterbridge');
|
|
328
232
|
this.matterbridgeInformation.matterbridgePluginDirectory = this.matterbridgePluginDirectory;
|
|
329
233
|
await createDirectory(this.matterbridgePluginDirectory, 'Matterbridge Plugin Directory', this.log);
|
|
330
|
-
// Set the matterbridge cert directory
|
|
331
234
|
this.matterbridgeCertDirectory = path.join(this.homeDirectory, '.mattercert');
|
|
332
235
|
this.matterbridgeInformation.matterbridgeCertDirectory = this.matterbridgeCertDirectory;
|
|
333
236
|
await createDirectory(this.matterbridgeCertDirectory, 'Matterbridge Matter Certificate Directory', this.log);
|
|
334
|
-
// Set the matterbridge root directory
|
|
335
237
|
const { fileURLToPath } = await import('node:url');
|
|
336
238
|
const currentFileDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
337
239
|
this.rootDirectory = path.resolve(currentFileDirectory, '../');
|
|
338
240
|
this.matterbridgeInformation.rootDirectory = this.rootDirectory;
|
|
339
|
-
// Setup the matter environment
|
|
340
241
|
this.environment.vars.set('log.level', MatterLogLevel.INFO);
|
|
341
242
|
this.environment.vars.set('log.format', MatterLogFormat.ANSI);
|
|
342
243
|
this.environment.vars.set('path.root', path.join(this.matterbridgeDirectory, this.matterStorageName));
|
|
343
244
|
this.environment.vars.set('runtime.signals', false);
|
|
344
245
|
this.environment.vars.set('runtime.exitcode', false);
|
|
345
|
-
// Register process handlers
|
|
346
246
|
this.registerProcessHandlers();
|
|
347
|
-
// Initialize nodeStorage and nodeContext
|
|
348
247
|
try {
|
|
349
248
|
this.log.debug(`Creating node storage manager: ${CYAN}${this.nodeStorageName}${db}`);
|
|
350
249
|
this.nodeStorage = new NodeStorageManager({ dir: path.join(this.matterbridgeDirectory, this.nodeStorageName), writeQueue: false, expiredInterval: undefined, logging: false });
|
|
351
250
|
this.log.debug('Creating node storage context for matterbridge');
|
|
352
251
|
this.nodeContext = await this.nodeStorage.createStorage('matterbridge');
|
|
353
|
-
// TODO: Remove this code when node-persist-manager is updated
|
|
354
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
355
252
|
const keys = (await this.nodeStorage?.storage.keys());
|
|
356
253
|
for (const key of keys) {
|
|
357
254
|
this.log.debug(`Checking node storage manager key: ${CYAN}${key}${db}`);
|
|
358
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
359
255
|
await this.nodeStorage?.storage.get(key);
|
|
360
256
|
}
|
|
361
257
|
const storages = await this.nodeStorage.getStorageNames();
|
|
362
258
|
for (const storage of storages) {
|
|
363
259
|
this.log.debug(`Checking storage: ${CYAN}${storage}${db}`);
|
|
364
260
|
const nodeContext = await this.nodeStorage?.createStorage(storage);
|
|
365
|
-
// TODO: Remove this code when node-persist-manager is updated
|
|
366
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
367
261
|
const keys = (await nodeContext?.storage.keys());
|
|
368
262
|
keys.forEach(async (key) => {
|
|
369
263
|
this.log.debug(`Checking key: ${CYAN}${storage}:${key}${db}`);
|
|
370
264
|
await nodeContext?.get(key);
|
|
371
265
|
});
|
|
372
266
|
}
|
|
373
|
-
// Creating a backup of the node storage since it is not corrupted
|
|
374
267
|
this.log.debug('Creating node storage backup...');
|
|
375
268
|
await copyDirectory(path.join(this.matterbridgeDirectory, this.nodeStorageName), path.join(this.matterbridgeDirectory, this.nodeStorageName + '.backup'));
|
|
376
269
|
this.log.debug('Created node storage backup');
|
|
377
270
|
}
|
|
378
271
|
catch (error) {
|
|
379
|
-
// Restoring the backup of the node storage since it is corrupted
|
|
380
272
|
this.log.error(`Error creating node storage manager and context: ${error instanceof Error ? error.message : error}`);
|
|
381
273
|
if (hasParameter('norestore')) {
|
|
382
274
|
this.log.fatal(`The matterbridge storage is corrupted. Found -norestore parameter: exiting...`);
|
|
@@ -390,20 +282,14 @@ export class Matterbridge extends EventEmitter {
|
|
|
390
282
|
if (!this.nodeStorage || !this.nodeContext) {
|
|
391
283
|
throw new Error('Fatal error creating node storage manager and context for matterbridge');
|
|
392
284
|
}
|
|
393
|
-
// Set the first port to use for the commissioning server (will be incremented in childbridge mode)
|
|
394
285
|
this.port = getIntParameter('port') ?? (await this.nodeContext.get('matterport', 5540)) ?? 5540;
|
|
395
|
-
// Set the first passcode to use for the commissioning server (will be incremented in childbridge mode)
|
|
396
286
|
this.passcode = getIntParameter('passcode') ?? (await this.nodeContext.get('matterpasscode')) ?? PaseClient.generateRandomPasscode(this.environment.get(Crypto));
|
|
397
|
-
// Set the first discriminator to use for the commissioning server (will be incremented in childbridge mode)
|
|
398
287
|
this.discriminator = getIntParameter('discriminator') ?? (await this.nodeContext.get('matterdiscriminator')) ?? PaseClient.generateRandomDiscriminator(this.environment.get(Crypto));
|
|
399
|
-
// Certificate management
|
|
400
288
|
const pairingFilePath = path.join(this.matterbridgeCertDirectory, 'pairing.json');
|
|
401
289
|
try {
|
|
402
|
-
// eslint-disable-next-line n/no-unsupported-features/node-builtins
|
|
403
290
|
await fs.access(pairingFilePath, fs.constants.R_OK);
|
|
404
291
|
const pairingFileContent = await fs.readFile(pairingFilePath, 'utf8');
|
|
405
292
|
const pairingFileJson = JSON.parse(pairingFileContent);
|
|
406
|
-
// Set the vendorId, vendorName, productId, productName, deviceType, serialNumber, uniqueId if they are present in the pairing file
|
|
407
293
|
if (isValidNumber(pairingFileJson.vendorId)) {
|
|
408
294
|
this.aggregatorVendorId = VendorId(pairingFileJson.vendorId);
|
|
409
295
|
this.log.info(`Pairing file ${CYAN}${pairingFilePath}${nf} found. Using vendorId ${CYAN}${this.aggregatorVendorId}${nf} from pairing file.`);
|
|
@@ -432,13 +318,11 @@ export class Matterbridge extends EventEmitter {
|
|
|
432
318
|
this.aggregatorUniqueId = pairingFileJson.uniqueId;
|
|
433
319
|
this.log.info(`Pairing file ${CYAN}${pairingFilePath}${nf} found. Using uniqueId ${CYAN}${this.aggregatorUniqueId}${nf} from pairing file.`);
|
|
434
320
|
}
|
|
435
|
-
// Override the passcode and discriminator if they are present in the pairing file
|
|
436
321
|
if (isValidNumber(pairingFileJson.passcode) && isValidNumber(pairingFileJson.discriminator)) {
|
|
437
322
|
this.passcode = pairingFileJson.passcode;
|
|
438
323
|
this.discriminator = pairingFileJson.discriminator;
|
|
439
324
|
this.log.info(`Pairing file ${CYAN}${pairingFilePath}${nf} found. Using passcode ${CYAN}${this.passcode}${nf} and discriminator ${CYAN}${this.discriminator}${nf} from pairing file.`);
|
|
440
325
|
}
|
|
441
|
-
// Set the certification for matter.js if it is present in the pairing file
|
|
442
326
|
if (pairingFileJson.privateKey && pairingFileJson.certificate && pairingFileJson.intermediateCertificate && pairingFileJson.declaration) {
|
|
443
327
|
const { hexToBuffer } = await import('./utils/hex.js');
|
|
444
328
|
this.certification = {
|
|
@@ -453,44 +337,41 @@ export class Matterbridge extends EventEmitter {
|
|
|
453
337
|
catch (error) {
|
|
454
338
|
this.log.debug(`Pairing file ${CYAN}${pairingFilePath}${db} not found: ${error instanceof Error ? error.message : error}`);
|
|
455
339
|
}
|
|
456
|
-
// Store the passcode, discriminator and port in the node context
|
|
457
340
|
await this.nodeContext.set('matterport', this.port);
|
|
458
341
|
await this.nodeContext.set('matterpasscode', this.passcode);
|
|
459
342
|
await this.nodeContext.set('matterdiscriminator', this.discriminator);
|
|
460
343
|
this.log.debug(`Initializing server node for Matterbridge on port ${this.port} with passcode ${this.passcode} and discriminator ${this.discriminator}`);
|
|
461
|
-
// Set matterbridge logger level (context: matterbridgeLogLevel)
|
|
462
344
|
if (hasParameter('logger')) {
|
|
463
345
|
const level = getParameter('logger');
|
|
464
346
|
if (level === 'debug') {
|
|
465
|
-
this.log.logLevel = "debug"
|
|
347
|
+
this.log.logLevel = "debug";
|
|
466
348
|
}
|
|
467
349
|
else if (level === 'info') {
|
|
468
|
-
this.log.logLevel = "info"
|
|
350
|
+
this.log.logLevel = "info";
|
|
469
351
|
}
|
|
470
352
|
else if (level === 'notice') {
|
|
471
|
-
this.log.logLevel = "notice"
|
|
353
|
+
this.log.logLevel = "notice";
|
|
472
354
|
}
|
|
473
355
|
else if (level === 'warn') {
|
|
474
|
-
this.log.logLevel = "warn"
|
|
356
|
+
this.log.logLevel = "warn";
|
|
475
357
|
}
|
|
476
358
|
else if (level === 'error') {
|
|
477
|
-
this.log.logLevel = "error"
|
|
359
|
+
this.log.logLevel = "error";
|
|
478
360
|
}
|
|
479
361
|
else if (level === 'fatal') {
|
|
480
|
-
this.log.logLevel = "fatal"
|
|
362
|
+
this.log.logLevel = "fatal";
|
|
481
363
|
}
|
|
482
364
|
else {
|
|
483
365
|
this.log.warn(`Invalid matterbridge logger level: ${level}. Using default level "info".`);
|
|
484
|
-
this.log.logLevel = "info"
|
|
366
|
+
this.log.logLevel = "info";
|
|
485
367
|
}
|
|
486
368
|
}
|
|
487
369
|
else {
|
|
488
|
-
this.log.logLevel = await this.nodeContext.get('matterbridgeLogLevel', this.matterbridgeInformation.shellyBoard ? "notice"
|
|
370
|
+
this.log.logLevel = await this.nodeContext.get('matterbridgeLogLevel', this.matterbridgeInformation.shellyBoard ? "notice" : "info");
|
|
489
371
|
}
|
|
490
372
|
this.frontend.logLevel = this.log.logLevel;
|
|
491
373
|
MatterbridgeEndpoint.logLevel = this.log.logLevel;
|
|
492
374
|
this.matterbridgeInformation.loggerLevel = this.log.logLevel;
|
|
493
|
-
// Create the file logger for matterbridge (context: matterbridgeFileLog)
|
|
494
375
|
if (hasParameter('filelogger') || (await this.nodeContext.get('matterbridgeFileLog', false))) {
|
|
495
376
|
AnsiLogger.setGlobalLogfile(path.join(this.matterbridgeDirectory, this.matterbridgeLoggerFile), this.log.logLevel, true);
|
|
496
377
|
this.matterbridgeInformation.fileLogger = true;
|
|
@@ -499,7 +380,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
499
380
|
this.log.debug(`Matterbridge logLevel: ${this.log.logLevel} fileLoger: ${this.matterbridgeInformation.fileLogger}.`);
|
|
500
381
|
if (this.profile !== undefined)
|
|
501
382
|
this.log.debug(`Matterbridge profile: ${this.profile}.`);
|
|
502
|
-
// Set matter.js logger level, format and logger (context: matterLogLevel)
|
|
503
383
|
if (hasParameter('matterlogger')) {
|
|
504
384
|
const level = getParameter('matterlogger');
|
|
505
385
|
if (level === 'debug') {
|
|
@@ -530,9 +410,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
530
410
|
}
|
|
531
411
|
Logger.format = MatterLogFormat.ANSI;
|
|
532
412
|
Logger.setLogger('default', this.createMatterLogger());
|
|
533
|
-
// Logger.destinations.default.write = this.createMatterLogger();
|
|
534
413
|
this.matterbridgeInformation.matterLoggerLevel = Logger.level;
|
|
535
|
-
// Create the file logger for matter.js (context: matterFileLog)
|
|
536
414
|
if (hasParameter('matterfilelogger') || (await this.nodeContext.get('matterFileLog', false))) {
|
|
537
415
|
this.matterbridgeInformation.matterFileLogger = true;
|
|
538
416
|
Logger.addLogger('matterfilelogger', await this.createMatterFileLogger(path.join(this.matterbridgeDirectory, this.matterLoggerFile), true), {
|
|
@@ -541,9 +419,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
541
419
|
});
|
|
542
420
|
}
|
|
543
421
|
this.log.debug(`Matter logLevel: ${Logger.level} fileLoger: ${this.matterbridgeInformation.matterFileLogger}.`);
|
|
544
|
-
// Log network interfaces
|
|
545
422
|
const networkInterfaces = os.networkInterfaces();
|
|
546
|
-
// console.log(`Network interfaces:`, networkInterfaces);
|
|
547
423
|
const availableAddresses = Object.entries(networkInterfaces);
|
|
548
424
|
const availableInterfaces = Object.keys(networkInterfaces);
|
|
549
425
|
for (const [ifaceName, ifaces] of availableAddresses) {
|
|
@@ -555,7 +431,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
555
431
|
});
|
|
556
432
|
}
|
|
557
433
|
}
|
|
558
|
-
// Set the interface to use for matter server node mdnsInterface
|
|
559
434
|
if (hasParameter('mdnsinterface')) {
|
|
560
435
|
this.mdnsInterface = getParameter('mdnsinterface');
|
|
561
436
|
}
|
|
@@ -564,7 +439,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
564
439
|
if (this.mdnsInterface === '')
|
|
565
440
|
this.mdnsInterface = undefined;
|
|
566
441
|
}
|
|
567
|
-
// Validate mdnsInterface
|
|
568
442
|
if (this.mdnsInterface) {
|
|
569
443
|
if (!availableInterfaces.includes(this.mdnsInterface)) {
|
|
570
444
|
this.log.error(`Invalid mdnsinterface: ${this.mdnsInterface}. Available interfaces are: ${availableInterfaces.join(', ')}. Using all available interfaces.`);
|
|
@@ -577,7 +451,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
577
451
|
}
|
|
578
452
|
if (this.mdnsInterface)
|
|
579
453
|
this.environment.vars.set('mdns.networkInterface', this.mdnsInterface);
|
|
580
|
-
// Set the listeningAddressIpv4 for the matter commissioning server
|
|
581
454
|
if (hasParameter('ipv4address')) {
|
|
582
455
|
this.ipv4address = getParameter('ipv4address');
|
|
583
456
|
}
|
|
@@ -586,7 +459,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
586
459
|
if (this.ipv4address === '')
|
|
587
460
|
this.ipv4address = undefined;
|
|
588
461
|
}
|
|
589
|
-
// Validate ipv4address
|
|
590
462
|
if (this.ipv4address) {
|
|
591
463
|
let isValid = false;
|
|
592
464
|
for (const [ifaceName, ifaces] of availableAddresses) {
|
|
@@ -602,7 +474,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
602
474
|
await this.nodeContext.remove('matteripv4address');
|
|
603
475
|
}
|
|
604
476
|
}
|
|
605
|
-
// Set the listeningAddressIpv6 for the matter commissioning server
|
|
606
477
|
if (hasParameter('ipv6address')) {
|
|
607
478
|
this.ipv6address = getParameter('ipv6address');
|
|
608
479
|
}
|
|
@@ -611,7 +482,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
611
482
|
if (this.ipv6address === '')
|
|
612
483
|
this.ipv6address = undefined;
|
|
613
484
|
}
|
|
614
|
-
// Validate ipv6address
|
|
615
485
|
if (this.ipv6address) {
|
|
616
486
|
let isValid = false;
|
|
617
487
|
for (const [ifaceName, ifaces] of availableAddresses) {
|
|
@@ -620,7 +490,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
620
490
|
isValid = true;
|
|
621
491
|
break;
|
|
622
492
|
}
|
|
623
|
-
/* istanbul ignore next */
|
|
624
493
|
if (ifaces && ifaces.find((iface) => iface.scopeid && iface.scopeid > 0 && iface.address + '%' + (process.platform === 'win32' ? iface.scopeid : ifaceName) === this.ipv6address)) {
|
|
625
494
|
this.log.info(`Using ipv6address ${CYAN}${this.ipv6address}${nf} on interface ${CYAN}${ifaceName}${nf} for the Matter server node.`);
|
|
626
495
|
isValid = true;
|
|
@@ -633,7 +502,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
633
502
|
await this.nodeContext.remove('matteripv6address');
|
|
634
503
|
}
|
|
635
504
|
}
|
|
636
|
-
// Initialize the virtual mode
|
|
637
505
|
if (hasParameter('novirtual')) {
|
|
638
506
|
this.matterbridgeInformation.virtualMode = 'disabled';
|
|
639
507
|
await this.nodeContext.set('virtualmode', 'disabled');
|
|
@@ -642,17 +510,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
642
510
|
this.matterbridgeInformation.virtualMode = (await this.nodeContext.get('virtualmode', 'outlet'));
|
|
643
511
|
}
|
|
644
512
|
this.log.debug(`Virtual mode ${this.matterbridgeInformation.virtualMode}.`);
|
|
645
|
-
// Initialize PluginManager
|
|
646
513
|
this.plugins.logLevel = this.log.logLevel;
|
|
647
514
|
await this.plugins.loadFromStorage();
|
|
648
|
-
// Initialize DeviceManager
|
|
649
515
|
this.devices.logLevel = this.log.logLevel;
|
|
650
|
-
// Get the plugins from node storage and create the plugins node storage contexts
|
|
651
516
|
for (const plugin of this.plugins) {
|
|
652
517
|
const packageJson = await this.plugins.parse(plugin);
|
|
653
518
|
if (packageJson === null && !hasParameter('add') && !hasParameter('remove') && !hasParameter('enable') && !hasParameter('disable') && !hasParameter('reset') && !hasParameter('factoryreset')) {
|
|
654
|
-
// Try to reinstall the plugin from npm (for Docker pull and external plugins)
|
|
655
|
-
// We don't do this when the add and other parameters are set because we shut down the process after adding the plugin
|
|
656
519
|
this.log.info(`Error parsing plugin ${plg}${plugin.name}${nf}. Trying to reinstall it from npm.`);
|
|
657
520
|
try {
|
|
658
521
|
const { spawnCommand } = await import('./utils/spawn.js');
|
|
@@ -675,7 +538,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
675
538
|
await plugin.nodeContext.set('description', plugin.description);
|
|
676
539
|
await plugin.nodeContext.set('author', plugin.author);
|
|
677
540
|
}
|
|
678
|
-
// Log system info and create .matterbridge directory
|
|
679
541
|
await this.logNodeAndSystemInfo();
|
|
680
542
|
this.log.notice(`Matterbridge version ${this.matterbridgeVersion} ` +
|
|
681
543
|
`${hasParameter('bridge') || (!hasParameter('childbridge') && (await this.nodeContext?.get('bridgeMode', '')) === 'bridge') ? 'mode bridge ' : ''}` +
|
|
@@ -683,7 +545,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
683
545
|
`${hasParameter('controller') ? 'mode controller ' : ''}` +
|
|
684
546
|
`${this.restartMode !== '' ? 'restart mode ' + this.restartMode + ' ' : ''}` +
|
|
685
547
|
`running on ${this.systemInformation.osType} (v.${this.systemInformation.osRelease}) platform ${this.systemInformation.osPlatform} arch ${this.systemInformation.osArch}`);
|
|
686
|
-
// Check node version and throw error
|
|
687
548
|
const minNodeVersion = 18;
|
|
688
549
|
const nodeVersion = process.versions.node;
|
|
689
550
|
const versionMajor = parseInt(nodeVersion.split('.')[0]);
|
|
@@ -691,18 +552,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
691
552
|
this.log.error(`Node version ${versionMajor} is not supported. Please upgrade to ${minNodeVersion} or above.`);
|
|
692
553
|
throw new Error(`Node version ${versionMajor} is not supported. Please upgrade to ${minNodeVersion} or above.`);
|
|
693
554
|
}
|
|
694
|
-
// Parse command line
|
|
695
555
|
await this.parseCommandLine();
|
|
696
|
-
// Emit the initialize_completed event
|
|
697
556
|
this.emit('initialize_completed');
|
|
698
557
|
this.initialized = true;
|
|
699
558
|
}
|
|
700
|
-
/**
|
|
701
|
-
* Parses the command line arguments and performs the corresponding actions.
|
|
702
|
-
*
|
|
703
|
-
* @private
|
|
704
|
-
* @returns {Promise<void>} A promise that resolves when the command line arguments have been processed, or the process exits.
|
|
705
|
-
*/
|
|
706
559
|
async parseCommandLine() {
|
|
707
560
|
if (hasParameter('help')) {
|
|
708
561
|
this.log.info(`\nUsage: matterbridge [options]\n
|
|
@@ -764,19 +617,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
764
617
|
}
|
|
765
618
|
index++;
|
|
766
619
|
}
|
|
767
|
-
/*
|
|
768
|
-
const serializedRegisteredDevices = await this.nodeContext?.get<SerializedMatterbridgeEndpoint[]>('devices', []);
|
|
769
|
-
this.log.info(`│ Registered devices (${serializedRegisteredDevices?.length})`);
|
|
770
|
-
serializedRegisteredDevices?.forEach((device, index) => {
|
|
771
|
-
if (index !== serializedRegisteredDevices.length - 1) {
|
|
772
|
-
this.log.info(`├─┬─ plugin ${plg}${device.pluginName}${nf} device: ${dev}${device.deviceName}${nf} uniqueId: ${YELLOW}${device.uniqueId}${nf}`);
|
|
773
|
-
this.log.info(`│ └─ endpoint ${RED}${device.endpoint}${nf} ${typ}${device.endpointName}${nf} ${debugStringify(device.clusterServersId)}`);
|
|
774
|
-
} else {
|
|
775
|
-
this.log.info(`└─┬─ plugin ${plg}${device.pluginName}${nf} device: ${dev}${device.deviceName}${nf} uniqueId: ${YELLOW}${device.uniqueId}${nf}`);
|
|
776
|
-
this.log.info(` └─ endpoint ${RED}${device.endpoint}${nf} ${typ}${device.endpointName}${nf} ${debugStringify(device.clusterServersId)}`);
|
|
777
|
-
}
|
|
778
|
-
});
|
|
779
|
-
*/
|
|
780
620
|
this.shutdown = true;
|
|
781
621
|
return;
|
|
782
622
|
}
|
|
@@ -826,7 +666,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
826
666
|
this.shutdown = true;
|
|
827
667
|
return;
|
|
828
668
|
}
|
|
829
|
-
// Start the matter storage and create the matterbridge context
|
|
830
669
|
try {
|
|
831
670
|
await this.startMatterStorage();
|
|
832
671
|
if (this.aggregatorSerialNumber && this.aggregatorUniqueId && this.matterStorageService) {
|
|
@@ -843,21 +682,18 @@ export class Matterbridge extends EventEmitter {
|
|
|
843
682
|
this.log.fatal(`Fatal error creating matter storage: ${error instanceof Error ? error.message : error}`);
|
|
844
683
|
throw new Error(`Fatal error creating matter storage: ${error instanceof Error ? error.message : error}`);
|
|
845
684
|
}
|
|
846
|
-
// Clear the matterbridge context if the reset parameter is set
|
|
847
685
|
if (hasParameter('reset') && getParameter('reset') === undefined) {
|
|
848
686
|
this.initialized = true;
|
|
849
687
|
await this.shutdownProcessAndReset();
|
|
850
688
|
this.shutdown = true;
|
|
851
689
|
return;
|
|
852
690
|
}
|
|
853
|
-
// Clear matterbridge plugin context if the reset parameter is set
|
|
854
691
|
if (hasParameter('reset') && getParameter('reset') !== undefined) {
|
|
855
692
|
this.log.debug(`Reset plugin ${getParameter('reset')}`);
|
|
856
693
|
const plugin = this.plugins.get(getParameter('reset'));
|
|
857
694
|
if (plugin) {
|
|
858
695
|
const matterStorageManager = await this.matterStorageService?.open(plugin.name);
|
|
859
696
|
if (!matterStorageManager) {
|
|
860
|
-
/* istanbul ignore next */
|
|
861
697
|
this.log.error(`Plugin ${plg}${plugin.name}${er} storageManager not found`);
|
|
862
698
|
}
|
|
863
699
|
else {
|
|
@@ -876,39 +712,32 @@ export class Matterbridge extends EventEmitter {
|
|
|
876
712
|
this.shutdown = true;
|
|
877
713
|
return;
|
|
878
714
|
}
|
|
879
|
-
// Initialize frontend
|
|
880
715
|
if (getIntParameter('frontend') !== 0 || getIntParameter('frontend') === undefined)
|
|
881
716
|
await this.frontend.start(getIntParameter('frontend'));
|
|
882
|
-
// Check in 30 seconds the latest and dev versions of matterbridge and the plugins
|
|
883
717
|
clearTimeout(this.checkUpdateTimeout);
|
|
884
718
|
this.checkUpdateTimeout = setTimeout(async () => {
|
|
885
719
|
const { checkUpdates } = await import('./update.js');
|
|
886
720
|
checkUpdates(this);
|
|
887
721
|
}, 30 * 1000).unref();
|
|
888
|
-
// Check each 12 hours the latest and dev versions of matterbridge and the plugins
|
|
889
722
|
clearInterval(this.checkUpdateInterval);
|
|
890
723
|
this.checkUpdateInterval = setInterval(async () => {
|
|
891
724
|
const { checkUpdates } = await import('./update.js');
|
|
892
725
|
checkUpdates(this);
|
|
893
726
|
}, 12 * 60 * 60 * 1000).unref();
|
|
894
|
-
// Start the matterbridge in mode test
|
|
895
727
|
if (hasParameter('test')) {
|
|
896
728
|
this.bridgeMode = 'bridge';
|
|
897
729
|
MatterbridgeEndpoint.bridgeMode = 'bridge';
|
|
898
730
|
return;
|
|
899
731
|
}
|
|
900
|
-
// Start the matterbridge in mode controller
|
|
901
732
|
if (hasParameter('controller')) {
|
|
902
733
|
this.bridgeMode = 'controller';
|
|
903
734
|
await this.startController();
|
|
904
735
|
return;
|
|
905
736
|
}
|
|
906
|
-
// Check if the bridge mode is set and start matterbridge in bridge mode if not set
|
|
907
737
|
if (!hasParameter('bridge') && !hasParameter('childbridge') && (await this.nodeContext?.get('bridgeMode', '')) === '') {
|
|
908
738
|
this.log.info('Setting default matterbridge start mode to bridge');
|
|
909
739
|
await this.nodeContext?.set('bridgeMode', 'bridge');
|
|
910
740
|
}
|
|
911
|
-
// Start matterbridge in bridge mode
|
|
912
741
|
if (hasParameter('bridge') || (!hasParameter('childbridge') && (await this.nodeContext?.get('bridgeMode', '')) === 'bridge')) {
|
|
913
742
|
this.bridgeMode = 'bridge';
|
|
914
743
|
MatterbridgeEndpoint.bridgeMode = 'bridge';
|
|
@@ -916,7 +745,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
916
745
|
await this.startBridge();
|
|
917
746
|
return;
|
|
918
747
|
}
|
|
919
|
-
// Start matterbridge in childbridge mode
|
|
920
748
|
if (hasParameter('childbridge') || (!hasParameter('bridge') && (await this.nodeContext?.get('bridgeMode', '')) === 'childbridge')) {
|
|
921
749
|
this.bridgeMode = 'childbridge';
|
|
922
750
|
MatterbridgeEndpoint.bridgeMode = 'childbridge';
|
|
@@ -925,20 +753,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
925
753
|
return;
|
|
926
754
|
}
|
|
927
755
|
}
|
|
928
|
-
/**
|
|
929
|
-
* Asynchronously loads and starts the registered plugins.
|
|
930
|
-
*
|
|
931
|
-
* This method is responsible for initializing and starting all enabled plugins.
|
|
932
|
-
* It ensures that each plugin is properly loaded and started before the bridge starts.
|
|
933
|
-
*
|
|
934
|
-
* @returns {Promise<void>} A promise that resolves when all plugins have been loaded and started.
|
|
935
|
-
*/
|
|
936
756
|
async startPlugins() {
|
|
937
|
-
// Check, load and start the plugins
|
|
938
757
|
for (const plugin of this.plugins) {
|
|
939
758
|
plugin.configJson = await this.plugins.loadConfig(plugin);
|
|
940
759
|
plugin.schemaJson = await this.plugins.loadSchema(plugin);
|
|
941
|
-
// Check if the plugin is available
|
|
942
760
|
if (!(await this.plugins.resolve(plugin.path))) {
|
|
943
761
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not found or not validated. Disabling it.`);
|
|
944
762
|
plugin.enabled = false;
|
|
@@ -956,14 +774,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
956
774
|
plugin.configured = false;
|
|
957
775
|
plugin.registeredDevices = undefined;
|
|
958
776
|
plugin.addedDevices = undefined;
|
|
959
|
-
this.plugins.load(plugin, true, 'Matterbridge is starting');
|
|
777
|
+
this.plugins.load(plugin, true, 'Matterbridge is starting');
|
|
960
778
|
}
|
|
961
779
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
962
780
|
}
|
|
963
|
-
/**
|
|
964
|
-
* Registers the process handlers for uncaughtException, unhandledRejection, SIGINT and SIGTERM.
|
|
965
|
-
* When either of these signals are received, the cleanup method is called with an appropriate message.
|
|
966
|
-
*/
|
|
967
781
|
registerProcessHandlers() {
|
|
968
782
|
this.log.debug(`Registering uncaughtException and unhandledRejection handlers...`);
|
|
969
783
|
process.removeAllListeners('uncaughtException');
|
|
@@ -990,9 +804,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
990
804
|
};
|
|
991
805
|
process.on('SIGTERM', this.sigtermHandler);
|
|
992
806
|
}
|
|
993
|
-
/**
|
|
994
|
-
* Deregisters the process uncaughtException, unhandledRejection, SIGINT and SIGTERM signal handlers.
|
|
995
|
-
*/
|
|
996
807
|
deregisterProcessHandlers() {
|
|
997
808
|
this.log.debug(`Deregistering uncaughtException and unhandledRejection handlers...`);
|
|
998
809
|
if (this.exceptionHandler)
|
|
@@ -1009,17 +820,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
1009
820
|
process.off('SIGTERM', this.sigtermHandler);
|
|
1010
821
|
this.sigtermHandler = undefined;
|
|
1011
822
|
}
|
|
1012
|
-
/**
|
|
1013
|
-
* Logs the node and system information.
|
|
1014
|
-
*/
|
|
1015
823
|
async logNodeAndSystemInfo() {
|
|
1016
|
-
// IP address information
|
|
1017
824
|
const networkInterfaces = os.networkInterfaces();
|
|
1018
825
|
this.systemInformation.interfaceName = '';
|
|
1019
826
|
this.systemInformation.ipv4Address = '';
|
|
1020
827
|
this.systemInformation.ipv6Address = '';
|
|
1021
828
|
for (const [interfaceName, interfaceDetails] of Object.entries(networkInterfaces)) {
|
|
1022
|
-
// this.log.debug(`Checking interface: '${interfaceName}' for '${this.mdnsInterface}'`);
|
|
1023
829
|
if (this.mdnsInterface && interfaceName !== this.mdnsInterface)
|
|
1024
830
|
continue;
|
|
1025
831
|
if (!interfaceDetails) {
|
|
@@ -1045,22 +851,19 @@ export class Matterbridge extends EventEmitter {
|
|
|
1045
851
|
break;
|
|
1046
852
|
}
|
|
1047
853
|
}
|
|
1048
|
-
// Node information
|
|
1049
854
|
this.systemInformation.nodeVersion = process.versions.node;
|
|
1050
855
|
const versionMajor = parseInt(this.systemInformation.nodeVersion.split('.')[0]);
|
|
1051
856
|
const versionMinor = parseInt(this.systemInformation.nodeVersion.split('.')[1]);
|
|
1052
857
|
const versionPatch = parseInt(this.systemInformation.nodeVersion.split('.')[2]);
|
|
1053
|
-
// Host system information
|
|
1054
858
|
this.systemInformation.hostname = os.hostname();
|
|
1055
859
|
this.systemInformation.user = os.userInfo().username;
|
|
1056
|
-
this.systemInformation.osType = os.type();
|
|
1057
|
-
this.systemInformation.osRelease = os.release();
|
|
1058
|
-
this.systemInformation.osPlatform = os.platform();
|
|
1059
|
-
this.systemInformation.osArch = os.arch();
|
|
1060
|
-
this.systemInformation.totalMemory = (os.totalmem() / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
|
1061
|
-
this.systemInformation.freeMemory = (os.freemem() / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
|
1062
|
-
this.systemInformation.systemUptime = (os.uptime() / 60 / 60).toFixed(2) + ' hours';
|
|
1063
|
-
// Log the system information
|
|
860
|
+
this.systemInformation.osType = os.type();
|
|
861
|
+
this.systemInformation.osRelease = os.release();
|
|
862
|
+
this.systemInformation.osPlatform = os.platform();
|
|
863
|
+
this.systemInformation.osArch = os.arch();
|
|
864
|
+
this.systemInformation.totalMemory = (os.totalmem() / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
|
865
|
+
this.systemInformation.freeMemory = (os.freemem() / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
|
866
|
+
this.systemInformation.systemUptime = (os.uptime() / 60 / 60).toFixed(2) + ' hours';
|
|
1064
867
|
this.log.debug('Host System Information:');
|
|
1065
868
|
this.log.debug(`- Hostname: ${this.systemInformation.hostname}`);
|
|
1066
869
|
this.log.debug(`- User: ${this.systemInformation.user}`);
|
|
@@ -1076,17 +879,14 @@ export class Matterbridge extends EventEmitter {
|
|
|
1076
879
|
this.log.debug(`- Total Memory: ${this.systemInformation.totalMemory}`);
|
|
1077
880
|
this.log.debug(`- Free Memory: ${this.systemInformation.freeMemory}`);
|
|
1078
881
|
this.log.debug(`- System Uptime: ${this.systemInformation.systemUptime}`);
|
|
1079
|
-
// Log directories
|
|
1080
882
|
this.log.debug(`Root Directory: ${this.rootDirectory}`);
|
|
1081
883
|
this.log.debug(`Home Directory: ${this.homeDirectory}`);
|
|
1082
884
|
this.log.debug(`Matterbridge Directory: ${this.matterbridgeDirectory}`);
|
|
1083
885
|
this.log.debug(`Matterbridge Plugin Directory: ${this.matterbridgePluginDirectory}`);
|
|
1084
886
|
this.log.debug(`Matterbridge Matter Certificate Directory: ${this.matterbridgeCertDirectory}`);
|
|
1085
|
-
// Global node_modules directory
|
|
1086
887
|
if (this.nodeContext)
|
|
1087
888
|
this.globalModulesDirectory = this.matterbridgeInformation.globalModulesDirectory = await this.nodeContext.get('globalModulesDirectory', '');
|
|
1088
889
|
if (this.globalModulesDirectory === '') {
|
|
1089
|
-
// First run of Matterbridge so the node storage is empty
|
|
1090
890
|
try {
|
|
1091
891
|
const { getGlobalNodeModules } = await import('./utils/network.js');
|
|
1092
892
|
this.execRunningCount++;
|
|
@@ -1096,87 +896,55 @@ export class Matterbridge extends EventEmitter {
|
|
|
1096
896
|
await this.nodeContext?.set('globalModulesDirectory', this.globalModulesDirectory);
|
|
1097
897
|
}
|
|
1098
898
|
catch (error) {
|
|
1099
|
-
// istanbul ignore next
|
|
1100
899
|
this.log.error(`Error getting global node_modules directory: ${error}`);
|
|
1101
900
|
}
|
|
1102
901
|
}
|
|
1103
902
|
else
|
|
1104
903
|
this.log.debug(`Global node_modules Directory: ${this.globalModulesDirectory}`);
|
|
1105
|
-
/* removed cause is too expensive for the shelly board and not really needed. Why should the globalModulesDirectory change?
|
|
1106
|
-
else {
|
|
1107
|
-
this.getGlobalNodeModules()
|
|
1108
|
-
.then(async (globalModulesDirectory) => {
|
|
1109
|
-
this.globalModulesDirectory = globalModulesDirectory;
|
|
1110
|
-
this.matterbridgeInformation.globalModulesDirectory = this.globalModulesDirectory;
|
|
1111
|
-
this.log.debug(`Global node_modules Directory: ${this.globalModulesDirectory}`);
|
|
1112
|
-
await this.nodeContext?.set<string>('globalModulesDirectory', this.globalModulesDirectory);
|
|
1113
|
-
})
|
|
1114
|
-
.catch((error) => {
|
|
1115
|
-
this.log.error(`Error getting global node_modules directory: ${error}`);
|
|
1116
|
-
});
|
|
1117
|
-
}*/
|
|
1118
|
-
// Matterbridge version
|
|
1119
904
|
const packageJson = JSON.parse(await fs.readFile(path.join(this.rootDirectory, 'package.json'), 'utf-8'));
|
|
1120
905
|
this.matterbridgeVersion = this.matterbridgeLatestVersion = this.matterbridgeDevVersion = packageJson.version;
|
|
1121
906
|
this.matterbridgeInformation.matterbridgeVersion = this.matterbridgeInformation.matterbridgeLatestVersion = this.matterbridgeInformation.matterbridgeDevVersion = packageJson.version;
|
|
1122
907
|
this.log.debug(`Matterbridge Version: ${this.matterbridgeVersion}`);
|
|
1123
|
-
// Matterbridge latest version (will be set in the checkUpdate function)
|
|
1124
908
|
if (this.nodeContext)
|
|
1125
909
|
this.matterbridgeLatestVersion = this.matterbridgeInformation.matterbridgeLatestVersion = await this.nodeContext.get('matterbridgeLatestVersion', this.matterbridgeVersion);
|
|
1126
910
|
this.log.debug(`Matterbridge Latest Version: ${this.matterbridgeLatestVersion}`);
|
|
1127
|
-
// Matterbridge dev version (will be set in the checkUpdate function)
|
|
1128
911
|
if (this.nodeContext)
|
|
1129
912
|
this.matterbridgeDevVersion = this.matterbridgeInformation.matterbridgeDevVersion = await this.nodeContext.get('matterbridgeDevVersion', this.matterbridgeVersion);
|
|
1130
913
|
this.log.debug(`Matterbridge Dev Version: ${this.matterbridgeDevVersion}`);
|
|
1131
|
-
// Current working directory
|
|
1132
914
|
const currentDir = process.cwd();
|
|
1133
915
|
this.log.debug(`Current Working Directory: ${currentDir}`);
|
|
1134
|
-
// Command line arguments (excluding 'node' and the script name)
|
|
1135
916
|
const cmdArgs = process.argv.slice(2).join(' ');
|
|
1136
917
|
this.log.debug(`Command Line Arguments: ${cmdArgs}`);
|
|
1137
918
|
}
|
|
1138
|
-
/**
|
|
1139
|
-
* Creates a MatterLogger function to show the matter.js log messages in AnsiLogger (for the frontend).
|
|
1140
|
-
*
|
|
1141
|
-
* @returns {Function} The MatterLogger function.
|
|
1142
|
-
*/
|
|
1143
919
|
createMatterLogger() {
|
|
1144
|
-
const matterLogger = new AnsiLogger({ logName: 'Matter', logTimestampFormat: 4
|
|
920
|
+
const matterLogger = new AnsiLogger({ logName: 'Matter', logTimestampFormat: 4, logLevel: "debug" });
|
|
1145
921
|
return (level, formattedLog) => {
|
|
1146
922
|
const logger = formattedLog.slice(44, 44 + 20).trim();
|
|
1147
923
|
const message = formattedLog.slice(65);
|
|
1148
924
|
matterLogger.logName = logger;
|
|
1149
925
|
switch (level) {
|
|
1150
926
|
case MatterLogLevel.DEBUG:
|
|
1151
|
-
matterLogger.log("debug"
|
|
927
|
+
matterLogger.log("debug", message);
|
|
1152
928
|
break;
|
|
1153
929
|
case MatterLogLevel.INFO:
|
|
1154
|
-
matterLogger.log("info"
|
|
930
|
+
matterLogger.log("info", message);
|
|
1155
931
|
break;
|
|
1156
932
|
case MatterLogLevel.NOTICE:
|
|
1157
|
-
matterLogger.log("notice"
|
|
933
|
+
matterLogger.log("notice", message);
|
|
1158
934
|
break;
|
|
1159
935
|
case MatterLogLevel.WARN:
|
|
1160
|
-
matterLogger.log("warn"
|
|
936
|
+
matterLogger.log("warn", message);
|
|
1161
937
|
break;
|
|
1162
938
|
case MatterLogLevel.ERROR:
|
|
1163
|
-
matterLogger.log("error"
|
|
939
|
+
matterLogger.log("error", message);
|
|
1164
940
|
break;
|
|
1165
941
|
case MatterLogLevel.FATAL:
|
|
1166
|
-
matterLogger.log("fatal"
|
|
942
|
+
matterLogger.log("fatal", message);
|
|
1167
943
|
break;
|
|
1168
944
|
}
|
|
1169
945
|
};
|
|
1170
946
|
}
|
|
1171
|
-
/**
|
|
1172
|
-
* Creates a Matter File Logger.
|
|
1173
|
-
*
|
|
1174
|
-
* @param {string} filePath - The path to the log file.
|
|
1175
|
-
* @param {boolean} [unlink] - Whether to unlink the log file before creating a new one.
|
|
1176
|
-
* @returns {Function} - A function that logs formatted messages to the log file.
|
|
1177
|
-
*/
|
|
1178
947
|
async createMatterFileLogger(filePath, unlink = false) {
|
|
1179
|
-
// 2024-08-21 08:55:19.488 DEBUG InteractionMessenger Sending DataReport chunk with 28 attributes and 0 events: 1004 bytes
|
|
1180
948
|
let fileSize = 0;
|
|
1181
949
|
if (unlink) {
|
|
1182
950
|
try {
|
|
@@ -1187,12 +955,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
1187
955
|
}
|
|
1188
956
|
}
|
|
1189
957
|
return async (level, formattedLog) => {
|
|
1190
|
-
/* istanbul ignore if */
|
|
1191
958
|
if (fileSize > 100000000) {
|
|
1192
|
-
return;
|
|
959
|
+
return;
|
|
1193
960
|
}
|
|
1194
961
|
fileSize += formattedLog.length;
|
|
1195
|
-
/* istanbul ignore if */
|
|
1196
962
|
if (fileSize > 100000000) {
|
|
1197
963
|
await fs.appendFile(filePath, `Logging on file has been stopped because the file size is greater than 100MB.` + os.EOL);
|
|
1198
964
|
return;
|
|
@@ -1225,27 +991,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
1225
991
|
}
|
|
1226
992
|
};
|
|
1227
993
|
}
|
|
1228
|
-
/**
|
|
1229
|
-
* Restarts the process by exiting the current instance and loading a new instance (/api/restart).
|
|
1230
|
-
*
|
|
1231
|
-
* @returns {Promise<void>} A promise that resolves when the restart is completed.
|
|
1232
|
-
*/
|
|
1233
994
|
async restartProcess() {
|
|
1234
995
|
await this.cleanup('restarting...', true);
|
|
1235
996
|
}
|
|
1236
|
-
/**
|
|
1237
|
-
* Shut down the process (/api/shutdown).
|
|
1238
|
-
*
|
|
1239
|
-
* @returns {Promise<void>} A promise that resolves when the shutdown is completed.
|
|
1240
|
-
*/
|
|
1241
997
|
async shutdownProcess() {
|
|
1242
998
|
await this.cleanup('shutting down...', false);
|
|
1243
999
|
}
|
|
1244
|
-
/**
|
|
1245
|
-
* Update matterbridge and shut down the process (virtual device 'Update Matterbridge').
|
|
1246
|
-
*
|
|
1247
|
-
* @returns {Promise<void>} A promise that resolves when the update is completed.
|
|
1248
|
-
*/
|
|
1249
1000
|
async updateProcess() {
|
|
1250
1001
|
this.log.info('Updating matterbridge...');
|
|
1251
1002
|
try {
|
|
@@ -1259,13 +1010,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1259
1010
|
this.frontend.wssSendRestartRequired();
|
|
1260
1011
|
await this.cleanup('updating...', false);
|
|
1261
1012
|
}
|
|
1262
|
-
/**
|
|
1263
|
-
* Unregister all devices and shut down the process (/api/unregister).
|
|
1264
|
-
*
|
|
1265
|
-
* @param {number} [timeout] - The timeout duration to wait for the message exchange to complete in milliseconds. Default is 1000.
|
|
1266
|
-
*
|
|
1267
|
-
* @returns {Promise<void>} A promise that resolves when the cleanup is completed.
|
|
1268
|
-
*/
|
|
1269
1013
|
async unregisterAndShutdownProcess(timeout = 1000) {
|
|
1270
1014
|
this.log.info('Unregistering all devices and shutting down...');
|
|
1271
1015
|
for (const plugin of this.plugins.array()) {
|
|
@@ -1279,71 +1023,46 @@ export class Matterbridge extends EventEmitter {
|
|
|
1279
1023
|
await this.removeAllBridgedEndpoints(plugin.name, 100);
|
|
1280
1024
|
}
|
|
1281
1025
|
this.log.debug('Waiting for the MessageExchange to finish...');
|
|
1282
|
-
await wait(timeout);
|
|
1026
|
+
await wait(timeout);
|
|
1283
1027
|
this.log.debug('Cleaning up and shutting down...');
|
|
1284
1028
|
await this.cleanup('unregistered all devices and shutting down...', false, timeout);
|
|
1285
1029
|
}
|
|
1286
|
-
/**
|
|
1287
|
-
* Reset commissioning and shut down the process (/api/reset).
|
|
1288
|
-
*
|
|
1289
|
-
* @returns {Promise<void>} A promise that resolves when the cleanup is completed.
|
|
1290
|
-
*/
|
|
1291
1030
|
async shutdownProcessAndReset() {
|
|
1292
1031
|
await this.cleanup('shutting down with reset...', false);
|
|
1293
1032
|
}
|
|
1294
|
-
/**
|
|
1295
|
-
* Factory reset and shut down the process (/api/factory-reset).
|
|
1296
|
-
*
|
|
1297
|
-
* @returns {Promise<void>} A promise that resolves when the cleanup is completed.
|
|
1298
|
-
*/
|
|
1299
1033
|
async shutdownProcessAndFactoryReset() {
|
|
1300
1034
|
await this.cleanup('shutting down with factory reset...', false);
|
|
1301
1035
|
}
|
|
1302
|
-
/**
|
|
1303
|
-
* Cleans up the Matterbridge instance.
|
|
1304
|
-
*
|
|
1305
|
-
* @param {string} message - The cleanup message.
|
|
1306
|
-
* @param {boolean} [restart] - Indicates whether to restart the instance after cleanup. Default is `false`.
|
|
1307
|
-
* @param {number} [timeout] - The timeout duration to wait for the message exchange to complete in milliseconds. Default is 1000.
|
|
1308
|
-
*
|
|
1309
|
-
* @returns {Promise<void>} A promise that resolves when the cleanup is completed.
|
|
1310
|
-
*/
|
|
1311
1036
|
async cleanup(message, restart = false, timeout = 1000) {
|
|
1312
1037
|
if (this.initialized && !this.hasCleanupStarted) {
|
|
1313
1038
|
this.emit('cleanup_started');
|
|
1314
1039
|
this.hasCleanupStarted = true;
|
|
1315
1040
|
this.log.info(message);
|
|
1316
|
-
// Clear the start matter interval
|
|
1317
1041
|
if (this.startMatterInterval) {
|
|
1318
1042
|
clearInterval(this.startMatterInterval);
|
|
1319
1043
|
this.startMatterInterval = undefined;
|
|
1320
1044
|
this.log.debug('Start matter interval cleared');
|
|
1321
1045
|
}
|
|
1322
|
-
// Clear the check update timeout
|
|
1323
1046
|
if (this.checkUpdateTimeout) {
|
|
1324
1047
|
clearTimeout(this.checkUpdateTimeout);
|
|
1325
1048
|
this.checkUpdateTimeout = undefined;
|
|
1326
1049
|
this.log.debug('Check update timeout cleared');
|
|
1327
1050
|
}
|
|
1328
|
-
// Clear the check update interval
|
|
1329
1051
|
if (this.checkUpdateInterval) {
|
|
1330
1052
|
clearInterval(this.checkUpdateInterval);
|
|
1331
1053
|
this.checkUpdateInterval = undefined;
|
|
1332
1054
|
this.log.debug('Check update interval cleared');
|
|
1333
1055
|
}
|
|
1334
|
-
// Clear the configure timeout
|
|
1335
1056
|
if (this.configureTimeout) {
|
|
1336
1057
|
clearTimeout(this.configureTimeout);
|
|
1337
1058
|
this.configureTimeout = undefined;
|
|
1338
1059
|
this.log.debug('Matterbridge configure timeout cleared');
|
|
1339
1060
|
}
|
|
1340
|
-
// Clear the reachability timeout
|
|
1341
1061
|
if (this.reachabilityTimeout) {
|
|
1342
1062
|
clearTimeout(this.reachabilityTimeout);
|
|
1343
1063
|
this.reachabilityTimeout = undefined;
|
|
1344
1064
|
this.log.debug('Matterbridge reachability timeout cleared');
|
|
1345
1065
|
}
|
|
1346
|
-
// Call the shutdown method of each plugin and clear the plugins reachability timeout
|
|
1347
1066
|
for (const plugin of this.plugins) {
|
|
1348
1067
|
if (!plugin.enabled || plugin.error)
|
|
1349
1068
|
continue;
|
|
@@ -1354,7 +1073,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1354
1073
|
this.log.debug(`Plugin ${plg}${plugin.name}${db} reachability timeout cleared`);
|
|
1355
1074
|
}
|
|
1356
1075
|
}
|
|
1357
|
-
// Stop matter server nodes
|
|
1358
1076
|
this.log.notice(`Stopping matter server nodes in ${this.bridgeMode} mode...`);
|
|
1359
1077
|
this.log.debug('Waiting for the MessageExchange to finish...');
|
|
1360
1078
|
await wait(timeout, 'Waiting for the MessageExchange to finish...', true);
|
|
@@ -1379,7 +1097,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1379
1097
|
}
|
|
1380
1098
|
}
|
|
1381
1099
|
this.log.notice('Stopped matter server nodes');
|
|
1382
|
-
// Matter commisioning reset
|
|
1383
1100
|
if (message === 'shutting down with reset...') {
|
|
1384
1101
|
this.log.info('Resetting Matterbridge commissioning information...');
|
|
1385
1102
|
await this.matterStorageManager?.createContext('events')?.clearAll();
|
|
@@ -1389,7 +1106,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1389
1106
|
await this.matterbridgeContext?.clearAll();
|
|
1390
1107
|
this.log.info('Matter storage reset done! Remove the bridge from the controller.');
|
|
1391
1108
|
}
|
|
1392
|
-
// Unregister all devices
|
|
1393
1109
|
if (message === 'unregistered all devices and shutting down...') {
|
|
1394
1110
|
if (this.bridgeMode === 'bridge') {
|
|
1395
1111
|
await this.matterStorageManager?.createContext('root')?.createContext('parts')?.createContext('Matterbridge')?.createContext('parts')?.clearAll();
|
|
@@ -1407,36 +1123,18 @@ export class Matterbridge extends EventEmitter {
|
|
|
1407
1123
|
}
|
|
1408
1124
|
this.log.info('Matter storage reset done!');
|
|
1409
1125
|
}
|
|
1410
|
-
// Stop matter storage
|
|
1411
1126
|
await this.stopMatterStorage();
|
|
1412
|
-
// Stop the frontend
|
|
1413
1127
|
await this.frontend.stop();
|
|
1414
|
-
// Remove the matterfilelogger
|
|
1415
1128
|
try {
|
|
1416
1129
|
Logger.removeLogger('matterfilelogger');
|
|
1417
1130
|
}
|
|
1418
1131
|
catch (error) {
|
|
1419
1132
|
this.log.debug(`Error removing the matterfilelogger for file ${CYAN}${path.join(this.matterbridgeDirectory, this.matterLoggerFile)}${db}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1420
1133
|
}
|
|
1421
|
-
// Close the matterbridge node storage and context
|
|
1422
1134
|
if (this.nodeStorage && this.nodeContext) {
|
|
1423
|
-
/*
|
|
1424
|
-
TODO: Implement serialization of registered devices in edge mode
|
|
1425
|
-
this.log.info('Saving registered devices...');
|
|
1426
|
-
const serializedRegisteredDevices: SerializedMatterbridgeEndpoint[] = [];
|
|
1427
|
-
this.devices.forEach(async (device) => {
|
|
1428
|
-
const serializedMatterbridgeDevice = MatterbridgeEndpoint.serialize(device);
|
|
1429
|
-
// this.log.info(`- ${serializedMatterbridgeDevice.deviceName}${rs}\n`, serializedMatterbridgeDevice);
|
|
1430
|
-
if (serializedMatterbridgeDevice) serializedRegisteredDevices.push(serializedMatterbridgeDevice);
|
|
1431
|
-
});
|
|
1432
|
-
await this.nodeContext.set<SerializedMatterbridgeEndpoint[]>('devices', serializedRegisteredDevices);
|
|
1433
|
-
this.log.info(`Saved registered devices (${serializedRegisteredDevices?.length})`);
|
|
1434
|
-
*/
|
|
1435
|
-
// Clear nodeContext and nodeStorage (they just need 1000ms to write the data to disk)
|
|
1436
1135
|
this.log.debug(`Closing node storage context for ${plg}Matterbridge${db}...`);
|
|
1437
1136
|
await this.nodeContext.close();
|
|
1438
1137
|
this.nodeContext = undefined;
|
|
1439
|
-
// Clear nodeContext for each plugin (they just need 1000ms to write the data to disk)
|
|
1440
1138
|
for (const plugin of this.plugins) {
|
|
1441
1139
|
if (plugin.nodeContext) {
|
|
1442
1140
|
this.log.debug(`Closing node storage context for plugin ${plg}${plugin.name}${db}...`);
|
|
@@ -1453,10 +1151,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
1453
1151
|
}
|
|
1454
1152
|
this.plugins.clear();
|
|
1455
1153
|
this.devices.clear();
|
|
1456
|
-
// Factory reset
|
|
1457
1154
|
if (message === 'shutting down with factory reset...') {
|
|
1458
1155
|
try {
|
|
1459
|
-
// Delete matter storage directory with its subdirectories and backup
|
|
1460
1156
|
const dir = path.join(this.matterbridgeDirectory, this.matterStorageName);
|
|
1461
1157
|
this.log.info(`Removing matter storage directory: ${dir}`);
|
|
1462
1158
|
await fs.rm(dir, { recursive: true });
|
|
@@ -1465,13 +1161,11 @@ export class Matterbridge extends EventEmitter {
|
|
|
1465
1161
|
await fs.rm(backup, { recursive: true });
|
|
1466
1162
|
}
|
|
1467
1163
|
catch (error) {
|
|
1468
|
-
// istanbul ignore next if
|
|
1469
1164
|
if (error instanceof Error && error.code !== 'ENOENT') {
|
|
1470
1165
|
this.log.error(`Error removing matter storage directory: ${error}`);
|
|
1471
1166
|
}
|
|
1472
1167
|
}
|
|
1473
1168
|
try {
|
|
1474
|
-
// Delete matterbridge storage directory with its subdirectories and backup
|
|
1475
1169
|
const dir = path.join(this.matterbridgeDirectory, this.nodeStorageName);
|
|
1476
1170
|
this.log.info(`Removing matterbridge storage directory: ${dir}`);
|
|
1477
1171
|
await fs.rm(dir, { recursive: true });
|
|
@@ -1480,20 +1174,18 @@ export class Matterbridge extends EventEmitter {
|
|
|
1480
1174
|
await fs.rm(backup, { recursive: true });
|
|
1481
1175
|
}
|
|
1482
1176
|
catch (error) {
|
|
1483
|
-
// istanbul ignore next if
|
|
1484
1177
|
if (error instanceof Error && error.code !== 'ENOENT') {
|
|
1485
1178
|
this.log.error(`Error removing matterbridge storage directory: ${error}`);
|
|
1486
1179
|
}
|
|
1487
1180
|
}
|
|
1488
1181
|
this.log.info('Factory reset done! Remove all paired fabrics from the controllers.');
|
|
1489
1182
|
}
|
|
1490
|
-
// Deregisters the process handlers
|
|
1491
1183
|
this.deregisterProcessHandlers();
|
|
1492
1184
|
if (restart) {
|
|
1493
1185
|
if (message === 'updating...') {
|
|
1494
1186
|
this.log.info('Cleanup completed. Updating...');
|
|
1495
1187
|
Matterbridge.instance = undefined;
|
|
1496
|
-
this.emit('update');
|
|
1188
|
+
this.emit('update');
|
|
1497
1189
|
}
|
|
1498
1190
|
else if (message === 'restarting...') {
|
|
1499
1191
|
this.log.info('Cleanup completed. Restarting...');
|
|
@@ -1514,13 +1206,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1514
1206
|
this.log.debug('Cleanup already started...');
|
|
1515
1207
|
}
|
|
1516
1208
|
}
|
|
1517
|
-
/**
|
|
1518
|
-
* Creates and configures the server node for a single not bridged device.
|
|
1519
|
-
*
|
|
1520
|
-
* @param {RegisteredPlugin} plugin - The plugin to configure.
|
|
1521
|
-
* @param {MatterbridgeEndpoint} device - The device to associate with the plugin.
|
|
1522
|
-
* @returns {Promise<void>} A promise that resolves when the server node for the accessory plugin is created and configured.
|
|
1523
|
-
*/
|
|
1524
1209
|
async createDeviceServerNode(plugin, device) {
|
|
1525
1210
|
if (device.mode === 'server' && !device.serverNode && device.deviceType && device.deviceName && device.vendorId && device.vendorName && device.productId && device.productName) {
|
|
1526
1211
|
this.log.debug(`Creating device ${plg}${plugin.name}${db}:${dev}${device.deviceName}${db} server node...`);
|
|
@@ -1531,13 +1216,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1531
1216
|
this.log.debug(`Added ${plg}${plugin.name}${db}:${dev}${device.deviceName}${db} to server node`);
|
|
1532
1217
|
}
|
|
1533
1218
|
}
|
|
1534
|
-
/**
|
|
1535
|
-
* Creates and configures the server node for an accessory plugin for a given device.
|
|
1536
|
-
*
|
|
1537
|
-
* @param {RegisteredPlugin} plugin - The plugin to configure.
|
|
1538
|
-
* @param {MatterbridgeEndpoint} device - The device to associate with the plugin.
|
|
1539
|
-
* @returns {Promise<void>} A promise that resolves when the server node for the accessory plugin is created and configured.
|
|
1540
|
-
*/
|
|
1541
1219
|
async createAccessoryPlugin(plugin, device) {
|
|
1542
1220
|
if (!plugin.locked && device.deviceType && device.deviceName && device.vendorId && device.productId && device.vendorName && device.productName) {
|
|
1543
1221
|
plugin.locked = true;
|
|
@@ -1549,12 +1227,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1549
1227
|
await plugin.serverNode.add(device);
|
|
1550
1228
|
}
|
|
1551
1229
|
}
|
|
1552
|
-
/**
|
|
1553
|
-
* Creates and configures the server node and the aggregator node for a dynamic plugin.
|
|
1554
|
-
*
|
|
1555
|
-
* @param {RegisteredPlugin} plugin - The plugin to configure.
|
|
1556
|
-
* @returns {Promise<void>} A promise that resolves when the server node and the aggregator node for the dynamic plugin is created and configured.
|
|
1557
|
-
*/
|
|
1558
1230
|
async createDynamicPlugin(plugin) {
|
|
1559
1231
|
if (!plugin.locked) {
|
|
1560
1232
|
plugin.locked = true;
|
|
@@ -1565,14 +1237,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
1565
1237
|
await plugin.serverNode.add(plugin.aggregatorNode);
|
|
1566
1238
|
}
|
|
1567
1239
|
}
|
|
1568
|
-
/**
|
|
1569
|
-
* Starts the Matterbridge in bridge mode.
|
|
1570
|
-
*
|
|
1571
|
-
* @private
|
|
1572
|
-
* @returns {Promise<void>} A promise that resolves when the Matterbridge is started.
|
|
1573
|
-
*/
|
|
1574
1240
|
async startBridge() {
|
|
1575
|
-
// Plugins are configured by a timer when matter server is started and plugin.configured is set to true
|
|
1576
1241
|
if (!this.matterStorageManager)
|
|
1577
1242
|
throw new Error('No storage manager initialized');
|
|
1578
1243
|
if (!this.matterbridgeContext)
|
|
@@ -1611,16 +1276,13 @@ export class Matterbridge extends EventEmitter {
|
|
|
1611
1276
|
clearInterval(this.startMatterInterval);
|
|
1612
1277
|
this.startMatterInterval = undefined;
|
|
1613
1278
|
this.log.debug('Cleared startMatterInterval interval for Matterbridge');
|
|
1614
|
-
|
|
1615
|
-
this.startServerNode(this.serverNode); // We don't await this, because the server node is started in the background
|
|
1616
|
-
// Start the Matter server node of single devices in mode 'server'
|
|
1279
|
+
this.startServerNode(this.serverNode);
|
|
1617
1280
|
for (const device of this.devices.array()) {
|
|
1618
1281
|
if (device.mode === 'server' && device.serverNode) {
|
|
1619
1282
|
this.log.debug(`Starting server node for device ${dev}${device.deviceName}${db} in server mode...`);
|
|
1620
|
-
this.startServerNode(device.serverNode);
|
|
1283
|
+
this.startServerNode(device.serverNode);
|
|
1621
1284
|
}
|
|
1622
1285
|
}
|
|
1623
|
-
// Configure the plugins
|
|
1624
1286
|
this.configureTimeout = setTimeout(async () => {
|
|
1625
1287
|
for (const plugin of this.plugins.array()) {
|
|
1626
1288
|
if (!plugin.enabled || !plugin.loaded || !plugin.started || plugin.error)
|
|
@@ -1638,25 +1300,16 @@ export class Matterbridge extends EventEmitter {
|
|
|
1638
1300
|
}
|
|
1639
1301
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
1640
1302
|
}, 30 * 1000).unref();
|
|
1641
|
-
// Setting reachability to true
|
|
1642
1303
|
this.reachabilityTimeout = setTimeout(() => {
|
|
1643
1304
|
this.log.info(`Setting reachability to true for ${plg}Matterbridge${db}`);
|
|
1644
1305
|
if (this.aggregatorNode)
|
|
1645
1306
|
this.setAggregatorReachability(this.aggregatorNode, true);
|
|
1646
1307
|
this.frontend.wssSendRefreshRequired('reachability');
|
|
1647
1308
|
}, 60 * 1000).unref();
|
|
1648
|
-
// Logger.get('LogServerNode').info(this.serverNode);
|
|
1649
1309
|
this.emit('bridge_started');
|
|
1650
1310
|
this.log.notice('Matterbridge bridge started successfully');
|
|
1651
1311
|
}, this.startMatterIntervalMs);
|
|
1652
1312
|
}
|
|
1653
|
-
/**
|
|
1654
|
-
* Starts the Matterbridge in childbridge mode.
|
|
1655
|
-
*
|
|
1656
|
-
* @param {number} [delay] - The delay before starting the childbridge. Default is 1000 milliseconds.
|
|
1657
|
-
*
|
|
1658
|
-
* @returns {Promise<void>} A promise that resolves when the Matterbridge is started.
|
|
1659
|
-
*/
|
|
1660
1313
|
async startChildbridge(delay = 1000) {
|
|
1661
1314
|
if (!this.matterStorageManager)
|
|
1662
1315
|
throw new Error('No storage manager initialized');
|
|
@@ -1694,9 +1347,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
1694
1347
|
clearInterval(this.startMatterInterval);
|
|
1695
1348
|
this.startMatterInterval = undefined;
|
|
1696
1349
|
if (delay > 0)
|
|
1697
|
-
await wait(delay);
|
|
1350
|
+
await wait(delay);
|
|
1698
1351
|
this.log.debug('Cleared startMatterInterval interval in childbridge mode');
|
|
1699
|
-
// Configure the plugins
|
|
1700
1352
|
this.configureTimeout = setTimeout(async () => {
|
|
1701
1353
|
for (const plugin of this.plugins.array()) {
|
|
1702
1354
|
if (!plugin.enabled || !plugin.loaded || !plugin.started || plugin.error)
|
|
@@ -1733,9 +1385,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
1733
1385
|
this.log.error(`Node storage context not found for plugin ${plg}${plugin.name}${er}`);
|
|
1734
1386
|
continue;
|
|
1735
1387
|
}
|
|
1736
|
-
|
|
1737
|
-
this.startServerNode(plugin.serverNode); // We don't await this, because the server node is started in the background
|
|
1738
|
-
// Setting reachability to true
|
|
1388
|
+
this.startServerNode(plugin.serverNode);
|
|
1739
1389
|
plugin.reachabilityTimeout = setTimeout(() => {
|
|
1740
1390
|
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}`);
|
|
1741
1391
|
if (plugin.type === 'DynamicPlatform' && plugin.aggregatorNode)
|
|
@@ -1743,241 +1393,19 @@ export class Matterbridge extends EventEmitter {
|
|
|
1743
1393
|
this.frontend.wssSendRefreshRequired('reachability');
|
|
1744
1394
|
}, 60 * 1000).unref();
|
|
1745
1395
|
}
|
|
1746
|
-
// Start the Matter server node of single devices in mode 'server'
|
|
1747
1396
|
for (const device of this.devices.array()) {
|
|
1748
1397
|
if (device.mode === 'server' && device.serverNode) {
|
|
1749
1398
|
this.log.debug(`Starting server node for device ${dev}${device.deviceName}${db} in server mode...`);
|
|
1750
|
-
this.startServerNode(device.serverNode);
|
|
1399
|
+
this.startServerNode(device.serverNode);
|
|
1751
1400
|
}
|
|
1752
1401
|
}
|
|
1753
|
-
// Logger.get('LogServerNode').info(this.serverNode);
|
|
1754
1402
|
this.emit('childbridge_started');
|
|
1755
1403
|
this.log.notice('Matterbridge childbridge started successfully');
|
|
1756
1404
|
}, this.startMatterIntervalMs);
|
|
1757
1405
|
}
|
|
1758
|
-
/**
|
|
1759
|
-
* Starts the Matterbridge controller.
|
|
1760
|
-
*
|
|
1761
|
-
* @private
|
|
1762
|
-
* @returns {Promise<void>} A promise that resolves when the Matterbridge is started.
|
|
1763
|
-
*/
|
|
1764
1406
|
async startController() {
|
|
1765
|
-
/*
|
|
1766
|
-
if (!this.matterStorageManager) {
|
|
1767
|
-
this.log.error('No storage manager initialized');
|
|
1768
|
-
await this.cleanup('No storage manager initialized');
|
|
1769
|
-
return;
|
|
1770
|
-
}
|
|
1771
|
-
this.log.info('Creating context: mattercontrollerContext');
|
|
1772
|
-
this.controllerContext = this.matterStorageManager.createContext('mattercontrollerContext');
|
|
1773
|
-
if (!this.controllerContext) {
|
|
1774
|
-
this.log.error('No storage context mattercontrollerContext initialized');
|
|
1775
|
-
await this.cleanup('No storage context mattercontrollerContext initialized');
|
|
1776
|
-
return;
|
|
1777
|
-
}
|
|
1778
|
-
|
|
1779
|
-
this.log.debug('Starting matterbridge in mode', this.bridgeMode);
|
|
1780
|
-
this.matterServer = await this.createMatterServer(this.storageManager);
|
|
1781
|
-
this.log.info('Creating matter commissioning controller');
|
|
1782
|
-
this.commissioningController = new CommissioningController({
|
|
1783
|
-
autoConnect: false,
|
|
1784
|
-
});
|
|
1785
|
-
this.log.info('Adding matter commissioning controller to matter server');
|
|
1786
|
-
await this.matterServer.addCommissioningController(this.commissioningController);
|
|
1787
|
-
|
|
1788
|
-
this.log.info('Starting matter server');
|
|
1789
|
-
await this.matterServer.start();
|
|
1790
|
-
this.log.info('Matter server started');
|
|
1791
|
-
const commissioningOptions: ControllerCommissioningFlowOptions = {
|
|
1792
|
-
regulatoryLocation: GeneralCommissioning.RegulatoryLocationType.IndoorOutdoor,
|
|
1793
|
-
regulatoryCountryCode: 'XX',
|
|
1794
|
-
};
|
|
1795
|
-
const commissioningController = new CommissioningController({
|
|
1796
|
-
environment: {
|
|
1797
|
-
environment,
|
|
1798
|
-
id: uniqueId,
|
|
1799
|
-
},
|
|
1800
|
-
autoConnect: false, // Do not auto connect to the commissioned nodes
|
|
1801
|
-
adminFabricLabel,
|
|
1802
|
-
});
|
|
1803
|
-
|
|
1804
|
-
if (hasParameter('pairingcode')) {
|
|
1805
|
-
this.log.info('Pairing device with pairingcode:', getParameter('pairingcode'));
|
|
1806
|
-
const pairingCode = getParameter('pairingcode');
|
|
1807
|
-
const ip = this.controllerContext.has('ip') ? this.controllerContext.get<string>('ip') : undefined;
|
|
1808
|
-
const port = this.controllerContext.has('port') ? this.controllerContext.get<number>('port') : undefined;
|
|
1809
|
-
|
|
1810
|
-
let longDiscriminator, setupPin, shortDiscriminator;
|
|
1811
|
-
if (pairingCode !== undefined) {
|
|
1812
|
-
const pairingCodeCodec = ManualPairingCodeCodec.decode(pairingCode);
|
|
1813
|
-
shortDiscriminator = pairingCodeCodec.shortDiscriminator;
|
|
1814
|
-
longDiscriminator = undefined;
|
|
1815
|
-
setupPin = pairingCodeCodec.passcode;
|
|
1816
|
-
this.log.info(`Data extracted from pairing code: ${Logger.toJSON(pairingCodeCodec)}`);
|
|
1817
|
-
} else {
|
|
1818
|
-
longDiscriminator = await this.controllerContext.get('longDiscriminator', 3840);
|
|
1819
|
-
if (longDiscriminator > 4095) throw new Error('Discriminator value must be less than 4096');
|
|
1820
|
-
setupPin = this.controllerContext.get('pin', 20202021);
|
|
1821
|
-
}
|
|
1822
|
-
if ((shortDiscriminator === undefined && longDiscriminator === undefined) || setupPin === undefined) {
|
|
1823
|
-
throw new Error('Please specify the longDiscriminator of the device to commission with -longDiscriminator or provide a valid passcode with -passcode');
|
|
1824
|
-
}
|
|
1825
|
-
|
|
1826
|
-
const options = {
|
|
1827
|
-
commissioning: commissioningOptions,
|
|
1828
|
-
discovery: {
|
|
1829
|
-
knownAddress: ip !== undefined && port !== undefined ? { ip, port, type: 'udp' } : undefined,
|
|
1830
|
-
identifierData: longDiscriminator !== undefined ? { longDiscriminator } : shortDiscriminator !== undefined ? { shortDiscriminator } : {},
|
|
1831
|
-
},
|
|
1832
|
-
passcode: setupPin,
|
|
1833
|
-
} as NodeCommissioningOptions;
|
|
1834
|
-
this.log.info('Commissioning with options:', options);
|
|
1835
|
-
const nodeId = await this.commissioningController.commissionNode(options);
|
|
1836
|
-
this.log.info(`Commissioning successfully done with nodeId: ${nodeId}`);
|
|
1837
|
-
this.log.info('ActiveSessionInformation:', this.commissioningController.getActiveSessionInformation());
|
|
1838
|
-
} // (hasParameter('pairingcode'))
|
|
1839
|
-
|
|
1840
|
-
if (hasParameter('unpairall')) {
|
|
1841
|
-
this.log.info('***Commissioning controller unpairing all nodes...');
|
|
1842
|
-
const nodeIds = this.commissioningController.getCommissionedNodes();
|
|
1843
|
-
for (const nodeId of nodeIds) {
|
|
1844
|
-
this.log.info('***Commissioning controller unpairing node:', nodeId);
|
|
1845
|
-
await this.commissioningController.removeNode(nodeId);
|
|
1846
|
-
}
|
|
1847
|
-
return;
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1850
|
-
if (hasParameter('discover')) {
|
|
1851
|
-
// const discover = await this.commissioningController.discoverCommissionableDevices({ productId: 0x8000, deviceType: 0xfff1 });
|
|
1852
|
-
// console.log(discover);
|
|
1853
|
-
}
|
|
1854
|
-
|
|
1855
|
-
if (!this.commissioningController.isCommissioned()) {
|
|
1856
|
-
this.log.info('***Commissioning controller is not commissioned: use matterbridge -controller -pairingcode [pairingcode] to commission a device');
|
|
1857
|
-
return;
|
|
1858
|
-
}
|
|
1859
|
-
|
|
1860
|
-
const nodeIds = this.commissioningController.getCommissionedNodes();
|
|
1861
|
-
this.log.info(`***Commissioning controller is commissioned ${this.commissioningController.isCommissioned()} and has ${nodeIds.length} nodes commisioned: `);
|
|
1862
|
-
for (const nodeId of nodeIds) {
|
|
1863
|
-
this.log.info(`***Connecting to commissioned node: ${nodeId}`);
|
|
1864
|
-
|
|
1865
|
-
const node = await this.commissioningController.connectNode(nodeId, {
|
|
1866
|
-
autoSubscribe: false,
|
|
1867
|
-
attributeChangedCallback: (peerNodeId, { path: { nodeId, clusterId, endpointId, attributeName }, value }) =>
|
|
1868
|
-
this.log.info(`***Commissioning controller attributeChangedCallback ${peerNodeId}: attribute ${nodeId}/${endpointId}/${clusterId}/${attributeName} changed to ${Logger.toJSON(value)}`),
|
|
1869
|
-
eventTriggeredCallback: (peerNodeId, { path: { nodeId, clusterId, endpointId, eventName }, events }) =>
|
|
1870
|
-
this.log.info(`***Commissioning controller eventTriggeredCallback ${peerNodeId}: Event ${nodeId}/${endpointId}/${clusterId}/${eventName} triggered with ${Logger.toJSON(events)}`),
|
|
1871
|
-
stateInformationCallback: (peerNodeId, info) => {
|
|
1872
|
-
switch (info) {
|
|
1873
|
-
case NodeStateInformation.Connected:
|
|
1874
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} connected`);
|
|
1875
|
-
break;
|
|
1876
|
-
case NodeStateInformation.Disconnected:
|
|
1877
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} disconnected`);
|
|
1878
|
-
break;
|
|
1879
|
-
case NodeStateInformation.Reconnecting:
|
|
1880
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} reconnecting`);
|
|
1881
|
-
break;
|
|
1882
|
-
case NodeStateInformation.WaitingForDeviceDiscovery:
|
|
1883
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} waiting for device discovery`);
|
|
1884
|
-
break;
|
|
1885
|
-
case NodeStateInformation.StructureChanged:
|
|
1886
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} structure changed`);
|
|
1887
|
-
break;
|
|
1888
|
-
case NodeStateInformation.Decommissioned:
|
|
1889
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} decommissioned`);
|
|
1890
|
-
break;
|
|
1891
|
-
default:
|
|
1892
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} NodeStateInformation.${info}`);
|
|
1893
|
-
break;
|
|
1894
|
-
}
|
|
1895
|
-
},
|
|
1896
|
-
});
|
|
1897
|
-
|
|
1898
|
-
node.logStructure();
|
|
1899
|
-
|
|
1900
|
-
// Get the interaction client
|
|
1901
|
-
this.log.info('Getting the interaction client');
|
|
1902
|
-
const interactionClient = await node.getInteractionClient();
|
|
1903
|
-
let cluster;
|
|
1904
|
-
let attributes;
|
|
1905
|
-
|
|
1906
|
-
// Log BasicInformationCluster
|
|
1907
|
-
cluster = BasicInformationCluster;
|
|
1908
|
-
attributes = await interactionClient.getMultipleAttributes({
|
|
1909
|
-
attributes: [{ clusterId: cluster.id }],
|
|
1910
|
-
});
|
|
1911
|
-
if (attributes.length > 0) this.log.info(`Cluster: ${idn}${cluster.name}${rs}${nf} attributes:`);
|
|
1912
|
-
attributes.forEach((attribute) => {
|
|
1913
|
-
this.log.info(
|
|
1914
|
-
`- 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}`,
|
|
1915
|
-
);
|
|
1916
|
-
});
|
|
1917
|
-
|
|
1918
|
-
// Log PowerSourceCluster
|
|
1919
|
-
cluster = PowerSourceCluster;
|
|
1920
|
-
attributes = await interactionClient.getMultipleAttributes({
|
|
1921
|
-
attributes: [{ clusterId: cluster.id }],
|
|
1922
|
-
});
|
|
1923
|
-
if (attributes.length > 0) this.log.info(`Cluster: ${idn}${cluster.name}${rs}${nf} attributes:`);
|
|
1924
|
-
attributes.forEach((attribute) => {
|
|
1925
|
-
this.log.info(
|
|
1926
|
-
`- 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}`,
|
|
1927
|
-
);
|
|
1928
|
-
});
|
|
1929
|
-
|
|
1930
|
-
// Log ThreadNetworkDiagnostics
|
|
1931
|
-
cluster = ThreadNetworkDiagnosticsCluster;
|
|
1932
|
-
attributes = await interactionClient.getMultipleAttributes({
|
|
1933
|
-
attributes: [{ clusterId: cluster.id }],
|
|
1934
|
-
});
|
|
1935
|
-
if (attributes.length > 0) this.log.info(`Cluster: ${idn}${cluster.name}${rs}${nf} attributes:`);
|
|
1936
|
-
attributes.forEach((attribute) => {
|
|
1937
|
-
this.log.info(
|
|
1938
|
-
`- 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}`,
|
|
1939
|
-
);
|
|
1940
|
-
});
|
|
1941
|
-
|
|
1942
|
-
// Log SwitchCluster
|
|
1943
|
-
cluster = SwitchCluster;
|
|
1944
|
-
attributes = await interactionClient.getMultipleAttributes({
|
|
1945
|
-
attributes: [{ clusterId: cluster.id }],
|
|
1946
|
-
});
|
|
1947
|
-
if (attributes.length > 0) this.log.info(`Cluster: ${idn}${cluster.name}${rs}${nf} attributes:`);
|
|
1948
|
-
attributes.forEach((attribute) => {
|
|
1949
|
-
this.log.info(
|
|
1950
|
-
`- 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}`,
|
|
1951
|
-
);
|
|
1952
|
-
});
|
|
1953
|
-
|
|
1954
|
-
this.log.info('Subscribing to all attributes and events');
|
|
1955
|
-
await node.subscribeAllAttributesAndEvents({
|
|
1956
|
-
ignoreInitialTriggers: false,
|
|
1957
|
-
attributeChangedCallback: ({ path: { nodeId, clusterId, endpointId, attributeName }, version, value }) =>
|
|
1958
|
-
this.log.info(
|
|
1959
|
-
`***${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}`,
|
|
1960
|
-
),
|
|
1961
|
-
eventTriggeredCallback: ({ path: { nodeId, clusterId, endpointId, eventName }, events }) => {
|
|
1962
|
-
this.log.info(
|
|
1963
|
-
`***${db}Commissioning controller eventTriggeredCallback: event ${BLUE}${nodeId}${db}/${or}${endpointId}${db}/${hk}${getClusterNameById(clusterId)}${db}/${zb}${eventName}${db} triggered with ${debugStringify(events ?? { none: true })}`,
|
|
1964
|
-
);
|
|
1965
|
-
},
|
|
1966
|
-
});
|
|
1967
|
-
this.log.info('Subscribed to all attributes and events');
|
|
1968
|
-
}
|
|
1969
|
-
*/
|
|
1970
1407
|
}
|
|
1971
|
-
/** */
|
|
1972
|
-
/** Matter.js methods */
|
|
1973
|
-
/** */
|
|
1974
|
-
/**
|
|
1975
|
-
* Starts the matter storage with name Matterbridge, create the matterbridge context and performs a backup.
|
|
1976
|
-
*
|
|
1977
|
-
* @returns {Promise<void>} - A promise that resolves when the storage is started.
|
|
1978
|
-
*/
|
|
1979
1408
|
async startMatterStorage() {
|
|
1980
|
-
// Setup Matter storage
|
|
1981
1409
|
this.log.info(`Starting matter node storage...`);
|
|
1982
1410
|
this.matterStorageService = this.environment.get(StorageService);
|
|
1983
1411
|
this.log.info(`Matter node storage service created: ${this.matterStorageService.location}`);
|
|
@@ -1986,17 +1414,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
1986
1414
|
this.matterbridgeContext = await this.createServerNodeContext('Matterbridge', 'Matterbridge', this.aggregatorDeviceType, this.aggregatorVendorId, this.aggregatorVendorName, this.aggregatorProductId, this.aggregatorProductName, this.aggregatorSerialNumber, this.aggregatorUniqueId);
|
|
1987
1415
|
this.matterbridgeInformation.matterbridgeSerialNumber = await this.matterbridgeContext.get('serialNumber', '');
|
|
1988
1416
|
this.log.info('Matter node storage started');
|
|
1989
|
-
// Backup matter storage since it is created/opened correctly
|
|
1990
1417
|
await this.backupMatterStorage(path.join(this.matterbridgeDirectory, this.matterStorageName), path.join(this.matterbridgeDirectory, this.matterStorageName + '.backup'));
|
|
1991
1418
|
}
|
|
1992
|
-
/**
|
|
1993
|
-
* Makes a backup copy of the specified matter storage directory.
|
|
1994
|
-
*
|
|
1995
|
-
* @param {string} storageName - The name of the storage directory to be backed up.
|
|
1996
|
-
* @param {string} backupName - The name of the backup directory to be created.
|
|
1997
|
-
* @private
|
|
1998
|
-
* @returns {Promise<void>} A promise that resolves when the has been done.
|
|
1999
|
-
*/
|
|
2000
1419
|
async backupMatterStorage(storageName, backupName) {
|
|
2001
1420
|
this.log.info('Creating matter node storage backup...');
|
|
2002
1421
|
try {
|
|
@@ -2007,11 +1426,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2007
1426
|
this.log.error(`Error creating matter node storage backup from ${storageName} to ${backupName}:`, error);
|
|
2008
1427
|
}
|
|
2009
1428
|
}
|
|
2010
|
-
/**
|
|
2011
|
-
* Stops the matter storage.
|
|
2012
|
-
*
|
|
2013
|
-
* @returns {Promise<void>} A promise that resolves when the storage is stopped.
|
|
2014
|
-
*/
|
|
2015
1429
|
async stopMatterStorage() {
|
|
2016
1430
|
this.log.info('Closing matter node storage...');
|
|
2017
1431
|
await this.matterStorageManager?.close();
|
|
@@ -2020,20 +1434,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2020
1434
|
this.matterbridgeContext = undefined;
|
|
2021
1435
|
this.log.info('Matter node storage closed');
|
|
2022
1436
|
}
|
|
2023
|
-
/**
|
|
2024
|
-
* Creates a server node storage context.
|
|
2025
|
-
*
|
|
2026
|
-
* @param {string} pluginName - The name of the plugin.
|
|
2027
|
-
* @param {string} deviceName - The name of the device.
|
|
2028
|
-
* @param {DeviceTypeId} deviceType - The device type of the device.
|
|
2029
|
-
* @param {number} vendorId - The vendor ID.
|
|
2030
|
-
* @param {string} vendorName - The vendor name.
|
|
2031
|
-
* @param {number} productId - The product ID.
|
|
2032
|
-
* @param {string} productName - The product name.
|
|
2033
|
-
* @param {string} [serialNumber] - The serial number of the device (optional).
|
|
2034
|
-
* @param {string} [uniqueId] - The unique ID of the device (optional).
|
|
2035
|
-
* @returns {Promise<StorageContext>} The storage context for the commissioning server.
|
|
2036
|
-
*/
|
|
2037
1437
|
async createServerNodeContext(pluginName, deviceName, deviceType, vendorId, vendorName, productId, productName, serialNumber, uniqueId) {
|
|
2038
1438
|
const { randomBytes } = await import('node:crypto');
|
|
2039
1439
|
if (!this.matterStorageService)
|
|
@@ -2067,15 +1467,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2067
1467
|
this.log.debug(`- hardwareVersion: ${await storageContext.get('hardwareVersion')} hardwareVersionString: ${await storageContext.get('hardwareVersionString')}`);
|
|
2068
1468
|
return storageContext;
|
|
2069
1469
|
}
|
|
2070
|
-
/**
|
|
2071
|
-
* Creates a server node.
|
|
2072
|
-
*
|
|
2073
|
-
* @param {StorageContext} storageContext - The storage context for the server node.
|
|
2074
|
-
* @param {number} [port] - The port number for the server node. Defaults to 5540.
|
|
2075
|
-
* @param {number} [passcode] - The passcode for the server node. Defaults to 20242025.
|
|
2076
|
-
* @param {number} [discriminator] - The discriminator for the server node. Defaults to 3850.
|
|
2077
|
-
* @returns {Promise<ServerNode<ServerNode.RootEndpoint>>} A promise that resolves to the created server node.
|
|
2078
|
-
*/
|
|
2079
1470
|
async createServerNode(storageContext, port = 5540, passcode = 20242025, discriminator = 3850) {
|
|
2080
1471
|
const storeId = await storageContext.get('storeId');
|
|
2081
1472
|
this.log.notice(`Creating server node for ${storeId} on port ${port} with passcode ${passcode} and discriminator ${discriminator}...`);
|
|
@@ -2085,37 +1476,24 @@ export class Matterbridge extends EventEmitter {
|
|
|
2085
1476
|
this.log.debug(`- uniqueId: ${await storageContext.get('uniqueId')}`);
|
|
2086
1477
|
this.log.debug(`- softwareVersion: ${await storageContext.get('softwareVersion')} softwareVersionString: ${await storageContext.get('softwareVersionString')}`);
|
|
2087
1478
|
this.log.debug(`- hardwareVersion: ${await storageContext.get('hardwareVersion')} hardwareVersionString: ${await storageContext.get('hardwareVersionString')}`);
|
|
2088
|
-
/**
|
|
2089
|
-
* Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration
|
|
2090
|
-
*/
|
|
2091
1479
|
const serverNode = await ServerNode.create({
|
|
2092
|
-
// Required: Give the Node a unique ID which is used to store the state of this node
|
|
2093
1480
|
id: storeId,
|
|
2094
|
-
// Provide Network relevant configuration like the port
|
|
2095
|
-
// Optional when operating only one device on a host, Default port is 5540
|
|
2096
1481
|
network: {
|
|
2097
1482
|
listeningAddressIpv4: this.ipv4address,
|
|
2098
1483
|
listeningAddressIpv6: this.ipv6address,
|
|
2099
1484
|
port,
|
|
2100
1485
|
},
|
|
2101
|
-
// Provide the certificate for the device
|
|
2102
1486
|
operationalCredentials: {
|
|
2103
1487
|
certification: this.certification,
|
|
2104
1488
|
},
|
|
2105
|
-
// Provide Commissioning relevant settings
|
|
2106
|
-
// Optional for development/testing purposes
|
|
2107
1489
|
commissioning: {
|
|
2108
1490
|
passcode,
|
|
2109
1491
|
discriminator,
|
|
2110
1492
|
},
|
|
2111
|
-
// Provide Node announcement settings
|
|
2112
|
-
// Optional: If Ommitted some development defaults are used
|
|
2113
1493
|
productDescription: {
|
|
2114
1494
|
name: await storageContext.get('deviceName'),
|
|
2115
1495
|
deviceType: DeviceTypeId(await storageContext.get('deviceType')),
|
|
2116
1496
|
},
|
|
2117
|
-
// Provide defaults for the BasicInformation cluster on the Root endpoint
|
|
2118
|
-
// Optional: If Omitted some development defaults are used
|
|
2119
1497
|
basicInformation: {
|
|
2120
1498
|
vendorId: VendorId(await storageContext.get('vendorId')),
|
|
2121
1499
|
vendorName: await storageContext.get('vendorName'),
|
|
@@ -2132,20 +1510,14 @@ export class Matterbridge extends EventEmitter {
|
|
|
2132
1510
|
reachable: true,
|
|
2133
1511
|
},
|
|
2134
1512
|
});
|
|
2135
|
-
/**
|
|
2136
|
-
* This event is triggered when the device is initially commissioned successfully.
|
|
2137
|
-
* This means: It is added to the first fabric.
|
|
2138
|
-
*/
|
|
2139
1513
|
serverNode.lifecycle.commissioned.on(() => {
|
|
2140
1514
|
this.log.notice(`Server node for ${storeId} was initially commissioned successfully!`);
|
|
2141
1515
|
clearTimeout(this.endAdvertiseTimeout);
|
|
2142
1516
|
});
|
|
2143
|
-
/** This event is triggered when all fabrics are removed from the device, usually it also does a factory reset then. */
|
|
2144
1517
|
serverNode.lifecycle.decommissioned.on(() => {
|
|
2145
1518
|
this.log.notice(`Server node for ${storeId} was fully decommissioned successfully!`);
|
|
2146
1519
|
clearTimeout(this.endAdvertiseTimeout);
|
|
2147
1520
|
});
|
|
2148
|
-
/** This event is triggered when the device went online. This means that it is discoverable in the network. */
|
|
2149
1521
|
serverNode.lifecycle.online.on(async () => {
|
|
2150
1522
|
this.log.notice(`Server node for ${storeId} is online`);
|
|
2151
1523
|
if (!serverNode.lifecycle.isCommissioned) {
|
|
@@ -2153,11 +1525,9 @@ export class Matterbridge extends EventEmitter {
|
|
|
2153
1525
|
const { qrPairingCode, manualPairingCode } = serverNode.state.commissioning.pairingCodes;
|
|
2154
1526
|
this.log.notice(`QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`);
|
|
2155
1527
|
this.log.notice(`Manual pairing code: ${manualPairingCode}`);
|
|
2156
|
-
// Set a timeout to show that advertising stops after 15 minutes if not commissioned
|
|
2157
1528
|
this.startEndAdvertiseTimer(serverNode);
|
|
2158
1529
|
}
|
|
2159
1530
|
else {
|
|
2160
|
-
// istanbul ignore next
|
|
2161
1531
|
this.log.notice(`Server node for ${storeId} is already commissioned. Waiting for controllers to connect ...`);
|
|
2162
1532
|
}
|
|
2163
1533
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
@@ -2165,19 +1535,14 @@ export class Matterbridge extends EventEmitter {
|
|
|
2165
1535
|
this.frontend.wssSendSnackbarMessage(`${storeId} is online`, 5, 'success');
|
|
2166
1536
|
this.emit('online', storeId);
|
|
2167
1537
|
});
|
|
2168
|
-
/** This event is triggered when the device went offline. it is not longer discoverable or connectable in the network. */
|
|
2169
1538
|
serverNode.lifecycle.offline.on(() => {
|
|
2170
1539
|
this.log.notice(`Server node for ${storeId} is offline`);
|
|
2171
|
-
this.matterbridgeInformation.matterbridgeEndAdvertise = true;
|
|
1540
|
+
this.matterbridgeInformation.matterbridgeEndAdvertise = true;
|
|
2172
1541
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
2173
1542
|
this.frontend.wssSendRefreshRequired('settings');
|
|
2174
1543
|
this.frontend.wssSendSnackbarMessage(`${storeId} is offline`, 5, 'warning');
|
|
2175
1544
|
this.emit('offline', storeId);
|
|
2176
1545
|
});
|
|
2177
|
-
/**
|
|
2178
|
-
* This event is triggered when a fabric is added, removed or updated on the device. Use this if more granular
|
|
2179
|
-
* information is needed.
|
|
2180
|
-
*/
|
|
2181
1546
|
serverNode.events.commissioning.fabricsChanged.on((fabricIndex, fabricAction) => {
|
|
2182
1547
|
let action = '';
|
|
2183
1548
|
switch (fabricAction) {
|
|
@@ -2194,22 +1559,14 @@ export class Matterbridge extends EventEmitter {
|
|
|
2194
1559
|
this.log.notice(`Commissioned fabric index ${fabricIndex} ${action} on server node for ${storeId}: ${debugStringify(serverNode.state.commissioning.fabrics[fabricIndex])}`);
|
|
2195
1560
|
this.frontend.wssSendRefreshRequired('fabrics');
|
|
2196
1561
|
});
|
|
2197
|
-
/**
|
|
2198
|
-
* This event is triggered when an operative new session was opened by a Controller.
|
|
2199
|
-
* It is not triggered for the initial commissioning process, just afterwards for real connections.
|
|
2200
|
-
*/
|
|
2201
1562
|
serverNode.events.sessions.opened.on((session) => {
|
|
2202
1563
|
this.log.notice(`Session opened on server node for ${storeId}: ${debugStringify(session)}`);
|
|
2203
1564
|
this.frontend.wssSendRefreshRequired('sessions');
|
|
2204
1565
|
});
|
|
2205
|
-
/**
|
|
2206
|
-
* This event is triggered when an operative session is closed by a Controller or because the Device goes offline.
|
|
2207
|
-
*/
|
|
2208
1566
|
serverNode.events.sessions.closed.on((session) => {
|
|
2209
1567
|
this.log.notice(`Session closed on server node for ${storeId}: ${debugStringify(session)}`);
|
|
2210
1568
|
this.frontend.wssSendRefreshRequired('sessions');
|
|
2211
1569
|
});
|
|
2212
|
-
/** This event is triggered when a subscription gets added or removed on an operative session. */
|
|
2213
1570
|
serverNode.events.sessions.subscriptionsChanged.on((session) => {
|
|
2214
1571
|
this.log.notice(`Session subscriptions changed on server node for ${storeId}: ${debugStringify(session)}`);
|
|
2215
1572
|
this.frontend.wssSendRefreshRequired('sessions');
|
|
@@ -2217,11 +1574,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2217
1574
|
this.log.info(`Created server node for ${storeId}`);
|
|
2218
1575
|
return serverNode;
|
|
2219
1576
|
}
|
|
2220
|
-
/**
|
|
2221
|
-
* Starts the 15 minutes timer to advice that advertising for the specified server node is ended.
|
|
2222
|
-
*
|
|
2223
|
-
* @param {ServerNode} [matterServerNode] - The server node to start.
|
|
2224
|
-
*/
|
|
2225
1577
|
startEndAdvertiseTimer(matterServerNode) {
|
|
2226
1578
|
if (this.endAdvertiseTimeout) {
|
|
2227
1579
|
this.log.debug(`Clear ${matterServerNode.id} server node end advertise timer`);
|
|
@@ -2240,25 +1592,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
2240
1592
|
this.log.notice(`Advertising stopped. Restart to commission again.`);
|
|
2241
1593
|
}, 15 * 60 * 1000).unref();
|
|
2242
1594
|
}
|
|
2243
|
-
/**
|
|
2244
|
-
* Starts the specified server node.
|
|
2245
|
-
*
|
|
2246
|
-
* @param {ServerNode} [matterServerNode] - The server node to start.
|
|
2247
|
-
* @returns {Promise<void>} A promise that resolves when the server node has started.
|
|
2248
|
-
*/
|
|
2249
1595
|
async startServerNode(matterServerNode) {
|
|
2250
1596
|
if (!matterServerNode)
|
|
2251
1597
|
return;
|
|
2252
1598
|
this.log.notice(`Starting ${matterServerNode.id} server node`);
|
|
2253
1599
|
await matterServerNode.start();
|
|
2254
1600
|
}
|
|
2255
|
-
/**
|
|
2256
|
-
* Stops the specified server node.
|
|
2257
|
-
*
|
|
2258
|
-
* @param {ServerNode} matterServerNode - The server node to stop.
|
|
2259
|
-
* @param {number} [timeout] - The timeout in milliseconds for stopping the server node. Defaults to 30 seconds.
|
|
2260
|
-
* @returns {Promise<void>} A promise that resolves when the server node has stopped.
|
|
2261
|
-
*/
|
|
2262
1601
|
async stopServerNode(matterServerNode, timeout = 30000) {
|
|
2263
1602
|
if (!matterServerNode)
|
|
2264
1603
|
return;
|
|
@@ -2271,12 +1610,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2271
1610
|
this.log.error(`Failed to close ${matterServerNode.id} server node: ${error instanceof Error ? error.message : error}`);
|
|
2272
1611
|
}
|
|
2273
1612
|
}
|
|
2274
|
-
/**
|
|
2275
|
-
* Advertises the specified server node.
|
|
2276
|
-
*
|
|
2277
|
-
* @param {ServerNode} [matterServerNode] - The server node to advertise.
|
|
2278
|
-
* @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.
|
|
2279
|
-
*/
|
|
2280
1613
|
async advertiseServerNode(matterServerNode) {
|
|
2281
1614
|
if (matterServerNode) {
|
|
2282
1615
|
await matterServerNode.env.get(DeviceCommissioner)?.allowBasicCommissioning();
|
|
@@ -2285,39 +1618,19 @@ export class Matterbridge extends EventEmitter {
|
|
|
2285
1618
|
return { qrPairingCode, manualPairingCode };
|
|
2286
1619
|
}
|
|
2287
1620
|
}
|
|
2288
|
-
/**
|
|
2289
|
-
* Stop advertise the specified server node.
|
|
2290
|
-
*
|
|
2291
|
-
* @param {ServerNode} [matterServerNode] - The server node to advertise.
|
|
2292
|
-
* @returns {Promise<void>} A promise that resolves when the server node has stopped advertising.
|
|
2293
|
-
*/
|
|
2294
1621
|
async stopAdvertiseServerNode(matterServerNode) {
|
|
2295
1622
|
if (matterServerNode && matterServerNode.lifecycle.isOnline) {
|
|
2296
1623
|
await matterServerNode.env.get(DeviceCommissioner)?.endCommissioning();
|
|
2297
1624
|
this.log.notice(`Stopped advertising for ${matterServerNode.id}`);
|
|
2298
1625
|
}
|
|
2299
1626
|
}
|
|
2300
|
-
/**
|
|
2301
|
-
* Creates an aggregator node with the specified storage context.
|
|
2302
|
-
*
|
|
2303
|
-
* @param {StorageContext} storageContext - The storage context for the aggregator node.
|
|
2304
|
-
* @returns {Promise<Endpoint<AggregatorEndpoint>>} A promise that resolves to the created aggregator node.
|
|
2305
|
-
*/
|
|
2306
1627
|
async createAggregatorNode(storageContext) {
|
|
2307
1628
|
this.log.notice(`Creating ${await storageContext.get('storeId')} aggregator...`);
|
|
2308
1629
|
const aggregatorNode = new Endpoint(AggregatorEndpoint, { id: `${await storageContext.get('storeId')}` });
|
|
2309
1630
|
this.log.info(`Created ${await storageContext.get('storeId')} aggregator`);
|
|
2310
1631
|
return aggregatorNode;
|
|
2311
1632
|
}
|
|
2312
|
-
/**
|
|
2313
|
-
* Adds a MatterbridgeEndpoint to the specified plugin.
|
|
2314
|
-
*
|
|
2315
|
-
* @param {string} pluginName - The name of the plugin.
|
|
2316
|
-
* @param {MatterbridgeEndpoint} device - The device to add as a bridged endpoint.
|
|
2317
|
-
* @returns {Promise<void>} A promise that resolves when the bridged endpoint has been added.
|
|
2318
|
-
*/
|
|
2319
1633
|
async addBridgedEndpoint(pluginName, device) {
|
|
2320
|
-
// Check if the plugin is registered
|
|
2321
1634
|
const plugin = this.plugins.get(pluginName);
|
|
2322
1635
|
if (!plugin) {
|
|
2323
1636
|
this.log.error(`Error adding bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.id}${er}) plugin ${plg}${pluginName}${er} not found`);
|
|
@@ -2337,7 +1650,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2337
1650
|
}
|
|
2338
1651
|
else if (this.bridgeMode === 'bridge') {
|
|
2339
1652
|
if (device.mode === 'matter') {
|
|
2340
|
-
// Register and add the device to the matterbridge server node
|
|
2341
1653
|
this.log.debug(`Adding matter endpoint ${plg}${pluginName}${db}:${dev}${device.deviceName}${db} to Matterbridge server node...`);
|
|
2342
1654
|
if (!this.serverNode) {
|
|
2343
1655
|
this.log.error('Server node not found for Matterbridge');
|
|
@@ -2354,7 +1666,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2354
1666
|
}
|
|
2355
1667
|
}
|
|
2356
1668
|
else {
|
|
2357
|
-
// Register and add the device to the matterbridge aggregator node
|
|
2358
1669
|
this.log.debug(`Adding bridged endpoint ${plg}${pluginName}${db}:${dev}${device.deviceName}${db} to Matterbridge aggregator node`);
|
|
2359
1670
|
if (!this.aggregatorNode) {
|
|
2360
1671
|
this.log.error('Aggregator node not found for Matterbridge');
|
|
@@ -2372,7 +1683,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2372
1683
|
}
|
|
2373
1684
|
}
|
|
2374
1685
|
else if (this.bridgeMode === 'childbridge') {
|
|
2375
|
-
// Register and add the device to the plugin server node
|
|
2376
1686
|
if (plugin.type === 'AccessoryPlatform') {
|
|
2377
1687
|
try {
|
|
2378
1688
|
this.log.debug(`Creating endpoint ${dev}${device.deviceName}${db} for AccessoryPlatform plugin ${plg}${plugin.name}${db} server node`);
|
|
@@ -2396,12 +1706,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
2396
1706
|
return;
|
|
2397
1707
|
}
|
|
2398
1708
|
}
|
|
2399
|
-
// Register and add the device to the plugin aggregator node
|
|
2400
1709
|
if (plugin.type === 'DynamicPlatform') {
|
|
2401
1710
|
try {
|
|
2402
1711
|
this.log.debug(`Adding bridged endpoint ${dev}${device.deviceName}${db} for DynamicPlatform plugin ${plg}${plugin.name}${db} aggregator node`);
|
|
2403
1712
|
await this.createDynamicPlugin(plugin);
|
|
2404
|
-
// Fast plugins can add another device before the server node is ready, so we wait for the server node to be ready
|
|
2405
1713
|
await waiter(`createDynamicPlugin(${plugin.name})`, () => plugin.serverNode?.hasParts === true);
|
|
2406
1714
|
if (!plugin.aggregatorNode) {
|
|
2407
1715
|
this.log.error(`Aggregator node not found for plugin ${plg}${plugin.name}${er}`);
|
|
@@ -2424,28 +1732,17 @@ export class Matterbridge extends EventEmitter {
|
|
|
2424
1732
|
plugin.registeredDevices++;
|
|
2425
1733
|
if (plugin.addedDevices !== undefined)
|
|
2426
1734
|
plugin.addedDevices++;
|
|
2427
|
-
// Add the device to the DeviceManager
|
|
2428
1735
|
this.devices.set(device);
|
|
2429
|
-
// Subscribe to the reachable$Changed event
|
|
2430
1736
|
await this.subscribeAttributeChanged(plugin, device);
|
|
2431
1737
|
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}`);
|
|
2432
1738
|
}
|
|
2433
|
-
/**
|
|
2434
|
-
* Removes a MatterbridgeEndpoint from the specified plugin.
|
|
2435
|
-
*
|
|
2436
|
-
* @param {string} pluginName - The name of the plugin.
|
|
2437
|
-
* @param {MatterbridgeEndpoint} device - The device to remove as a bridged endpoint.
|
|
2438
|
-
* @returns {Promise<void>} A promise that resolves when the bridged endpoint has been removed.
|
|
2439
|
-
*/
|
|
2440
1739
|
async removeBridgedEndpoint(pluginName, device) {
|
|
2441
1740
|
this.log.debug(`Removing bridged endpoint ${plg}${pluginName}${db}:${dev}${device.deviceName}${db} (${zb}${device.name}${db}) for plugin ${plg}${pluginName}${db}`);
|
|
2442
|
-
// Check if the plugin is registered
|
|
2443
1741
|
const plugin = this.plugins.get(pluginName);
|
|
2444
1742
|
if (!plugin) {
|
|
2445
1743
|
this.log.error(`Error removing bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.name}${er}) for plugin ${plg}${pluginName}${er}: plugin not found`);
|
|
2446
1744
|
return;
|
|
2447
1745
|
}
|
|
2448
|
-
// Register and add the device to the matterbridge aggregator node
|
|
2449
1746
|
if (this.bridgeMode === 'bridge') {
|
|
2450
1747
|
if (!this.aggregatorNode) {
|
|
2451
1748
|
this.log.error(`Error removing bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.name}${er}) for plugin ${plg}${pluginName}${er}: aggregator node not found`);
|
|
@@ -2460,7 +1757,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2460
1757
|
}
|
|
2461
1758
|
else if (this.bridgeMode === 'childbridge') {
|
|
2462
1759
|
if (plugin.type === 'AccessoryPlatform') {
|
|
2463
|
-
// Nothing to do here since the server node has no aggregator node but only the device itself
|
|
2464
1760
|
}
|
|
2465
1761
|
else if (plugin.type === 'DynamicPlatform') {
|
|
2466
1762
|
if (!plugin.aggregatorNode) {
|
|
@@ -2475,21 +1771,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
2475
1771
|
if (plugin.addedDevices !== undefined)
|
|
2476
1772
|
plugin.addedDevices--;
|
|
2477
1773
|
}
|
|
2478
|
-
// Remove the device from the DeviceManager
|
|
2479
1774
|
this.devices.remove(device);
|
|
2480
1775
|
}
|
|
2481
|
-
/**
|
|
2482
|
-
* Removes all bridged endpoints from the specified plugin.
|
|
2483
|
-
*
|
|
2484
|
-
* @param {string} pluginName - The name of the plugin.
|
|
2485
|
-
* @param {number} [delay] - The delay in milliseconds between removing each bridged endpoint (default: 0).
|
|
2486
|
-
* @returns {Promise<void>} A promise that resolves when all bridged endpoints have been removed.
|
|
2487
|
-
*
|
|
2488
|
-
* @remarks
|
|
2489
|
-
* This method iterates through all devices in the DeviceManager and removes each bridged endpoint associated with the specified plugin.
|
|
2490
|
-
* It also applies a delay between each removal if specified.
|
|
2491
|
-
* The delay is useful to allow the controllers to receive a single subscription for each device removed.
|
|
2492
|
-
*/
|
|
2493
1776
|
async removeAllBridgedEndpoints(pluginName, delay = 0) {
|
|
2494
1777
|
this.log.debug(`Removing all bridged endpoints for plugin ${plg}${pluginName}${db}${delay > 0 ? ` with delay ${delay} ms` : ''}`);
|
|
2495
1778
|
for (const device of this.devices.array().filter((device) => device.plugin === pluginName)) {
|
|
@@ -2500,15 +1783,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2500
1783
|
if (delay > 0)
|
|
2501
1784
|
await wait(2000);
|
|
2502
1785
|
}
|
|
2503
|
-
/**
|
|
2504
|
-
* Subscribes to the attribute change event for the given device and plugin.
|
|
2505
|
-
* Specifically, it listens for changes in the 'reachable' attribute of the
|
|
2506
|
-
* BridgedDeviceBasicInformationServer cluster server of the bridged device or BasicInformationServer cluster server of server node.
|
|
2507
|
-
*
|
|
2508
|
-
* @param {RegisteredPlugin} plugin - The plugin associated with the device.
|
|
2509
|
-
* @param {MatterbridgeEndpoint} device - The device to subscribe to attribute changes for.
|
|
2510
|
-
* @returns {Promise<void>} A promise that resolves when the subscription is set up.
|
|
2511
|
-
*/
|
|
2512
1786
|
async subscribeAttributeChanged(plugin, device) {
|
|
2513
1787
|
this.log.info(`Subscribing attributes for endpoint ${dev}${device.deviceName}${nf} (${dev}${device.id}${nf}) plugin ${plg}${plugin.name}${nf}`);
|
|
2514
1788
|
if (this.bridgeMode === 'childbridge' && plugin.type === 'AccessoryPlatform' && plugin.serverNode) {
|
|
@@ -2524,12 +1798,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2524
1798
|
});
|
|
2525
1799
|
}
|
|
2526
1800
|
}
|
|
2527
|
-
/**
|
|
2528
|
-
* Sanitizes the fabric information by converting bigint properties to strings because `res.json` doesn't support bigint.
|
|
2529
|
-
*
|
|
2530
|
-
* @param {ExposedFabricInformation[]} fabricInfo - The array of exposed fabric information objects.
|
|
2531
|
-
* @returns {SanitizedExposedFabricInformation[]} An array of sanitized exposed fabric information objects.
|
|
2532
|
-
*/
|
|
2533
1801
|
sanitizeFabricInformations(fabricInfo) {
|
|
2534
1802
|
return fabricInfo.map((info) => {
|
|
2535
1803
|
return {
|
|
@@ -2543,12 +1811,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2543
1811
|
};
|
|
2544
1812
|
});
|
|
2545
1813
|
}
|
|
2546
|
-
/**
|
|
2547
|
-
* Sanitizes the session information by converting bigint properties to strings because `res.json` doesn't support bigint.
|
|
2548
|
-
*
|
|
2549
|
-
* @param {SessionsBehavior.Session[]} sessions - The array of session information objects.
|
|
2550
|
-
* @returns {SanitizedSession[]} An array of sanitized session information objects.
|
|
2551
|
-
*/
|
|
2552
1814
|
sanitizeSessionInformation(sessions) {
|
|
2553
1815
|
return sessions
|
|
2554
1816
|
.filter((session) => session.isPeerActive)
|
|
@@ -2575,21 +1837,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
2575
1837
|
};
|
|
2576
1838
|
});
|
|
2577
1839
|
}
|
|
2578
|
-
/**
|
|
2579
|
-
* Sets the reachability of the specified aggregator node bridged devices and trigger.
|
|
2580
|
-
*
|
|
2581
|
-
* @param {Endpoint<AggregatorEndpoint>} aggregatorNode - The aggregator node to set the reachability for.
|
|
2582
|
-
* @param {boolean} reachable - A boolean indicating the reachability status to set.
|
|
2583
|
-
*/
|
|
2584
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2585
1840
|
async setAggregatorReachability(aggregatorNode, reachable) {
|
|
2586
|
-
/*
|
|
2587
|
-
for (const child of aggregatorNode.parts) {
|
|
2588
|
-
this.log.debug(`Setting reachability of ${(child as unknown as MatterbridgeEndpoint)?.deviceName} to ${reachable}`);
|
|
2589
|
-
await child.setStateOf(BridgedDeviceBasicInformationServer, { reachable });
|
|
2590
|
-
child.act((agent) => child.eventsOf(BridgedDeviceBasicInformationServer).reachableChanged.emit({ reachableNewValue: true }, agent.context));
|
|
2591
|
-
}
|
|
2592
|
-
*/
|
|
2593
1841
|
}
|
|
2594
1842
|
getVendorIdName = (vendorId) => {
|
|
2595
1843
|
if (!vendorId)
|
|
@@ -2629,11 +1877,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
2629
1877
|
case 0x1488:
|
|
2630
1878
|
vendorName = '(ShortcutLabsFlic)';
|
|
2631
1879
|
break;
|
|
2632
|
-
case 65521:
|
|
1880
|
+
case 65521:
|
|
2633
1881
|
vendorName = '(MatterTest)';
|
|
2634
1882
|
break;
|
|
2635
1883
|
}
|
|
2636
1884
|
return vendorName;
|
|
2637
1885
|
};
|
|
2638
1886
|
}
|
|
2639
|
-
//# sourceMappingURL=matterbridge.js.map
|