matterbridge 3.3.4 → 3.3.5-dev-20251025-26d5c31
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 +10 -0
- package/dist/broadcastServer.js +1 -92
- package/dist/broadcastServerTypes.js +0 -24
- package/dist/cli.js +1 -97
- package/dist/cliEmitter.js +0 -37
- package/dist/cliHistory.js +0 -38
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -24
- package/dist/deviceManager.js +1 -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 -24
- package/dist/devices/waterHeater.js +2 -82
- package/dist/dgram/coap.js +13 -126
- package/dist/dgram/dgram.js +2 -114
- package/dist/dgram/mb_coap.js +3 -41
- package/dist/dgram/mb_mdns.js +15 -80
- package/dist/dgram/mdns.js +137 -299
- package/dist/dgram/multicast.js +1 -62
- package/dist/dgram/unicast.js +0 -54
- package/dist/frontend.js +34 -436
- 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 +50 -828
- package/dist/matterbridgeAccessoryPlatform.js +0 -37
- package/dist/matterbridgeBehaviors.js +5 -68
- package/dist/matterbridgeDeviceTypes.js +17 -638
- package/dist/matterbridgeDynamicPlatform.js +0 -37
- package/dist/matterbridgeEndpoint.js +52 -1402
- package/dist/matterbridgeEndpointHelpers.js +19 -464
- package/dist/matterbridgePlatform.js +1 -341
- package/dist/matterbridgeTypes.js +0 -26
- package/dist/pluginManager.js +3 -319
- package/dist/shelly.js +7 -168
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -69
- package/dist/utils/colorUtils.js +2 -97
- package/dist/utils/commandLine.js +0 -60
- package/dist/utils/copyDirectory.js +1 -38
- package/dist/utils/createDirectory.js +0 -33
- package/dist/utils/createZip.js +2 -47
- package/dist/utils/deepCopy.js +0 -39
- package/dist/utils/deepEqual.js +1 -72
- package/dist/utils/error.js +0 -41
- package/dist/utils/export.js +0 -1
- package/dist/utils/format.js +0 -49
- package/dist/utils/hex.js +0 -124
- package/dist/utils/inspector.js +1 -69
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/jestHelpers.js +3 -153
- package/dist/utils/network.js +5 -96
- package/dist/utils/spawn.js +0 -71
- package/dist/utils/tracker.js +1 -64
- package/dist/utils/wait.js +8 -60
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -2
- package/dist/broadcastServer.d.ts +0 -112
- package/dist/broadcastServer.d.ts.map +0 -1
- package/dist/broadcastServer.js.map +0 -1
- package/dist/broadcastServerTypes.d.ts +0 -793
- package/dist/broadcastServerTypes.d.ts.map +0 -1
- package/dist/broadcastServerTypes.js.map +0 -1
- package/dist/cli.d.ts +0 -30
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cliEmitter.d.ts +0 -50
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.js.map +0 -1
- package/dist/cliHistory.d.ts +0 -48
- package/dist/cliHistory.d.ts.map +0 -1
- package/dist/cliHistory.js.map +0 -1
- package/dist/clusters/export.d.ts +0 -2
- package/dist/clusters/export.d.ts.map +0 -1
- package/dist/clusters/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -28
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -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 -76
- package/dist/devices/evse.d.ts.map +0 -1
- package/dist/devices/evse.js.map +0 -1
- package/dist/devices/export.d.ts +0 -17
- package/dist/devices/export.d.ts.map +0 -1
- package/dist/devices/export.js.map +0 -1
- package/dist/devices/extractorHood.d.ts +0 -46
- package/dist/devices/extractorHood.d.ts.map +0 -1
- package/dist/devices/extractorHood.js.map +0 -1
- package/dist/devices/heatPump.d.ts +0 -47
- package/dist/devices/heatPump.d.ts.map +0 -1
- package/dist/devices/heatPump.js.map +0 -1
- package/dist/devices/laundryDryer.d.ts +0 -67
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -81
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.js.map +0 -1
- package/dist/devices/microwaveOven.d.ts +0 -168
- package/dist/devices/microwaveOven.d.ts.map +0 -1
- package/dist/devices/microwaveOven.js.map +0 -1
- package/dist/devices/oven.d.ts +0 -105
- package/dist/devices/oven.d.ts.map +0 -1
- package/dist/devices/oven.js.map +0 -1
- package/dist/devices/refrigerator.d.ts +0 -118
- package/dist/devices/refrigerator.d.ts.map +0 -1
- package/dist/devices/refrigerator.js.map +0 -1
- package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
- package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/devices/roboticVacuumCleaner.js.map +0 -1
- package/dist/devices/solarPower.d.ts +0 -40
- package/dist/devices/solarPower.d.ts.map +0 -1
- package/dist/devices/solarPower.js.map +0 -1
- package/dist/devices/speaker.d.ts +0 -87
- package/dist/devices/speaker.d.ts.map +0 -1
- package/dist/devices/speaker.js.map +0 -1
- package/dist/devices/temperatureControl.d.ts +0 -166
- package/dist/devices/temperatureControl.d.ts.map +0 -1
- package/dist/devices/temperatureControl.js.map +0 -1
- package/dist/devices/waterHeater.d.ts +0 -111
- package/dist/devices/waterHeater.d.ts.map +0 -1
- package/dist/devices/waterHeater.js.map +0 -1
- package/dist/dgram/coap.d.ts +0 -205
- package/dist/dgram/coap.d.ts.map +0 -1
- package/dist/dgram/coap.js.map +0 -1
- package/dist/dgram/dgram.d.ts +0 -141
- package/dist/dgram/dgram.d.ts.map +0 -1
- package/dist/dgram/dgram.js.map +0 -1
- package/dist/dgram/mb_coap.d.ts +0 -24
- package/dist/dgram/mb_coap.d.ts.map +0 -1
- package/dist/dgram/mb_coap.js.map +0 -1
- package/dist/dgram/mb_mdns.d.ts +0 -24
- package/dist/dgram/mb_mdns.d.ts.map +0 -1
- package/dist/dgram/mb_mdns.js.map +0 -1
- package/dist/dgram/mdns.d.ts +0 -290
- package/dist/dgram/mdns.d.ts.map +0 -1
- package/dist/dgram/mdns.js.map +0 -1
- package/dist/dgram/multicast.d.ts +0 -67
- package/dist/dgram/multicast.d.ts.map +0 -1
- package/dist/dgram/multicast.js.map +0 -1
- package/dist/dgram/unicast.d.ts +0 -56
- package/dist/dgram/unicast.d.ts.map +0 -1
- package/dist/dgram/unicast.js.map +0 -1
- package/dist/frontend.d.ts +0 -235
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/frontendTypes.d.ts +0 -529
- package/dist/frontendTypes.d.ts.map +0 -1
- package/dist/frontendTypes.js.map +0 -1
- package/dist/helpers.d.ts +0 -48
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js.map +0 -1
- package/dist/index.d.ts +0 -33
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger/export.d.ts +0 -2
- package/dist/logger/export.d.ts.map +0 -1
- package/dist/logger/export.js.map +0 -1
- package/dist/matter/behaviors.d.ts +0 -2
- package/dist/matter/behaviors.d.ts.map +0 -1
- package/dist/matter/behaviors.js.map +0 -1
- package/dist/matter/clusters.d.ts +0 -2
- package/dist/matter/clusters.d.ts.map +0 -1
- package/dist/matter/clusters.js.map +0 -1
- package/dist/matter/devices.d.ts +0 -2
- package/dist/matter/devices.d.ts.map +0 -1
- package/dist/matter/devices.js.map +0 -1
- package/dist/matter/endpoints.d.ts +0 -2
- package/dist/matter/endpoints.d.ts.map +0 -1
- package/dist/matter/endpoints.js.map +0 -1
- package/dist/matter/export.d.ts +0 -5
- package/dist/matter/export.d.ts.map +0 -1
- package/dist/matter/export.js.map +0 -1
- package/dist/matter/types.d.ts +0 -3
- package/dist/matter/types.d.ts.map +0 -1
- package/dist/matter/types.js.map +0 -1
- package/dist/matterbridge.d.ts +0 -475
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -2404
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -770
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1550
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -758
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -402
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -226
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -347
- 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 -66
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -33
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createDirectory.d.ts +0 -34
- package/dist/utils/createDirectory.d.ts.map +0 -1
- package/dist/utils/createDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -39
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -32
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -54
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/error.d.ts +0 -44
- package/dist/utils/error.d.ts.map +0 -1
- package/dist/utils/error.js.map +0 -1
- package/dist/utils/export.d.ts +0 -13
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/format.d.ts +0 -53
- package/dist/utils/format.d.ts.map +0 -1
- package/dist/utils/format.js.map +0 -1
- package/dist/utils/hex.d.ts +0 -89
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.js.map +0 -1
- package/dist/utils/inspector.d.ts +0 -87
- package/dist/utils/inspector.d.ts.map +0 -1
- package/dist/utils/inspector.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -103
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/jestHelpers.d.ts +0 -139
- package/dist/utils/jestHelpers.d.ts.map +0 -1
- package/dist/utils/jestHelpers.js.map +0 -1
- package/dist/utils/network.d.ts +0 -101
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/spawn.d.ts +0 -35
- package/dist/utils/spawn.d.ts.map +0 -1
- package/dist/utils/spawn.js.map +0 -1
- package/dist/utils/tracker.d.ts +0 -108
- package/dist/utils/tracker.d.ts.map +0 -1
- package/dist/utils/tracker.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -54
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
package/dist/pluginManager.js
CHANGED
|
@@ -1,50 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the Plugins class.
|
|
3
|
-
*
|
|
4
|
-
* @file plugins.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @created 2024-07-14
|
|
7
|
-
* @version 1.2.0
|
|
8
|
-
* @license Apache-2.0
|
|
9
|
-
*
|
|
10
|
-
* Copyright 2024, 2025, 2026 Luca Liguori.
|
|
11
|
-
*
|
|
12
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License.
|
|
14
|
-
* You may obtain a copy of the License at
|
|
15
|
-
*
|
|
16
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
-
* See the License for the specific language governing permissions and
|
|
22
|
-
* limitations under the License.
|
|
23
|
-
*/
|
|
24
|
-
// Node.js import
|
|
25
1
|
import EventEmitter from 'node:events';
|
|
26
|
-
// AnsiLogger module
|
|
27
2
|
import { AnsiLogger, UNDERLINE, UNDERLINEOFF, BLUE, db, er, nf, nt, rs, wr, debugStringify, CYAN } from 'node-ansi-logger';
|
|
28
3
|
import { plg, typ } from './matterbridgeTypes.js';
|
|
29
4
|
import { inspectError, logError } from './utils/error.js';
|
|
30
5
|
import { BroadcastServer } from './broadcastServer.js';
|
|
31
|
-
/**
|
|
32
|
-
* Manages Matterbridge plugins.
|
|
33
|
-
*/
|
|
34
6
|
export class PluginManager extends EventEmitter {
|
|
35
7
|
_plugins = new Map();
|
|
36
8
|
matterbridge;
|
|
37
9
|
log;
|
|
38
10
|
server;
|
|
39
|
-
/**
|
|
40
|
-
* Creates an instance of PluginManager.
|
|
41
|
-
*
|
|
42
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
43
|
-
*/
|
|
44
11
|
constructor(matterbridge) {
|
|
45
12
|
super();
|
|
46
13
|
this.matterbridge = matterbridge;
|
|
47
|
-
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4
|
|
14
|
+
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: matterbridge.log.logLevel });
|
|
48
15
|
this.log.debug('Matterbridge plugin manager starting...');
|
|
49
16
|
this.server = new BroadcastServer('plugins', this.log);
|
|
50
17
|
this.server.on('broadcast_message', this.msgHandler.bind(this));
|
|
@@ -86,69 +53,28 @@ export class PluginManager extends EventEmitter {
|
|
|
86
53
|
}
|
|
87
54
|
}
|
|
88
55
|
}
|
|
89
|
-
/**
|
|
90
|
-
* Gets the number of plugins.
|
|
91
|
-
*
|
|
92
|
-
* @returns {number} The number of plugins.
|
|
93
|
-
*/
|
|
94
56
|
get length() {
|
|
95
57
|
return this._plugins.size;
|
|
96
58
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Gets the number of plugins.
|
|
99
|
-
*
|
|
100
|
-
* @returns {number} The number of plugins.
|
|
101
|
-
*/
|
|
102
59
|
get size() {
|
|
103
60
|
return this._plugins.size;
|
|
104
61
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Checks if a plugin with the specified name exists.
|
|
107
|
-
*
|
|
108
|
-
* @param {string} name - The name of the plugin.
|
|
109
|
-
* @returns {boolean} True if the plugin exists, false otherwise.
|
|
110
|
-
*/
|
|
111
62
|
has(name) {
|
|
112
63
|
return this._plugins.has(name);
|
|
113
64
|
}
|
|
114
|
-
/**
|
|
115
|
-
* Gets a plugin by its name.
|
|
116
|
-
*
|
|
117
|
-
* @param {string} name - The name of the plugin.
|
|
118
|
-
* @returns {Plugin | undefined} The plugin, or undefined if not found.
|
|
119
|
-
*/
|
|
120
65
|
get(name) {
|
|
121
66
|
return this._plugins.get(name);
|
|
122
67
|
}
|
|
123
|
-
/**
|
|
124
|
-
* Adds a plugin to the manager.
|
|
125
|
-
*
|
|
126
|
-
* @param {Plugin} plugin - The plugin to add.
|
|
127
|
-
* @returns {Plugin} The added plugin.
|
|
128
|
-
*/
|
|
129
68
|
set(plugin) {
|
|
130
69
|
this._plugins.set(plugin.name, plugin);
|
|
131
70
|
return plugin;
|
|
132
71
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Clears all plugins from the manager.
|
|
135
|
-
*/
|
|
136
72
|
clear() {
|
|
137
73
|
this._plugins.clear();
|
|
138
74
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Gets an array of all plugins.
|
|
141
|
-
*
|
|
142
|
-
* @returns {Plugin[]} An array of all plugins.
|
|
143
|
-
*/
|
|
144
75
|
array() {
|
|
145
76
|
return Array.from(this._plugins.values());
|
|
146
77
|
}
|
|
147
|
-
/**
|
|
148
|
-
* Gets an array of all plugins suitable for serialization.
|
|
149
|
-
*
|
|
150
|
-
* @returns {ApiPlugin[]} An array of all plugins.
|
|
151
|
-
*/
|
|
152
78
|
baseArray() {
|
|
153
79
|
const basePlugins = [];
|
|
154
80
|
for (const plugin of this._plugins.values()) {
|
|
@@ -182,20 +108,9 @@ export class PluginManager extends EventEmitter {
|
|
|
182
108
|
}
|
|
183
109
|
return basePlugins;
|
|
184
110
|
}
|
|
185
|
-
/**
|
|
186
|
-
* Gets an iterator for the plugins.
|
|
187
|
-
*
|
|
188
|
-
* @returns {IterableIterator<Plugin>} An iterator for the plugins.
|
|
189
|
-
*/
|
|
190
111
|
[Symbol.iterator]() {
|
|
191
112
|
return this._plugins.values();
|
|
192
113
|
}
|
|
193
|
-
/**
|
|
194
|
-
* Executes a provided function once for each plugin.
|
|
195
|
-
*
|
|
196
|
-
* @param {Function} callback - The function to execute for each plugin.
|
|
197
|
-
* @returns {Promise<void>}
|
|
198
|
-
*/
|
|
199
114
|
async forEach(callback) {
|
|
200
115
|
if (this.size === 0)
|
|
201
116
|
return;
|
|
@@ -209,39 +124,22 @@ export class PluginManager extends EventEmitter {
|
|
|
209
124
|
});
|
|
210
125
|
await Promise.all(tasks);
|
|
211
126
|
}
|
|
212
|
-
/**
|
|
213
|
-
* Sets the log level for the plugin manager.
|
|
214
|
-
*
|
|
215
|
-
* @param {LogLevel} logLevel - The log level to set.
|
|
216
|
-
*/
|
|
217
127
|
set logLevel(logLevel) {
|
|
218
128
|
this.log.logLevel = logLevel;
|
|
219
129
|
}
|
|
220
|
-
/**
|
|
221
|
-
* Loads registered plugins from storage.
|
|
222
|
-
*
|
|
223
|
-
* @returns {Promise<StoragePlugin[]>} A promise that resolves to an array of registered plugins.
|
|
224
|
-
*/
|
|
225
130
|
async loadFromStorage() {
|
|
226
131
|
if (!this.matterbridge.nodeContext) {
|
|
227
132
|
throw new Error('loadFromStorage: node context is not available.');
|
|
228
133
|
}
|
|
229
|
-
// Load the array from storage and convert it to a map
|
|
230
134
|
const pluginsArray = await this.matterbridge.nodeContext.get('plugins', []);
|
|
231
135
|
for (const plugin of pluginsArray)
|
|
232
136
|
this._plugins.set(plugin.name, plugin);
|
|
233
137
|
return pluginsArray;
|
|
234
138
|
}
|
|
235
|
-
/**
|
|
236
|
-
* Saves registered plugins to storage.
|
|
237
|
-
*
|
|
238
|
-
* @returns {Promise<number>} A promise that resolves to the number of registered plugins.
|
|
239
|
-
*/
|
|
240
139
|
async saveToStorage() {
|
|
241
140
|
if (!this.matterbridge.nodeContext) {
|
|
242
141
|
throw new Error('loadFromStorage: node context is not available.');
|
|
243
142
|
}
|
|
244
|
-
// Convert the map to an array
|
|
245
143
|
const plugins = [];
|
|
246
144
|
for (const plugin of this.array()) {
|
|
247
145
|
plugins.push({
|
|
@@ -258,21 +156,13 @@ export class PluginManager extends EventEmitter {
|
|
|
258
156
|
this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
|
|
259
157
|
return plugins.length;
|
|
260
158
|
}
|
|
261
|
-
/**
|
|
262
|
-
* Resolves the name of a plugin by loading and parsing its package.json file.
|
|
263
|
-
*
|
|
264
|
-
* @param {string} pluginPath - The path to the plugin or the path to the plugin's package.json file.
|
|
265
|
-
* @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.
|
|
266
|
-
*/
|
|
267
159
|
async resolve(pluginPath) {
|
|
268
160
|
const { default: path } = await import('node:path');
|
|
269
161
|
const { promises } = await import('node:fs');
|
|
270
162
|
if (!pluginPath.endsWith('package.json'))
|
|
271
163
|
pluginPath = path.join(pluginPath, 'package.json');
|
|
272
|
-
// Resolve the package.json of the plugin
|
|
273
164
|
let packageJsonPath = path.resolve(pluginPath);
|
|
274
165
|
this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
|
|
275
|
-
// Check if the package.json file exists
|
|
276
166
|
try {
|
|
277
167
|
await promises.access(packageJsonPath);
|
|
278
168
|
}
|
|
@@ -282,9 +172,7 @@ export class PluginManager extends EventEmitter {
|
|
|
282
172
|
this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
|
|
283
173
|
}
|
|
284
174
|
try {
|
|
285
|
-
// Load the package.json of the plugin
|
|
286
175
|
const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
|
|
287
|
-
// Check for main issues
|
|
288
176
|
if (!packageJson.name) {
|
|
289
177
|
this.log.error(`Package.json name not found at ${packageJsonPath}`);
|
|
290
178
|
return null;
|
|
@@ -297,7 +185,6 @@ export class PluginManager extends EventEmitter {
|
|
|
297
185
|
this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
|
|
298
186
|
return null;
|
|
299
187
|
}
|
|
300
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
301
188
|
const checkForProjectChipPackages = (dependencies) => {
|
|
302
189
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
303
190
|
};
|
|
@@ -319,7 +206,6 @@ export class PluginManager extends EventEmitter {
|
|
|
319
206
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
320
207
|
return null;
|
|
321
208
|
}
|
|
322
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
323
209
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
324
210
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
325
211
|
};
|
|
@@ -349,12 +235,6 @@ export class PluginManager extends EventEmitter {
|
|
|
349
235
|
return null;
|
|
350
236
|
}
|
|
351
237
|
}
|
|
352
|
-
/**
|
|
353
|
-
* Installs a package globally using npm.
|
|
354
|
-
*
|
|
355
|
-
* @param {string} packageName - The name of the package to install.
|
|
356
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the installation was successful, false otherwise.
|
|
357
|
-
*/
|
|
358
238
|
async install(packageName) {
|
|
359
239
|
const { spawnCommand } = await import('./utils/spawn.js');
|
|
360
240
|
try {
|
|
@@ -381,12 +261,6 @@ export class PluginManager extends EventEmitter {
|
|
|
381
261
|
return false;
|
|
382
262
|
}
|
|
383
263
|
}
|
|
384
|
-
/**
|
|
385
|
-
* Uninstalls a package globally using npm.
|
|
386
|
-
*
|
|
387
|
-
* @param {string} packageName - The name of the package to uninstall.
|
|
388
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the uninstallation was successful, false otherwise.
|
|
389
|
-
*/
|
|
390
264
|
async uninstall(packageName) {
|
|
391
265
|
const { spawnCommand } = await import('./utils/spawn.js');
|
|
392
266
|
packageName = packageName.replace(/@.*$/, '');
|
|
@@ -407,12 +281,6 @@ export class PluginManager extends EventEmitter {
|
|
|
407
281
|
return false;
|
|
408
282
|
}
|
|
409
283
|
}
|
|
410
|
-
/**
|
|
411
|
-
* Get the author of a plugin from its package.json.
|
|
412
|
-
*
|
|
413
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
414
|
-
* @returns {string} The author of the plugin, or 'Unknown author' if not found.
|
|
415
|
-
*/
|
|
416
284
|
getAuthor(packageJson) {
|
|
417
285
|
if (packageJson.author && typeof packageJson.author === 'string')
|
|
418
286
|
return packageJson.author;
|
|
@@ -420,12 +288,6 @@ export class PluginManager extends EventEmitter {
|
|
|
420
288
|
return packageJson.author.name;
|
|
421
289
|
return 'Unknown author';
|
|
422
290
|
}
|
|
423
|
-
/**
|
|
424
|
-
* Get the homepage of a plugin from its package.json.
|
|
425
|
-
*
|
|
426
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
427
|
-
* @returns {string | undefined} The homepage of the plugin, or undefined if not found.
|
|
428
|
-
*/
|
|
429
291
|
getHomepage(packageJson) {
|
|
430
292
|
if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
|
|
431
293
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
@@ -434,14 +296,7 @@ export class PluginManager extends EventEmitter {
|
|
|
434
296
|
return packageJson.repository.url.replace('git+', '').replace('.git', '');
|
|
435
297
|
}
|
|
436
298
|
}
|
|
437
|
-
/**
|
|
438
|
-
* Get the help URL of a plugin from its package.json.
|
|
439
|
-
*
|
|
440
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
441
|
-
* @returns {string | undefined} The URL to the help page or to the README file, or undefined if not found.
|
|
442
|
-
*/
|
|
443
299
|
getHelp(packageJson) {
|
|
444
|
-
// If there's a help field that looks like a URL, return it.
|
|
445
300
|
if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
|
|
446
301
|
return packageJson.help;
|
|
447
302
|
}
|
|
@@ -452,14 +307,7 @@ export class PluginManager extends EventEmitter {
|
|
|
452
307
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
453
308
|
}
|
|
454
309
|
}
|
|
455
|
-
/**
|
|
456
|
-
* Get the changelog URL of a plugin from its package.json.
|
|
457
|
-
*
|
|
458
|
-
* @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
|
|
459
|
-
* @returns {string | undefined} The URL to the CHANGELOG file, or undefined if not found.
|
|
460
|
-
*/
|
|
461
310
|
getChangelog(packageJson) {
|
|
462
|
-
// If there's a changelog field that looks like a URL, return it.
|
|
463
311
|
if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
|
|
464
312
|
return packageJson.changelog;
|
|
465
313
|
}
|
|
@@ -470,13 +318,6 @@ export class PluginManager extends EventEmitter {
|
|
|
470
318
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
471
319
|
}
|
|
472
320
|
}
|
|
473
|
-
/**
|
|
474
|
-
* Get the first funding URL(s) of a plugin from its package.json.
|
|
475
|
-
*
|
|
476
|
-
* @param {Record<string, any>} packageJson - The package.json object of the plugin.
|
|
477
|
-
* @returns {string | undefined} The first funding URLs, or undefined if not found.
|
|
478
|
-
*/
|
|
479
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
480
321
|
getFunding(packageJson) {
|
|
481
322
|
const funding = packageJson.funding;
|
|
482
323
|
if (!funding)
|
|
@@ -485,25 +326,16 @@ export class PluginManager extends EventEmitter {
|
|
|
485
326
|
return;
|
|
486
327
|
if (typeof funding === 'string' && funding.startsWith('http'))
|
|
487
328
|
return funding;
|
|
488
|
-
// Normalize funding into an array.
|
|
489
329
|
const fundingEntries = Array.isArray(funding) ? funding : [funding];
|
|
490
330
|
for (const entry of fundingEntries) {
|
|
491
331
|
if (entry && typeof entry === 'string' && entry.startsWith('http')) {
|
|
492
|
-
// If the funding entry is a string, assume it is a URL.
|
|
493
332
|
return entry;
|
|
494
333
|
}
|
|
495
334
|
else if (entry && typeof entry === 'object' && typeof entry.url === 'string' && entry.url.startsWith('http')) {
|
|
496
|
-
// If it's an object with a 'url' property, use that.
|
|
497
335
|
return entry.url;
|
|
498
336
|
}
|
|
499
337
|
}
|
|
500
338
|
}
|
|
501
|
-
/**
|
|
502
|
-
* Loads and parses the plugin package.json and returns it.
|
|
503
|
-
*
|
|
504
|
-
* @param {Plugin} plugin - The plugin to load the package from.
|
|
505
|
-
* @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.
|
|
506
|
-
*/
|
|
507
339
|
async parse(plugin) {
|
|
508
340
|
const { promises } = await import('node:fs');
|
|
509
341
|
try {
|
|
@@ -533,7 +365,6 @@ export class PluginManager extends EventEmitter {
|
|
|
533
365
|
plugin.funding = this.getFunding(packageJson);
|
|
534
366
|
if (!plugin.type)
|
|
535
367
|
this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
|
|
536
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
537
368
|
const checkForProjectChipPackages = (dependencies) => {
|
|
538
369
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
539
370
|
};
|
|
@@ -555,7 +386,6 @@ export class PluginManager extends EventEmitter {
|
|
|
555
386
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
556
387
|
return null;
|
|
557
388
|
}
|
|
558
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
559
389
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
560
390
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
561
391
|
};
|
|
@@ -585,16 +415,6 @@ export class PluginManager extends EventEmitter {
|
|
|
585
415
|
return null;
|
|
586
416
|
}
|
|
587
417
|
}
|
|
588
|
-
/**
|
|
589
|
-
* Enables a plugin by its name or path.
|
|
590
|
-
*
|
|
591
|
-
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
592
|
-
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
593
|
-
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
594
|
-
*
|
|
595
|
-
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
596
|
-
* @returns {Promise<Plugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
597
|
-
*/
|
|
598
418
|
async enable(nameOrPath) {
|
|
599
419
|
const { promises } = await import('node:fs');
|
|
600
420
|
if (!nameOrPath)
|
|
@@ -630,16 +450,6 @@ export class PluginManager extends EventEmitter {
|
|
|
630
450
|
return null;
|
|
631
451
|
}
|
|
632
452
|
}
|
|
633
|
-
/**
|
|
634
|
-
* Enables a plugin by its name or path.
|
|
635
|
-
*
|
|
636
|
-
* This method enables a plugin by setting its `enabled` property to `true` and saving the updated
|
|
637
|
-
* plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
|
|
638
|
-
* If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
|
|
639
|
-
*
|
|
640
|
-
* @param {string} nameOrPath - The name or path of the plugin to enable.
|
|
641
|
-
* @returns {Promise<Plugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
|
|
642
|
-
*/
|
|
643
453
|
async disable(nameOrPath) {
|
|
644
454
|
const { promises } = await import('node:fs');
|
|
645
455
|
if (!nameOrPath)
|
|
@@ -675,16 +485,6 @@ export class PluginManager extends EventEmitter {
|
|
|
675
485
|
return null;
|
|
676
486
|
}
|
|
677
487
|
}
|
|
678
|
-
/**
|
|
679
|
-
* Removes a plugin by its name or path.
|
|
680
|
-
*
|
|
681
|
-
* This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
|
|
682
|
-
* It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
|
|
683
|
-
* the plugin's `package.json` file to retrieve its name and remove it.
|
|
684
|
-
*
|
|
685
|
-
* @param {string} nameOrPath - The name or path of the plugin to remove.
|
|
686
|
-
* @returns {Promise<Plugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
|
|
687
|
-
*/
|
|
688
488
|
async remove(nameOrPath) {
|
|
689
489
|
const { promises } = await import('node:fs');
|
|
690
490
|
if (!nameOrPath)
|
|
@@ -720,17 +520,6 @@ export class PluginManager extends EventEmitter {
|
|
|
720
520
|
return null;
|
|
721
521
|
}
|
|
722
522
|
}
|
|
723
|
-
/**
|
|
724
|
-
* Adds a plugin by its name or path.
|
|
725
|
-
*
|
|
726
|
-
* This method adds a plugin to the plugins map and saves the updated plugin information to storage.
|
|
727
|
-
* It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
|
|
728
|
-
* registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
|
|
729
|
-
* and saves the updated plugin information to storage.
|
|
730
|
-
*
|
|
731
|
-
* @param {string} nameOrPath - The name or path of the plugin to add.
|
|
732
|
-
* @returns {Promise<Plugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
|
|
733
|
-
*/
|
|
734
523
|
async add(nameOrPath) {
|
|
735
524
|
const { promises } = await import('node:fs');
|
|
736
525
|
if (!nameOrPath)
|
|
@@ -770,15 +559,6 @@ export class PluginManager extends EventEmitter {
|
|
|
770
559
|
return null;
|
|
771
560
|
}
|
|
772
561
|
}
|
|
773
|
-
/**
|
|
774
|
-
* Loads a plugin and returns the corresponding MatterbridgePlatform instance.
|
|
775
|
-
*
|
|
776
|
-
* @param {Plugin} plugin - The plugin to load.
|
|
777
|
-
* @param {boolean} start - Optional flag indicating whether to start the plugin after loading. Default is false.
|
|
778
|
-
* @param {string} message - Optional message to pass to the plugin when starting.
|
|
779
|
-
* @param {boolean} configure - Optional flag indicating whether to configure the plugin after loading. Default is false.
|
|
780
|
-
* @returns {Promise<MatterbridgePlatform | undefined>} A Promise that resolves to the loaded MatterbridgePlatform instance or undefined.
|
|
781
|
-
*/
|
|
782
562
|
async load(plugin, start = false, message = '', configure = false) {
|
|
783
563
|
const { promises } = await import('node:fs');
|
|
784
564
|
const { default: path } = await import('node:path');
|
|
@@ -792,20 +572,15 @@ export class PluginManager extends EventEmitter {
|
|
|
792
572
|
}
|
|
793
573
|
this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
|
|
794
574
|
try {
|
|
795
|
-
// Load the package.json of the plugin
|
|
796
575
|
const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
|
|
797
|
-
// Resolve the main module path relative to package.json
|
|
798
576
|
const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
|
|
799
|
-
// Dynamically import the plugin
|
|
800
577
|
const { pathToFileURL } = await import('node:url');
|
|
801
578
|
const pluginUrl = pathToFileURL(pluginEntry);
|
|
802
579
|
this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
803
580
|
const pluginInstance = await import(pluginUrl.href);
|
|
804
581
|
this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
805
|
-
// Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
|
|
806
582
|
if (pluginInstance.default) {
|
|
807
583
|
const config = await this.loadConfig(plugin);
|
|
808
|
-
// 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.
|
|
809
584
|
plugin.name = packageJson.name;
|
|
810
585
|
plugin.description = packageJson.description ?? 'No description';
|
|
811
586
|
plugin.version = packageJson.version;
|
|
@@ -814,7 +589,7 @@ export class PluginManager extends EventEmitter {
|
|
|
814
589
|
plugin.schemaJson = await this.loadSchema(plugin);
|
|
815
590
|
config.name = plugin.name;
|
|
816
591
|
config.version = packageJson.version;
|
|
817
|
-
const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4
|
|
592
|
+
const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
|
|
818
593
|
const platform = pluginInstance.default(this.matterbridge, log, config);
|
|
819
594
|
config.type = platform.type;
|
|
820
595
|
platform.name = packageJson.name;
|
|
@@ -832,7 +607,7 @@ export class PluginManager extends EventEmitter {
|
|
|
832
607
|
plugin.platform = platform;
|
|
833
608
|
plugin.loaded = true;
|
|
834
609
|
plugin.registeredDevices = 0;
|
|
835
|
-
await this.saveToStorage();
|
|
610
|
+
await this.saveToStorage();
|
|
836
611
|
this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
|
|
837
612
|
this.emit('loaded', plugin.name);
|
|
838
613
|
if (start)
|
|
@@ -852,14 +627,6 @@ export class PluginManager extends EventEmitter {
|
|
|
852
627
|
}
|
|
853
628
|
return undefined;
|
|
854
629
|
}
|
|
855
|
-
/**
|
|
856
|
-
* Starts a plugin.
|
|
857
|
-
*
|
|
858
|
-
* @param {Plugin} plugin - The plugin to start.
|
|
859
|
-
* @param {string} [message] - Optional message to pass to the plugin's onStart method.
|
|
860
|
-
* @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
|
|
861
|
-
* @returns {Promise<Plugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
|
|
862
|
-
*/
|
|
863
630
|
async start(plugin, message, configure = false) {
|
|
864
631
|
if (!plugin.loaded) {
|
|
865
632
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -890,12 +657,6 @@ export class PluginManager extends EventEmitter {
|
|
|
890
657
|
}
|
|
891
658
|
return undefined;
|
|
892
659
|
}
|
|
893
|
-
/**
|
|
894
|
-
* Configures a plugin.
|
|
895
|
-
*
|
|
896
|
-
* @param {Plugin} plugin - The plugin to configure.
|
|
897
|
-
* @returns {Promise<Plugin | undefined>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
|
|
898
|
-
*/
|
|
899
660
|
async configure(plugin) {
|
|
900
661
|
if (!plugin.loaded) {
|
|
901
662
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -927,18 +688,6 @@ export class PluginManager extends EventEmitter {
|
|
|
927
688
|
}
|
|
928
689
|
return undefined;
|
|
929
690
|
}
|
|
930
|
-
/**
|
|
931
|
-
* Shuts down a plugin.
|
|
932
|
-
*
|
|
933
|
-
* This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
|
|
934
|
-
* It logs the shutdown process and optionally removes all devices associated with the plugin.
|
|
935
|
-
*
|
|
936
|
-
* @param {Plugin} plugin - The plugin to shut down.
|
|
937
|
-
* @param {string} [reason] - The reason for shutting down the plugin.
|
|
938
|
-
* @param {boolean} [removeAllDevices] - Whether to remove all devices associated with the plugin.
|
|
939
|
-
* @param {boolean} [force] - Whether to force the shutdown even if the plugin is not loaded or started.
|
|
940
|
-
* @returns {Promise<Plugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
|
|
941
|
-
*/
|
|
942
691
|
async shutdown(plugin, reason, removeAllDevices = false, force = false) {
|
|
943
692
|
this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
|
|
944
693
|
if (!plugin.loaded) {
|
|
@@ -981,15 +730,6 @@ export class PluginManager extends EventEmitter {
|
|
|
981
730
|
}
|
|
982
731
|
return undefined;
|
|
983
732
|
}
|
|
984
|
-
/**
|
|
985
|
-
* Loads the configuration for a plugin.
|
|
986
|
-
* If the configuration file exists, it reads the file and returns the parsed JSON data.
|
|
987
|
-
* If the configuration file does not exist, it creates a new file with default configuration and returns it.
|
|
988
|
-
* If any error occurs during file access or creation, it logs an error and return un empty config.
|
|
989
|
-
*
|
|
990
|
-
* @param {Plugin} plugin - The plugin for which to load the configuration.
|
|
991
|
-
* @returns {Promise<PlatformConfig>} A promise that resolves to the loaded or created configuration.
|
|
992
|
-
*/
|
|
993
733
|
async loadConfig(plugin) {
|
|
994
734
|
const { default: path } = await import('node:path');
|
|
995
735
|
const { promises } = await import('node:fs');
|
|
@@ -1001,8 +741,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1001
741
|
const data = await promises.readFile(configFile, 'utf8');
|
|
1002
742
|
const config = JSON.parse(data);
|
|
1003
743
|
this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
1004
|
-
// this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
1005
|
-
// The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
|
|
1006
744
|
config.name = plugin.name;
|
|
1007
745
|
config.type = plugin.type;
|
|
1008
746
|
if (config.debug === undefined)
|
|
@@ -1024,8 +762,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1024
762
|
}
|
|
1025
763
|
catch (_err) {
|
|
1026
764
|
this.log.debug(`Default config file ${defaultConfigFile} for plugin ${plg}${plugin.name}${db} does not exist, creating new config file...`);
|
|
1027
|
-
// TODO: Remove this when all these plugins have their own default config file
|
|
1028
|
-
// istanbul ignore next if
|
|
1029
765
|
if (plugin.name === 'matterbridge-zigbee2mqtt')
|
|
1030
766
|
config = zigbee2mqtt_config;
|
|
1031
767
|
else if (plugin.name === 'matterbridge-somfy-tahoma')
|
|
@@ -1038,7 +774,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1038
774
|
try {
|
|
1039
775
|
await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
1040
776
|
this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
1041
|
-
// this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
1042
777
|
return config;
|
|
1043
778
|
}
|
|
1044
779
|
catch (err) {
|
|
@@ -1052,19 +787,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1052
787
|
}
|
|
1053
788
|
}
|
|
1054
789
|
}
|
|
1055
|
-
/**
|
|
1056
|
-
* Saves the configuration of a plugin to a file.
|
|
1057
|
-
*
|
|
1058
|
-
* This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
1059
|
-
* If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
|
|
1060
|
-
* is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
|
|
1061
|
-
* the error and rejects the promise.
|
|
1062
|
-
*
|
|
1063
|
-
* @param {Plugin} plugin - The plugin whose configuration is to be saved.
|
|
1064
|
-
* @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
|
|
1065
|
-
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
|
|
1066
|
-
* @throws {Error} If the plugin's configuration is not found.
|
|
1067
|
-
*/
|
|
1068
790
|
async saveConfigFromPlugin(plugin, restartRequired = false) {
|
|
1069
791
|
const { default: path } = await import('node:path');
|
|
1070
792
|
const { promises } = await import('node:fs');
|
|
@@ -1079,7 +801,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1079
801
|
if (restartRequired)
|
|
1080
802
|
plugin.restartRequired = true;
|
|
1081
803
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
1082
|
-
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
|
|
1083
804
|
return Promise.resolve();
|
|
1084
805
|
}
|
|
1085
806
|
catch (err) {
|
|
@@ -1087,20 +808,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1087
808
|
return Promise.reject(err);
|
|
1088
809
|
}
|
|
1089
810
|
}
|
|
1090
|
-
/**
|
|
1091
|
-
* Saves the configuration of a plugin from a JSON object to a file.
|
|
1092
|
-
*
|
|
1093
|
-
* This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
|
|
1094
|
-
* It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
|
|
1095
|
-
* the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
|
|
1096
|
-
* successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
|
|
1097
|
-
* during the file write operation, it logs the error and returns.
|
|
1098
|
-
*
|
|
1099
|
-
* @param {Plugin} plugin - The plugin whose configuration is to be saved.
|
|
1100
|
-
* @param {PlatformConfig} config - The configuration data to be saved.
|
|
1101
|
-
* @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
|
|
1102
|
-
* @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
|
|
1103
|
-
*/
|
|
1104
811
|
async saveConfigFromJson(plugin, config, restartRequired = false) {
|
|
1105
812
|
const { default: path } = await import('node:path');
|
|
1106
813
|
const { promises } = await import('node:fs');
|
|
@@ -1119,23 +826,12 @@ export class PluginManager extends EventEmitter {
|
|
|
1119
826
|
plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
|
|
1120
827
|
}
|
|
1121
828
|
this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
|
|
1122
|
-
// this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
|
|
1123
829
|
}
|
|
1124
830
|
catch (err) {
|
|
1125
831
|
logError(this.log, `Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}`, err);
|
|
1126
832
|
return;
|
|
1127
833
|
}
|
|
1128
834
|
}
|
|
1129
|
-
/**
|
|
1130
|
-
* Loads the schema for a plugin.
|
|
1131
|
-
*
|
|
1132
|
-
* This method attempts to load the schema file for the specified plugin. If the schema file is found,
|
|
1133
|
-
* it reads and parses the file, updates the schema's title and description, and logs the process.
|
|
1134
|
-
* If the schema file is not found, it logs the event and loads a default schema for the plugin.
|
|
1135
|
-
*
|
|
1136
|
-
* @param {Plugin} plugin - The plugin whose schema is to be loaded.
|
|
1137
|
-
* @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
|
|
1138
|
-
*/
|
|
1139
835
|
async loadSchema(plugin) {
|
|
1140
836
|
const { promises } = await import('node:fs');
|
|
1141
837
|
const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
|
|
@@ -1146,7 +842,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1146
842
|
schema.title = plugin.description;
|
|
1147
843
|
schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
|
|
1148
844
|
this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
|
|
1149
|
-
// this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
|
|
1150
845
|
return schema;
|
|
1151
846
|
}
|
|
1152
847
|
catch (_err) {
|
|
@@ -1154,16 +849,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1154
849
|
return this.getDefaultSchema(plugin);
|
|
1155
850
|
}
|
|
1156
851
|
}
|
|
1157
|
-
/**
|
|
1158
|
-
* Returns the default schema for a plugin.
|
|
1159
|
-
*
|
|
1160
|
-
* This method generates a default schema object for the specified plugin. The schema includes
|
|
1161
|
-
* metadata such as the plugin's title, description, version, and author. It also defines the
|
|
1162
|
-
* properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
|
|
1163
|
-
*
|
|
1164
|
-
* @param {Plugin} plugin - The plugin for which the default schema is to be generated.
|
|
1165
|
-
* @returns {PlatformSchema} The default schema object for the plugin.
|
|
1166
|
-
*/
|
|
1167
852
|
getDefaultSchema(plugin) {
|
|
1168
853
|
return {
|
|
1169
854
|
title: plugin.description,
|
|
@@ -1194,4 +879,3 @@ export class PluginManager extends EventEmitter {
|
|
|
1194
879
|
};
|
|
1195
880
|
}
|
|
1196
881
|
}
|
|
1197
|
-
//# sourceMappingURL=pluginManager.js.map
|