matterbridge 3.3.0 → 3.3.1-dev-20251007-4e5eaac
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 +29 -3
- package/README.md +9 -1
- package/dist/broadcastServer.js +73 -0
- package/dist/broadcastServerTypes.js +1 -0
- 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 +44 -98
- package/dist/devices/airConditioner.js +0 -57
- package/dist/devices/batteryStorage.js +1 -48
- package/dist/devices/cooktop.js +0 -55
- package/dist/devices/dishwasher.js +0 -57
- package/dist/devices/evse.js +10 -74
- package/dist/devices/export.js +0 -5
- package/dist/devices/extractorHood.js +0 -42
- package/dist/devices/heatPump.js +2 -50
- package/dist/devices/laundryDryer.js +3 -62
- package/dist/devices/laundryWasher.js +4 -70
- package/dist/devices/microwaveOven.js +5 -88
- package/dist/devices/oven.js +0 -85
- package/dist/devices/refrigerator.js +0 -102
- package/dist/devices/roboticVacuumCleaner.js +9 -100
- package/dist/devices/solarPower.js +0 -38
- package/dist/devices/speaker.js +0 -84
- package/dist/devices/temperatureControl.js +3 -25
- package/dist/devices/waterHeater.js +2 -82
- package/dist/dgram/coap.js +13 -126
- package/dist/dgram/dgram.js +2 -114
- package/dist/dgram/mb_coap.js +3 -41
- package/dist/dgram/mb_mdns.js +15 -80
- package/dist/dgram/mdns.js +137 -299
- package/dist/dgram/multicast.js +1 -62
- package/dist/dgram/unicast.js +0 -54
- package/dist/frontend.js +172 -604
- package/dist/frontendTypes.js +0 -45
- package/dist/helpers.js +4 -57
- package/dist/index.js +0 -41
- 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 +148 -877
- package/dist/matterbridgeAccessoryPlatform.js +0 -36
- package/dist/matterbridgeBehaviors.js +5 -65
- package/dist/matterbridgeDeviceTypes.js +17 -630
- package/dist/matterbridgeDynamicPlatform.js +0 -36
- package/dist/matterbridgeEndpoint.js +58 -1398
- package/dist/matterbridgeEndpointHelpers.js +12 -345
- package/dist/matterbridgePlatform.js +2 -341
- package/dist/matterbridgeTypes.js +0 -26
- package/dist/pluginManager.js +133 -254
- package/dist/shelly.js +11 -172
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -71
- package/dist/utils/colorUtils.js +2 -97
- package/dist/utils/commandLine.js +0 -54
- package/dist/utils/copyDirectory.js +1 -38
- package/dist/utils/createDirectory.js +0 -33
- package/dist/utils/createZip.js +2 -47
- package/dist/utils/deepCopy.js +0 -39
- package/dist/utils/deepEqual.js +1 -72
- package/dist/utils/error.js +0 -41
- package/dist/utils/export.js +0 -1
- package/dist/utils/hex.js +0 -124
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/jestHelpers.js +3 -153
- package/dist/utils/network.js +76 -129
- package/dist/utils/spawn.js +5 -75
- package/dist/utils/wait.js +8 -60
- package/frontend/build/assets/index.js +4 -7
- package/frontend/build/assets/vendor_mui.js +1 -1
- package/frontend/package.json +1 -1
- package/npm-shrinkwrap.json +44 -44
- package/package.json +2 -3
- package/dist/cli.d.ts +0 -26
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cliEmitter.d.ts +0 -34
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.js.map +0 -1
- package/dist/clusters/export.d.ts +0 -2
- package/dist/clusters/export.d.ts.map +0 -1
- package/dist/clusters/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -28
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -112
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/devices/airConditioner.d.ts +0 -98
- package/dist/devices/airConditioner.d.ts.map +0 -1
- package/dist/devices/airConditioner.js.map +0 -1
- package/dist/devices/batteryStorage.d.ts +0 -48
- package/dist/devices/batteryStorage.d.ts.map +0 -1
- package/dist/devices/batteryStorage.js.map +0 -1
- package/dist/devices/cooktop.d.ts +0 -60
- package/dist/devices/cooktop.d.ts.map +0 -1
- package/dist/devices/cooktop.js.map +0 -1
- package/dist/devices/dishwasher.d.ts +0 -71
- package/dist/devices/dishwasher.d.ts.map +0 -1
- package/dist/devices/dishwasher.js.map +0 -1
- package/dist/devices/evse.d.ts +0 -75
- package/dist/devices/evse.d.ts.map +0 -1
- package/dist/devices/evse.js.map +0 -1
- package/dist/devices/export.d.ts +0 -17
- package/dist/devices/export.d.ts.map +0 -1
- package/dist/devices/export.js.map +0 -1
- package/dist/devices/extractorHood.d.ts +0 -46
- package/dist/devices/extractorHood.d.ts.map +0 -1
- package/dist/devices/extractorHood.js.map +0 -1
- package/dist/devices/heatPump.d.ts +0 -47
- package/dist/devices/heatPump.d.ts.map +0 -1
- package/dist/devices/heatPump.js.map +0 -1
- package/dist/devices/laundryDryer.d.ts +0 -67
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -81
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.js.map +0 -1
- package/dist/devices/microwaveOven.d.ts +0 -168
- package/dist/devices/microwaveOven.d.ts.map +0 -1
- package/dist/devices/microwaveOven.js.map +0 -1
- package/dist/devices/oven.d.ts +0 -105
- package/dist/devices/oven.d.ts.map +0 -1
- package/dist/devices/oven.js.map +0 -1
- package/dist/devices/refrigerator.d.ts +0 -118
- package/dist/devices/refrigerator.d.ts.map +0 -1
- package/dist/devices/refrigerator.js.map +0 -1
- package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
- package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/devices/roboticVacuumCleaner.js.map +0 -1
- package/dist/devices/solarPower.d.ts +0 -40
- package/dist/devices/solarPower.d.ts.map +0 -1
- package/dist/devices/solarPower.js.map +0 -1
- package/dist/devices/speaker.d.ts +0 -87
- package/dist/devices/speaker.d.ts.map +0 -1
- package/dist/devices/speaker.js.map +0 -1
- package/dist/devices/temperatureControl.d.ts +0 -166
- package/dist/devices/temperatureControl.d.ts.map +0 -1
- package/dist/devices/temperatureControl.js.map +0 -1
- package/dist/devices/waterHeater.d.ts +0 -111
- package/dist/devices/waterHeater.d.ts.map +0 -1
- package/dist/devices/waterHeater.js.map +0 -1
- package/dist/dgram/coap.d.ts +0 -205
- package/dist/dgram/coap.d.ts.map +0 -1
- package/dist/dgram/coap.js.map +0 -1
- package/dist/dgram/dgram.d.ts +0 -141
- package/dist/dgram/dgram.d.ts.map +0 -1
- package/dist/dgram/dgram.js.map +0 -1
- package/dist/dgram/mb_coap.d.ts +0 -24
- package/dist/dgram/mb_coap.d.ts.map +0 -1
- package/dist/dgram/mb_coap.js.map +0 -1
- package/dist/dgram/mb_mdns.d.ts +0 -24
- package/dist/dgram/mb_mdns.d.ts.map +0 -1
- package/dist/dgram/mb_mdns.js.map +0 -1
- package/dist/dgram/mdns.d.ts +0 -290
- package/dist/dgram/mdns.d.ts.map +0 -1
- package/dist/dgram/mdns.js.map +0 -1
- package/dist/dgram/multicast.d.ts +0 -67
- package/dist/dgram/multicast.d.ts.map +0 -1
- package/dist/dgram/multicast.js.map +0 -1
- package/dist/dgram/unicast.d.ts +0 -56
- package/dist/dgram/unicast.d.ts.map +0 -1
- package/dist/dgram/unicast.js.map +0 -1
- package/dist/frontend.d.ts +0 -232
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/frontendTypes.d.ts +0 -514
- package/dist/frontendTypes.d.ts.map +0 -1
- package/dist/frontendTypes.js.map +0 -1
- package/dist/globalMatterbridge.d.ts +0 -59
- package/dist/globalMatterbridge.d.ts.map +0 -1
- package/dist/globalMatterbridge.js +0 -70
- 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 -430
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1747
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -761
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1534
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -407
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -402
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -201
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -270
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -174
- package/dist/shelly.d.ts.map +0 -1
- package/dist/shelly.js.map +0 -1
- package/dist/storage/export.d.ts +0 -2
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/update.d.ts +0 -75
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -99
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/commandLine.d.ts +0 -59
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -33
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createDirectory.d.ts +0 -34
- package/dist/utils/createDirectory.d.ts.map +0 -1
- package/dist/utils/createDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -39
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -32
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -54
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/error.d.ts +0 -44
- package/dist/utils/error.d.ts.map +0 -1
- package/dist/utils/error.js.map +0 -1
- package/dist/utils/export.d.ts +0 -13
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/hex.d.ts +0 -89
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -103
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/jestHelpers.d.ts +0 -137
- package/dist/utils/jestHelpers.d.ts.map +0 -1
- package/dist/utils/jestHelpers.js.map +0 -1
- package/dist/utils/network.d.ts +0 -84
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/spawn.d.ts +0 -34
- package/dist/utils/spawn.d.ts.map +0 -1
- package/dist/utils/spawn.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -54
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
package/dist/pluginManager.js
CHANGED
|
@@ -1,41 +1,59 @@
|
|
|
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.2.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
|
-
|
|
27
|
-
import { AnsiLogger, UNDERLINE, UNDERLINEOFF, BLUE, db, er, nf, nt, rs, wr } from 'node-ansi-logger';
|
|
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
|
-
import { logError } from './utils/error.js';
|
|
4
|
+
import { inspectError, logError } from './utils/error.js';
|
|
5
|
+
import { BroadcastServer } from './broadcastServer.js';
|
|
30
6
|
export class PluginManager extends EventEmitter {
|
|
31
7
|
_plugins = new Map();
|
|
32
8
|
matterbridge;
|
|
33
9
|
log;
|
|
10
|
+
server;
|
|
34
11
|
constructor(matterbridge) {
|
|
35
12
|
super();
|
|
36
13
|
this.matterbridge = matterbridge;
|
|
37
|
-
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4
|
|
14
|
+
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: matterbridge.log.logLevel });
|
|
38
15
|
this.log.debug('Matterbridge plugin manager starting...');
|
|
16
|
+
this.server = new BroadcastServer('plugins', this.log);
|
|
17
|
+
this.server.on('broadcast_message', this.msgHandler.bind(this));
|
|
18
|
+
this.log.debug('Matterbridge plugin manager started');
|
|
19
|
+
}
|
|
20
|
+
destroy() {
|
|
21
|
+
this.server.close();
|
|
22
|
+
}
|
|
23
|
+
async msgHandler(msg) {
|
|
24
|
+
if (!this.server.isWorkerRequest(msg, msg.type))
|
|
25
|
+
return;
|
|
26
|
+
if (!msg.id || (msg.dst !== 'all' && msg.dst !== 'plugins'))
|
|
27
|
+
return;
|
|
28
|
+
this.log.debug(`**Received request message ${CYAN}${msg.type}${db} from ${CYAN}${msg.src}${db}: ${debugStringify(msg)}${db}`);
|
|
29
|
+
switch (msg.type) {
|
|
30
|
+
case 'plugins_length':
|
|
31
|
+
this.server.respond({ ...msg, id: msg.id, response: { length: this.length } });
|
|
32
|
+
break;
|
|
33
|
+
case 'plugins_size':
|
|
34
|
+
this.server.respond({ ...msg, id: msg.id, response: { size: this.size } });
|
|
35
|
+
break;
|
|
36
|
+
case 'plugins_has':
|
|
37
|
+
this.server.respond({ ...msg, id: msg.id, response: { has: this.has(msg.params.name) } });
|
|
38
|
+
break;
|
|
39
|
+
case 'plugins_get':
|
|
40
|
+
this.server.respond({ ...msg, id: msg.id, response: { plugin: this.get(msg.params.name) } });
|
|
41
|
+
break;
|
|
42
|
+
case 'plugins_set':
|
|
43
|
+
this.server.respond({ ...msg, id: msg.id, response: { plugin: this.set(msg.params.plugin) } });
|
|
44
|
+
break;
|
|
45
|
+
case 'plugins_baseArray':
|
|
46
|
+
this.server.respond({ ...msg, id: msg.id, response: { plugins: this.baseArray() } });
|
|
47
|
+
break;
|
|
48
|
+
case 'plugins_install':
|
|
49
|
+
this.server.respond({ ...msg, id: msg.id, response: { packageName: msg.params.packageName, success: await this.install(msg.params.packageName) } });
|
|
50
|
+
break;
|
|
51
|
+
case 'plugins_uninstall':
|
|
52
|
+
this.server.respond({ ...msg, id: msg.id, response: { packageName: msg.params.packageName, success: await this.uninstall(msg.params.packageName) } });
|
|
53
|
+
break;
|
|
54
|
+
default:
|
|
55
|
+
this.log.warn(`Unknown broadcast message ${CYAN}${msg.type}${wr} from ${CYAN}${msg.src}${wr}`);
|
|
56
|
+
}
|
|
39
57
|
}
|
|
40
58
|
get length() {
|
|
41
59
|
return this._plugins.size;
|
|
@@ -59,6 +77,39 @@ export class PluginManager extends EventEmitter {
|
|
|
59
77
|
array() {
|
|
60
78
|
return Array.from(this._plugins.values());
|
|
61
79
|
}
|
|
80
|
+
baseArray() {
|
|
81
|
+
const basePlugins = [];
|
|
82
|
+
for (const plugin of this._plugins.values()) {
|
|
83
|
+
basePlugins.push({
|
|
84
|
+
name: plugin.name,
|
|
85
|
+
version: plugin.version,
|
|
86
|
+
description: plugin.description,
|
|
87
|
+
author: plugin.author,
|
|
88
|
+
path: plugin.path,
|
|
89
|
+
type: plugin.type,
|
|
90
|
+
latestVersion: plugin.latestVersion,
|
|
91
|
+
devVersion: plugin.devVersion,
|
|
92
|
+
homepage: plugin.homepage,
|
|
93
|
+
help: plugin.help,
|
|
94
|
+
changelog: plugin.changelog,
|
|
95
|
+
funding: plugin.funding,
|
|
96
|
+
locked: plugin.locked,
|
|
97
|
+
error: plugin.error,
|
|
98
|
+
enabled: plugin.enabled,
|
|
99
|
+
loaded: plugin.loaded,
|
|
100
|
+
started: plugin.started,
|
|
101
|
+
configured: plugin.configured,
|
|
102
|
+
restartRequired: plugin.restartRequired,
|
|
103
|
+
registeredDevices: plugin.registeredDevices,
|
|
104
|
+
configJson: plugin.configJson,
|
|
105
|
+
schemaJson: plugin.schemaJson,
|
|
106
|
+
hasWhiteList: plugin.hasWhiteList,
|
|
107
|
+
hasBlackList: plugin.hasBlackList,
|
|
108
|
+
matter: plugin.serverNode ? this.matterbridge.getServerNodeData(plugin.serverNode) : undefined,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return basePlugins;
|
|
112
|
+
}
|
|
62
113
|
[Symbol.iterator]() {
|
|
63
114
|
return this._plugins.values();
|
|
64
115
|
}
|
|
@@ -78,40 +129,21 @@ export class PluginManager extends EventEmitter {
|
|
|
78
129
|
set logLevel(logLevel) {
|
|
79
130
|
this.log.logLevel = logLevel;
|
|
80
131
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Loads registered plugins from storage.
|
|
83
|
-
*
|
|
84
|
-
* This method retrieves an array of registered plugins from the storage and converts it
|
|
85
|
-
* into a map where the plugin names are the keys and the plugin objects are the values.
|
|
86
|
-
*
|
|
87
|
-
* @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
|
|
88
|
-
*/
|
|
89
132
|
async loadFromStorage() {
|
|
90
133
|
if (!this.matterbridge.nodeContext) {
|
|
91
134
|
throw new Error('loadFromStorage: node context is not available.');
|
|
92
135
|
}
|
|
93
|
-
// Load the array from storage and convert it to a map
|
|
94
136
|
const pluginsArray = await this.matterbridge.nodeContext.get('plugins', []);
|
|
95
137
|
for (const plugin of pluginsArray)
|
|
96
138
|
this._plugins.set(plugin.name, plugin);
|
|
97
139
|
return pluginsArray;
|
|
98
140
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Loads registered plugins from storage.
|
|
101
|
-
*
|
|
102
|
-
* This method retrieves an array of registered plugins from the storage and converts it
|
|
103
|
-
* into a map where the plugin names are the keys and the plugin objects are the values.
|
|
104
|
-
*
|
|
105
|
-
* @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
|
|
106
|
-
*/
|
|
107
141
|
async saveToStorage() {
|
|
108
142
|
if (!this.matterbridge.nodeContext) {
|
|
109
143
|
throw new Error('loadFromStorage: node context is not available.');
|
|
110
144
|
}
|
|
111
|
-
// Convert the map to an array
|
|
112
145
|
const plugins = [];
|
|
113
|
-
const
|
|
114
|
-
for (const plugin of pluginArrayFromMap) {
|
|
146
|
+
for (const plugin of this.array()) {
|
|
115
147
|
plugins.push({
|
|
116
148
|
name: plugin.name,
|
|
117
149
|
path: plugin.path,
|
|
@@ -126,21 +158,13 @@ export class PluginManager extends EventEmitter {
|
|
|
126
158
|
this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
|
|
127
159
|
return plugins.length;
|
|
128
160
|
}
|
|
129
|
-
/**
|
|
130
|
-
* Resolves the name of a plugin by loading and parsing its package.json file.
|
|
131
|
-
*
|
|
132
|
-
* @param {string} pluginPath - The path to the plugin or the path to the plugin's package.json file.
|
|
133
|
-
* @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.
|
|
134
|
-
*/
|
|
135
161
|
async resolve(pluginPath) {
|
|
136
162
|
const { default: path } = await import('node:path');
|
|
137
163
|
const { promises } = await import('node:fs');
|
|
138
164
|
if (!pluginPath.endsWith('package.json'))
|
|
139
165
|
pluginPath = path.join(pluginPath, 'package.json');
|
|
140
|
-
// Resolve the package.json of the plugin
|
|
141
166
|
let packageJsonPath = path.resolve(pluginPath);
|
|
142
167
|
this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
|
|
143
|
-
// Check if the package.json file exists
|
|
144
168
|
try {
|
|
145
169
|
await promises.access(packageJsonPath);
|
|
146
170
|
}
|
|
@@ -150,9 +174,7 @@ export class PluginManager extends EventEmitter {
|
|
|
150
174
|
this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
|
|
151
175
|
}
|
|
152
176
|
try {
|
|
153
|
-
// Load the package.json of the plugin
|
|
154
177
|
const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
|
|
155
|
-
// Check for main issues
|
|
156
178
|
if (!packageJson.name) {
|
|
157
179
|
this.log.error(`Package.json name not found at ${packageJsonPath}`);
|
|
158
180
|
return null;
|
|
@@ -165,7 +187,6 @@ export class PluginManager extends EventEmitter {
|
|
|
165
187
|
this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
|
|
166
188
|
return null;
|
|
167
189
|
}
|
|
168
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
169
190
|
const checkForProjectChipPackages = (dependencies) => {
|
|
170
191
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
171
192
|
};
|
|
@@ -187,7 +208,6 @@ export class PluginManager extends EventEmitter {
|
|
|
187
208
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
188
209
|
return null;
|
|
189
210
|
}
|
|
190
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
191
211
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
192
212
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
193
213
|
};
|
|
@@ -217,12 +237,52 @@ export class PluginManager extends EventEmitter {
|
|
|
217
237
|
return null;
|
|
218
238
|
}
|
|
219
239
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
240
|
+
async install(packageName) {
|
|
241
|
+
const { spawnCommand } = await import('./utils/spawn.js');
|
|
242
|
+
try {
|
|
243
|
+
await spawnCommand(this.matterbridge, 'npm', ['install', '-g', packageName, '--omit=dev', '--verbose'], 'install', packageName);
|
|
244
|
+
this.matterbridge.restartRequired = true;
|
|
245
|
+
this.matterbridge.fixedRestartRequired = true;
|
|
246
|
+
packageName = packageName.replace(/@.*$/, '');
|
|
247
|
+
if (packageName !== 'matterbridge') {
|
|
248
|
+
if (!this.has(packageName))
|
|
249
|
+
await this.add(packageName);
|
|
250
|
+
const plugin = this.get(packageName);
|
|
251
|
+
if (plugin && !plugin.loaded)
|
|
252
|
+
await this.load(plugin);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
if (this.matterbridge.restartMode !== '') {
|
|
256
|
+
await this.matterbridge.shutdownProcess();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
inspectError(this.log, `Failed to install package ${plg}${packageName}${er}`, error);
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async uninstall(packageName) {
|
|
267
|
+
const { spawnCommand } = await import('./utils/spawn.js');
|
|
268
|
+
packageName = packageName.replace(/@.*$/, '');
|
|
269
|
+
if (packageName === 'matterbridge')
|
|
270
|
+
return false;
|
|
271
|
+
try {
|
|
272
|
+
if (this.has(packageName)) {
|
|
273
|
+
const plugin = this.get(packageName);
|
|
274
|
+
if (plugin && plugin.loaded)
|
|
275
|
+
await this.shutdown(plugin, 'Matterbridge is uninstalling the plugin');
|
|
276
|
+
await this.remove(packageName);
|
|
277
|
+
}
|
|
278
|
+
await spawnCommand(this.matterbridge, 'npm', ['uninstall', '-g', packageName, '--verbose'], 'uninstall', packageName);
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
inspectError(this.log, `Failed to uninstall package ${plg}${packageName}${er}`, error);
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
226
286
|
getAuthor(packageJson) {
|
|
227
287
|
if (packageJson.author && typeof packageJson.author === 'string')
|
|
228
288
|
return packageJson.author;
|
|
@@ -230,12 +290,6 @@ export class PluginManager extends EventEmitter {
|
|
|
230
290
|
return packageJson.author.name;
|
|
231
291
|
return 'Unknown author';
|
|
232
292
|
}
|
|
233
|
-
/**
|
|
234
|
-
* Get the homepage of a plugin from its package.json.
|
|
235
|
-
*
|
|
236
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
237
|
-
* @returns {string | undefined} The homepage of the plugin, or undefined if not found.
|
|
238
|
-
*/
|
|
239
293
|
getHomepage(packageJson) {
|
|
240
294
|
if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
|
|
241
295
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
@@ -244,14 +298,7 @@ export class PluginManager extends EventEmitter {
|
|
|
244
298
|
return packageJson.repository.url.replace('git+', '').replace('.git', '');
|
|
245
299
|
}
|
|
246
300
|
}
|
|
247
|
-
/**
|
|
248
|
-
* Get the help URL of a plugin from its package.json.
|
|
249
|
-
*
|
|
250
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
251
|
-
* @returns {string | undefined} The URL to the help page or to the README file, or undefined if not found.
|
|
252
|
-
*/
|
|
253
301
|
getHelp(packageJson) {
|
|
254
|
-
// If there's a help field that looks like a URL, return it.
|
|
255
302
|
if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
|
|
256
303
|
return packageJson.help;
|
|
257
304
|
}
|
|
@@ -262,14 +309,7 @@ export class PluginManager extends EventEmitter {
|
|
|
262
309
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
263
310
|
}
|
|
264
311
|
}
|
|
265
|
-
/**
|
|
266
|
-
* Get the changelog URL of a plugin from its package.json.
|
|
267
|
-
*
|
|
268
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
269
|
-
* @returns {string | undefined} The URL to the CHANGELOG file, or undefined if not found.
|
|
270
|
-
*/
|
|
271
312
|
getChangelog(packageJson) {
|
|
272
|
-
// If there's a changelog field that looks like a URL, return it.
|
|
273
313
|
if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
|
|
274
314
|
return packageJson.changelog;
|
|
275
315
|
}
|
|
@@ -280,13 +320,6 @@ export class PluginManager extends EventEmitter {
|
|
|
280
320
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
281
321
|
}
|
|
282
322
|
}
|
|
283
|
-
/**
|
|
284
|
-
* Get the first funding URL(s) of a plugin from its package.json.
|
|
285
|
-
*
|
|
286
|
-
* @param {Record<string, any>} packageJson - The package.json object of the plugin.
|
|
287
|
-
* @returns {string | undefined} The first funding URLs, or undefined if not found.
|
|
288
|
-
*/
|
|
289
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
290
323
|
getFunding(packageJson) {
|
|
291
324
|
const funding = packageJson.funding;
|
|
292
325
|
if (!funding)
|
|
@@ -295,25 +328,16 @@ export class PluginManager extends EventEmitter {
|
|
|
295
328
|
return;
|
|
296
329
|
if (typeof funding === 'string' && funding.startsWith('http'))
|
|
297
330
|
return funding;
|
|
298
|
-
// Normalize funding into an array.
|
|
299
331
|
const fundingEntries = Array.isArray(funding) ? funding : [funding];
|
|
300
332
|
for (const entry of fundingEntries) {
|
|
301
333
|
if (entry && typeof entry === 'string' && entry.startsWith('http')) {
|
|
302
|
-
// If the funding entry is a string, assume it is a URL.
|
|
303
334
|
return entry;
|
|
304
335
|
}
|
|
305
336
|
else if (entry && typeof entry === 'object' && typeof entry.url === 'string' && entry.url.startsWith('http')) {
|
|
306
|
-
// If it's an object with a 'url' property, use that.
|
|
307
337
|
return entry.url;
|
|
308
338
|
}
|
|
309
339
|
}
|
|
310
340
|
}
|
|
311
|
-
/**
|
|
312
|
-
* Loads and parses the plugin package.json and returns it.
|
|
313
|
-
*
|
|
314
|
-
* @param {RegisteredPlugin} plugin - The plugin to load the package from.
|
|
315
|
-
* @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.
|
|
316
|
-
*/
|
|
317
341
|
async parse(plugin) {
|
|
318
342
|
const { promises } = await import('node:fs');
|
|
319
343
|
try {
|
|
@@ -343,7 +367,6 @@ export class PluginManager extends EventEmitter {
|
|
|
343
367
|
plugin.funding = this.getFunding(packageJson);
|
|
344
368
|
if (!plugin.type)
|
|
345
369
|
this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
|
|
346
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
347
370
|
const checkForProjectChipPackages = (dependencies) => {
|
|
348
371
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
349
372
|
};
|
|
@@ -365,7 +388,6 @@ export class PluginManager extends EventEmitter {
|
|
|
365
388
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
366
389
|
return null;
|
|
367
390
|
}
|
|
368
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
369
391
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
370
392
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
371
393
|
};
|
|
@@ -395,16 +417,6 @@ export class PluginManager extends EventEmitter {
|
|
|
395
417
|
return null;
|
|
396
418
|
}
|
|
397
419
|
}
|
|
398
|
-
/**
|
|
399
|
-
* Enables a plugin by its name or path.
|
|
400
|
-
*
|
|
401
|
-
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
402
|
-
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
403
|
-
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
404
|
-
*
|
|
405
|
-
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
406
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
407
|
-
*/
|
|
408
420
|
async enable(nameOrPath) {
|
|
409
421
|
const { promises } = await import('node:fs');
|
|
410
422
|
if (!nameOrPath)
|
|
@@ -440,16 +452,6 @@ export class PluginManager extends EventEmitter {
|
|
|
440
452
|
return null;
|
|
441
453
|
}
|
|
442
454
|
}
|
|
443
|
-
/**
|
|
444
|
-
* Enables a plugin by its name or path.
|
|
445
|
-
*
|
|
446
|
-
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
447
|
-
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
448
|
-
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
449
|
-
*
|
|
450
|
-
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
451
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
452
|
-
*/
|
|
453
455
|
async disable(nameOrPath) {
|
|
454
456
|
const { promises } = await import('node:fs');
|
|
455
457
|
if (!nameOrPath)
|
|
@@ -485,16 +487,6 @@ export class PluginManager extends EventEmitter {
|
|
|
485
487
|
return null;
|
|
486
488
|
}
|
|
487
489
|
}
|
|
488
|
-
/**
|
|
489
|
-
* Removes a plugin by its name or path.
|
|
490
|
-
*
|
|
491
|
-
* This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
|
|
492
|
-
* It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
|
|
493
|
-
* the plugin's `package.json` file to retrieve its name and remove it.
|
|
494
|
-
*
|
|
495
|
-
* @param {string} nameOrPath - The name or path of the plugin to remove.
|
|
496
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
|
|
497
|
-
*/
|
|
498
490
|
async remove(nameOrPath) {
|
|
499
491
|
const { promises } = await import('node:fs');
|
|
500
492
|
if (!nameOrPath)
|
|
@@ -530,17 +522,6 @@ export class PluginManager extends EventEmitter {
|
|
|
530
522
|
return null;
|
|
531
523
|
}
|
|
532
524
|
}
|
|
533
|
-
/**
|
|
534
|
-
* Adds a plugin by its name or path.
|
|
535
|
-
*
|
|
536
|
-
* This method adds a plugin to the plugins map and saves the updated plugin information to storage.
|
|
537
|
-
* It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
|
|
538
|
-
* registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
|
|
539
|
-
* and saves the updated plugin information to storage.
|
|
540
|
-
*
|
|
541
|
-
* @param {string} nameOrPath - The name or path of the plugin to add.
|
|
542
|
-
* @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
|
|
543
|
-
*/
|
|
544
525
|
async add(nameOrPath) {
|
|
545
526
|
const { promises } = await import('node:fs');
|
|
546
527
|
if (!nameOrPath)
|
|
@@ -564,28 +545,22 @@ export class PluginManager extends EventEmitter {
|
|
|
564
545
|
version: packageJson.version,
|
|
565
546
|
description: packageJson.description,
|
|
566
547
|
author: this.getAuthor(packageJson),
|
|
548
|
+
homepage: this.getHomepage(packageJson),
|
|
549
|
+
help: this.getHelp(packageJson),
|
|
550
|
+
changelog: this.getChangelog(packageJson),
|
|
551
|
+
funding: this.getFunding(packageJson),
|
|
567
552
|
});
|
|
568
553
|
this.log.info(`Added plugin ${plg}${packageJson.name}${nf}`);
|
|
569
554
|
await this.saveToStorage();
|
|
570
555
|
const plugin = this._plugins.get(packageJson.name);
|
|
571
556
|
this.emit('added', packageJson.name);
|
|
572
|
-
|
|
573
|
-
return plugin || null;
|
|
557
|
+
return plugin;
|
|
574
558
|
}
|
|
575
559
|
catch (err) {
|
|
576
560
|
logError(this.log, `Failed to parse package.json of plugin ${plg}${nameOrPath}${er}`, err);
|
|
577
561
|
return null;
|
|
578
562
|
}
|
|
579
563
|
}
|
|
580
|
-
/**
|
|
581
|
-
* Loads a plugin and returns the corresponding MatterbridgePlatform instance.
|
|
582
|
-
*
|
|
583
|
-
* @param {RegisteredPlugin} plugin - The plugin to load.
|
|
584
|
-
* @param {boolean} start - Optional flag indicating whether to start the plugin after loading. Default is false.
|
|
585
|
-
* @param {string} message - Optional message to pass to the plugin when starting.
|
|
586
|
-
* @param {boolean} configure - Optional flag indicating whether to configure the plugin after loading. Default is false.
|
|
587
|
-
* @returns {Promise<MatterbridgePlatform | undefined>} A Promise that resolves to the loaded MatterbridgePlatform instance or undefined.
|
|
588
|
-
*/
|
|
589
564
|
async load(plugin, start = false, message = '', configure = false) {
|
|
590
565
|
const { promises } = await import('node:fs');
|
|
591
566
|
const { default: path } = await import('node:path');
|
|
@@ -599,20 +574,15 @@ export class PluginManager extends EventEmitter {
|
|
|
599
574
|
}
|
|
600
575
|
this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
|
|
601
576
|
try {
|
|
602
|
-
// Load the package.json of the plugin
|
|
603
577
|
const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
|
|
604
|
-
// Resolve the main module path relative to package.json
|
|
605
578
|
const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
|
|
606
|
-
// Dynamically import the plugin
|
|
607
579
|
const { pathToFileURL } = await import('node:url');
|
|
608
580
|
const pluginUrl = pathToFileURL(pluginEntry);
|
|
609
581
|
this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
610
582
|
const pluginInstance = await import(pluginUrl.href);
|
|
611
583
|
this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
612
|
-
// Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
|
|
613
584
|
if (pluginInstance.default) {
|
|
614
585
|
const config = await this.loadConfig(plugin);
|
|
615
|
-
// 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.
|
|
616
586
|
plugin.name = packageJson.name;
|
|
617
587
|
plugin.description = packageJson.description ?? 'No description';
|
|
618
588
|
plugin.version = packageJson.version;
|
|
@@ -621,7 +591,7 @@ export class PluginManager extends EventEmitter {
|
|
|
621
591
|
plugin.schemaJson = await this.loadSchema(plugin);
|
|
622
592
|
config.name = plugin.name;
|
|
623
593
|
config.version = packageJson.version;
|
|
624
|
-
const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4
|
|
594
|
+
const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
|
|
625
595
|
const platform = pluginInstance.default(this.matterbridge, log, config);
|
|
626
596
|
config.type = platform.type;
|
|
627
597
|
platform.name = packageJson.name;
|
|
@@ -639,7 +609,7 @@ export class PluginManager extends EventEmitter {
|
|
|
639
609
|
plugin.platform = platform;
|
|
640
610
|
plugin.loaded = true;
|
|
641
611
|
plugin.registeredDevices = 0;
|
|
642
|
-
await this.saveToStorage();
|
|
612
|
+
await this.saveToStorage();
|
|
643
613
|
this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
|
|
644
614
|
this.emit('loaded', plugin.name);
|
|
645
615
|
if (start)
|
|
@@ -659,14 +629,6 @@ export class PluginManager extends EventEmitter {
|
|
|
659
629
|
}
|
|
660
630
|
return undefined;
|
|
661
631
|
}
|
|
662
|
-
/**
|
|
663
|
-
* Starts a plugin.
|
|
664
|
-
*
|
|
665
|
-
* @param {RegisteredPlugin} plugin - The plugin to start.
|
|
666
|
-
* @param {string} [message] - Optional message to pass to the plugin's onStart method.
|
|
667
|
-
* @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
|
|
668
|
-
* @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
|
|
669
|
-
*/
|
|
670
632
|
async start(plugin, message, configure = false) {
|
|
671
633
|
if (!plugin.loaded) {
|
|
672
634
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -697,12 +659,6 @@ export class PluginManager extends EventEmitter {
|
|
|
697
659
|
}
|
|
698
660
|
return undefined;
|
|
699
661
|
}
|
|
700
|
-
/**
|
|
701
|
-
* Configures a plugin.
|
|
702
|
-
*
|
|
703
|
-
* @param {RegisteredPlugin} plugin - The plugin to configure.
|
|
704
|
-
* @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
|
|
705
|
-
*/
|
|
706
662
|
async configure(plugin) {
|
|
707
663
|
if (!plugin.loaded) {
|
|
708
664
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -734,18 +690,6 @@ export class PluginManager extends EventEmitter {
|
|
|
734
690
|
}
|
|
735
691
|
return undefined;
|
|
736
692
|
}
|
|
737
|
-
/**
|
|
738
|
-
* Shuts down a plugin.
|
|
739
|
-
*
|
|
740
|
-
* This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
|
|
741
|
-
* It logs the shutdown process and optionally removes all devices associated with the plugin.
|
|
742
|
-
*
|
|
743
|
-
* @param {RegisteredPlugin} plugin - The plugin to shut down.
|
|
744
|
-
* @param {string} [reason] - The reason for shutting down the plugin.
|
|
745
|
-
* @param {boolean} [removeAllDevices] - Whether to remove all devices associated with the plugin.
|
|
746
|
-
* @param {boolean} [force] - Whether to force the shutdown even if the plugin is not loaded or started.
|
|
747
|
-
* @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
|
|
748
|
-
*/
|
|
749
693
|
async shutdown(plugin, reason, removeAllDevices = false, force = false) {
|
|
750
694
|
this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
|
|
751
695
|
if (!plugin.loaded) {
|
|
@@ -788,15 +732,6 @@ export class PluginManager extends EventEmitter {
|
|
|
788
732
|
}
|
|
789
733
|
return undefined;
|
|
790
734
|
}
|
|
791
|
-
/**
|
|
792
|
-
* Loads the configuration for a plugin.
|
|
793
|
-
* If the configuration file exists, it reads the file and returns the parsed JSON data.
|
|
794
|
-
* If the configuration file does not exist, it creates a new file with default configuration and returns it.
|
|
795
|
-
* If any error occurs during file access or creation, it logs an error and return un empty config.
|
|
796
|
-
*
|
|
797
|
-
* @param {RegisteredPlugin} plugin - The plugin for which to load the configuration.
|
|
798
|
-
* @returns {Promise<PlatformConfig>} A promise that resolves to the loaded or created configuration.
|
|
799
|
-
*/
|
|
800
735
|
async loadConfig(plugin) {
|
|
801
736
|
const { default: path } = await import('node:path');
|
|
802
737
|
const { promises } = await import('node:fs');
|
|
@@ -808,8 +743,6 @@ export class PluginManager extends EventEmitter {
|
|
|
808
743
|
const data = await promises.readFile(configFile, 'utf8');
|
|
809
744
|
const config = JSON.parse(data);
|
|
810
745
|
this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
811
|
-
// this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
812
|
-
// The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
|
|
813
746
|
config.name = plugin.name;
|
|
814
747
|
config.type = plugin.type;
|
|
815
748
|
if (config.debug === undefined)
|
|
@@ -831,8 +764,6 @@ export class PluginManager extends EventEmitter {
|
|
|
831
764
|
}
|
|
832
765
|
catch (_err) {
|
|
833
766
|
this.log.debug(`Default config file ${defaultConfigFile} for plugin ${plg}${plugin.name}${db} does not exist, creating new config file...`);
|
|
834
|
-
// TODO: Remove this when all these plugins have their own default config file
|
|
835
|
-
// istanbul ignore next if
|
|
836
767
|
if (plugin.name === 'matterbridge-zigbee2mqtt')
|
|
837
768
|
config = zigbee2mqtt_config;
|
|
838
769
|
else if (plugin.name === 'matterbridge-somfy-tahoma')
|
|
@@ -845,7 +776,6 @@ export class PluginManager extends EventEmitter {
|
|
|
845
776
|
try {
|
|
846
777
|
await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
847
778
|
this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
848
|
-
// this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
849
779
|
return config;
|
|
850
780
|
}
|
|
851
781
|
catch (err) {
|
|
@@ -859,19 +789,6 @@ export class PluginManager extends EventEmitter {
|
|
|
859
789
|
}
|
|
860
790
|
}
|
|
861
791
|
}
|
|
862
|
-
/**
|
|
863
|
-
* Saves the configuration of a plugin to a file.
|
|
864
|
-
*
|
|
865
|
-
* This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
866
|
-
* If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
|
|
867
|
-
* is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
|
|
868
|
-
* the error and rejects the promise.
|
|
869
|
-
*
|
|
870
|
-
* @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
|
|
871
|
-
* @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
|
|
872
|
-
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
|
|
873
|
-
* @throws {Error} If the plugin's configuration is not found.
|
|
874
|
-
*/
|
|
875
792
|
async saveConfigFromPlugin(plugin, restartRequired = false) {
|
|
876
793
|
const { default: path } = await import('node:path');
|
|
877
794
|
const { promises } = await import('node:fs');
|
|
@@ -886,7 +803,6 @@ export class PluginManager extends EventEmitter {
|
|
|
886
803
|
if (restartRequired)
|
|
887
804
|
plugin.restartRequired = true;
|
|
888
805
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
889
|
-
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
|
|
890
806
|
return Promise.resolve();
|
|
891
807
|
}
|
|
892
808
|
catch (err) {
|
|
@@ -894,20 +810,6 @@ export class PluginManager extends EventEmitter {
|
|
|
894
810
|
return Promise.reject(err);
|
|
895
811
|
}
|
|
896
812
|
}
|
|
897
|
-
/**
|
|
898
|
-
* Saves the configuration of a plugin from a JSON object to a file.
|
|
899
|
-
*
|
|
900
|
-
* This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
901
|
-
* It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
|
|
902
|
-
* the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
|
|
903
|
-
* successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
|
|
904
|
-
* during the file write operation, it logs the error and returns.
|
|
905
|
-
*
|
|
906
|
-
* @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
|
|
907
|
-
* @param {PlatformConfig} config - The configuration data to be saved.
|
|
908
|
-
* @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
|
|
909
|
-
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
|
|
910
|
-
*/
|
|
911
813
|
async saveConfigFromJson(plugin, config, restartRequired = false) {
|
|
912
814
|
const { default: path } = await import('node:path');
|
|
913
815
|
const { promises } = await import('node:fs');
|
|
@@ -926,23 +828,12 @@ export class PluginManager extends EventEmitter {
|
|
|
926
828
|
plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
|
|
927
829
|
}
|
|
928
830
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
929
|
-
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
930
831
|
}
|
|
931
832
|
catch (err) {
|
|
932
833
|
logError(this.log, `Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}`, err);
|
|
933
834
|
return;
|
|
934
835
|
}
|
|
935
836
|
}
|
|
936
|
-
/**
|
|
937
|
-
* Loads the schema for a plugin.
|
|
938
|
-
*
|
|
939
|
-
* This method attempts to load the schema file for the specified plugin. If the schema file is found,
|
|
940
|
-
* it reads and parses the file, updates the schema's title and description, and logs the process.
|
|
941
|
-
* If the schema file is not found, it logs the event and loads a default schema for the plugin.
|
|
942
|
-
*
|
|
943
|
-
* @param {RegisteredPlugin} plugin - The plugin whose schema is to be loaded.
|
|
944
|
-
* @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
|
|
945
|
-
*/
|
|
946
837
|
async loadSchema(plugin) {
|
|
947
838
|
const { promises } = await import('node:fs');
|
|
948
839
|
const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
|
|
@@ -953,7 +844,6 @@ export class PluginManager extends EventEmitter {
|
|
|
953
844
|
schema.title = plugin.description;
|
|
954
845
|
schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
|
|
955
846
|
this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
956
|
-
// this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
|
|
957
847
|
return schema;
|
|
958
848
|
}
|
|
959
849
|
catch (_err) {
|
|
@@ -961,16 +851,6 @@ export class PluginManager extends EventEmitter {
|
|
|
961
851
|
return this.getDefaultSchema(plugin);
|
|
962
852
|
}
|
|
963
853
|
}
|
|
964
|
-
/**
|
|
965
|
-
* Returns the default schema for a plugin.
|
|
966
|
-
*
|
|
967
|
-
* This method generates a default schema object for the specified plugin. The schema includes
|
|
968
|
-
* metadata such as the plugin's title, description, version, and author. It also defines the
|
|
969
|
-
* properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
|
|
970
|
-
*
|
|
971
|
-
* @param {RegisteredPlugin} plugin - The plugin for which the default schema is to be generated.
|
|
972
|
-
* @returns {PlatformSchema} The default schema object for the plugin.
|
|
973
|
-
*/
|
|
974
854
|
getDefaultSchema(plugin) {
|
|
975
855
|
return {
|
|
976
856
|
title: plugin.description,
|
|
@@ -1001,4 +881,3 @@ export class PluginManager extends EventEmitter {
|
|
|
1001
881
|
};
|
|
1002
882
|
}
|
|
1003
883
|
}
|
|
1004
|
-
//# sourceMappingURL=pluginManager.js.map
|