matterbridge 3.3.7 → 3.3.8-dev-20251114-9b65e59
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 +37 -0
- package/README-SERVICE-OPT.md +4 -4
- package/README.md +4 -0
- package/dist/broadcastServer.js +1 -93
- package/dist/broadcastServerTypes.js +0 -24
- package/dist/cli.js +1 -97
- package/dist/cliEmitter.js +0 -37
- package/dist/cliHistory.js +0 -38
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -24
- package/dist/deviceManager.js +1 -105
- package/dist/devices/airConditioner.js +1 -58
- package/dist/devices/batteryStorage.js +2 -49
- package/dist/devices/cooktop.js +1 -56
- package/dist/devices/dishwasher.js +1 -58
- package/dist/devices/evse.js +11 -75
- package/dist/devices/export.js +0 -5
- package/dist/devices/extractorHood.js +1 -43
- package/dist/devices/heatPump.js +3 -51
- package/dist/devices/laundryDryer.js +4 -63
- package/dist/devices/laundryWasher.js +5 -71
- package/dist/devices/microwaveOven.js +6 -89
- package/dist/devices/oven.js +1 -86
- package/dist/devices/refrigerator.js +2 -104
- package/dist/devices/roboticVacuumCleaner.js +10 -101
- package/dist/devices/solarPower.js +1 -39
- package/dist/devices/speaker.js +1 -85
- package/dist/devices/temperatureControl.js +3 -24
- package/dist/devices/waterHeater.js +3 -83
- package/dist/dgram/coap.js +13 -126
- package/dist/dgram/dgram.js +2 -114
- package/dist/dgram/mb_coap.js +3 -41
- package/dist/dgram/mb_mdns.js +15 -80
- package/dist/dgram/mdns.js +137 -299
- package/dist/dgram/multicast.js +1 -62
- package/dist/dgram/unicast.js +0 -54
- package/dist/frontend.js +40 -452
- package/dist/frontendTypes.js +0 -45
- package/dist/helpers.js +0 -53
- package/dist/index.js +1 -25
- package/dist/jestutils/export.js +1 -0
- package/dist/{utils → jestutils}/jestHelpers.js +167 -175
- 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 -838
- package/dist/matterbridgeAccessoryPlatform.js +0 -37
- package/dist/matterbridgeBehaviors.js +5 -68
- package/dist/matterbridgeDeviceTypes.js +27 -653
- package/dist/matterbridgeDynamicPlatform.js +0 -37
- package/dist/matterbridgeEndpoint.js +73 -1429
- package/dist/matterbridgeEndpointHelpers.js +42 -475
- package/dist/matterbridgeEndpointTypes.js +3 -0
- package/dist/matterbridgePlatform.js +18 -341
- package/dist/matterbridgeTypes.js +0 -26
- package/dist/pluginManager.js +5 -340
- package/dist/shelly.js +7 -168
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -69
- package/dist/utils/colorUtils.js +2 -97
- package/dist/utils/commandLine.js +0 -60
- 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 +2 -43
- package/dist/utils/export.js +0 -1
- package/dist/utils/format.js +0 -49
- package/dist/utils/hex.js +0 -124
- package/dist/utils/inspector.js +1 -69
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/network.js +5 -96
- package/dist/utils/spawn.js +0 -71
- package/dist/utils/tracker.js +1 -64
- package/dist/utils/wait.js +8 -60
- package/npm-shrinkwrap.json +8 -8
- package/package.json +5 -2
- package/scripts/fetch-chip.mjs +100 -0
- package/dist/broadcastServer.d.ts +0 -115
- package/dist/broadcastServer.d.ts.map +0 -1
- package/dist/broadcastServer.js.map +0 -1
- package/dist/broadcastServerTypes.d.ts +0 -806
- package/dist/broadcastServerTypes.d.ts.map +0 -1
- package/dist/broadcastServerTypes.js.map +0 -1
- package/dist/cli.d.ts +0 -30
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cliEmitter.d.ts +0 -50
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.js.map +0 -1
- package/dist/cliHistory.d.ts +0 -48
- package/dist/cliHistory.d.ts.map +0 -1
- package/dist/cliHistory.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 -128
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/devices/airConditioner.d.ts +0 -98
- package/dist/devices/airConditioner.d.ts.map +0 -1
- package/dist/devices/airConditioner.js.map +0 -1
- package/dist/devices/batteryStorage.d.ts +0 -48
- package/dist/devices/batteryStorage.d.ts.map +0 -1
- package/dist/devices/batteryStorage.js.map +0 -1
- package/dist/devices/cooktop.d.ts +0 -60
- package/dist/devices/cooktop.d.ts.map +0 -1
- package/dist/devices/cooktop.js.map +0 -1
- package/dist/devices/dishwasher.d.ts +0 -71
- package/dist/devices/dishwasher.d.ts.map +0 -1
- package/dist/devices/dishwasher.js.map +0 -1
- package/dist/devices/evse.d.ts +0 -76
- package/dist/devices/evse.d.ts.map +0 -1
- package/dist/devices/evse.js.map +0 -1
- package/dist/devices/export.d.ts +0 -17
- package/dist/devices/export.d.ts.map +0 -1
- package/dist/devices/export.js.map +0 -1
- package/dist/devices/extractorHood.d.ts +0 -46
- package/dist/devices/extractorHood.d.ts.map +0 -1
- package/dist/devices/extractorHood.js.map +0 -1
- package/dist/devices/heatPump.d.ts +0 -47
- package/dist/devices/heatPump.d.ts.map +0 -1
- package/dist/devices/heatPump.js.map +0 -1
- package/dist/devices/laundryDryer.d.ts +0 -67
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -81
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.js.map +0 -1
- package/dist/devices/microwaveOven.d.ts +0 -168
- package/dist/devices/microwaveOven.d.ts.map +0 -1
- package/dist/devices/microwaveOven.js.map +0 -1
- package/dist/devices/oven.d.ts +0 -105
- package/dist/devices/oven.d.ts.map +0 -1
- package/dist/devices/oven.js.map +0 -1
- package/dist/devices/refrigerator.d.ts +0 -118
- package/dist/devices/refrigerator.d.ts.map +0 -1
- package/dist/devices/refrigerator.js.map +0 -1
- package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
- package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/devices/roboticVacuumCleaner.js.map +0 -1
- package/dist/devices/solarPower.d.ts +0 -40
- package/dist/devices/solarPower.d.ts.map +0 -1
- package/dist/devices/solarPower.js.map +0 -1
- package/dist/devices/speaker.d.ts +0 -87
- package/dist/devices/speaker.d.ts.map +0 -1
- package/dist/devices/speaker.js.map +0 -1
- package/dist/devices/temperatureControl.d.ts +0 -166
- package/dist/devices/temperatureControl.d.ts.map +0 -1
- package/dist/devices/temperatureControl.js.map +0 -1
- package/dist/devices/waterHeater.d.ts +0 -111
- package/dist/devices/waterHeater.d.ts.map +0 -1
- package/dist/devices/waterHeater.js.map +0 -1
- package/dist/dgram/coap.d.ts +0 -205
- package/dist/dgram/coap.d.ts.map +0 -1
- package/dist/dgram/coap.js.map +0 -1
- package/dist/dgram/dgram.d.ts +0 -141
- package/dist/dgram/dgram.d.ts.map +0 -1
- package/dist/dgram/dgram.js.map +0 -1
- package/dist/dgram/mb_coap.d.ts +0 -24
- package/dist/dgram/mb_coap.d.ts.map +0 -1
- package/dist/dgram/mb_coap.js.map +0 -1
- package/dist/dgram/mb_mdns.d.ts +0 -24
- package/dist/dgram/mb_mdns.d.ts.map +0 -1
- package/dist/dgram/mb_mdns.js.map +0 -1
- package/dist/dgram/mdns.d.ts +0 -290
- package/dist/dgram/mdns.d.ts.map +0 -1
- package/dist/dgram/mdns.js.map +0 -1
- package/dist/dgram/multicast.d.ts +0 -67
- package/dist/dgram/multicast.d.ts.map +0 -1
- package/dist/dgram/multicast.js.map +0 -1
- package/dist/dgram/unicast.d.ts +0 -56
- package/dist/dgram/unicast.d.ts.map +0 -1
- package/dist/dgram/unicast.js.map +0 -1
- package/dist/frontend.d.ts +0 -238
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/frontendTypes.d.ts +0 -529
- package/dist/frontendTypes.d.ts.map +0 -1
- package/dist/frontendTypes.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 -478
- 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 -2404
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -770
- 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 -1556
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -758
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -402
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -239
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -371
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -174
- package/dist/shelly.d.ts.map +0 -1
- package/dist/shelly.js.map +0 -1
- package/dist/storage/export.d.ts +0 -2
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/update.d.ts +0 -75
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -101
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/commandLine.d.ts +0 -66
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -33
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createDirectory.d.ts +0 -34
- package/dist/utils/createDirectory.d.ts.map +0 -1
- package/dist/utils/createDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -39
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -32
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -54
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/error.d.ts +0 -44
- package/dist/utils/error.d.ts.map +0 -1
- package/dist/utils/error.js.map +0 -1
- package/dist/utils/export.d.ts +0 -13
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/format.d.ts +0 -53
- package/dist/utils/format.d.ts.map +0 -1
- package/dist/utils/format.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/inspector.d.ts +0 -87
- package/dist/utils/inspector.d.ts.map +0 -1
- package/dist/utils/inspector.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -103
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/jestHelpers.d.ts +0 -139
- package/dist/utils/jestHelpers.d.ts.map +0 -1
- package/dist/utils/jestHelpers.js.map +0 -1
- package/dist/utils/network.d.ts +0 -101
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/spawn.d.ts +0 -35
- package/dist/utils/spawn.d.ts.map +0 -1
- package/dist/utils/spawn.js.map +0 -1
- package/dist/utils/tracker.d.ts +0 -108
- package/dist/utils/tracker.d.ts.map +0 -1
- package/dist/utils/tracker.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -54
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
package/dist/pluginManager.js
CHANGED
|
@@ -1,37 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the Plugins class.
|
|
3
|
-
*
|
|
4
|
-
* @file plugins.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @created 2024-07-14
|
|
7
|
-
* @version 1.3.0
|
|
8
|
-
* @license Apache-2.0
|
|
9
|
-
*
|
|
10
|
-
* Copyright 2024, 2025, 2026 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 import
|
|
25
1
|
import EventEmitter from 'node:events';
|
|
26
|
-
// AnsiLogger module
|
|
27
2
|
import { AnsiLogger, UNDERLINE, UNDERLINEOFF, BLUE, db, er, nf, nt, rs, wr, debugStringify, CYAN } from 'node-ansi-logger';
|
|
28
3
|
import { plg, typ } from './matterbridgeTypes.js';
|
|
29
4
|
import { inspectError, logError } from './utils/error.js';
|
|
30
5
|
import { hasParameter } from './utils/commandLine.js';
|
|
31
6
|
import { BroadcastServer } from './broadcastServer.js';
|
|
32
|
-
/**
|
|
33
|
-
* Manages Matterbridge plugins.
|
|
34
|
-
*/
|
|
35
7
|
export class PluginManager extends EventEmitter {
|
|
36
8
|
matterbridge;
|
|
37
9
|
_plugins = new Map();
|
|
@@ -39,15 +11,10 @@ export class PluginManager extends EventEmitter {
|
|
|
39
11
|
server;
|
|
40
12
|
debug = hasParameter('debug') || hasParameter('verbose');
|
|
41
13
|
verbose = hasParameter('verbose');
|
|
42
|
-
/**
|
|
43
|
-
* Creates an instance of PluginManager.
|
|
44
|
-
*
|
|
45
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
46
|
-
*/
|
|
47
14
|
constructor(matterbridge) {
|
|
48
15
|
super();
|
|
49
16
|
this.matterbridge = matterbridge;
|
|
50
|
-
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4
|
|
17
|
+
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: hasParameter('debug') ? "debug" : "info" });
|
|
51
18
|
this.log.debug('Matterbridge plugin manager starting...');
|
|
52
19
|
this.server = new BroadcastServer('plugins', this.log);
|
|
53
20
|
this.server.on('broadcast_message', this.msgHandler.bind(this));
|
|
@@ -197,62 +164,25 @@ export class PluginManager extends EventEmitter {
|
|
|
197
164
|
}
|
|
198
165
|
}
|
|
199
166
|
}
|
|
200
|
-
/**
|
|
201
|
-
* Gets the number of plugins.
|
|
202
|
-
*
|
|
203
|
-
* @returns {number} The number of plugins.
|
|
204
|
-
*/
|
|
205
167
|
get length() {
|
|
206
168
|
return this._plugins.size;
|
|
207
169
|
}
|
|
208
|
-
/**
|
|
209
|
-
* Gets the number of plugins.
|
|
210
|
-
*
|
|
211
|
-
* @returns {number} The number of plugins.
|
|
212
|
-
*/
|
|
213
170
|
get size() {
|
|
214
171
|
return this._plugins.size;
|
|
215
172
|
}
|
|
216
|
-
/**
|
|
217
|
-
* Checks if a plugin with the specified name exists.
|
|
218
|
-
*
|
|
219
|
-
* @param {string} name - The name of the plugin.
|
|
220
|
-
* @returns {boolean} True if the plugin exists, false otherwise.
|
|
221
|
-
*/
|
|
222
173
|
has(name) {
|
|
223
174
|
return this._plugins.has(name);
|
|
224
175
|
}
|
|
225
|
-
/**
|
|
226
|
-
* Gets a plugin by its name.
|
|
227
|
-
*
|
|
228
|
-
* @param {string} name - The name of the plugin.
|
|
229
|
-
* @returns {Plugin | undefined} The plugin, or undefined if not found.
|
|
230
|
-
*/
|
|
231
176
|
get(name) {
|
|
232
177
|
return this._plugins.get(name);
|
|
233
178
|
}
|
|
234
|
-
/**
|
|
235
|
-
* Adds a plugin to the manager.
|
|
236
|
-
*
|
|
237
|
-
* @param {Plugin} plugin - The plugin to add.
|
|
238
|
-
* @returns {Plugin} The added plugin.
|
|
239
|
-
*/
|
|
240
179
|
set(plugin) {
|
|
241
180
|
this._plugins.set(plugin.name, plugin);
|
|
242
181
|
return plugin;
|
|
243
182
|
}
|
|
244
|
-
/**
|
|
245
|
-
* Clears all plugins from the manager.
|
|
246
|
-
*/
|
|
247
183
|
clear() {
|
|
248
184
|
this._plugins.clear();
|
|
249
185
|
}
|
|
250
|
-
/**
|
|
251
|
-
* Converts a plugin or API plugin to a storage plugin.
|
|
252
|
-
*
|
|
253
|
-
* @param {Plugin | ApiPlugin} plugin - The plugin or API plugin to convert.
|
|
254
|
-
* @returns {StoragePlugin} The converted storage plugin.
|
|
255
|
-
*/
|
|
256
186
|
toStoragePlugin(plugin) {
|
|
257
187
|
return {
|
|
258
188
|
name: plugin.name,
|
|
@@ -264,12 +194,6 @@ export class PluginManager extends EventEmitter {
|
|
|
264
194
|
enabled: plugin.enabled,
|
|
265
195
|
};
|
|
266
196
|
}
|
|
267
|
-
/**
|
|
268
|
-
* Converts a plugin to an API plugin.
|
|
269
|
-
*
|
|
270
|
-
* @param {Plugin} plugin - The plugin to convert.
|
|
271
|
-
* @returns {ApiPlugin} The converted API plugin.
|
|
272
|
-
*/
|
|
273
197
|
toApiPlugin(plugin) {
|
|
274
198
|
return {
|
|
275
199
|
name: plugin.name,
|
|
@@ -299,19 +223,9 @@ export class PluginManager extends EventEmitter {
|
|
|
299
223
|
matter: plugin.serverNode ? this.matterbridge.getServerNodeData(plugin.serverNode) : undefined,
|
|
300
224
|
};
|
|
301
225
|
}
|
|
302
|
-
/**
|
|
303
|
-
* Gets an array of all plugins.
|
|
304
|
-
*
|
|
305
|
-
* @returns {Plugin[]} An array of all plugins.
|
|
306
|
-
*/
|
|
307
226
|
array() {
|
|
308
227
|
return Array.from(this._plugins.values());
|
|
309
228
|
}
|
|
310
|
-
/**
|
|
311
|
-
* Gets a StoragePlugin array of all plugins suitable for serialization.
|
|
312
|
-
*
|
|
313
|
-
* @returns {StoragePlugin[]} An array of all plugins.
|
|
314
|
-
*/
|
|
315
229
|
storagePluginArray() {
|
|
316
230
|
const storagePlugins = [];
|
|
317
231
|
for (const plugin of this._plugins.values()) {
|
|
@@ -319,11 +233,6 @@ export class PluginManager extends EventEmitter {
|
|
|
319
233
|
}
|
|
320
234
|
return storagePlugins;
|
|
321
235
|
}
|
|
322
|
-
/**
|
|
323
|
-
* Gets an ApiPlugin array of all plugins suitable for serialization.
|
|
324
|
-
*
|
|
325
|
-
* @returns {ApiPlugin[]} An array of all plugins.
|
|
326
|
-
*/
|
|
327
236
|
apiPluginArray() {
|
|
328
237
|
const apiPlugins = [];
|
|
329
238
|
for (const plugin of this._plugins.values()) {
|
|
@@ -331,20 +240,9 @@ export class PluginManager extends EventEmitter {
|
|
|
331
240
|
}
|
|
332
241
|
return apiPlugins;
|
|
333
242
|
}
|
|
334
|
-
/**
|
|
335
|
-
* Gets an iterator for the plugins.
|
|
336
|
-
*
|
|
337
|
-
* @returns {IterableIterator<Plugin>} An iterator for the plugins.
|
|
338
|
-
*/
|
|
339
243
|
[Symbol.iterator]() {
|
|
340
244
|
return this._plugins.values();
|
|
341
245
|
}
|
|
342
|
-
/**
|
|
343
|
-
* Executes a provided function once for each plugin.
|
|
344
|
-
*
|
|
345
|
-
* @param {Function} callback - The function to execute for each plugin.
|
|
346
|
-
* @returns {Promise<void>}
|
|
347
|
-
*/
|
|
348
246
|
async forEach(callback) {
|
|
349
247
|
if (this.size === 0)
|
|
350
248
|
return;
|
|
@@ -358,39 +256,22 @@ export class PluginManager extends EventEmitter {
|
|
|
358
256
|
});
|
|
359
257
|
await Promise.all(tasks);
|
|
360
258
|
}
|
|
361
|
-
/**
|
|
362
|
-
* Sets the log level for the plugin manager.
|
|
363
|
-
*
|
|
364
|
-
* @param {LogLevel} logLevel - The log level to set.
|
|
365
|
-
*/
|
|
366
259
|
set logLevel(logLevel) {
|
|
367
260
|
this.log.logLevel = logLevel;
|
|
368
261
|
}
|
|
369
|
-
/**
|
|
370
|
-
* Loads registered plugins from storage.
|
|
371
|
-
*
|
|
372
|
-
* @returns {Promise<StoragePlugin[]>} A promise that resolves to an array of registered plugins.
|
|
373
|
-
*/
|
|
374
262
|
async loadFromStorage() {
|
|
375
263
|
if (!this.matterbridge.nodeContext) {
|
|
376
264
|
throw new Error('loadFromStorage: node context is not available.');
|
|
377
265
|
}
|
|
378
|
-
// Load the array from storage and convert it to a map
|
|
379
266
|
const pluginsArray = await this.matterbridge.nodeContext.get('plugins', []);
|
|
380
267
|
for (const plugin of pluginsArray)
|
|
381
268
|
this._plugins.set(plugin.name, plugin);
|
|
382
269
|
return pluginsArray;
|
|
383
270
|
}
|
|
384
|
-
/**
|
|
385
|
-
* Saves registered plugins to storage.
|
|
386
|
-
*
|
|
387
|
-
* @returns {Promise<number>} A promise that resolves to the number of registered plugins.
|
|
388
|
-
*/
|
|
389
271
|
async saveToStorage() {
|
|
390
272
|
if (!this.matterbridge.nodeContext) {
|
|
391
273
|
throw new Error('loadFromStorage: node context is not available.');
|
|
392
274
|
}
|
|
393
|
-
// Convert the map to an array
|
|
394
275
|
const plugins = [];
|
|
395
276
|
for (const plugin of this.array()) {
|
|
396
277
|
plugins.push({
|
|
@@ -407,21 +288,13 @@ export class PluginManager extends EventEmitter {
|
|
|
407
288
|
this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
|
|
408
289
|
return plugins.length;
|
|
409
290
|
}
|
|
410
|
-
/**
|
|
411
|
-
* Resolves the name of a plugin by loading and parsing its package.json file.
|
|
412
|
-
*
|
|
413
|
-
* @param {string} pluginPath - The path to the plugin or the path to the plugin's package.json file.
|
|
414
|
-
* @returns {Promise<string | null>} A promise that resolves to the path of the plugin's package.json file or null if it could not be resolved.
|
|
415
|
-
*/
|
|
416
291
|
async resolve(pluginPath) {
|
|
417
292
|
const { default: path } = await import('node:path');
|
|
418
293
|
const { promises } = await import('node:fs');
|
|
419
294
|
if (!pluginPath.endsWith('package.json'))
|
|
420
295
|
pluginPath = path.join(pluginPath, 'package.json');
|
|
421
|
-
// Resolve the package.json of the plugin
|
|
422
296
|
let packageJsonPath = path.resolve(pluginPath);
|
|
423
297
|
this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
|
|
424
|
-
// Check if the package.json file exists
|
|
425
298
|
try {
|
|
426
299
|
await promises.access(packageJsonPath);
|
|
427
300
|
}
|
|
@@ -431,9 +304,7 @@ export class PluginManager extends EventEmitter {
|
|
|
431
304
|
this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
|
|
432
305
|
}
|
|
433
306
|
try {
|
|
434
|
-
// Load the package.json of the plugin
|
|
435
307
|
const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
|
|
436
|
-
// Check for main issues
|
|
437
308
|
if (!packageJson.name) {
|
|
438
309
|
this.log.error(`Package.json name not found at ${packageJsonPath}`);
|
|
439
310
|
return null;
|
|
@@ -446,7 +317,6 @@ export class PluginManager extends EventEmitter {
|
|
|
446
317
|
this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
|
|
447
318
|
return null;
|
|
448
319
|
}
|
|
449
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
450
320
|
const checkForProjectChipPackages = (dependencies) => {
|
|
451
321
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
452
322
|
};
|
|
@@ -468,7 +338,6 @@ export class PluginManager extends EventEmitter {
|
|
|
468
338
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
469
339
|
return null;
|
|
470
340
|
}
|
|
471
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
472
341
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
473
342
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
474
343
|
};
|
|
@@ -498,12 +367,6 @@ export class PluginManager extends EventEmitter {
|
|
|
498
367
|
return null;
|
|
499
368
|
}
|
|
500
369
|
}
|
|
501
|
-
/**
|
|
502
|
-
* Installs a package globally using npm.
|
|
503
|
-
*
|
|
504
|
-
* @param {string} packageName - The name of the package to install.
|
|
505
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the installation was successful, false otherwise.
|
|
506
|
-
*/
|
|
507
370
|
async install(packageName) {
|
|
508
371
|
this.log.debug(`Installing plugin ${plg}${packageName}${db}...`);
|
|
509
372
|
const { spawnCommand } = await import('./utils/spawn.js');
|
|
@@ -511,7 +374,7 @@ export class PluginManager extends EventEmitter {
|
|
|
511
374
|
await spawnCommand(this.matterbridge, 'npm', ['install', '-g', packageName, '--omit=dev', '--verbose'], 'install', packageName);
|
|
512
375
|
this.matterbridge.restartRequired = true;
|
|
513
376
|
this.matterbridge.fixedRestartRequired = true;
|
|
514
|
-
packageName = packageName.replace(/@.*$/, '');
|
|
377
|
+
packageName = packageName.replace(/@.*$/, '');
|
|
515
378
|
if (packageName !== 'matterbridge') {
|
|
516
379
|
if (!this.has(packageName))
|
|
517
380
|
await this.add(packageName);
|
|
@@ -533,12 +396,6 @@ export class PluginManager extends EventEmitter {
|
|
|
533
396
|
return false;
|
|
534
397
|
}
|
|
535
398
|
}
|
|
536
|
-
/**
|
|
537
|
-
* Uninstalls a package globally using npm.
|
|
538
|
-
*
|
|
539
|
-
* @param {string} packageName - The name of the package to uninstall.
|
|
540
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the uninstallation was successful, false otherwise.
|
|
541
|
-
*/
|
|
542
399
|
async uninstall(packageName) {
|
|
543
400
|
this.log.debug(`Uninstalling plugin ${plg}${packageName}${db}...`);
|
|
544
401
|
const { spawnCommand } = await import('./utils/spawn.js');
|
|
@@ -562,12 +419,6 @@ export class PluginManager extends EventEmitter {
|
|
|
562
419
|
return false;
|
|
563
420
|
}
|
|
564
421
|
}
|
|
565
|
-
/**
|
|
566
|
-
* Get the author of a plugin from its package.json.
|
|
567
|
-
*
|
|
568
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
569
|
-
* @returns {string} The author of the plugin, or 'Unknown author' if not found.
|
|
570
|
-
*/
|
|
571
422
|
getAuthor(packageJson) {
|
|
572
423
|
if (packageJson.author && typeof packageJson.author === 'string')
|
|
573
424
|
return packageJson.author;
|
|
@@ -575,12 +426,6 @@ export class PluginManager extends EventEmitter {
|
|
|
575
426
|
return packageJson.author.name;
|
|
576
427
|
return 'Unknown author';
|
|
577
428
|
}
|
|
578
|
-
/**
|
|
579
|
-
* Get the homepage of a plugin from its package.json.
|
|
580
|
-
*
|
|
581
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
582
|
-
* @returns {string | undefined} The homepage of the plugin, or undefined if not found.
|
|
583
|
-
*/
|
|
584
429
|
getHomepage(packageJson) {
|
|
585
430
|
if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
|
|
586
431
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
@@ -589,14 +434,7 @@ export class PluginManager extends EventEmitter {
|
|
|
589
434
|
return packageJson.repository.url.replace('git+', '').replace('.git', '');
|
|
590
435
|
}
|
|
591
436
|
}
|
|
592
|
-
/**
|
|
593
|
-
* Get the help URL of a plugin from its package.json.
|
|
594
|
-
*
|
|
595
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
596
|
-
* @returns {string | undefined} The URL to the help page or to the README file, or undefined if not found.
|
|
597
|
-
*/
|
|
598
437
|
getHelp(packageJson) {
|
|
599
|
-
// If there's a help field that looks like a URL, return it.
|
|
600
438
|
if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
|
|
601
439
|
return packageJson.help;
|
|
602
440
|
}
|
|
@@ -607,14 +445,7 @@ export class PluginManager extends EventEmitter {
|
|
|
607
445
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
608
446
|
}
|
|
609
447
|
}
|
|
610
|
-
/**
|
|
611
|
-
* Get the changelog URL of a plugin from its package.json.
|
|
612
|
-
*
|
|
613
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
614
|
-
* @returns {string | undefined} The URL to the CHANGELOG file, or undefined if not found.
|
|
615
|
-
*/
|
|
616
448
|
getChangelog(packageJson) {
|
|
617
|
-
// If there's a changelog field that looks like a URL, return it.
|
|
618
449
|
if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
|
|
619
450
|
return packageJson.changelog;
|
|
620
451
|
}
|
|
@@ -625,13 +456,6 @@ export class PluginManager extends EventEmitter {
|
|
|
625
456
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
626
457
|
}
|
|
627
458
|
}
|
|
628
|
-
/**
|
|
629
|
-
* Get the first funding URL(s) of a plugin from its package.json.
|
|
630
|
-
*
|
|
631
|
-
* @param {Record<string, any>} packageJson - The package.json object of the plugin.
|
|
632
|
-
* @returns {string | undefined} The first funding URLs, or undefined if not found.
|
|
633
|
-
*/
|
|
634
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
635
459
|
getFunding(packageJson) {
|
|
636
460
|
const funding = packageJson.funding;
|
|
637
461
|
if (!funding)
|
|
@@ -640,27 +464,16 @@ export class PluginManager extends EventEmitter {
|
|
|
640
464
|
return;
|
|
641
465
|
if (typeof funding === 'string' && funding.startsWith('http'))
|
|
642
466
|
return funding;
|
|
643
|
-
// Normalize funding into an array.
|
|
644
467
|
const fundingEntries = Array.isArray(funding) ? funding : [funding];
|
|
645
468
|
for (const entry of fundingEntries) {
|
|
646
469
|
if (entry && typeof entry === 'string' && entry.startsWith('http')) {
|
|
647
|
-
// If the funding entry is a string, assume it is a URL.
|
|
648
470
|
return entry;
|
|
649
471
|
}
|
|
650
472
|
else if (entry && typeof entry === 'object' && typeof entry.url === 'string' && entry.url.startsWith('http')) {
|
|
651
|
-
// If it's an object with a 'url' property, use that.
|
|
652
473
|
return entry.url;
|
|
653
474
|
}
|
|
654
475
|
}
|
|
655
476
|
}
|
|
656
|
-
/**
|
|
657
|
-
* Parses the plugin package.json and returns it.
|
|
658
|
-
* It will also log warnings and errors for missing or invalid fields.
|
|
659
|
-
* It will return null if critical errors are found.
|
|
660
|
-
*
|
|
661
|
-
* @param {Plugin | PluginName} plugin - The plugin to load the package from.
|
|
662
|
-
* @returns {Promise<Record<string, string | number | object> | null>} A promise that resolves to the parsed package.json object or null if it could not be parsed.
|
|
663
|
-
*/
|
|
664
477
|
async parse(plugin) {
|
|
665
478
|
const { promises } = await import('node:fs');
|
|
666
479
|
if (typeof plugin === 'string') {
|
|
@@ -698,7 +511,6 @@ export class PluginManager extends EventEmitter {
|
|
|
698
511
|
plugin.funding = this.getFunding(packageJson);
|
|
699
512
|
if (!plugin.type)
|
|
700
513
|
this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
|
|
701
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
702
514
|
const checkForProjectChipPackages = (dependencies) => {
|
|
703
515
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
704
516
|
};
|
|
@@ -720,7 +532,6 @@ export class PluginManager extends EventEmitter {
|
|
|
720
532
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
721
533
|
return null;
|
|
722
534
|
}
|
|
723
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
724
535
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
725
536
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
726
537
|
};
|
|
@@ -750,16 +561,6 @@ export class PluginManager extends EventEmitter {
|
|
|
750
561
|
return null;
|
|
751
562
|
}
|
|
752
563
|
}
|
|
753
|
-
/**
|
|
754
|
-
* Enables a plugin by its name or path.
|
|
755
|
-
*
|
|
756
|
-
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
757
|
-
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
758
|
-
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
759
|
-
*
|
|
760
|
-
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
761
|
-
* @returns {Promise<Plugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
762
|
-
*/
|
|
763
564
|
async enable(nameOrPath) {
|
|
764
565
|
const { promises } = await import('node:fs');
|
|
765
566
|
if (!nameOrPath)
|
|
@@ -795,16 +596,6 @@ export class PluginManager extends EventEmitter {
|
|
|
795
596
|
return null;
|
|
796
597
|
}
|
|
797
598
|
}
|
|
798
|
-
/**
|
|
799
|
-
* Disables a plugin by its name or path.
|
|
800
|
-
*
|
|
801
|
-
* This method disables a plugin by setting its `enabled` property to `false` and saving the updated
|
|
802
|
-
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
803
|
-
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and disable it.
|
|
804
|
-
*
|
|
805
|
-
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
806
|
-
* @returns {Promise<Plugin | null>} A promise that resolves to the disabled plugin object, or null if the plugin could not be disabled.
|
|
807
|
-
*/
|
|
808
599
|
async disable(nameOrPath) {
|
|
809
600
|
const { promises } = await import('node:fs');
|
|
810
601
|
if (!nameOrPath)
|
|
@@ -840,16 +631,6 @@ export class PluginManager extends EventEmitter {
|
|
|
840
631
|
return null;
|
|
841
632
|
}
|
|
842
633
|
}
|
|
843
|
-
/**
|
|
844
|
-
* Removes a plugin by its name or path.
|
|
845
|
-
*
|
|
846
|
-
* This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
|
|
847
|
-
* It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
|
|
848
|
-
* the plugin's `package.json` file to retrieve its name and remove it.
|
|
849
|
-
*
|
|
850
|
-
* @param {string} nameOrPath - The name or path of the plugin to remove.
|
|
851
|
-
* @returns {Promise<Plugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
|
|
852
|
-
*/
|
|
853
634
|
async remove(nameOrPath) {
|
|
854
635
|
const { promises } = await import('node:fs');
|
|
855
636
|
if (!nameOrPath)
|
|
@@ -885,17 +666,6 @@ export class PluginManager extends EventEmitter {
|
|
|
885
666
|
return null;
|
|
886
667
|
}
|
|
887
668
|
}
|
|
888
|
-
/**
|
|
889
|
-
* Adds a plugin by its name or path.
|
|
890
|
-
*
|
|
891
|
-
* This method adds a plugin to the plugins map and saves the updated plugin information to storage.
|
|
892
|
-
* It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
|
|
893
|
-
* registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
|
|
894
|
-
* and saves the updated plugin information to storage.
|
|
895
|
-
*
|
|
896
|
-
* @param {string} nameOrPath - The name or path of the plugin to add.
|
|
897
|
-
* @returns {Promise<Plugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
|
|
898
|
-
*/
|
|
899
669
|
async add(nameOrPath) {
|
|
900
670
|
const { promises } = await import('node:fs');
|
|
901
671
|
if (!nameOrPath)
|
|
@@ -935,15 +705,6 @@ export class PluginManager extends EventEmitter {
|
|
|
935
705
|
return null;
|
|
936
706
|
}
|
|
937
707
|
}
|
|
938
|
-
/**
|
|
939
|
-
* Loads a plugin and returns the corresponding MatterbridgePlatform instance.
|
|
940
|
-
*
|
|
941
|
-
* @param {Plugin | PluginName} plugin - The plugin to load.
|
|
942
|
-
* @param {boolean} start - Optional flag indicating whether to start the plugin after loading. Default is false.
|
|
943
|
-
* @param {string} message - Optional message to pass to the plugin when starting.
|
|
944
|
-
* @param {boolean} configure - Optional flag indicating whether to configure the plugin after loading. Default is false.
|
|
945
|
-
* @returns {Promise<MatterbridgePlatform | undefined>} A Promise that resolves to the loaded MatterbridgePlatform instance or undefined.
|
|
946
|
-
*/
|
|
947
708
|
async load(plugin, start = false, message = '', configure = false) {
|
|
948
709
|
const { promises } = await import('node:fs');
|
|
949
710
|
const { default: path } = await import('node:path');
|
|
@@ -965,20 +726,15 @@ export class PluginManager extends EventEmitter {
|
|
|
965
726
|
}
|
|
966
727
|
this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
|
|
967
728
|
try {
|
|
968
|
-
// Load the package.json of the plugin
|
|
969
729
|
const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
|
|
970
|
-
// Resolve the main module path relative to package.json
|
|
971
730
|
const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
|
|
972
|
-
// Dynamically import the plugin
|
|
973
731
|
const { pathToFileURL } = await import('node:url');
|
|
974
732
|
const pluginUrl = pathToFileURL(pluginEntry);
|
|
975
733
|
this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
976
734
|
const pluginInstance = await import(pluginUrl.href);
|
|
977
735
|
this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
978
|
-
// Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
|
|
979
736
|
if (pluginInstance.default) {
|
|
980
737
|
const config = await this.loadConfig(plugin);
|
|
981
|
-
// Preset the plugin properties here in case the plugin throws an error during loading. In this case the user can change the config and restart the plugin.
|
|
982
738
|
plugin.name = packageJson.name;
|
|
983
739
|
plugin.description = packageJson.description ?? 'No description';
|
|
984
740
|
plugin.version = packageJson.version;
|
|
@@ -987,7 +743,7 @@ export class PluginManager extends EventEmitter {
|
|
|
987
743
|
plugin.schemaJson = await this.loadSchema(plugin);
|
|
988
744
|
config.name = plugin.name;
|
|
989
745
|
config.version = packageJson.version;
|
|
990
|
-
const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4
|
|
746
|
+
const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
|
|
991
747
|
const platform = pluginInstance.default(this.matterbridge, log, config);
|
|
992
748
|
config.type = platform.type;
|
|
993
749
|
platform.name = packageJson.name;
|
|
@@ -1005,7 +761,7 @@ export class PluginManager extends EventEmitter {
|
|
|
1005
761
|
plugin.platform = platform;
|
|
1006
762
|
plugin.loaded = true;
|
|
1007
763
|
plugin.registeredDevices = 0;
|
|
1008
|
-
await this.saveToStorage();
|
|
764
|
+
await this.saveToStorage();
|
|
1009
765
|
this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
|
|
1010
766
|
this.emit('loaded', plugin.name);
|
|
1011
767
|
if (start)
|
|
@@ -1020,19 +776,11 @@ export class PluginManager extends EventEmitter {
|
|
|
1020
776
|
}
|
|
1021
777
|
}
|
|
1022
778
|
catch (err) {
|
|
1023
|
-
|
|
779
|
+
inspectError(this.log, `Failed to load plugin ${plg}${plugin.name}${er}`, err);
|
|
1024
780
|
plugin.error = true;
|
|
1025
781
|
}
|
|
1026
782
|
return undefined;
|
|
1027
783
|
}
|
|
1028
|
-
/**
|
|
1029
|
-
* Starts a plugin.
|
|
1030
|
-
*
|
|
1031
|
-
* @param {Plugin | PluginName} plugin - The plugin to start.
|
|
1032
|
-
* @param {string} [message] - Optional message to pass to the plugin's onStart method.
|
|
1033
|
-
* @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
|
|
1034
|
-
* @returns {Promise<Plugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
|
|
1035
|
-
*/
|
|
1036
784
|
async start(plugin, message, configure = false) {
|
|
1037
785
|
if (typeof plugin === 'string') {
|
|
1038
786
|
const p = this._plugins.get(plugin);
|
|
@@ -1071,12 +819,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1071
819
|
}
|
|
1072
820
|
return undefined;
|
|
1073
821
|
}
|
|
1074
|
-
/**
|
|
1075
|
-
* Configures a plugin.
|
|
1076
|
-
*
|
|
1077
|
-
* @param {Plugin | PluginName} plugin - The plugin to configure.
|
|
1078
|
-
* @returns {Promise<Plugin | undefined>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
|
|
1079
|
-
*/
|
|
1080
822
|
async configure(plugin) {
|
|
1081
823
|
if (typeof plugin === 'string') {
|
|
1082
824
|
const p = this._plugins.get(plugin);
|
|
@@ -1116,18 +858,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1116
858
|
}
|
|
1117
859
|
return undefined;
|
|
1118
860
|
}
|
|
1119
|
-
/**
|
|
1120
|
-
* Shuts down a plugin.
|
|
1121
|
-
*
|
|
1122
|
-
* This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
|
|
1123
|
-
* It logs the shutdown process and optionally removes all devices associated with the plugin.
|
|
1124
|
-
*
|
|
1125
|
-
* @param {Plugin | PluginName} plugin - The plugin to shut down.
|
|
1126
|
-
* @param {string} [reason] - The reason for shutting down the plugin.
|
|
1127
|
-
* @param {boolean} [removeAllDevices] - Whether to remove all devices associated with the plugin.
|
|
1128
|
-
* @param {boolean} [force] - Whether to force the shutdown even if the plugin is not loaded or started.
|
|
1129
|
-
* @returns {Promise<Plugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
|
|
1130
|
-
*/
|
|
1131
861
|
async shutdown(plugin, reason, removeAllDevices = false, force = false) {
|
|
1132
862
|
if (typeof plugin === 'string') {
|
|
1133
863
|
const p = this._plugins.get(plugin);
|
|
@@ -1178,15 +908,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1178
908
|
}
|
|
1179
909
|
return undefined;
|
|
1180
910
|
}
|
|
1181
|
-
/**
|
|
1182
|
-
* Loads the configuration for a plugin.
|
|
1183
|
-
* If the configuration file exists, it reads the file and returns the parsed JSON data.
|
|
1184
|
-
* If the configuration file does not exist, it creates a new file with default configuration and returns it.
|
|
1185
|
-
* If any error occurs during file access or creation, it logs an error and return un empty config.
|
|
1186
|
-
*
|
|
1187
|
-
* @param {Plugin} plugin - The plugin for which to load the configuration.
|
|
1188
|
-
* @returns {Promise<PlatformConfig>} A promise that resolves to the loaded or created configuration.
|
|
1189
|
-
*/
|
|
1190
911
|
async loadConfig(plugin) {
|
|
1191
912
|
const { default: path } = await import('node:path');
|
|
1192
913
|
const { promises } = await import('node:fs');
|
|
@@ -1198,8 +919,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1198
919
|
const data = await promises.readFile(configFile, 'utf8');
|
|
1199
920
|
const config = JSON.parse(data);
|
|
1200
921
|
this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
1201
|
-
// this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
1202
|
-
// The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
|
|
1203
922
|
config.name = plugin.name;
|
|
1204
923
|
config.type = plugin.type;
|
|
1205
924
|
if (config.debug === undefined)
|
|
@@ -1221,8 +940,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1221
940
|
}
|
|
1222
941
|
catch (_err) {
|
|
1223
942
|
this.log.debug(`Default config file ${defaultConfigFile} for plugin ${plg}${plugin.name}${db} does not exist, creating new config file...`);
|
|
1224
|
-
// TODO: Remove this when all these plugins have their own default config file
|
|
1225
|
-
// istanbul ignore next if
|
|
1226
943
|
if (plugin.name === 'matterbridge-zigbee2mqtt')
|
|
1227
944
|
config = zigbee2mqtt_config;
|
|
1228
945
|
else if (plugin.name === 'matterbridge-somfy-tahoma')
|
|
@@ -1235,7 +952,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1235
952
|
try {
|
|
1236
953
|
await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
1237
954
|
this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
1238
|
-
// this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
1239
955
|
return config;
|
|
1240
956
|
}
|
|
1241
957
|
catch (err) {
|
|
@@ -1249,19 +965,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1249
965
|
}
|
|
1250
966
|
}
|
|
1251
967
|
}
|
|
1252
|
-
/**
|
|
1253
|
-
* Saves the configuration of a plugin to a file.
|
|
1254
|
-
*
|
|
1255
|
-
* This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
1256
|
-
* If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
|
|
1257
|
-
* is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
|
|
1258
|
-
* the error and rejects the promise.
|
|
1259
|
-
*
|
|
1260
|
-
* @param {Plugin} plugin - The plugin whose configuration is to be saved.
|
|
1261
|
-
* @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
|
|
1262
|
-
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
|
|
1263
|
-
* @throws {Error} If the plugin's configuration is not found.
|
|
1264
|
-
*/
|
|
1265
968
|
async saveConfigFromPlugin(plugin, restartRequired = false) {
|
|
1266
969
|
const { default: path } = await import('node:path');
|
|
1267
970
|
const { promises } = await import('node:fs');
|
|
@@ -1276,7 +979,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1276
979
|
if (restartRequired)
|
|
1277
980
|
plugin.restartRequired = true;
|
|
1278
981
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
1279
|
-
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
|
|
1280
982
|
return Promise.resolve();
|
|
1281
983
|
}
|
|
1282
984
|
catch (err) {
|
|
@@ -1284,20 +986,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1284
986
|
return Promise.reject(err);
|
|
1285
987
|
}
|
|
1286
988
|
}
|
|
1287
|
-
/**
|
|
1288
|
-
* Saves the configuration of a plugin from a JSON object to a file.
|
|
1289
|
-
*
|
|
1290
|
-
* This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
1291
|
-
* It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
|
|
1292
|
-
* the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
|
|
1293
|
-
* successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
|
|
1294
|
-
* during the file write operation, it logs the error and returns.
|
|
1295
|
-
*
|
|
1296
|
-
* @param {Plugin} plugin - The plugin whose configuration is to be saved.
|
|
1297
|
-
* @param {PlatformConfig} config - The configuration data to be saved.
|
|
1298
|
-
* @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
|
|
1299
|
-
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
|
|
1300
|
-
*/
|
|
1301
989
|
async saveConfigFromJson(plugin, config, restartRequired = false) {
|
|
1302
990
|
const { default: path } = await import('node:path');
|
|
1303
991
|
const { promises } = await import('node:fs');
|
|
@@ -1316,23 +1004,12 @@ export class PluginManager extends EventEmitter {
|
|
|
1316
1004
|
plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
|
|
1317
1005
|
}
|
|
1318
1006
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
1319
|
-
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
1320
1007
|
}
|
|
1321
1008
|
catch (err) {
|
|
1322
1009
|
logError(this.log, `Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}`, err);
|
|
1323
1010
|
return;
|
|
1324
1011
|
}
|
|
1325
1012
|
}
|
|
1326
|
-
/**
|
|
1327
|
-
* Loads the schema for a plugin.
|
|
1328
|
-
*
|
|
1329
|
-
* This method attempts to load the schema file for the specified plugin. If the schema file is found,
|
|
1330
|
-
* it reads and parses the file, updates the schema's title and description, and logs the process.
|
|
1331
|
-
* If the schema file is not found, it logs the event and loads a default schema for the plugin.
|
|
1332
|
-
*
|
|
1333
|
-
* @param {Plugin} plugin - The plugin whose schema is to be loaded.
|
|
1334
|
-
* @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
|
|
1335
|
-
*/
|
|
1336
1013
|
async loadSchema(plugin) {
|
|
1337
1014
|
const { promises } = await import('node:fs');
|
|
1338
1015
|
const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
|
|
@@ -1343,7 +1020,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1343
1020
|
schema.title = plugin.description;
|
|
1344
1021
|
schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
|
|
1345
1022
|
this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
1346
|
-
// this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
|
|
1347
1023
|
return schema;
|
|
1348
1024
|
}
|
|
1349
1025
|
catch (_err) {
|
|
@@ -1351,16 +1027,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1351
1027
|
return this.getDefaultSchema(plugin);
|
|
1352
1028
|
}
|
|
1353
1029
|
}
|
|
1354
|
-
/**
|
|
1355
|
-
* Returns the default schema for a plugin.
|
|
1356
|
-
*
|
|
1357
|
-
* This method generates a default schema object for the specified plugin. The schema includes
|
|
1358
|
-
* metadata such as the plugin's title, description, version, and author. It also defines the
|
|
1359
|
-
* properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
|
|
1360
|
-
*
|
|
1361
|
-
* @param {Plugin} plugin - The plugin for which the default schema is to be generated.
|
|
1362
|
-
* @returns {PlatformSchema} The default schema object for the plugin.
|
|
1363
|
-
*/
|
|
1364
1030
|
getDefaultSchema(plugin) {
|
|
1365
1031
|
return {
|
|
1366
1032
|
title: plugin.description,
|
|
@@ -1391,4 +1057,3 @@ export class PluginManager extends EventEmitter {
|
|
|
1391
1057
|
};
|
|
1392
1058
|
}
|
|
1393
1059
|
}
|
|
1394
|
-
//# sourceMappingURL=pluginManager.js.map
|