matterbridge 3.3.3 → 3.3.4-dev-20251020-4d2dd49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/broadcastServer.js +1 -86
- package/dist/broadcastServerTypes.js +0 -24
- package/dist/cli.js +110 -444
- package/dist/cliEmitter.js +0 -37
- package/dist/cliHistory.js +15 -95
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -24
- package/dist/deviceManager.js +1 -124
- 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 +34 -413
- package/dist/frontendTypes.js +0 -45
- package/dist/helpers.js +0 -53
- package/dist/index.js +0 -25
- 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 +51 -873
- package/dist/matterbridgeAccessoryPlatform.js +0 -36
- package/dist/matterbridgeBehaviors.js +5 -71
- package/dist/matterbridgeDeviceTypes.js +17 -630
- package/dist/matterbridgeDynamicPlatform.js +0 -36
- package/dist/matterbridgeEndpoint.js +58 -1412
- package/dist/matterbridgeEndpointHelpers.js +10 -368
- package/dist/matterbridgePlatform.js +1 -341
- package/dist/matterbridgeTypes.js +0 -26
- package/dist/pluginManager.js +3 -325
- 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 +6 -55
- 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/inspector.js +200 -0
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/jestHelpers.js +3 -153
- package/dist/utils/network.js +5 -108
- package/dist/utils/spawn.js +0 -71
- package/dist/utils/tracker.js +229 -0
- package/dist/utils/wait.js +8 -60
- package/frontend/build/assets/index.js +4 -4
- package/frontend/build/assets/vendor_mdi.js +1 -1
- package/frontend/package.json +1 -1
- package/npm-shrinkwrap.json +44 -44
- package/package.json +2 -3
- package/dist/broadcastServer.d.ts +0 -105
- package/dist/broadcastServer.d.ts.map +0 -1
- package/dist/broadcastServer.js.map +0 -1
- package/dist/broadcastServerTypes.d.ts +0 -719
- package/dist/broadcastServerTypes.d.ts.map +0 -1
- package/dist/broadcastServerTypes.js.map +0 -1
- 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 -50
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.js.map +0 -1
- package/dist/cliHistory.d.ts +0 -74
- 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 -117
- 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 -235
- 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 -469
- 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 -2399
- 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 -1545
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -560
- 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 -209
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -353
- 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 -115
- 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/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,50 +1,17 @@
|
|
|
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
|
-
// 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 { BroadcastServer } from './broadcastServer.js';
|
|
31
|
-
/**
|
|
32
|
-
* Manages Matterbridge plugins.
|
|
33
|
-
*/
|
|
34
6
|
export class PluginManager extends EventEmitter {
|
|
35
7
|
_plugins = new Map();
|
|
36
8
|
matterbridge;
|
|
37
9
|
log;
|
|
38
10
|
server;
|
|
39
|
-
/**
|
|
40
|
-
* Creates an instance of PluginManager.
|
|
41
|
-
*
|
|
42
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
43
|
-
*/
|
|
44
11
|
constructor(matterbridge) {
|
|
45
12
|
super();
|
|
46
13
|
this.matterbridge = matterbridge;
|
|
47
|
-
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4
|
|
14
|
+
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: matterbridge.log.logLevel });
|
|
48
15
|
this.log.debug('Matterbridge plugin manager starting...');
|
|
49
16
|
this.server = new BroadcastServer('plugins', this.log);
|
|
50
17
|
this.server.on('broadcast_message', this.msgHandler.bind(this));
|
|
@@ -86,69 +53,28 @@ export class PluginManager extends EventEmitter {
|
|
|
86
53
|
}
|
|
87
54
|
}
|
|
88
55
|
}
|
|
89
|
-
/**
|
|
90
|
-
* Gets the number of plugins.
|
|
91
|
-
*
|
|
92
|
-
* @returns {number} The number of plugins.
|
|
93
|
-
*/
|
|
94
56
|
get length() {
|
|
95
57
|
return this._plugins.size;
|
|
96
58
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Gets the number of plugins.
|
|
99
|
-
*
|
|
100
|
-
* @returns {number} The number of plugins.
|
|
101
|
-
*/
|
|
102
59
|
get size() {
|
|
103
60
|
return this._plugins.size;
|
|
104
61
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Checks if a plugin with the specified name exists.
|
|
107
|
-
*
|
|
108
|
-
* @param {string} name - The name of the plugin.
|
|
109
|
-
* @returns {boolean} True if the plugin exists, false otherwise.
|
|
110
|
-
*/
|
|
111
62
|
has(name) {
|
|
112
63
|
return this._plugins.has(name);
|
|
113
64
|
}
|
|
114
|
-
/**
|
|
115
|
-
* Gets a plugin by its name.
|
|
116
|
-
*
|
|
117
|
-
* @param {string} name - The name of the plugin.
|
|
118
|
-
* @returns {Plugin | undefined} The plugin, or undefined if not found.
|
|
119
|
-
*/
|
|
120
65
|
get(name) {
|
|
121
66
|
return this._plugins.get(name);
|
|
122
67
|
}
|
|
123
|
-
/**
|
|
124
|
-
* Adds a plugin to the manager.
|
|
125
|
-
*
|
|
126
|
-
* @param {Plugin} plugin - The plugin to add.
|
|
127
|
-
* @returns {Plugin} The added plugin.
|
|
128
|
-
*/
|
|
129
68
|
set(plugin) {
|
|
130
69
|
this._plugins.set(plugin.name, plugin);
|
|
131
70
|
return plugin;
|
|
132
71
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Clears all plugins from the manager.
|
|
135
|
-
*/
|
|
136
72
|
clear() {
|
|
137
73
|
this._plugins.clear();
|
|
138
74
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Gets an array of all plugins.
|
|
141
|
-
*
|
|
142
|
-
* @returns {Plugin[]} An array of all plugins.
|
|
143
|
-
*/
|
|
144
75
|
array() {
|
|
145
76
|
return Array.from(this._plugins.values());
|
|
146
77
|
}
|
|
147
|
-
/**
|
|
148
|
-
* Gets an array of all plugins suitable for serialization.
|
|
149
|
-
*
|
|
150
|
-
* @returns {ApiPlugin[]} An array of all plugins.
|
|
151
|
-
*/
|
|
152
78
|
baseArray() {
|
|
153
79
|
const basePlugins = [];
|
|
154
80
|
for (const plugin of this._plugins.values()) {
|
|
@@ -182,20 +108,9 @@ export class PluginManager extends EventEmitter {
|
|
|
182
108
|
}
|
|
183
109
|
return basePlugins;
|
|
184
110
|
}
|
|
185
|
-
/**
|
|
186
|
-
* Gets an iterator for the plugins.
|
|
187
|
-
*
|
|
188
|
-
* @returns {IterableIterator<Plugin>} An iterator for the plugins.
|
|
189
|
-
*/
|
|
190
111
|
[Symbol.iterator]() {
|
|
191
112
|
return this._plugins.values();
|
|
192
113
|
}
|
|
193
|
-
/**
|
|
194
|
-
* Executes a provided function once for each plugin.
|
|
195
|
-
*
|
|
196
|
-
* @param {Function} callback - The function to execute for each plugin.
|
|
197
|
-
* @returns {Promise<void>}
|
|
198
|
-
*/
|
|
199
114
|
async forEach(callback) {
|
|
200
115
|
if (this.size === 0)
|
|
201
116
|
return;
|
|
@@ -209,45 +124,22 @@ export class PluginManager extends EventEmitter {
|
|
|
209
124
|
});
|
|
210
125
|
await Promise.all(tasks);
|
|
211
126
|
}
|
|
212
|
-
/**
|
|
213
|
-
* Sets the log level for the plugin manager.
|
|
214
|
-
*
|
|
215
|
-
* @param {LogLevel} logLevel - The log level to set.
|
|
216
|
-
*/
|
|
217
127
|
set logLevel(logLevel) {
|
|
218
128
|
this.log.logLevel = logLevel;
|
|
219
129
|
}
|
|
220
|
-
/**
|
|
221
|
-
* Loads registered plugins from storage.
|
|
222
|
-
*
|
|
223
|
-
* This method retrieves an array of registered plugins from the storage and converts it
|
|
224
|
-
* into a map where the plugin names are the keys and the plugin objects are the values.
|
|
225
|
-
*
|
|
226
|
-
* @returns {Promise<Plugin[]>} A promise that resolves to an array of registered plugins.
|
|
227
|
-
*/
|
|
228
130
|
async loadFromStorage() {
|
|
229
131
|
if (!this.matterbridge.nodeContext) {
|
|
230
132
|
throw new Error('loadFromStorage: node context is not available.');
|
|
231
133
|
}
|
|
232
|
-
// Load the array from storage and convert it to a map
|
|
233
134
|
const pluginsArray = await this.matterbridge.nodeContext.get('plugins', []);
|
|
234
135
|
for (const plugin of pluginsArray)
|
|
235
136
|
this._plugins.set(plugin.name, plugin);
|
|
236
137
|
return pluginsArray;
|
|
237
138
|
}
|
|
238
|
-
/**
|
|
239
|
-
* Loads registered plugins from storage.
|
|
240
|
-
*
|
|
241
|
-
* This method retrieves an array of registered plugins from the storage and converts it
|
|
242
|
-
* into a map where the plugin names are the keys and the plugin objects are the values.
|
|
243
|
-
*
|
|
244
|
-
* @returns {Promise<Plugin[]>} A promise that resolves to an array of registered plugins.
|
|
245
|
-
*/
|
|
246
139
|
async saveToStorage() {
|
|
247
140
|
if (!this.matterbridge.nodeContext) {
|
|
248
141
|
throw new Error('loadFromStorage: node context is not available.');
|
|
249
142
|
}
|
|
250
|
-
// Convert the map to an array
|
|
251
143
|
const plugins = [];
|
|
252
144
|
for (const plugin of this.array()) {
|
|
253
145
|
plugins.push({
|
|
@@ -264,21 +156,13 @@ export class PluginManager extends EventEmitter {
|
|
|
264
156
|
this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
|
|
265
157
|
return plugins.length;
|
|
266
158
|
}
|
|
267
|
-
/**
|
|
268
|
-
* Resolves the name of a plugin by loading and parsing its package.json file.
|
|
269
|
-
*
|
|
270
|
-
* @param {string} pluginPath - The path to the plugin or the path to the plugin's package.json file.
|
|
271
|
-
* @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.
|
|
272
|
-
*/
|
|
273
159
|
async resolve(pluginPath) {
|
|
274
160
|
const { default: path } = await import('node:path');
|
|
275
161
|
const { promises } = await import('node:fs');
|
|
276
162
|
if (!pluginPath.endsWith('package.json'))
|
|
277
163
|
pluginPath = path.join(pluginPath, 'package.json');
|
|
278
|
-
// Resolve the package.json of the plugin
|
|
279
164
|
let packageJsonPath = path.resolve(pluginPath);
|
|
280
165
|
this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
|
|
281
|
-
// Check if the package.json file exists
|
|
282
166
|
try {
|
|
283
167
|
await promises.access(packageJsonPath);
|
|
284
168
|
}
|
|
@@ -288,9 +172,7 @@ export class PluginManager extends EventEmitter {
|
|
|
288
172
|
this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
|
|
289
173
|
}
|
|
290
174
|
try {
|
|
291
|
-
// Load the package.json of the plugin
|
|
292
175
|
const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
|
|
293
|
-
// Check for main issues
|
|
294
176
|
if (!packageJson.name) {
|
|
295
177
|
this.log.error(`Package.json name not found at ${packageJsonPath}`);
|
|
296
178
|
return null;
|
|
@@ -303,7 +185,6 @@ export class PluginManager extends EventEmitter {
|
|
|
303
185
|
this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
|
|
304
186
|
return null;
|
|
305
187
|
}
|
|
306
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
307
188
|
const checkForProjectChipPackages = (dependencies) => {
|
|
308
189
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
309
190
|
};
|
|
@@ -325,7 +206,6 @@ export class PluginManager extends EventEmitter {
|
|
|
325
206
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
326
207
|
return null;
|
|
327
208
|
}
|
|
328
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
329
209
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
330
210
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
331
211
|
};
|
|
@@ -355,12 +235,6 @@ export class PluginManager extends EventEmitter {
|
|
|
355
235
|
return null;
|
|
356
236
|
}
|
|
357
237
|
}
|
|
358
|
-
/**
|
|
359
|
-
* Installs a package globally using npm.
|
|
360
|
-
*
|
|
361
|
-
* @param {string} packageName - The name of the package to install.
|
|
362
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the installation was successful, false otherwise.
|
|
363
|
-
*/
|
|
364
238
|
async install(packageName) {
|
|
365
239
|
const { spawnCommand } = await import('./utils/spawn.js');
|
|
366
240
|
try {
|
|
@@ -387,12 +261,6 @@ export class PluginManager extends EventEmitter {
|
|
|
387
261
|
return false;
|
|
388
262
|
}
|
|
389
263
|
}
|
|
390
|
-
/**
|
|
391
|
-
* Uninstalls a package globally using npm.
|
|
392
|
-
*
|
|
393
|
-
* @param {string} packageName - The name of the package to uninstall.
|
|
394
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the uninstallation was successful, false otherwise.
|
|
395
|
-
*/
|
|
396
264
|
async uninstall(packageName) {
|
|
397
265
|
const { spawnCommand } = await import('./utils/spawn.js');
|
|
398
266
|
packageName = packageName.replace(/@.*$/, '');
|
|
@@ -413,12 +281,6 @@ export class PluginManager extends EventEmitter {
|
|
|
413
281
|
return false;
|
|
414
282
|
}
|
|
415
283
|
}
|
|
416
|
-
/**
|
|
417
|
-
* Get the author of a plugin from its package.json.
|
|
418
|
-
*
|
|
419
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
420
|
-
* @returns {string} The author of the plugin, or 'Unknown author' if not found.
|
|
421
|
-
*/
|
|
422
284
|
getAuthor(packageJson) {
|
|
423
285
|
if (packageJson.author && typeof packageJson.author === 'string')
|
|
424
286
|
return packageJson.author;
|
|
@@ -426,12 +288,6 @@ export class PluginManager extends EventEmitter {
|
|
|
426
288
|
return packageJson.author.name;
|
|
427
289
|
return 'Unknown author';
|
|
428
290
|
}
|
|
429
|
-
/**
|
|
430
|
-
* Get the homepage of a plugin from its package.json.
|
|
431
|
-
*
|
|
432
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
433
|
-
* @returns {string | undefined} The homepage of the plugin, or undefined if not found.
|
|
434
|
-
*/
|
|
435
291
|
getHomepage(packageJson) {
|
|
436
292
|
if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
|
|
437
293
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
@@ -440,14 +296,7 @@ export class PluginManager extends EventEmitter {
|
|
|
440
296
|
return packageJson.repository.url.replace('git+', '').replace('.git', '');
|
|
441
297
|
}
|
|
442
298
|
}
|
|
443
|
-
/**
|
|
444
|
-
* Get the help URL of a plugin from its package.json.
|
|
445
|
-
*
|
|
446
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
447
|
-
* @returns {string | undefined} The URL to the help page or to the README file, or undefined if not found.
|
|
448
|
-
*/
|
|
449
299
|
getHelp(packageJson) {
|
|
450
|
-
// If there's a help field that looks like a URL, return it.
|
|
451
300
|
if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
|
|
452
301
|
return packageJson.help;
|
|
453
302
|
}
|
|
@@ -458,14 +307,7 @@ export class PluginManager extends EventEmitter {
|
|
|
458
307
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
459
308
|
}
|
|
460
309
|
}
|
|
461
|
-
/**
|
|
462
|
-
* Get the changelog URL of a plugin from its package.json.
|
|
463
|
-
*
|
|
464
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
465
|
-
* @returns {string | undefined} The URL to the CHANGELOG file, or undefined if not found.
|
|
466
|
-
*/
|
|
467
310
|
getChangelog(packageJson) {
|
|
468
|
-
// If there's a changelog field that looks like a URL, return it.
|
|
469
311
|
if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
|
|
470
312
|
return packageJson.changelog;
|
|
471
313
|
}
|
|
@@ -476,13 +318,6 @@ export class PluginManager extends EventEmitter {
|
|
|
476
318
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
477
319
|
}
|
|
478
320
|
}
|
|
479
|
-
/**
|
|
480
|
-
* Get the first funding URL(s) of a plugin from its package.json.
|
|
481
|
-
*
|
|
482
|
-
* @param {Record<string, any>} packageJson - The package.json object of the plugin.
|
|
483
|
-
* @returns {string | undefined} The first funding URLs, or undefined if not found.
|
|
484
|
-
*/
|
|
485
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
486
321
|
getFunding(packageJson) {
|
|
487
322
|
const funding = packageJson.funding;
|
|
488
323
|
if (!funding)
|
|
@@ -491,25 +326,16 @@ export class PluginManager extends EventEmitter {
|
|
|
491
326
|
return;
|
|
492
327
|
if (typeof funding === 'string' && funding.startsWith('http'))
|
|
493
328
|
return funding;
|
|
494
|
-
// Normalize funding into an array.
|
|
495
329
|
const fundingEntries = Array.isArray(funding) ? funding : [funding];
|
|
496
330
|
for (const entry of fundingEntries) {
|
|
497
331
|
if (entry && typeof entry === 'string' && entry.startsWith('http')) {
|
|
498
|
-
// If the funding entry is a string, assume it is a URL.
|
|
499
332
|
return entry;
|
|
500
333
|
}
|
|
501
334
|
else if (entry && typeof entry === 'object' && typeof entry.url === 'string' && entry.url.startsWith('http')) {
|
|
502
|
-
// If it's an object with a 'url' property, use that.
|
|
503
335
|
return entry.url;
|
|
504
336
|
}
|
|
505
337
|
}
|
|
506
338
|
}
|
|
507
|
-
/**
|
|
508
|
-
* Loads and parses the plugin package.json and returns it.
|
|
509
|
-
*
|
|
510
|
-
* @param {Plugin} plugin - The plugin to load the package from.
|
|
511
|
-
* @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.
|
|
512
|
-
*/
|
|
513
339
|
async parse(plugin) {
|
|
514
340
|
const { promises } = await import('node:fs');
|
|
515
341
|
try {
|
|
@@ -539,7 +365,6 @@ export class PluginManager extends EventEmitter {
|
|
|
539
365
|
plugin.funding = this.getFunding(packageJson);
|
|
540
366
|
if (!plugin.type)
|
|
541
367
|
this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
|
|
542
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
543
368
|
const checkForProjectChipPackages = (dependencies) => {
|
|
544
369
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
545
370
|
};
|
|
@@ -561,7 +386,6 @@ export class PluginManager extends EventEmitter {
|
|
|
561
386
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
562
387
|
return null;
|
|
563
388
|
}
|
|
564
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
565
389
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
566
390
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
567
391
|
};
|
|
@@ -591,16 +415,6 @@ export class PluginManager extends EventEmitter {
|
|
|
591
415
|
return null;
|
|
592
416
|
}
|
|
593
417
|
}
|
|
594
|
-
/**
|
|
595
|
-
* Enables a plugin by its name or path.
|
|
596
|
-
*
|
|
597
|
-
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
598
|
-
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
599
|
-
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
600
|
-
*
|
|
601
|
-
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
602
|
-
* @returns {Promise<Plugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
603
|
-
*/
|
|
604
418
|
async enable(nameOrPath) {
|
|
605
419
|
const { promises } = await import('node:fs');
|
|
606
420
|
if (!nameOrPath)
|
|
@@ -636,16 +450,6 @@ export class PluginManager extends EventEmitter {
|
|
|
636
450
|
return null;
|
|
637
451
|
}
|
|
638
452
|
}
|
|
639
|
-
/**
|
|
640
|
-
* Enables a plugin by its name or path.
|
|
641
|
-
*
|
|
642
|
-
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
643
|
-
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
644
|
-
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
645
|
-
*
|
|
646
|
-
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
647
|
-
* @returns {Promise<Plugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
648
|
-
*/
|
|
649
453
|
async disable(nameOrPath) {
|
|
650
454
|
const { promises } = await import('node:fs');
|
|
651
455
|
if (!nameOrPath)
|
|
@@ -681,16 +485,6 @@ export class PluginManager extends EventEmitter {
|
|
|
681
485
|
return null;
|
|
682
486
|
}
|
|
683
487
|
}
|
|
684
|
-
/**
|
|
685
|
-
* Removes a plugin by its name or path.
|
|
686
|
-
*
|
|
687
|
-
* This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
|
|
688
|
-
* It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
|
|
689
|
-
* the plugin's `package.json` file to retrieve its name and remove it.
|
|
690
|
-
*
|
|
691
|
-
* @param {string} nameOrPath - The name or path of the plugin to remove.
|
|
692
|
-
* @returns {Promise<Plugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
|
|
693
|
-
*/
|
|
694
488
|
async remove(nameOrPath) {
|
|
695
489
|
const { promises } = await import('node:fs');
|
|
696
490
|
if (!nameOrPath)
|
|
@@ -726,17 +520,6 @@ export class PluginManager extends EventEmitter {
|
|
|
726
520
|
return null;
|
|
727
521
|
}
|
|
728
522
|
}
|
|
729
|
-
/**
|
|
730
|
-
* Adds a plugin by its name or path.
|
|
731
|
-
*
|
|
732
|
-
* This method adds a plugin to the plugins map and saves the updated plugin information to storage.
|
|
733
|
-
* It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
|
|
734
|
-
* registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
|
|
735
|
-
* and saves the updated plugin information to storage.
|
|
736
|
-
*
|
|
737
|
-
* @param {string} nameOrPath - The name or path of the plugin to add.
|
|
738
|
-
* @returns {Promise<Plugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
|
|
739
|
-
*/
|
|
740
523
|
async add(nameOrPath) {
|
|
741
524
|
const { promises } = await import('node:fs');
|
|
742
525
|
if (!nameOrPath)
|
|
@@ -776,15 +559,6 @@ export class PluginManager extends EventEmitter {
|
|
|
776
559
|
return null;
|
|
777
560
|
}
|
|
778
561
|
}
|
|
779
|
-
/**
|
|
780
|
-
* Loads a plugin and returns the corresponding MatterbridgePlatform instance.
|
|
781
|
-
*
|
|
782
|
-
* @param {Plugin} plugin - The plugin to load.
|
|
783
|
-
* @param {boolean} start - Optional flag indicating whether to start the plugin after loading. Default is false.
|
|
784
|
-
* @param {string} message - Optional message to pass to the plugin when starting.
|
|
785
|
-
* @param {boolean} configure - Optional flag indicating whether to configure the plugin after loading. Default is false.
|
|
786
|
-
* @returns {Promise<MatterbridgePlatform | undefined>} A Promise that resolves to the loaded MatterbridgePlatform instance or undefined.
|
|
787
|
-
*/
|
|
788
562
|
async load(plugin, start = false, message = '', configure = false) {
|
|
789
563
|
const { promises } = await import('node:fs');
|
|
790
564
|
const { default: path } = await import('node:path');
|
|
@@ -798,20 +572,15 @@ export class PluginManager extends EventEmitter {
|
|
|
798
572
|
}
|
|
799
573
|
this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
|
|
800
574
|
try {
|
|
801
|
-
// Load the package.json of the plugin
|
|
802
575
|
const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
|
|
803
|
-
// Resolve the main module path relative to package.json
|
|
804
576
|
const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
|
|
805
|
-
// Dynamically import the plugin
|
|
806
577
|
const { pathToFileURL } = await import('node:url');
|
|
807
578
|
const pluginUrl = pathToFileURL(pluginEntry);
|
|
808
579
|
this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
809
580
|
const pluginInstance = await import(pluginUrl.href);
|
|
810
581
|
this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
811
|
-
// Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
|
|
812
582
|
if (pluginInstance.default) {
|
|
813
583
|
const config = await this.loadConfig(plugin);
|
|
814
|
-
// 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.
|
|
815
584
|
plugin.name = packageJson.name;
|
|
816
585
|
plugin.description = packageJson.description ?? 'No description';
|
|
817
586
|
plugin.version = packageJson.version;
|
|
@@ -820,7 +589,7 @@ export class PluginManager extends EventEmitter {
|
|
|
820
589
|
plugin.schemaJson = await this.loadSchema(plugin);
|
|
821
590
|
config.name = plugin.name;
|
|
822
591
|
config.version = packageJson.version;
|
|
823
|
-
const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4
|
|
592
|
+
const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
|
|
824
593
|
const platform = pluginInstance.default(this.matterbridge, log, config);
|
|
825
594
|
config.type = platform.type;
|
|
826
595
|
platform.name = packageJson.name;
|
|
@@ -838,7 +607,7 @@ export class PluginManager extends EventEmitter {
|
|
|
838
607
|
plugin.platform = platform;
|
|
839
608
|
plugin.loaded = true;
|
|
840
609
|
plugin.registeredDevices = 0;
|
|
841
|
-
await this.saveToStorage();
|
|
610
|
+
await this.saveToStorage();
|
|
842
611
|
this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
|
|
843
612
|
this.emit('loaded', plugin.name);
|
|
844
613
|
if (start)
|
|
@@ -858,14 +627,6 @@ export class PluginManager extends EventEmitter {
|
|
|
858
627
|
}
|
|
859
628
|
return undefined;
|
|
860
629
|
}
|
|
861
|
-
/**
|
|
862
|
-
* Starts a plugin.
|
|
863
|
-
*
|
|
864
|
-
* @param {Plugin} plugin - The plugin to start.
|
|
865
|
-
* @param {string} [message] - Optional message to pass to the plugin's onStart method.
|
|
866
|
-
* @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
|
|
867
|
-
* @returns {Promise<Plugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
|
|
868
|
-
*/
|
|
869
630
|
async start(plugin, message, configure = false) {
|
|
870
631
|
if (!plugin.loaded) {
|
|
871
632
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -896,12 +657,6 @@ export class PluginManager extends EventEmitter {
|
|
|
896
657
|
}
|
|
897
658
|
return undefined;
|
|
898
659
|
}
|
|
899
|
-
/**
|
|
900
|
-
* Configures a plugin.
|
|
901
|
-
*
|
|
902
|
-
* @param {Plugin} plugin - The plugin to configure.
|
|
903
|
-
* @returns {Promise<Plugin | undefined>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
|
|
904
|
-
*/
|
|
905
660
|
async configure(plugin) {
|
|
906
661
|
if (!plugin.loaded) {
|
|
907
662
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -933,18 +688,6 @@ export class PluginManager extends EventEmitter {
|
|
|
933
688
|
}
|
|
934
689
|
return undefined;
|
|
935
690
|
}
|
|
936
|
-
/**
|
|
937
|
-
* Shuts down a plugin.
|
|
938
|
-
*
|
|
939
|
-
* This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
|
|
940
|
-
* It logs the shutdown process and optionally removes all devices associated with the plugin.
|
|
941
|
-
*
|
|
942
|
-
* @param {Plugin} plugin - The plugin to shut down.
|
|
943
|
-
* @param {string} [reason] - The reason for shutting down the plugin.
|
|
944
|
-
* @param {boolean} [removeAllDevices] - Whether to remove all devices associated with the plugin.
|
|
945
|
-
* @param {boolean} [force] - Whether to force the shutdown even if the plugin is not loaded or started.
|
|
946
|
-
* @returns {Promise<Plugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
|
|
947
|
-
*/
|
|
948
691
|
async shutdown(plugin, reason, removeAllDevices = false, force = false) {
|
|
949
692
|
this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
|
|
950
693
|
if (!plugin.loaded) {
|
|
@@ -987,15 +730,6 @@ export class PluginManager extends EventEmitter {
|
|
|
987
730
|
}
|
|
988
731
|
return undefined;
|
|
989
732
|
}
|
|
990
|
-
/**
|
|
991
|
-
* Loads the configuration for a plugin.
|
|
992
|
-
* If the configuration file exists, it reads the file and returns the parsed JSON data.
|
|
993
|
-
* If the configuration file does not exist, it creates a new file with default configuration and returns it.
|
|
994
|
-
* If any error occurs during file access or creation, it logs an error and return un empty config.
|
|
995
|
-
*
|
|
996
|
-
* @param {Plugin} plugin - The plugin for which to load the configuration.
|
|
997
|
-
* @returns {Promise<PlatformConfig>} A promise that resolves to the loaded or created configuration.
|
|
998
|
-
*/
|
|
999
733
|
async loadConfig(plugin) {
|
|
1000
734
|
const { default: path } = await import('node:path');
|
|
1001
735
|
const { promises } = await import('node:fs');
|
|
@@ -1007,8 +741,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1007
741
|
const data = await promises.readFile(configFile, 'utf8');
|
|
1008
742
|
const config = JSON.parse(data);
|
|
1009
743
|
this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
1010
|
-
// this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
1011
|
-
// The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
|
|
1012
744
|
config.name = plugin.name;
|
|
1013
745
|
config.type = plugin.type;
|
|
1014
746
|
if (config.debug === undefined)
|
|
@@ -1030,8 +762,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1030
762
|
}
|
|
1031
763
|
catch (_err) {
|
|
1032
764
|
this.log.debug(`Default config file ${defaultConfigFile} for plugin ${plg}${plugin.name}${db} does not exist, creating new config file...`);
|
|
1033
|
-
// TODO: Remove this when all these plugins have their own default config file
|
|
1034
|
-
// istanbul ignore next if
|
|
1035
765
|
if (plugin.name === 'matterbridge-zigbee2mqtt')
|
|
1036
766
|
config = zigbee2mqtt_config;
|
|
1037
767
|
else if (plugin.name === 'matterbridge-somfy-tahoma')
|
|
@@ -1044,7 +774,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1044
774
|
try {
|
|
1045
775
|
await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
1046
776
|
this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
1047
|
-
// this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
1048
777
|
return config;
|
|
1049
778
|
}
|
|
1050
779
|
catch (err) {
|
|
@@ -1058,19 +787,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1058
787
|
}
|
|
1059
788
|
}
|
|
1060
789
|
}
|
|
1061
|
-
/**
|
|
1062
|
-
* Saves the configuration of a plugin to a file.
|
|
1063
|
-
*
|
|
1064
|
-
* This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
1065
|
-
* If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
|
|
1066
|
-
* is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
|
|
1067
|
-
* the error and rejects the promise.
|
|
1068
|
-
*
|
|
1069
|
-
* @param {Plugin} plugin - The plugin whose configuration is to be saved.
|
|
1070
|
-
* @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
|
|
1071
|
-
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
|
|
1072
|
-
* @throws {Error} If the plugin's configuration is not found.
|
|
1073
|
-
*/
|
|
1074
790
|
async saveConfigFromPlugin(plugin, restartRequired = false) {
|
|
1075
791
|
const { default: path } = await import('node:path');
|
|
1076
792
|
const { promises } = await import('node:fs');
|
|
@@ -1085,7 +801,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1085
801
|
if (restartRequired)
|
|
1086
802
|
plugin.restartRequired = true;
|
|
1087
803
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
1088
|
-
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
|
|
1089
804
|
return Promise.resolve();
|
|
1090
805
|
}
|
|
1091
806
|
catch (err) {
|
|
@@ -1093,20 +808,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1093
808
|
return Promise.reject(err);
|
|
1094
809
|
}
|
|
1095
810
|
}
|
|
1096
|
-
/**
|
|
1097
|
-
* Saves the configuration of a plugin from a JSON object to a file.
|
|
1098
|
-
*
|
|
1099
|
-
* This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
1100
|
-
* It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
|
|
1101
|
-
* the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
|
|
1102
|
-
* successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
|
|
1103
|
-
* during the file write operation, it logs the error and returns.
|
|
1104
|
-
*
|
|
1105
|
-
* @param {Plugin} plugin - The plugin whose configuration is to be saved.
|
|
1106
|
-
* @param {PlatformConfig} config - The configuration data to be saved.
|
|
1107
|
-
* @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
|
|
1108
|
-
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
|
|
1109
|
-
*/
|
|
1110
811
|
async saveConfigFromJson(plugin, config, restartRequired = false) {
|
|
1111
812
|
const { default: path } = await import('node:path');
|
|
1112
813
|
const { promises } = await import('node:fs');
|
|
@@ -1125,23 +826,12 @@ export class PluginManager extends EventEmitter {
|
|
|
1125
826
|
plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
|
|
1126
827
|
}
|
|
1127
828
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
1128
|
-
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
1129
829
|
}
|
|
1130
830
|
catch (err) {
|
|
1131
831
|
logError(this.log, `Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}`, err);
|
|
1132
832
|
return;
|
|
1133
833
|
}
|
|
1134
834
|
}
|
|
1135
|
-
/**
|
|
1136
|
-
* Loads the schema for a plugin.
|
|
1137
|
-
*
|
|
1138
|
-
* This method attempts to load the schema file for the specified plugin. If the schema file is found,
|
|
1139
|
-
* it reads and parses the file, updates the schema's title and description, and logs the process.
|
|
1140
|
-
* If the schema file is not found, it logs the event and loads a default schema for the plugin.
|
|
1141
|
-
*
|
|
1142
|
-
* @param {Plugin} plugin - The plugin whose schema is to be loaded.
|
|
1143
|
-
* @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
|
|
1144
|
-
*/
|
|
1145
835
|
async loadSchema(plugin) {
|
|
1146
836
|
const { promises } = await import('node:fs');
|
|
1147
837
|
const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
|
|
@@ -1152,7 +842,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1152
842
|
schema.title = plugin.description;
|
|
1153
843
|
schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
|
|
1154
844
|
this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
1155
|
-
// this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
|
|
1156
845
|
return schema;
|
|
1157
846
|
}
|
|
1158
847
|
catch (_err) {
|
|
@@ -1160,16 +849,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1160
849
|
return this.getDefaultSchema(plugin);
|
|
1161
850
|
}
|
|
1162
851
|
}
|
|
1163
|
-
/**
|
|
1164
|
-
* Returns the default schema for a plugin.
|
|
1165
|
-
*
|
|
1166
|
-
* This method generates a default schema object for the specified plugin. The schema includes
|
|
1167
|
-
* metadata such as the plugin's title, description, version, and author. It also defines the
|
|
1168
|
-
* properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
|
|
1169
|
-
*
|
|
1170
|
-
* @param {Plugin} plugin - The plugin for which the default schema is to be generated.
|
|
1171
|
-
* @returns {PlatformSchema} The default schema object for the plugin.
|
|
1172
|
-
*/
|
|
1173
852
|
getDefaultSchema(plugin) {
|
|
1174
853
|
return {
|
|
1175
854
|
title: plugin.description,
|
|
@@ -1200,4 +879,3 @@ export class PluginManager extends EventEmitter {
|
|
|
1200
879
|
};
|
|
1201
880
|
}
|
|
1202
881
|
}
|
|
1203
|
-
//# sourceMappingURL=pluginManager.js.map
|