matterbridge 3.3.6 → 3.3.7-dev-20251104-7c779b9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/broadcastServer.js +1 -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 +55 -451
- 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 +66 -841
- 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 -1408
- 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/frontend/build/assets/index.css +1 -1
- package/frontend/build/assets/index.js +4 -4
- package/frontend/package.json +1 -1
- 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 -803
- 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 -236
- 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 -476
- 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 -1556
- 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 -101
- 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,51 +1,18 @@
|
|
|
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 { hasParameter } from './utils/commandLine.js';
|
|
31
6
|
import { BroadcastServer } from './broadcastServer.js';
|
|
32
|
-
/**
|
|
33
|
-
* Manages Matterbridge plugins.
|
|
34
|
-
*/
|
|
35
7
|
export class PluginManager extends EventEmitter {
|
|
36
8
|
_plugins = new Map();
|
|
37
9
|
matterbridge;
|
|
38
10
|
log;
|
|
39
11
|
server;
|
|
40
|
-
/**
|
|
41
|
-
* Creates an instance of PluginManager.
|
|
42
|
-
*
|
|
43
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
44
|
-
*/
|
|
45
12
|
constructor(matterbridge) {
|
|
46
13
|
super();
|
|
47
14
|
this.matterbridge = matterbridge;
|
|
48
|
-
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4
|
|
15
|
+
this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: hasParameter('debug') ? "debug" : "info" });
|
|
49
16
|
this.log.debug('Matterbridge plugin manager starting...');
|
|
50
17
|
this.server = new BroadcastServer('plugins', this.log);
|
|
51
18
|
this.server.on('broadcast_message', this.msgHandler.bind(this));
|
|
@@ -94,69 +61,28 @@ export class PluginManager extends EventEmitter {
|
|
|
94
61
|
}
|
|
95
62
|
}
|
|
96
63
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Gets the number of plugins.
|
|
99
|
-
*
|
|
100
|
-
* @returns {number} The number of plugins.
|
|
101
|
-
*/
|
|
102
64
|
get length() {
|
|
103
65
|
return this._plugins.size;
|
|
104
66
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Gets the number of plugins.
|
|
107
|
-
*
|
|
108
|
-
* @returns {number} The number of plugins.
|
|
109
|
-
*/
|
|
110
67
|
get size() {
|
|
111
68
|
return this._plugins.size;
|
|
112
69
|
}
|
|
113
|
-
/**
|
|
114
|
-
* Checks if a plugin with the specified name exists.
|
|
115
|
-
*
|
|
116
|
-
* @param {string} name - The name of the plugin.
|
|
117
|
-
* @returns {boolean} True if the plugin exists, false otherwise.
|
|
118
|
-
*/
|
|
119
70
|
has(name) {
|
|
120
71
|
return this._plugins.has(name);
|
|
121
72
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Gets a plugin by its name.
|
|
124
|
-
*
|
|
125
|
-
* @param {string} name - The name of the plugin.
|
|
126
|
-
* @returns {Plugin | undefined} The plugin, or undefined if not found.
|
|
127
|
-
*/
|
|
128
73
|
get(name) {
|
|
129
74
|
return this._plugins.get(name);
|
|
130
75
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Adds a plugin to the manager.
|
|
133
|
-
*
|
|
134
|
-
* @param {Plugin} plugin - The plugin to add.
|
|
135
|
-
* @returns {Plugin} The added plugin.
|
|
136
|
-
*/
|
|
137
76
|
set(plugin) {
|
|
138
77
|
this._plugins.set(plugin.name, plugin);
|
|
139
78
|
return plugin;
|
|
140
79
|
}
|
|
141
|
-
/**
|
|
142
|
-
* Clears all plugins from the manager.
|
|
143
|
-
*/
|
|
144
80
|
clear() {
|
|
145
81
|
this._plugins.clear();
|
|
146
82
|
}
|
|
147
|
-
/**
|
|
148
|
-
* Gets an array of all plugins.
|
|
149
|
-
*
|
|
150
|
-
* @returns {Plugin[]} An array of all plugins.
|
|
151
|
-
*/
|
|
152
83
|
array() {
|
|
153
84
|
return Array.from(this._plugins.values());
|
|
154
85
|
}
|
|
155
|
-
/**
|
|
156
|
-
* Gets an array of all plugins suitable for serialization.
|
|
157
|
-
*
|
|
158
|
-
* @returns {ApiPlugin[]} An array of all plugins.
|
|
159
|
-
*/
|
|
160
86
|
baseArray() {
|
|
161
87
|
const basePlugins = [];
|
|
162
88
|
for (const plugin of this._plugins.values()) {
|
|
@@ -190,20 +116,9 @@ export class PluginManager extends EventEmitter {
|
|
|
190
116
|
}
|
|
191
117
|
return basePlugins;
|
|
192
118
|
}
|
|
193
|
-
/**
|
|
194
|
-
* Gets an iterator for the plugins.
|
|
195
|
-
*
|
|
196
|
-
* @returns {IterableIterator<Plugin>} An iterator for the plugins.
|
|
197
|
-
*/
|
|
198
119
|
[Symbol.iterator]() {
|
|
199
120
|
return this._plugins.values();
|
|
200
121
|
}
|
|
201
|
-
/**
|
|
202
|
-
* Executes a provided function once for each plugin.
|
|
203
|
-
*
|
|
204
|
-
* @param {Function} callback - The function to execute for each plugin.
|
|
205
|
-
* @returns {Promise<void>}
|
|
206
|
-
*/
|
|
207
122
|
async forEach(callback) {
|
|
208
123
|
if (this.size === 0)
|
|
209
124
|
return;
|
|
@@ -217,39 +132,22 @@ export class PluginManager extends EventEmitter {
|
|
|
217
132
|
});
|
|
218
133
|
await Promise.all(tasks);
|
|
219
134
|
}
|
|
220
|
-
/**
|
|
221
|
-
* Sets the log level for the plugin manager.
|
|
222
|
-
*
|
|
223
|
-
* @param {LogLevel} logLevel - The log level to set.
|
|
224
|
-
*/
|
|
225
135
|
set logLevel(logLevel) {
|
|
226
136
|
this.log.logLevel = logLevel;
|
|
227
137
|
}
|
|
228
|
-
/**
|
|
229
|
-
* Loads registered plugins from storage.
|
|
230
|
-
*
|
|
231
|
-
* @returns {Promise<StoragePlugin[]>} A promise that resolves to an array of registered plugins.
|
|
232
|
-
*/
|
|
233
138
|
async loadFromStorage() {
|
|
234
139
|
if (!this.matterbridge.nodeContext) {
|
|
235
140
|
throw new Error('loadFromStorage: node context is not available.');
|
|
236
141
|
}
|
|
237
|
-
// Load the array from storage and convert it to a map
|
|
238
142
|
const pluginsArray = await this.matterbridge.nodeContext.get('plugins', []);
|
|
239
143
|
for (const plugin of pluginsArray)
|
|
240
144
|
this._plugins.set(plugin.name, plugin);
|
|
241
145
|
return pluginsArray;
|
|
242
146
|
}
|
|
243
|
-
/**
|
|
244
|
-
* Saves registered plugins to storage.
|
|
245
|
-
*
|
|
246
|
-
* @returns {Promise<number>} A promise that resolves to the number of registered plugins.
|
|
247
|
-
*/
|
|
248
147
|
async saveToStorage() {
|
|
249
148
|
if (!this.matterbridge.nodeContext) {
|
|
250
149
|
throw new Error('loadFromStorage: node context is not available.');
|
|
251
150
|
}
|
|
252
|
-
// Convert the map to an array
|
|
253
151
|
const plugins = [];
|
|
254
152
|
for (const plugin of this.array()) {
|
|
255
153
|
plugins.push({
|
|
@@ -266,21 +164,13 @@ export class PluginManager extends EventEmitter {
|
|
|
266
164
|
this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
|
|
267
165
|
return plugins.length;
|
|
268
166
|
}
|
|
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
167
|
async resolve(pluginPath) {
|
|
276
168
|
const { default: path } = await import('node:path');
|
|
277
169
|
const { promises } = await import('node:fs');
|
|
278
170
|
if (!pluginPath.endsWith('package.json'))
|
|
279
171
|
pluginPath = path.join(pluginPath, 'package.json');
|
|
280
|
-
// Resolve the package.json of the plugin
|
|
281
172
|
let packageJsonPath = path.resolve(pluginPath);
|
|
282
173
|
this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
|
|
283
|
-
// Check if the package.json file exists
|
|
284
174
|
try {
|
|
285
175
|
await promises.access(packageJsonPath);
|
|
286
176
|
}
|
|
@@ -290,9 +180,7 @@ export class PluginManager extends EventEmitter {
|
|
|
290
180
|
this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
|
|
291
181
|
}
|
|
292
182
|
try {
|
|
293
|
-
// Load the package.json of the plugin
|
|
294
183
|
const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
|
|
295
|
-
// Check for main issues
|
|
296
184
|
if (!packageJson.name) {
|
|
297
185
|
this.log.error(`Package.json name not found at ${packageJsonPath}`);
|
|
298
186
|
return null;
|
|
@@ -305,7 +193,6 @@ export class PluginManager extends EventEmitter {
|
|
|
305
193
|
this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
|
|
306
194
|
return null;
|
|
307
195
|
}
|
|
308
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
309
196
|
const checkForProjectChipPackages = (dependencies) => {
|
|
310
197
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
311
198
|
};
|
|
@@ -327,7 +214,6 @@ export class PluginManager extends EventEmitter {
|
|
|
327
214
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
328
215
|
return null;
|
|
329
216
|
}
|
|
330
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
331
217
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
332
218
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
333
219
|
};
|
|
@@ -357,12 +243,6 @@ export class PluginManager extends EventEmitter {
|
|
|
357
243
|
return null;
|
|
358
244
|
}
|
|
359
245
|
}
|
|
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
246
|
async install(packageName) {
|
|
367
247
|
const { spawnCommand } = await import('./utils/spawn.js');
|
|
368
248
|
try {
|
|
@@ -389,12 +269,6 @@ export class PluginManager extends EventEmitter {
|
|
|
389
269
|
return false;
|
|
390
270
|
}
|
|
391
271
|
}
|
|
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
272
|
async uninstall(packageName) {
|
|
399
273
|
const { spawnCommand } = await import('./utils/spawn.js');
|
|
400
274
|
packageName = packageName.replace(/@.*$/, '');
|
|
@@ -415,12 +289,6 @@ export class PluginManager extends EventEmitter {
|
|
|
415
289
|
return false;
|
|
416
290
|
}
|
|
417
291
|
}
|
|
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
292
|
getAuthor(packageJson) {
|
|
425
293
|
if (packageJson.author && typeof packageJson.author === 'string')
|
|
426
294
|
return packageJson.author;
|
|
@@ -428,12 +296,6 @@ export class PluginManager extends EventEmitter {
|
|
|
428
296
|
return packageJson.author.name;
|
|
429
297
|
return 'Unknown author';
|
|
430
298
|
}
|
|
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
299
|
getHomepage(packageJson) {
|
|
438
300
|
if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
|
|
439
301
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
@@ -442,14 +304,7 @@ export class PluginManager extends EventEmitter {
|
|
|
442
304
|
return packageJson.repository.url.replace('git+', '').replace('.git', '');
|
|
443
305
|
}
|
|
444
306
|
}
|
|
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
307
|
getHelp(packageJson) {
|
|
452
|
-
// If there's a help field that looks like a URL, return it.
|
|
453
308
|
if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
|
|
454
309
|
return packageJson.help;
|
|
455
310
|
}
|
|
@@ -460,14 +315,7 @@ export class PluginManager extends EventEmitter {
|
|
|
460
315
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
461
316
|
}
|
|
462
317
|
}
|
|
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
318
|
getChangelog(packageJson) {
|
|
470
|
-
// If there's a changelog field that looks like a URL, return it.
|
|
471
319
|
if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
|
|
472
320
|
return packageJson.changelog;
|
|
473
321
|
}
|
|
@@ -478,13 +326,6 @@ export class PluginManager extends EventEmitter {
|
|
|
478
326
|
return packageJson.homepage.replace('git+', '').replace('.git', '');
|
|
479
327
|
}
|
|
480
328
|
}
|
|
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
329
|
getFunding(packageJson) {
|
|
489
330
|
const funding = packageJson.funding;
|
|
490
331
|
if (!funding)
|
|
@@ -493,25 +334,16 @@ export class PluginManager extends EventEmitter {
|
|
|
493
334
|
return;
|
|
494
335
|
if (typeof funding === 'string' && funding.startsWith('http'))
|
|
495
336
|
return funding;
|
|
496
|
-
// Normalize funding into an array.
|
|
497
337
|
const fundingEntries = Array.isArray(funding) ? funding : [funding];
|
|
498
338
|
for (const entry of fundingEntries) {
|
|
499
339
|
if (entry && typeof entry === 'string' && entry.startsWith('http')) {
|
|
500
|
-
// If the funding entry is a string, assume it is a URL.
|
|
501
340
|
return entry;
|
|
502
341
|
}
|
|
503
342
|
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
343
|
return entry.url;
|
|
506
344
|
}
|
|
507
345
|
}
|
|
508
346
|
}
|
|
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
347
|
async parse(plugin) {
|
|
516
348
|
const { promises } = await import('node:fs');
|
|
517
349
|
try {
|
|
@@ -541,7 +373,6 @@ export class PluginManager extends EventEmitter {
|
|
|
541
373
|
plugin.funding = this.getFunding(packageJson);
|
|
542
374
|
if (!plugin.type)
|
|
543
375
|
this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
|
|
544
|
-
// Check for @project-chip and @matter packages in dependencies and devDependencies
|
|
545
376
|
const checkForProjectChipPackages = (dependencies) => {
|
|
546
377
|
return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
|
|
547
378
|
};
|
|
@@ -563,7 +394,6 @@ export class PluginManager extends EventEmitter {
|
|
|
563
394
|
this.log.error(`Please open an issue on the plugin repository to remove them.`);
|
|
564
395
|
return null;
|
|
565
396
|
}
|
|
566
|
-
// Check for matterbridge package in dependencies and devDependencies
|
|
567
397
|
const checkForMatterbridgePackage = (dependencies) => {
|
|
568
398
|
return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
|
|
569
399
|
};
|
|
@@ -593,16 +423,6 @@ export class PluginManager extends EventEmitter {
|
|
|
593
423
|
return null;
|
|
594
424
|
}
|
|
595
425
|
}
|
|
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
426
|
async enable(nameOrPath) {
|
|
607
427
|
const { promises } = await import('node:fs');
|
|
608
428
|
if (!nameOrPath)
|
|
@@ -638,16 +458,6 @@ export class PluginManager extends EventEmitter {
|
|
|
638
458
|
return null;
|
|
639
459
|
}
|
|
640
460
|
}
|
|
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
461
|
async disable(nameOrPath) {
|
|
652
462
|
const { promises } = await import('node:fs');
|
|
653
463
|
if (!nameOrPath)
|
|
@@ -683,16 +493,6 @@ export class PluginManager extends EventEmitter {
|
|
|
683
493
|
return null;
|
|
684
494
|
}
|
|
685
495
|
}
|
|
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
496
|
async remove(nameOrPath) {
|
|
697
497
|
const { promises } = await import('node:fs');
|
|
698
498
|
if (!nameOrPath)
|
|
@@ -728,17 +528,6 @@ export class PluginManager extends EventEmitter {
|
|
|
728
528
|
return null;
|
|
729
529
|
}
|
|
730
530
|
}
|
|
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
531
|
async add(nameOrPath) {
|
|
743
532
|
const { promises } = await import('node:fs');
|
|
744
533
|
if (!nameOrPath)
|
|
@@ -778,15 +567,6 @@ export class PluginManager extends EventEmitter {
|
|
|
778
567
|
return null;
|
|
779
568
|
}
|
|
780
569
|
}
|
|
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
570
|
async load(plugin, start = false, message = '', configure = false) {
|
|
791
571
|
const { promises } = await import('node:fs');
|
|
792
572
|
const { default: path } = await import('node:path');
|
|
@@ -800,20 +580,15 @@ export class PluginManager extends EventEmitter {
|
|
|
800
580
|
}
|
|
801
581
|
this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
|
|
802
582
|
try {
|
|
803
|
-
// Load the package.json of the plugin
|
|
804
583
|
const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
|
|
805
|
-
// Resolve the main module path relative to package.json
|
|
806
584
|
const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
|
|
807
|
-
// Dynamically import the plugin
|
|
808
585
|
const { pathToFileURL } = await import('node:url');
|
|
809
586
|
const pluginUrl = pathToFileURL(pluginEntry);
|
|
810
587
|
this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
|
|
811
588
|
const pluginInstance = await import(pluginUrl.href);
|
|
812
589
|
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
590
|
if (pluginInstance.default) {
|
|
815
591
|
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
592
|
plugin.name = packageJson.name;
|
|
818
593
|
plugin.description = packageJson.description ?? 'No description';
|
|
819
594
|
plugin.version = packageJson.version;
|
|
@@ -822,7 +597,7 @@ export class PluginManager extends EventEmitter {
|
|
|
822
597
|
plugin.schemaJson = await this.loadSchema(plugin);
|
|
823
598
|
config.name = plugin.name;
|
|
824
599
|
config.version = packageJson.version;
|
|
825
|
-
const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4
|
|
600
|
+
const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
|
|
826
601
|
const platform = pluginInstance.default(this.matterbridge, log, config);
|
|
827
602
|
config.type = platform.type;
|
|
828
603
|
platform.name = packageJson.name;
|
|
@@ -840,7 +615,7 @@ export class PluginManager extends EventEmitter {
|
|
|
840
615
|
plugin.platform = platform;
|
|
841
616
|
plugin.loaded = true;
|
|
842
617
|
plugin.registeredDevices = 0;
|
|
843
|
-
await this.saveToStorage();
|
|
618
|
+
await this.saveToStorage();
|
|
844
619
|
this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
|
|
845
620
|
this.emit('loaded', plugin.name);
|
|
846
621
|
if (start)
|
|
@@ -860,14 +635,6 @@ export class PluginManager extends EventEmitter {
|
|
|
860
635
|
}
|
|
861
636
|
return undefined;
|
|
862
637
|
}
|
|
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
638
|
async start(plugin, message, configure = false) {
|
|
872
639
|
if (!plugin.loaded) {
|
|
873
640
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -898,12 +665,6 @@ export class PluginManager extends EventEmitter {
|
|
|
898
665
|
}
|
|
899
666
|
return undefined;
|
|
900
667
|
}
|
|
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
668
|
async configure(plugin) {
|
|
908
669
|
if (!plugin.loaded) {
|
|
909
670
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
|
|
@@ -935,18 +696,6 @@ export class PluginManager extends EventEmitter {
|
|
|
935
696
|
}
|
|
936
697
|
return undefined;
|
|
937
698
|
}
|
|
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
699
|
async shutdown(plugin, reason, removeAllDevices = false, force = false) {
|
|
951
700
|
this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
|
|
952
701
|
if (!plugin.loaded) {
|
|
@@ -989,15 +738,6 @@ export class PluginManager extends EventEmitter {
|
|
|
989
738
|
}
|
|
990
739
|
return undefined;
|
|
991
740
|
}
|
|
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
741
|
async loadConfig(plugin) {
|
|
1002
742
|
const { default: path } = await import('node:path');
|
|
1003
743
|
const { promises } = await import('node:fs');
|
|
@@ -1009,8 +749,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1009
749
|
const data = await promises.readFile(configFile, 'utf8');
|
|
1010
750
|
const config = JSON.parse(data);
|
|
1011
751
|
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
752
|
config.name = plugin.name;
|
|
1015
753
|
config.type = plugin.type;
|
|
1016
754
|
if (config.debug === undefined)
|
|
@@ -1032,8 +770,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1032
770
|
}
|
|
1033
771
|
catch (_err) {
|
|
1034
772
|
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
773
|
if (plugin.name === 'matterbridge-zigbee2mqtt')
|
|
1038
774
|
config = zigbee2mqtt_config;
|
|
1039
775
|
else if (plugin.name === 'matterbridge-somfy-tahoma')
|
|
@@ -1046,7 +782,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1046
782
|
try {
|
|
1047
783
|
await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
|
|
1048
784
|
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
785
|
return config;
|
|
1051
786
|
}
|
|
1052
787
|
catch (err) {
|
|
@@ -1060,19 +795,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1060
795
|
}
|
|
1061
796
|
}
|
|
1062
797
|
}
|
|
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
798
|
async saveConfigFromPlugin(plugin, restartRequired = false) {
|
|
1077
799
|
const { default: path } = await import('node:path');
|
|
1078
800
|
const { promises } = await import('node:fs');
|
|
@@ -1087,7 +809,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1087
809
|
if (restartRequired)
|
|
1088
810
|
plugin.restartRequired = true;
|
|
1089
811
|
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
812
|
return Promise.resolve();
|
|
1092
813
|
}
|
|
1093
814
|
catch (err) {
|
|
@@ -1095,20 +816,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1095
816
|
return Promise.reject(err);
|
|
1096
817
|
}
|
|
1097
818
|
}
|
|
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
819
|
async saveConfigFromJson(plugin, config, restartRequired = false) {
|
|
1113
820
|
const { default: path } = await import('node:path');
|
|
1114
821
|
const { promises } = await import('node:fs');
|
|
@@ -1127,23 +834,12 @@ export class PluginManager extends EventEmitter {
|
|
|
1127
834
|
plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
|
|
1128
835
|
}
|
|
1129
836
|
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
837
|
}
|
|
1132
838
|
catch (err) {
|
|
1133
839
|
logError(this.log, `Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}`, err);
|
|
1134
840
|
return;
|
|
1135
841
|
}
|
|
1136
842
|
}
|
|
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
843
|
async loadSchema(plugin) {
|
|
1148
844
|
const { promises } = await import('node:fs');
|
|
1149
845
|
const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
|
|
@@ -1154,7 +850,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1154
850
|
schema.title = plugin.description;
|
|
1155
851
|
schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
|
|
1156
852
|
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
853
|
return schema;
|
|
1159
854
|
}
|
|
1160
855
|
catch (_err) {
|
|
@@ -1162,16 +857,6 @@ export class PluginManager extends EventEmitter {
|
|
|
1162
857
|
return this.getDefaultSchema(plugin);
|
|
1163
858
|
}
|
|
1164
859
|
}
|
|
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
860
|
getDefaultSchema(plugin) {
|
|
1176
861
|
return {
|
|
1177
862
|
title: plugin.description,
|
|
@@ -1202,4 +887,3 @@ export class PluginManager extends EventEmitter {
|
|
|
1202
887
|
};
|
|
1203
888
|
}
|
|
1204
889
|
}
|
|
1205
|
-
//# sourceMappingURL=pluginManager.js.map
|