matterbridge 3.3.1 → 3.3.2-dev-20251012-0a89052
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 +31 -7
- package/dist/broadcastServer.js +1 -86
- package/dist/broadcastServerTypes.js +0 -24
- package/dist/cli.js +5 -134
- package/dist/cliEmitter.js +0 -37
- package/dist/cliHistory.js +0 -44
- 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 +31 -404
- 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 +45 -795
- package/dist/matterbridgeAccessoryPlatform.js +0 -36
- package/dist/matterbridgeBehaviors.js +5 -65
- package/dist/matterbridgeDeviceTypes.js +17 -630
- package/dist/matterbridgeDynamicPlatform.js +0 -36
- package/dist/matterbridgeEndpoint.js +58 -1398
- package/dist/matterbridgeEndpointHelpers.js +12 -345
- package/dist/matterbridgePlatform.js +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 +0 -54
- package/dist/utils/copyDirectory.js +1 -38
- package/dist/utils/createDirectory.js +0 -33
- package/dist/utils/createZip.js +2 -47
- package/dist/utils/deepCopy.js +0 -39
- package/dist/utils/deepEqual.js +1 -72
- package/dist/utils/error.js +0 -41
- package/dist/utils/export.js +0 -1
- package/dist/utils/hex.js +0 -124
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/jestHelpers.js +3 -153
- package/dist/utils/network.js +5 -108
- package/dist/utils/spawn.js +0 -71
- package/dist/utils/wait.js +8 -60
- package/npm-shrinkwrap.json +14 -6
- package/package.json +1 -2
- 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 -717
- 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 -70
- 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 -234
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/frontendTypes.d.ts +0 -522
- 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 -1747
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -761
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1534
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -407
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -402
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -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));
|
|
@@ -88,69 +55,28 @@ export class PluginManager extends EventEmitter {
|
|
|
88
55
|
this.log.warn(`Unknown broadcast message ${CYAN}${msg.type}${wr} from ${CYAN}${msg.src}${wr}`);
|
|
89
56
|
}
|
|
90
57
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Gets the number of plugins.
|
|
93
|
-
*
|
|
94
|
-
* @returns {number} The number of plugins.
|
|
95
|
-
*/
|
|
96
58
|
get length() {
|
|
97
59
|
return this._plugins.size;
|
|
98
60
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Gets the number of plugins.
|
|
101
|
-
*
|
|
102
|
-
* @returns {number} The number of plugins.
|
|
103
|
-
*/
|
|
104
61
|
get size() {
|
|
105
62
|
return this._plugins.size;
|
|
106
63
|
}
|
|
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
|
-
*/
|
|
113
64
|
has(name) {
|
|
114
65
|
return this._plugins.has(name);
|
|
115
66
|
}
|
|
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
|
-
*/
|
|
122
67
|
get(name) {
|
|
123
68
|
return this._plugins.get(name);
|
|
124
69
|
}
|
|
125
|
-
/**
|
|
126
|
-
* Adds a plugin to the manager.
|
|
127
|
-
*
|
|
128
|
-
* @param {Plugin} plugin - The plugin to add.
|
|
129
|
-
* @returns {Plugin} The added plugin.
|
|
130
|
-
*/
|
|
131
70
|
set(plugin) {
|
|
132
71
|
this._plugins.set(plugin.name, plugin);
|
|
133
72
|
return plugin;
|
|
134
73
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Clears all plugins from the manager.
|
|
137
|
-
*/
|
|
138
74
|
clear() {
|
|
139
75
|
this._plugins.clear();
|
|
140
76
|
}
|
|
141
|
-
/**
|
|
142
|
-
* Gets an array of all plugins.
|
|
143
|
-
*
|
|
144
|
-
* @returns {Plugin[]} An array of all plugins.
|
|
145
|
-
*/
|
|
146
77
|
array() {
|
|
147
78
|
return Array.from(this._plugins.values());
|
|
148
79
|
}
|
|
149
|
-
/**
|
|
150
|
-
* Gets an array of all plugins suitable for serialization.
|
|
151
|
-
*
|
|
152
|
-
* @returns {ApiPlugin[]} An array of all plugins.
|
|
153
|
-
*/
|
|
154
80
|
baseArray() {
|
|
155
81
|
const basePlugins = [];
|
|
156
82
|
for (const plugin of this._plugins.values()) {
|
|
@@ -184,20 +110,9 @@ export class PluginManager extends EventEmitter {
|
|
|
184
110
|
}
|
|
185
111
|
return basePlugins;
|
|
186
112
|
}
|
|
187
|
-
/**
|
|
188
|
-
* Gets an iterator for the plugins.
|
|
189
|
-
*
|
|
190
|
-
* @returns {IterableIterator<Plugin>} An iterator for the plugins.
|
|
191
|
-
*/
|
|
192
113
|
[Symbol.iterator]() {
|
|
193
114
|
return this._plugins.values();
|
|
194
115
|
}
|
|
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
|
-
*/
|
|
201
116
|
async forEach(callback) {
|
|
202
117
|
if (this.size === 0)
|
|
203
118
|
return;
|
|
@@ -211,45 +126,22 @@ export class PluginManager extends EventEmitter {
|
|
|
211
126
|
});
|
|
212
127
|
await Promise.all(tasks);
|
|
213
128
|
}
|
|
214
|
-
/**
|
|
215
|
-
* Sets the log level for the plugin manager.
|
|
216
|
-
*
|
|
217
|
-
* @param {LogLevel} logLevel - The log level to set.
|
|
218
|
-
*/
|
|
219
129
|
set logLevel(logLevel) {
|
|
220
130
|
this.log.logLevel = logLevel;
|
|
221
131
|
}
|
|
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
|
-
*/
|
|
230
132
|
async loadFromStorage() {
|
|
231
133
|
if (!this.matterbridge.nodeContext) {
|
|
232
134
|
throw new Error('loadFromStorage: node context is not available.');
|
|
233
135
|
}
|
|
234
|
-
// Load the array from storage and convert it to a map
|
|
235
136
|
const pluginsArray = await this.matterbridge.nodeContext.get('plugins', []);
|
|
236
137
|
for (const plugin of pluginsArray)
|
|
237
138
|
this._plugins.set(plugin.name, plugin);
|
|
238
139
|
return pluginsArray;
|
|
239
140
|
}
|
|
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
|
-
*/
|
|
248
141
|
async saveToStorage() {
|
|
249
142
|
if (!this.matterbridge.nodeContext) {
|
|
250
143
|
throw new Error('loadFromStorage: node context is not available.');
|
|
251
144
|
}
|
|
252
|
-
// Convert the map to an array
|
|
253
145
|
const plugins = [];
|
|
254
146
|
for (const plugin of this.array()) {
|
|
255
147
|
plugins.push({
|
|
@@ -266,21 +158,13 @@ export class PluginManager extends EventEmitter {
|
|
|
266
158
|
this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
|
|
267
159
|
return plugins.length;
|
|
268
160
|
}
|
|
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
|
-
*/
|
|
275
161
|
async resolve(pluginPath) {
|
|
276
162
|
const { default: path } = await import('node:path');
|
|
277
163
|
const { promises } = await import('node:fs');
|
|
278
164
|
if (!pluginPath.endsWith('package.json'))
|
|
279
165
|
pluginPath = path.join(pluginPath, 'package.json');
|
|
280
|
-
// Resolve the package.json of the plugin
|
|
281
166
|
let packageJsonPath = path.resolve(pluginPath);
|
|
282
167
|
this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
|
|
283
|
-
// Check if the package.json file exists
|
|
284
168
|
try {
|
|
285
169
|
await promises.access(packageJsonPath);
|
|
286
170
|
}
|
|
@@ -290,9 +174,7 @@ export class PluginManager extends EventEmitter {
|
|
|
290
174
|
this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
|
|
291
175
|
}
|
|
292
176
|
try {
|
|
293
|
-
// Load the package.json of the plugin
|
|
294
177
|
const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
|
|
295
|
-
// Check for main issues
|
|
296
178
|
if (!packageJson.name) {
|
|
297
179
|
this.log.error(`Package.json name not found at ${packageJsonPath}`);
|
|
298
180
|
return null;
|
|
@@ -305,7 +187,6 @@ export class PluginManager extends EventEmitter {
|
|
|
305
187
|
this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
|
|
306
188
|
return null;
|
|
307
189
|
}
|
|
308
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
309
190
|
const checkForProjectChipPackages = (dependencies) => {
|
|
310
191
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
311
192
|
};
|
|
@@ -327,7 +208,6 @@ export class PluginManager extends EventEmitter {
|
|
|
327
208
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
328
209
|
return null;
|
|
329
210
|
}
|
|
330
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
331
211
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
332
212
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
333
213
|
};
|
|
@@ -357,12 +237,6 @@ export class PluginManager extends EventEmitter {
|
|
|
357
237
|
return null;
|
|
358
238
|
}
|
|
359
239
|
}
|
|
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
|
-
*/
|
|
366
240
|
async install(packageName) {
|
|
367
241
|
const { spawnCommand } = await import('./utils/spawn.js');
|
|
368
242
|
try {
|
|
@@ -389,12 +263,6 @@ export class PluginManager extends EventEmitter {
|
|
|
389
263
|
return false;
|
|
390
264
|
}
|
|
391
265
|
}
|
|
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
|
-
*/
|
|
398
266
|
async uninstall(packageName) {
|
|
399
267
|
const { spawnCommand } = await import('./utils/spawn.js');
|
|
400
268
|
packageName = packageName.replace(/@.*$/, '');
|
|
@@ -415,12 +283,6 @@ export class PluginManager extends EventEmitter {
|
|
|
415
283
|
return false;
|
|
416
284
|
}
|
|
417
285
|
}
|
|
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
|
-
*/
|
|
424
286
|
getAuthor(packageJson) {
|
|
425
287
|
if (packageJson.author && typeof packageJson.author === 'string')
|
|
426
288
|
return packageJson.author;
|
|
@@ -428,12 +290,6 @@ export class PluginManager extends EventEmitter {
|
|
|
428
290
|
return packageJson.author.name;
|
|
429
291
|
return 'Unknown author';
|
|
430
292
|
}
|
|
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
|
-
*/
|
|
437
293
|
getHomepage(packageJson) {
|
|
438
294
|
if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
|
|
439
295
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
@@ -442,14 +298,7 @@ export class PluginManager extends EventEmitter {
|
|
|
442
298
|
return packageJson.repository.url.replace('git+', '').replace('.git', '');
|
|
443
299
|
}
|
|
444
300
|
}
|
|
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
|
-
*/
|
|
451
301
|
getHelp(packageJson) {
|
|
452
|
-
// If there's a help field that looks like a URL, return it.
|
|
453
302
|
if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
|
|
454
303
|
return packageJson.help;
|
|
455
304
|
}
|
|
@@ -460,14 +309,7 @@ export class PluginManager extends EventEmitter {
|
|
|
460
309
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
461
310
|
}
|
|
462
311
|
}
|
|
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
|
-
*/
|
|
469
312
|
getChangelog(packageJson) {
|
|
470
|
-
// If there's a changelog field that looks like a URL, return it.
|
|
471
313
|
if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
|
|
472
314
|
return packageJson.changelog;
|
|
473
315
|
}
|
|
@@ -478,13 +320,6 @@ export class PluginManager extends EventEmitter {
|
|
|
478
320
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
479
321
|
}
|
|
480
322
|
}
|
|
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
|
|
488
323
|
getFunding(packageJson) {
|
|
489
324
|
const funding = packageJson.funding;
|
|
490
325
|
if (!funding)
|
|
@@ -493,25 +328,16 @@ export class PluginManager extends EventEmitter {
|
|
|
493
328
|
return;
|
|
494
329
|
if (typeof funding === 'string' && funding.startsWith('http'))
|
|
495
330
|
return funding;
|
|
496
|
-
// Normalize funding into an array.
|
|
497
331
|
const fundingEntries = Array.isArray(funding) ? funding : [funding];
|
|
498
332
|
for (const entry of fundingEntries) {
|
|
499
333
|
if (entry && typeof entry === 'string' && entry.startsWith('http')) {
|
|
500
|
-
// If the funding entry is a string, assume it is a URL.
|
|
501
334
|
return entry;
|
|
502
335
|
}
|
|
503
336
|
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.
|
|
505
337
|
return entry.url;
|
|
506
338
|
}
|
|
507
339
|
}
|
|
508
340
|
}
|
|
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
|
-
*/
|
|
515
341
|
async parse(plugin) {
|
|
516
342
|
const { promises } = await import('node:fs');
|
|
517
343
|
try {
|
|
@@ -541,7 +367,6 @@ export class PluginManager extends EventEmitter {
|
|
|
541
367
|
plugin.funding = this.getFunding(packageJson);
|
|
542
368
|
if (!plugin.type)
|
|
543
369
|
this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
|
|
544
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
545
370
|
const checkForProjectChipPackages = (dependencies) => {
|
|
546
371
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
547
372
|
};
|
|
@@ -563,7 +388,6 @@ export class PluginManager extends EventEmitter {
|
|
|
563
388
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
564
389
|
return null;
|
|
565
390
|
}
|
|
566
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
567
391
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
568
392
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
569
393
|
};
|
|
@@ -593,16 +417,6 @@ export class PluginManager extends EventEmitter {
|
|
|
593
417
|
return null;
|
|
594
418
|
}
|
|
595
419
|
}
|
|
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
|
-
*/
|
|
606
420
|
async enable(nameOrPath) {
|
|
607
421
|
const { promises } = await import('node:fs');
|
|
608
422
|
if (!nameOrPath)
|
|
@@ -638,16 +452,6 @@ export class PluginManager extends EventEmitter {
|
|
|
638
452
|
return null;
|
|
639
453
|
}
|
|
640
454
|
}
|
|
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
|
-
*/
|
|
651
455
|
async disable(nameOrPath) {
|
|
652
456
|
const { promises } = await import('node:fs');
|
|
653
457
|
if (!nameOrPath)
|
|
@@ -683,16 +487,6 @@ export class PluginManager extends EventEmitter {
|
|
|
683
487
|
return null;
|
|
684
488
|
}
|
|
685
489
|
}
|
|
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
|
-
*/
|
|
696
490
|
async remove(nameOrPath) {
|
|
697
491
|
const { promises } = await import('node:fs');
|
|
698
492
|
if (!nameOrPath)
|
|
@@ -728,17 +522,6 @@ export class PluginManager extends EventEmitter {
|
|
|
728
522
|
return null;
|
|
729
523
|
}
|
|
730
524
|
}
|
|
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
|
-
*/
|
|
742
525
|
async add(nameOrPath) {
|
|
743
526
|
const { promises } = await import('node:fs');
|
|
744
527
|
if (!nameOrPath)
|
|
@@ -778,15 +561,6 @@ export class PluginManager extends EventEmitter {
|
|
|
778
561
|
return null;
|
|
779
562
|
}
|
|
780
563
|
}
|
|
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
|
-
*/
|
|
790
564
|
async load(plugin, start = false, message = '', configure = false) {
|
|
791
565
|
const { promises } = await import('node:fs');
|
|
792
566
|
const { default: path } = await import('node:path');
|
|
@@ -800,20 +574,15 @@ export class PluginManager extends EventEmitter {
|
|
|
800
574
|
}
|
|
801
575
|
this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
|
|
802
576
|
try {
|
|
803
|
-
// Load the package.json of the plugin
|
|
804
577
|
const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
|
|
805
|
-
// Resolve the main module path relative to package.json
|
|
806
578
|
const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
|
|
807
|
-
// Dynamically import the plugin
|
|
808
579
|
const { pathToFileURL } = await import('node:url');
|
|
809
580
|
const pluginUrl = pathToFileURL(pluginEntry);
|
|
810
581
|
this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
811
582
|
const pluginInstance = await import(pluginUrl.href);
|
|
812
583
|
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
|
|
814
584
|
if (pluginInstance.default) {
|
|
815
585
|
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.
|
|
817
586
|
plugin.name = packageJson.name;
|
|
818
587
|
plugin.description = packageJson.description ?? 'No description';
|
|
819
588
|
plugin.version = packageJson.version;
|
|
@@ -822,7 +591,7 @@ export class PluginManager extends EventEmitter {
|
|
|
822
591
|
plugin.schemaJson = await this.loadSchema(plugin);
|
|
823
592
|
config.name = plugin.name;
|
|
824
593
|
config.version = packageJson.version;
|
|
825
|
-
const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4
|
|
594
|
+
const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
|
|
826
595
|
const platform = pluginInstance.default(this.matterbridge, log, config);
|
|
827
596
|
config.type = platform.type;
|
|
828
597
|
platform.name = packageJson.name;
|
|
@@ -840,7 +609,7 @@ export class PluginManager extends EventEmitter {
|
|
|
840
609
|
plugin.platform = platform;
|
|
841
610
|
plugin.loaded = true;
|
|
842
611
|
plugin.registeredDevices = 0;
|
|
843
|
-
await this.saveToStorage();
|
|
612
|
+
await this.saveToStorage();
|
|
844
613
|
this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
|
|
845
614
|
this.emit('loaded', plugin.name);
|
|
846
615
|
if (start)
|
|
@@ -860,14 +629,6 @@ export class PluginManager extends EventEmitter {
|
|
|
860
629
|
}
|
|
861
630
|
return undefined;
|
|
862
631
|
}
|
|
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
|
-
*/
|
|
871
632
|
async start(plugin, message, configure = false) {
|
|
872
633
|
if (!plugin.loaded) {
|
|
873
634
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -898,12 +659,6 @@ export class PluginManager extends EventEmitter {
|
|
|
898
659
|
}
|
|
899
660
|
return undefined;
|
|
900
661
|
}
|
|
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
|
-
*/
|
|
907
662
|
async configure(plugin) {
|
|
908
663
|
if (!plugin.loaded) {
|
|
909
664
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -935,18 +690,6 @@ export class PluginManager extends EventEmitter {
|
|
|
935
690
|
}
|
|
936
691
|
return undefined;
|
|
937
692
|
}
|
|
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
|
-
*/
|
|
950
693
|
async shutdown(plugin, reason, removeAllDevices = false, force = false) {
|
|
951
694
|
this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
|
|
952
695
|
if (!plugin.loaded) {
|
|
@@ -989,15 +732,6 @@ export class PluginManager extends EventEmitter {
|
|
|
989
732
|
}
|
|
990
733
|
return undefined;
|
|
991
734
|
}
|
|
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
|
-
*/
|
|
1001
735
|
async loadConfig(plugin) {
|
|
1002
736
|
const { default: path } = await import('node:path');
|
|
1003
737
|
const { promises } = await import('node:fs');
|
|
@@ -1009,8 +743,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1009
743
|
const data = await promises.readFile(configFile, 'utf8');
|
|
1010
744
|
const config = JSON.parse(data);
|
|
1011
745
|
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".
|
|
1014
746
|
config.name = plugin.name;
|
|
1015
747
|
config.type = plugin.type;
|
|
1016
748
|
if (config.debug === undefined)
|
|
@@ -1032,8 +764,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1032
764
|
}
|
|
1033
765
|
catch (_err) {
|
|
1034
766
|
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
|
|
1037
767
|
if (plugin.name === 'matterbridge-zigbee2mqtt')
|
|
1038
768
|
config = zigbee2mqtt_config;
|
|
1039
769
|
else if (plugin.name === 'matterbridge-somfy-tahoma')
|
|
@@ -1046,7 +776,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1046
776
|
try {
|
|
1047
777
|
await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
1048
778
|
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);
|
|
1050
779
|
return config;
|
|
1051
780
|
}
|
|
1052
781
|
catch (err) {
|
|
@@ -1060,19 +789,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1060
789
|
}
|
|
1061
790
|
}
|
|
1062
791
|
}
|
|
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
|
-
*/
|
|
1076
792
|
async saveConfigFromPlugin(plugin, restartRequired = false) {
|
|
1077
793
|
const { default: path } = await import('node:path');
|
|
1078
794
|
const { promises } = await import('node:fs');
|
|
@@ -1087,7 +803,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1087
803
|
if (restartRequired)
|
|
1088
804
|
plugin.restartRequired = true;
|
|
1089
805
|
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);
|
|
1091
806
|
return Promise.resolve();
|
|
1092
807
|
}
|
|
1093
808
|
catch (err) {
|
|
@@ -1095,20 +810,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1095
810
|
return Promise.reject(err);
|
|
1096
811
|
}
|
|
1097
812
|
}
|
|
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
|
-
*/
|
|
1112
813
|
async saveConfigFromJson(plugin, config, restartRequired = false) {
|
|
1113
814
|
const { default: path } = await import('node:path');
|
|
1114
815
|
const { promises } = await import('node:fs');
|
|
@@ -1127,23 +828,12 @@ export class PluginManager extends EventEmitter {
|
|
|
1127
828
|
plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
|
|
1128
829
|
}
|
|
1129
830
|
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);
|
|
1131
831
|
}
|
|
1132
832
|
catch (err) {
|
|
1133
833
|
logError(this.log, `Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}`, err);
|
|
1134
834
|
return;
|
|
1135
835
|
}
|
|
1136
836
|
}
|
|
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
|
-
*/
|
|
1147
837
|
async loadSchema(plugin) {
|
|
1148
838
|
const { promises } = await import('node:fs');
|
|
1149
839
|
const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
|
|
@@ -1154,7 +844,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1154
844
|
schema.title = plugin.description;
|
|
1155
845
|
schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
|
|
1156
846
|
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);
|
|
1158
847
|
return schema;
|
|
1159
848
|
}
|
|
1160
849
|
catch (_err) {
|
|
@@ -1162,16 +851,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1162
851
|
return this.getDefaultSchema(plugin);
|
|
1163
852
|
}
|
|
1164
853
|
}
|
|
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
|
-
*/
|
|
1175
854
|
getDefaultSchema(plugin) {
|
|
1176
855
|
return {
|
|
1177
856
|
title: plugin.description,
|
|
@@ -1202,4 +881,3 @@ export class PluginManager extends EventEmitter {
|
|
|
1202
881
|
};
|
|
1203
882
|
}
|
|
1204
883
|
}
|
|
1205
|
-
//# sourceMappingURL=pluginManager.js.map
|