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