matterbridge 1.7.3 → 2.0.0-edge.2

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.
Files changed (102) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/dist/cli.js +3 -39
  3. package/dist/cluster/export.js +0 -2
  4. package/dist/defaultConfigSchema.js +0 -23
  5. package/dist/deviceManager.js +1 -26
  6. package/dist/frontend.js +1203 -0
  7. package/dist/index.js +1 -36
  8. package/dist/logger/export.js +0 -1
  9. package/dist/matter/export.js +0 -5
  10. package/dist/matterbridge.js +516 -2678
  11. package/dist/matterbridgeAccessoryPlatform.js +0 -33
  12. package/dist/matterbridgeBehaviors.js +23 -31
  13. package/dist/matterbridgeDeviceTypes.js +11 -82
  14. package/dist/matterbridgeDynamicPlatform.js +0 -33
  15. package/dist/matterbridgeEndpoint.js +45 -1145
  16. package/dist/matterbridgePlatform.js +14 -145
  17. package/dist/matterbridgeTypes.js +3 -24
  18. package/dist/pluginManager.js +5 -246
  19. package/dist/storage/export.js +0 -1
  20. package/dist/utils/colorUtils.js +2 -205
  21. package/dist/utils/export.js +0 -1
  22. package/dist/utils/utils.js +7 -252
  23. package/frontend/build/asset-manifest.json +3 -3
  24. package/frontend/build/index.html +1 -1
  25. package/frontend/build/static/js/{main.6bbd1772.js → main.6204ae54.js} +3 -3
  26. package/frontend/build/static/js/main.6204ae54.js.map +1 -0
  27. package/npm-shrinkwrap.json +9 -9
  28. package/package.json +2 -3
  29. package/dist/cli.d.ts +0 -25
  30. package/dist/cli.d.ts.map +0 -1
  31. package/dist/cli.js.map +0 -1
  32. package/dist/cluster/export.d.ts +0 -2
  33. package/dist/cluster/export.d.ts.map +0 -1
  34. package/dist/cluster/export.js.map +0 -1
  35. package/dist/defaultConfigSchema.d.ts +0 -27
  36. package/dist/defaultConfigSchema.d.ts.map +0 -1
  37. package/dist/defaultConfigSchema.js.map +0 -1
  38. package/dist/deviceManager.d.ts +0 -46
  39. package/dist/deviceManager.d.ts.map +0 -1
  40. package/dist/deviceManager.js.map +0 -1
  41. package/dist/index.d.ts +0 -40
  42. package/dist/index.d.ts.map +0 -1
  43. package/dist/index.js.map +0 -1
  44. package/dist/logger/export.d.ts +0 -2
  45. package/dist/logger/export.d.ts.map +0 -1
  46. package/dist/logger/export.js.map +0 -1
  47. package/dist/matter/export.d.ts +0 -11
  48. package/dist/matter/export.d.ts.map +0 -1
  49. package/dist/matter/export.js.map +0 -1
  50. package/dist/matterbridge.d.ts +0 -483
  51. package/dist/matterbridge.d.ts.map +0 -1
  52. package/dist/matterbridge.js.map +0 -1
  53. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -39
  54. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  55. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  56. package/dist/matterbridgeBehaviors.d.ts +0 -942
  57. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  58. package/dist/matterbridgeBehaviors.js.map +0 -1
  59. package/dist/matterbridgeDevice.d.ts +0 -7077
  60. package/dist/matterbridgeDevice.d.ts.map +0 -1
  61. package/dist/matterbridgeDevice.js +0 -2736
  62. package/dist/matterbridgeDevice.js.map +0 -1
  63. package/dist/matterbridgeDeviceTypes.d.ts +0 -109
  64. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  65. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  66. package/dist/matterbridgeDynamicPlatform.d.ts +0 -39
  67. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  68. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  69. package/dist/matterbridgeEdge.d.ts +0 -91
  70. package/dist/matterbridgeEdge.d.ts.map +0 -1
  71. package/dist/matterbridgeEdge.js +0 -1077
  72. package/dist/matterbridgeEdge.js.map +0 -1
  73. package/dist/matterbridgeEndpoint.d.ts +0 -10156
  74. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  75. package/dist/matterbridgeEndpoint.js.map +0 -1
  76. package/dist/matterbridgePlatform.d.ts +0 -168
  77. package/dist/matterbridgePlatform.d.ts.map +0 -1
  78. package/dist/matterbridgePlatform.js.map +0 -1
  79. package/dist/matterbridgeTypes.d.ts +0 -172
  80. package/dist/matterbridgeTypes.d.ts.map +0 -1
  81. package/dist/matterbridgeTypes.js.map +0 -1
  82. package/dist/matterbridgeWebsocket.d.ts +0 -49
  83. package/dist/matterbridgeWebsocket.d.ts.map +0 -1
  84. package/dist/matterbridgeWebsocket.js +0 -325
  85. package/dist/matterbridgeWebsocket.js.map +0 -1
  86. package/dist/pluginManager.d.ts +0 -238
  87. package/dist/pluginManager.d.ts.map +0 -1
  88. package/dist/pluginManager.js.map +0 -1
  89. package/dist/storage/export.d.ts +0 -2
  90. package/dist/storage/export.d.ts.map +0 -1
  91. package/dist/storage/export.js.map +0 -1
  92. package/dist/utils/colorUtils.d.ts +0 -61
  93. package/dist/utils/colorUtils.d.ts.map +0 -1
  94. package/dist/utils/colorUtils.js.map +0 -1
  95. package/dist/utils/export.d.ts +0 -3
  96. package/dist/utils/export.d.ts.map +0 -1
  97. package/dist/utils/export.js.map +0 -1
  98. package/dist/utils/utils.d.ts +0 -221
  99. package/dist/utils/utils.d.ts.map +0 -1
  100. package/dist/utils/utils.js.map +0 -1
  101. package/frontend/build/static/js/main.6bbd1772.js.map +0 -1
  102. /package/frontend/build/static/js/{main.6bbd1772.js.LICENSE.txt → main.6204ae54.js.LICENSE.txt} +0 -0
@@ -1,29 +1,4 @@
1
- /**
2
- * This file contains the Plugins class.
3
- *
4
- * @file plugins.ts
5
- * @author Luca Liguori
6
- * @date 2024-07-14
7
- * @version 1.1.0
8
- *
9
- * Copyright 2024, 2025, 2026 Luca Liguori.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License. *
22
- */
23
- /* eslint-disable @typescript-eslint/no-unused-vars */
24
- // NodeStorage and AnsiLogger modules
25
1
  import { AnsiLogger, BLUE, db, er, nf, nt, rs, UNDERLINE, UNDERLINEOFF, wr } from 'node-ansi-logger';
26
- // Node.js modules
27
2
  import path from 'path';
28
3
  import { promises as fs } from 'fs';
29
4
  import { pathToFileURL } from 'url';
@@ -37,9 +12,8 @@ export class PluginManager {
37
12
  log;
38
13
  constructor(matterbridge) {
39
14
  this.matterbridge = matterbridge;
40
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
15
  this.nodeContext = matterbridge.nodeContext;
42
- this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: matterbridge.log.logLevel });
16
+ this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: matterbridge.log.logLevel });
43
17
  this.log.debug('Matterbridge plugin manager starting...');
44
18
  }
45
19
  get length() {
@@ -74,7 +48,6 @@ export class PluginManager {
74
48
  }
75
49
  catch (error) {
76
50
  this.log.error(`Error processing forEach plugin ${plg}${plugin.name}${er}:`, error);
77
- // throw error;
78
51
  }
79
52
  });
80
53
  await Promise.all(tasks);
@@ -85,31 +58,13 @@ export class PluginManager {
85
58
  set logLevel(logLevel) {
86
59
  this.log.logLevel = logLevel;
87
60
  }
88
- /**
89
- * Loads registered plugins from storage.
90
- *
91
- * This method retrieves an array of registered plugins from the storage and converts it
92
- * into a map where the plugin names are the keys and the plugin objects are the values.
93
- *
94
- * @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
95
- */
96
61
  async loadFromStorage() {
97
- // Load the array from storage and convert it to a map
98
62
  const pluginsArray = await this.nodeContext.get('plugins', []);
99
63
  for (const plugin of pluginsArray)
100
64
  this._plugins.set(plugin.name, plugin);
101
65
  return pluginsArray;
102
66
  }
103
- /**
104
- * Loads registered plugins from storage.
105
- *
106
- * This method retrieves an array of registered plugins from the storage and converts it
107
- * into a map where the plugin names are the keys and the plugin objects are the values.
108
- *
109
- * @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
110
- */
111
67
  async saveToStorage() {
112
- // Convert the map to an array
113
68
  const plugins = [];
114
69
  const pluginArrayFromMap = Array.from(this._plugins.values());
115
70
  for (const plugin of pluginArrayFromMap) {
@@ -129,18 +84,11 @@ export class PluginManager {
129
84
  this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
130
85
  return plugins.length;
131
86
  }
132
- /**
133
- * Resolves the name of a plugin by loading and parsing its package.json file.
134
- * @param pluginPath - The path to the plugin or the path to the plugin's package.json file.
135
- * @returns The path to the resolved package.json file, or null if the package.json file is not found or does not contain a name.
136
- */
137
87
  async resolve(pluginPath) {
138
88
  if (!pluginPath.endsWith('package.json'))
139
89
  pluginPath = path.join(pluginPath, 'package.json');
140
- // Resolve the package.json of the plugin
141
90
  let packageJsonPath = path.resolve(pluginPath);
142
91
  this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
143
- // Check if the package.json file exists
144
92
  try {
145
93
  await fs.access(packageJsonPath);
146
94
  }
@@ -150,13 +98,11 @@ export class PluginManager {
150
98
  this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
151
99
  }
152
100
  try {
153
- // Load the package.json of the plugin
154
101
  const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
155
102
  if (!packageJson.name) {
156
103
  this.log.error(`Package.json name not found at ${packageJsonPath}`);
157
104
  return null;
158
105
  }
159
- // Check for main issues
160
106
  if (!packageJson.type || packageJson.type !== 'module') {
161
107
  this.log.error(`Plugin at ${packageJsonPath} is not a module`);
162
108
  return null;
@@ -165,13 +111,6 @@ export class PluginManager {
165
111
  this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
166
112
  return null;
167
113
  }
168
- /*
169
- if (!packageJson.types) {
170
- this.log.error(`Plugin at ${packageJsonPath} has no types in package.json`);
171
- return null;
172
- }
173
- */
174
- // Check for @project-chip packages in dependencies and devDependencies
175
114
  const checkForProjectChipPackages = (dependencies) => {
176
115
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
177
116
  };
@@ -193,7 +132,6 @@ export class PluginManager {
193
132
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
194
133
  return null;
195
134
  }
196
- // Check for matterbridge package in dependencies and devDependencies
197
135
  const checkForMatterbridgePackage = (dependencies) => {
198
136
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
199
137
  };
@@ -223,11 +161,6 @@ export class PluginManager {
223
161
  return null;
224
162
  }
225
163
  }
226
- /**
227
- * Loads and parse the plugin package.json and returns it.
228
- * @param plugin - The plugin to load the package from.
229
- * @returns A Promise that resolves to the package.json object or undefined if the package.json could not be loaded.
230
- */
231
164
  async parse(plugin) {
232
165
  this.log.debug(`Parsing package.json of plugin ${plg}${plugin.name}${db}`);
233
166
  try {
@@ -244,7 +177,6 @@ export class PluginManager {
244
177
  this.log.error(`Plugin ${plg}${plugin.name}${er} is not a module`);
245
178
  if (!packageJson.main)
246
179
  this.log.error(`Plugin ${plg}${plugin.name}${er} has no main entrypoint in package.json`);
247
- // if (!packageJson.types) this.log.error(`Plugin ${plg}${plugin.name}${er} has no types in package.json`);
248
180
  plugin.name = packageJson.name || 'Unknown name';
249
181
  plugin.version = packageJson.version || '1.0.0';
250
182
  plugin.description = packageJson.description || 'Unknown description';
@@ -253,7 +185,6 @@ export class PluginManager {
253
185
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no path`);
254
186
  if (!plugin.type)
255
187
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
256
- // Check for @project-chip packages in dependencies and devDependencies
257
188
  const checkForProjectChipPackages = (dependencies) => {
258
189
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
259
190
  };
@@ -275,7 +206,6 @@ export class PluginManager {
275
206
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
276
207
  return null;
277
208
  }
278
- // Check for matterbridge package in dependencies and devDependencies
279
209
  const checkForMatterbridgePackage = (dependencies) => {
280
210
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
281
211
  };
@@ -297,7 +227,6 @@ export class PluginManager {
297
227
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
298
228
  return null;
299
229
  }
300
- // await this.saveToStorage(); // No need to save the plugin to storage
301
230
  return packageJson;
302
231
  }
303
232
  catch (err) {
@@ -306,16 +235,6 @@ export class PluginManager {
306
235
  return null;
307
236
  }
308
237
  }
309
- /**
310
- * Enables a plugin by its name or path.
311
- *
312
- * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
313
- * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
314
- * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
315
- *
316
- * @param {string} nameOrPath - The name or path of the plugin to enable.
317
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
318
- */
319
238
  async enable(nameOrPath) {
320
239
  if (!nameOrPath || nameOrPath === '')
321
240
  return null;
@@ -348,16 +267,6 @@ export class PluginManager {
348
267
  return null;
349
268
  }
350
269
  }
351
- /**
352
- * Enables a plugin by its name or path.
353
- *
354
- * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
355
- * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
356
- * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
357
- *
358
- * @param {string} nameOrPath - The name or path of the plugin to enable.
359
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
360
- */
361
270
  async disable(nameOrPath) {
362
271
  if (!nameOrPath || nameOrPath === '')
363
272
  return null;
@@ -390,16 +299,6 @@ export class PluginManager {
390
299
  return null;
391
300
  }
392
301
  }
393
- /**
394
- * Removes a plugin by its name or path.
395
- *
396
- * This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
397
- * It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
398
- * the plugin's `package.json` file to retrieve its name and remove it.
399
- *
400
- * @param {string} nameOrPath - The name or path of the plugin to remove.
401
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
402
- */
403
302
  async remove(nameOrPath) {
404
303
  if (!nameOrPath || nameOrPath === '')
405
304
  return null;
@@ -432,17 +331,6 @@ export class PluginManager {
432
331
  return null;
433
332
  }
434
333
  }
435
- /**
436
- * Adds a plugin by its name or path.
437
- *
438
- * This method adds a plugin to the `_plugins` map and saves the updated plugin information to storage.
439
- * It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
440
- * registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
441
- * and saves the updated plugin information to storage.
442
- *
443
- * @param {string} nameOrPath - The name or path of the plugin to add.
444
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
445
- */
446
334
  async add(nameOrPath) {
447
335
  if (!nameOrPath || nameOrPath === '')
448
336
  return null;
@@ -468,15 +356,6 @@ export class PluginManager {
468
356
  return null;
469
357
  }
470
358
  }
471
- /**
472
- * Installs a plugin by its name.
473
- *
474
- * This method first uninstalls any existing version of the plugin, then installs the plugin globally using npm.
475
- * It logs the installation process and retrieves the installed version of the plugin.
476
- *
477
- * @param {string} name - The name of the plugin to install.
478
- * @returns {Promise<string | undefined>} A promise that resolves to the installed version of the plugin, or undefined if the installation failed.
479
- */
480
359
  async install(name) {
481
360
  await this.uninstall(name);
482
361
  this.log.info(`Installing plugin ${plg}${name}${nf}`);
@@ -490,13 +369,11 @@ export class PluginManager {
490
369
  else {
491
370
  this.log.info(`Installed plugin ${plg}${name}${nf}`);
492
371
  this.log.debug(`Installed plugin ${plg}${name}${db}: ${stdout}`);
493
- // Get the installed version
494
372
  exec(`npm list -g ${name} --depth=0`, (listError, listStdout, listStderr) => {
495
373
  if (listError) {
496
374
  this.log.error(`List error: ${listError}`);
497
375
  resolve(undefined);
498
376
  }
499
- // Clean the output to get only the package name and version
500
377
  const lines = listStdout.split('\n');
501
378
  const versionLine = lines.find((line) => line.includes(`${name}@`));
502
379
  if (versionLine) {
@@ -512,15 +389,6 @@ export class PluginManager {
512
389
  });
513
390
  });
514
391
  }
515
- /**
516
- * Uninstalls a plugin by its name.
517
- *
518
- * This method uninstalls a globally installed plugin using npm. It logs the uninstallation process
519
- * and returns the name of the uninstalled plugin if successful, or undefined if the uninstallation failed.
520
- *
521
- * @param {string} name - The name of the plugin to uninstall.
522
- * @returns {Promise<string | undefined>} A promise that resolves to the name of the uninstalled plugin, or undefined if the uninstallation failed.
523
- */
524
392
  async uninstall(name) {
525
393
  this.log.info(`Uninstalling plugin ${plg}${name}${nf}`);
526
394
  return new Promise((resolve, reject) => {
@@ -538,14 +406,6 @@ export class PluginManager {
538
406
  });
539
407
  });
540
408
  }
541
- /**
542
- * Loads a plugin and returns the corresponding MatterbridgePlatform instance.
543
- * @param plugin - The plugin to load.
544
- * @param start - Optional flag indicating whether to start the plugin after loading. Default is false.
545
- * @param message - Optional message to pass to the plugin when starting.
546
- * @returns A Promise that resolves to the loaded MatterbridgePlatform instance.
547
- * @throws An error if the plugin is not enabled, already loaded, or fails to load.
548
- */
549
409
  async load(plugin, start = false, message = '', configure = false) {
550
410
  if (!plugin.enabled) {
551
411
  this.log.error(`Plugin ${plg}${plugin.name}${er} not enabled`);
@@ -557,19 +417,14 @@ export class PluginManager {
557
417
  }
558
418
  this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
559
419
  try {
560
- // Load the package.json of the plugin
561
420
  const packageJson = JSON.parse(await fs.readFile(plugin.path, 'utf8'));
562
- // Resolve the main module path relative to package.json
563
421
  const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
564
- // Dynamically import the plugin
565
422
  const pluginUrl = pathToFileURL(pluginEntry);
566
423
  this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
567
424
  const pluginInstance = await import(pluginUrl.href);
568
425
  this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
569
- // Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
570
426
  if (pluginInstance.default) {
571
427
  const config = await this.loadConfig(plugin);
572
- // 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.
573
428
  plugin.name = packageJson.name;
574
429
  plugin.description = packageJson.description ?? 'No description';
575
430
  plugin.version = packageJson.version;
@@ -578,7 +433,7 @@ export class PluginManager {
578
433
  plugin.schemaJson = await this.loadSchema(plugin);
579
434
  config.name = plugin.name;
580
435
  config.version = packageJson.version;
581
- const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: config.debug ? "debug" /* LogLevel.DEBUG */ : this.matterbridge.log.logLevel });
436
+ const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
582
437
  const platform = pluginInstance.default(this.matterbridge, log, config);
583
438
  config.type = platform.type;
584
439
  platform.name = packageJson.name;
@@ -595,7 +450,7 @@ export class PluginManager {
595
450
  plugin.addedDevices = 0;
596
451
  plugin.configJson = config;
597
452
  plugin.schemaJson = await this.loadSchema(plugin);
598
- await this.saveToStorage(); // Save the plugin to storage
453
+ await this.saveToStorage();
599
454
  this.log.notice(`Loaded plugin ${plg}${plugin.name}${nf} type ${typ}${platform.type}${db} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
600
455
  if (start)
601
456
  await this.start(plugin, message, false);
@@ -614,14 +469,6 @@ export class PluginManager {
614
469
  }
615
470
  return undefined;
616
471
  }
617
- /**
618
- * Starts a plugin.
619
- *
620
- * @param {RegisteredPlugin} plugin - The plugin to start.
621
- * @param {string} [message] - Optional message to pass to the plugin's onStart method.
622
- * @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
623
- * @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
624
- */
625
472
  async start(plugin, message, configure = false) {
626
473
  if (!plugin.loaded) {
627
474
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -651,12 +498,6 @@ export class PluginManager {
651
498
  }
652
499
  return undefined;
653
500
  }
654
- /**
655
- * Configures a plugin.
656
- *
657
- * @param {RegisteredPlugin} plugin - The plugin to configure.
658
- * @returns {Promise<void>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
659
- */
660
501
  async configure(plugin) {
661
502
  if (!plugin.loaded) {
662
503
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -679,7 +520,6 @@ export class PluginManager {
679
520
  await plugin.platform.onConfigure();
680
521
  this.log.notice(`Configured plugin ${plg}${plugin.name}${nt} type ${typ}${plugin.type}${nt}`);
681
522
  plugin.configured = true;
682
- // await this.saveConfigFromPlugin(plugin);
683
523
  return plugin;
684
524
  }
685
525
  catch (err) {
@@ -688,18 +528,6 @@ export class PluginManager {
688
528
  }
689
529
  return undefined;
690
530
  }
691
- /**
692
- * Shuts down a plugin.
693
- *
694
- * This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
695
- * It logs the shutdown process and optionally removes all devices associated with the plugin.
696
- *
697
- * @param {RegisteredPlugin} plugin - The plugin to shut down.
698
- * @param {string} [reason] - The reason for shutting down the plugin.
699
- * @param {boolean} [removeAllDevices=false] - Whether to remove all devices associated with the plugin.
700
- * @param {boolean} [force=false] - Whether to force the shutdown even if the plugin is not loaded or started.
701
- * @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
702
- */
703
531
  async shutdown(plugin, reason, removeAllDevices = false, force = false) {
704
532
  this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
705
533
  if (!plugin.loaded) {
@@ -730,14 +558,8 @@ export class PluginManager {
730
558
  plugin.connected = undefined;
731
559
  plugin.platform = undefined;
732
560
  if (removeAllDevices) {
733
- if (this.matterbridge.edge) {
734
- this.log.info(`Removing all endpoints for plugin ${plg}${plugin.name}${nf}: ${reason}...`);
735
- await this.matterbridge.removeAllBridgedEndpoints(plugin.name);
736
- }
737
- else {
738
- this.log.info(`Removing all devices for plugin ${plg}${plugin.name}${nf}: ${reason}...`);
739
- await this.matterbridge.removeAllBridgedDevices(plugin.name);
740
- }
561
+ this.log.info(`Removing all endpoints for plugin ${plg}${plugin.name}${nf}: ${reason}...`);
562
+ await this.matterbridge.removeAllBridgedEndpoints(plugin.name);
741
563
  }
742
564
  plugin.registeredDevices = undefined;
743
565
  plugin.addedDevices = undefined;
@@ -749,15 +571,6 @@ export class PluginManager {
749
571
  }
750
572
  return undefined;
751
573
  }
752
- /**
753
- * Loads the configuration for a plugin.
754
- * If the configuration file exists, it reads the file and returns the parsed JSON data.
755
- * If the configuration file does not exist, it creates a new file with default configuration and returns it.
756
- * If any error occurs during file access or creation, it logs an error and return un empty config.
757
- *
758
- * @param plugin - The plugin for which to load the configuration.
759
- * @returns A promise that resolves to the loaded or created configuration.
760
- */
761
574
  async loadConfig(plugin) {
762
575
  const configFile = path.join(this.matterbridge.matterbridgeDirectory, `${plugin.name}.config.json`);
763
576
  try {
@@ -765,8 +578,6 @@ export class PluginManager {
765
578
  const data = await fs.readFile(configFile, 'utf8');
766
579
  const config = JSON.parse(data);
767
580
  this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
768
- // this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
769
- // The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
770
581
  config.name = plugin.name;
771
582
  config.type = plugin.type;
772
583
  if (config.debug === undefined)
@@ -791,7 +602,6 @@ export class PluginManager {
791
602
  try {
792
603
  await fs.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
793
604
  this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
794
- // this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
795
605
  return config;
796
606
  }
797
607
  catch (err) {
@@ -808,18 +618,6 @@ export class PluginManager {
808
618
  return { name: plugin.name, type: plugin.type, debug: false, unregisterOnShutdown: false };
809
619
  }
810
620
  }
811
- /**
812
- * Saves the configuration of a plugin to a file.
813
- *
814
- * This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
815
- * If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
816
- * is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
817
- * the error and rejects the promise.
818
- *
819
- * @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
820
- * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
821
- * @throws {Error} If the plugin's configuration is not found.
822
- */
823
621
  async saveConfigFromPlugin(plugin) {
824
622
  if (!plugin.platform?.config) {
825
623
  this.log.error(`Error saving config file for plugin ${plg}${plugin.name}${er}: config not found`);
@@ -829,7 +627,6 @@ export class PluginManager {
829
627
  try {
830
628
  await fs.writeFile(configFile, JSON.stringify(plugin.platform.config, null, 2), 'utf8');
831
629
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
832
- // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
833
630
  return Promise.resolve();
834
631
  }
835
632
  catch (err) {
@@ -837,19 +634,6 @@ export class PluginManager {
837
634
  return Promise.reject(err);
838
635
  }
839
636
  }
840
- /**
841
- * Saves the configuration of a plugin from a JSON object to a file.
842
- *
843
- * This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
844
- * It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
845
- * the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
846
- * successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
847
- * during the file write operation, it logs the error and returns.
848
- *
849
- * @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
850
- * @param {PlatformConfig} config - The configuration data to be saved.
851
- * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
852
- */
853
637
  async saveConfigFromJson(plugin, config) {
854
638
  if (!config.name || !config.type || config.name !== plugin.name) {
855
639
  this.log.error(`Error saving config file for plugin ${plg}${plugin.name}${er}. Wrong config data content:${rs}\n`, config);
@@ -860,24 +644,12 @@ export class PluginManager {
860
644
  await fs.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
861
645
  plugin.configJson = config;
862
646
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
863
- // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
864
647
  }
865
648
  catch (err) {
866
649
  this.log.error(`Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err}`);
867
650
  return;
868
651
  }
869
652
  }
870
- /**
871
- * Loads the schema for a plugin.
872
- *
873
- * This method attempts to load the schema file for the specified plugin. If the schema file is found,
874
- * it reads and parses the file, updates the schema's title and description, and logs the process.
875
- * It also attempts to delete any old schema file from the matterbridge directory. If the schema file
876
- * is not found, it logs the event and loads a default schema for the plugin.
877
- *
878
- * @param {RegisteredPlugin} plugin - The plugin whose schema is to be loaded.
879
- * @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
880
- */
881
653
  async loadSchema(plugin) {
882
654
  let schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
883
655
  try {
@@ -887,8 +659,6 @@ export class PluginManager {
887
659
  schema.title = plugin.description;
888
660
  schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
889
661
  this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
890
- // this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
891
- // Delete the schema file from old position
892
662
  schemaFile = path.join(this.matterbridge.matterbridgeDirectory, `${plugin.name}.schema.json`);
893
663
  try {
894
664
  await fs.unlink(schemaFile);
@@ -904,16 +674,6 @@ export class PluginManager {
904
674
  return this.getDefaultSchema(plugin);
905
675
  }
906
676
  }
907
- /**
908
- * Returns the default schema for a plugin.
909
- *
910
- * This method generates a default schema object for the specified plugin. The schema includes
911
- * metadata such as the plugin's title, description, version, and author. It also defines the
912
- * properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
913
- *
914
- * @param {RegisteredPlugin} plugin - The plugin for which the default schema is to be generated.
915
- * @returns {PlatformSchema} The default schema object for the plugin.
916
- */
917
677
  getDefaultSchema(plugin) {
918
678
  return {
919
679
  title: plugin.description,
@@ -944,4 +704,3 @@ export class PluginManager {
944
704
  };
945
705
  }
946
706
  }
947
- //# sourceMappingURL=pluginManager.js.map
@@ -1,2 +1 @@
1
1
  export * from 'node-persist-manager';
2
- //# sourceMappingURL=export.js.map