matterbridge 1.6.5-dev.2 → 1.6.5-dev.3

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 (88) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/dist/cli.js +0 -26
  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/index.js +0 -30
  7. package/dist/logger/export.js +0 -1
  8. package/dist/matter/export.js +0 -1
  9. package/dist/matterbridge.js +62 -702
  10. package/dist/matterbridgeAccessoryPlatform.js +0 -33
  11. package/dist/matterbridgeBehaviors.js +1 -29
  12. package/dist/matterbridgeDevice.js +117 -884
  13. package/dist/matterbridgeDeviceTypes.js +12 -40
  14. package/dist/matterbridgeDynamicPlatform.js +0 -33
  15. package/dist/matterbridgeEdge.js +0 -525
  16. package/dist/matterbridgeEndpoint.js +100 -943
  17. package/dist/matterbridgePlatform.js +3 -74
  18. package/dist/matterbridgeTypes.js +0 -24
  19. package/dist/matterbridgeWebsocket.js +0 -45
  20. package/dist/pluginManager.js +3 -231
  21. package/dist/storage/export.js +0 -1
  22. package/dist/utils/colorUtils.js +2 -78
  23. package/dist/utils/export.js +0 -1
  24. package/dist/utils/utils.js +7 -252
  25. package/frontend/build/asset-manifest.json +3 -3
  26. package/frontend/build/index.html +1 -1
  27. package/frontend/build/static/js/{main.a14c87e7.js → main.0ab89802.js} +3 -3
  28. package/frontend/build/static/js/{main.a14c87e7.js.map → main.0ab89802.js.map} +1 -1
  29. package/npm-shrinkwrap.json +5 -5
  30. package/package.json +4 -4
  31. package/tsconfig.production.json +19 -0
  32. package/dist/cli.d.ts.map +0 -1
  33. package/dist/cli.js.map +0 -1
  34. package/dist/cluster/export.d.ts.map +0 -1
  35. package/dist/cluster/export.js.map +0 -1
  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.map +0 -1
  42. package/dist/index.js.map +0 -1
  43. package/dist/logger/export.d.ts.map +0 -1
  44. package/dist/logger/export.js.map +0 -1
  45. package/dist/matter/export.d.ts.map +0 -1
  46. package/dist/matter/export.js.map +0 -1
  47. package/dist/matterbridge.d.ts +0 -466
  48. package/dist/matterbridge.d.ts.map +0 -1
  49. package/dist/matterbridge.js.map +0 -1
  50. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  51. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  52. package/dist/matterbridgeBehaviors.d.ts +0 -934
  53. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  54. package/dist/matterbridgeBehaviors.js.map +0 -1
  55. package/dist/matterbridgeDevice.d.ts +0 -5307
  56. package/dist/matterbridgeDevice.d.ts.map +0 -1
  57. package/dist/matterbridgeDevice.js.map +0 -1
  58. package/dist/matterbridgeDeviceTypes.d.ts +0 -65
  59. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  60. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  61. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  62. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  63. package/dist/matterbridgeEdge.d.ts +0 -89
  64. package/dist/matterbridgeEdge.d.ts.map +0 -1
  65. package/dist/matterbridgeEdge.js.map +0 -1
  66. package/dist/matterbridgeEndpoint.d.ts +0 -7368
  67. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  68. package/dist/matterbridgeEndpoint.js.map +0 -1
  69. package/dist/matterbridgePlatform.d.ts +0 -96
  70. package/dist/matterbridgePlatform.d.ts.map +0 -1
  71. package/dist/matterbridgePlatform.js.map +0 -1
  72. package/dist/matterbridgeTypes.d.ts.map +0 -1
  73. package/dist/matterbridgeTypes.js.map +0 -1
  74. package/dist/matterbridgeWebsocket.d.ts.map +0 -1
  75. package/dist/matterbridgeWebsocket.js.map +0 -1
  76. package/dist/pluginManager.d.ts +0 -238
  77. package/dist/pluginManager.d.ts.map +0 -1
  78. package/dist/pluginManager.js.map +0 -1
  79. package/dist/storage/export.d.ts.map +0 -1
  80. package/dist/storage/export.js.map +0 -1
  81. package/dist/utils/colorUtils.d.ts.map +0 -1
  82. package/dist/utils/colorUtils.js.map +0 -1
  83. package/dist/utils/export.d.ts.map +0 -1
  84. package/dist/utils/export.js.map +0 -1
  85. package/dist/utils/utils.d.ts +0 -221
  86. package/dist/utils/utils.d.ts.map +0 -1
  87. package/dist/utils/utils.js.map +0 -1
  88. /package/frontend/build/static/js/{main.a14c87e7.js.LICENSE.txt → main.0ab89802.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;
@@ -169,7 +115,6 @@ export class PluginManager {
169
115
  this.log.error(`Plugin at ${packageJsonPath} has no types in package.json`);
170
116
  return null;
171
117
  }
172
- // Check for @project-chip packages in dependencies and devDependencies
173
118
  const checkForProjectChipPackages = (dependencies) => {
174
119
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
175
120
  };
@@ -191,7 +136,6 @@ export class PluginManager {
191
136
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
192
137
  return null;
193
138
  }
194
- // Check for matterbridge package in dependencies and devDependencies
195
139
  const checkForMatterbridgePackage = (dependencies) => {
196
140
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
197
141
  };
@@ -221,11 +165,6 @@ export class PluginManager {
221
165
  return null;
222
166
  }
223
167
  }
224
- /**
225
- * Loads and parse the plugin package.json and returns it.
226
- * @param plugin - The plugin to load the package from.
227
- * @returns A Promise that resolves to the package.json object or undefined if the package.json could not be loaded.
228
- */
229
168
  async parse(plugin) {
230
169
  this.log.debug(`Parsing package.json of plugin ${plg}${plugin.name}${db}`);
231
170
  try {
@@ -252,7 +191,6 @@ export class PluginManager {
252
191
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no path`);
253
192
  if (!plugin.type)
254
193
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
255
- // Check for @project-chip packages in dependencies and devDependencies
256
194
  const checkForProjectChipPackages = (dependencies) => {
257
195
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
258
196
  };
@@ -274,7 +212,6 @@ export class PluginManager {
274
212
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
275
213
  return null;
276
214
  }
277
- // Check for matterbridge package in dependencies and devDependencies
278
215
  const checkForMatterbridgePackage = (dependencies) => {
279
216
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
280
217
  };
@@ -296,7 +233,6 @@ export class PluginManager {
296
233
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
297
234
  return null;
298
235
  }
299
- // await this.saveToStorage(); // No need to save the plugin to storage
300
236
  return packageJson;
301
237
  }
302
238
  catch (err) {
@@ -305,16 +241,6 @@ export class PluginManager {
305
241
  return null;
306
242
  }
307
243
  }
308
- /**
309
- * Enables a plugin by its name or path.
310
- *
311
- * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
312
- * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
313
- * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
314
- *
315
- * @param {string} nameOrPath - The name or path of the plugin to enable.
316
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
317
- */
318
244
  async enable(nameOrPath) {
319
245
  if (!nameOrPath || nameOrPath === '')
320
246
  return null;
@@ -347,16 +273,6 @@ export class PluginManager {
347
273
  return null;
348
274
  }
349
275
  }
350
- /**
351
- * Enables a plugin by its name or path.
352
- *
353
- * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
354
- * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
355
- * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
356
- *
357
- * @param {string} nameOrPath - The name or path of the plugin to enable.
358
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
359
- */
360
276
  async disable(nameOrPath) {
361
277
  if (!nameOrPath || nameOrPath === '')
362
278
  return null;
@@ -389,16 +305,6 @@ export class PluginManager {
389
305
  return null;
390
306
  }
391
307
  }
392
- /**
393
- * Removes a plugin by its name or path.
394
- *
395
- * This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
396
- * It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
397
- * the plugin's `package.json` file to retrieve its name and remove it.
398
- *
399
- * @param {string} nameOrPath - The name or path of the plugin to remove.
400
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
401
- */
402
308
  async remove(nameOrPath) {
403
309
  if (!nameOrPath || nameOrPath === '')
404
310
  return null;
@@ -431,17 +337,6 @@ export class PluginManager {
431
337
  return null;
432
338
  }
433
339
  }
434
- /**
435
- * Adds a plugin by its name or path.
436
- *
437
- * This method adds a plugin to the `_plugins` map and saves the updated plugin information to storage.
438
- * It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
439
- * registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
440
- * and saves the updated plugin information to storage.
441
- *
442
- * @param {string} nameOrPath - The name or path of the plugin to add.
443
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
444
- */
445
340
  async add(nameOrPath) {
446
341
  if (!nameOrPath || nameOrPath === '')
447
342
  return null;
@@ -467,15 +362,6 @@ export class PluginManager {
467
362
  return null;
468
363
  }
469
364
  }
470
- /**
471
- * Installs a plugin by its name.
472
- *
473
- * This method first uninstalls any existing version of the plugin, then installs the plugin globally using npm.
474
- * It logs the installation process and retrieves the installed version of the plugin.
475
- *
476
- * @param {string} name - The name of the plugin to install.
477
- * @returns {Promise<string | undefined>} A promise that resolves to the installed version of the plugin, or undefined if the installation failed.
478
- */
479
365
  async install(name) {
480
366
  await this.uninstall(name);
481
367
  this.log.info(`Installing plugin ${plg}${name}${nf}`);
@@ -489,13 +375,11 @@ export class PluginManager {
489
375
  else {
490
376
  this.log.info(`Installed plugin ${plg}${name}${nf}`);
491
377
  this.log.debug(`Installed plugin ${plg}${name}${db}: ${stdout}`);
492
- // Get the installed version
493
378
  exec(`npm list -g ${name} --depth=0`, (listError, listStdout, listStderr) => {
494
379
  if (listError) {
495
380
  this.log.error(`List error: ${listError}`);
496
381
  resolve(undefined);
497
382
  }
498
- // Clean the output to get only the package name and version
499
383
  const lines = listStdout.split('\n');
500
384
  const versionLine = lines.find((line) => line.includes(`${name}@`));
501
385
  if (versionLine) {
@@ -511,15 +395,6 @@ export class PluginManager {
511
395
  });
512
396
  });
513
397
  }
514
- /**
515
- * Uninstalls a plugin by its name.
516
- *
517
- * This method uninstalls a globally installed plugin using npm. It logs the uninstallation process
518
- * and returns the name of the uninstalled plugin if successful, or undefined if the uninstallation failed.
519
- *
520
- * @param {string} name - The name of the plugin to uninstall.
521
- * @returns {Promise<string | undefined>} A promise that resolves to the name of the uninstalled plugin, or undefined if the uninstallation failed.
522
- */
523
398
  async uninstall(name) {
524
399
  this.log.info(`Uninstalling plugin ${plg}${name}${nf}`);
525
400
  return new Promise((resolve, reject) => {
@@ -537,14 +412,6 @@ export class PluginManager {
537
412
  });
538
413
  });
539
414
  }
540
- /**
541
- * Loads a plugin and returns the corresponding MatterbridgePlatform instance.
542
- * @param plugin - The plugin to load.
543
- * @param start - Optional flag indicating whether to start the plugin after loading. Default is false.
544
- * @param message - Optional message to pass to the plugin when starting.
545
- * @returns A Promise that resolves to the loaded MatterbridgePlatform instance.
546
- * @throws An error if the plugin is not enabled, already loaded, or fails to load.
547
- */
548
415
  async load(plugin, start = false, message = '', configure = false) {
549
416
  if (!plugin.enabled) {
550
417
  this.log.error(`Plugin ${plg}${plugin.name}${er} not enabled`);
@@ -556,19 +423,14 @@ export class PluginManager {
556
423
  }
557
424
  this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
558
425
  try {
559
- // Load the package.json of the plugin
560
426
  const packageJson = JSON.parse(await fs.readFile(plugin.path, 'utf8'));
561
- // Resolve the main module path relative to package.json
562
427
  const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
563
- // Dynamically import the plugin
564
428
  const pluginUrl = pathToFileURL(pluginEntry);
565
429
  this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
566
430
  const pluginInstance = await import(pluginUrl.href);
567
431
  this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
568
- // Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
569
432
  if (pluginInstance.default) {
570
433
  const config = await this.loadConfig(plugin);
571
- // 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.
572
434
  plugin.name = packageJson.name;
573
435
  plugin.description = packageJson.description ?? 'No description';
574
436
  plugin.version = packageJson.version;
@@ -577,7 +439,7 @@ export class PluginManager {
577
439
  plugin.schemaJson = await this.loadSchema(plugin);
578
440
  config.name = plugin.name;
579
441
  config.version = packageJson.version;
580
- const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: config.debug ? "debug" /* LogLevel.DEBUG */ : this.matterbridge.log.logLevel });
442
+ const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
581
443
  const platform = pluginInstance.default(this.matterbridge, log, config);
582
444
  config.type = platform.type;
583
445
  platform.name = packageJson.name;
@@ -594,7 +456,7 @@ export class PluginManager {
594
456
  plugin.addedDevices = 0;
595
457
  plugin.configJson = config;
596
458
  plugin.schemaJson = await this.loadSchema(plugin);
597
- await this.saveToStorage(); // Save the plugin to storage
459
+ await this.saveToStorage();
598
460
  this.log.notice(`Loaded plugin ${plg}${plugin.name}${nf} type ${typ}${platform.type}${db} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
599
461
  if (start)
600
462
  await this.start(plugin, message, false);
@@ -613,14 +475,6 @@ export class PluginManager {
613
475
  }
614
476
  return undefined;
615
477
  }
616
- /**
617
- * Starts a plugin.
618
- *
619
- * @param {RegisteredPlugin} plugin - The plugin to start.
620
- * @param {string} [message] - Optional message to pass to the plugin's onStart method.
621
- * @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
622
- * @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
623
- */
624
478
  async start(plugin, message, configure = false) {
625
479
  if (!plugin.loaded) {
626
480
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -650,12 +504,6 @@ export class PluginManager {
650
504
  }
651
505
  return undefined;
652
506
  }
653
- /**
654
- * Configures a plugin.
655
- *
656
- * @param {RegisteredPlugin} plugin - The plugin to configure.
657
- * @returns {Promise<void>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
658
- */
659
507
  async configure(plugin) {
660
508
  if (!plugin.loaded) {
661
509
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -678,7 +526,6 @@ export class PluginManager {
678
526
  await plugin.platform.onConfigure();
679
527
  this.log.notice(`Configured plugin ${plg}${plugin.name}${nt} type ${typ}${plugin.type}${nt}`);
680
528
  plugin.configured = true;
681
- // await this.saveConfigFromPlugin(plugin);
682
529
  return plugin;
683
530
  }
684
531
  catch (err) {
@@ -687,18 +534,6 @@ export class PluginManager {
687
534
  }
688
535
  return undefined;
689
536
  }
690
- /**
691
- * Shuts down a plugin.
692
- *
693
- * This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
694
- * It logs the shutdown process and optionally removes all devices associated with the plugin.
695
- *
696
- * @param {RegisteredPlugin} plugin - The plugin to shut down.
697
- * @param {string} [reason] - The reason for shutting down the plugin.
698
- * @param {boolean} [removeAllDevices=false] - Whether to remove all devices associated with the plugin.
699
- * @param {boolean} [force=false] - Whether to force the shutdown even if the plugin is not loaded or started.
700
- * @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
701
- */
702
537
  async shutdown(plugin, reason, removeAllDevices = false, force = false) {
703
538
  this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
704
539
  if (!plugin.loaded) {
@@ -742,15 +577,6 @@ export class PluginManager {
742
577
  }
743
578
  return undefined;
744
579
  }
745
- /**
746
- * Loads the configuration for a plugin.
747
- * If the configuration file exists, it reads the file and returns the parsed JSON data.
748
- * If the configuration file does not exist, it creates a new file with default configuration and returns it.
749
- * If any error occurs during file access or creation, it logs an error and return un empty config.
750
- *
751
- * @param plugin - The plugin for which to load the configuration.
752
- * @returns A promise that resolves to the loaded or created configuration.
753
- */
754
580
  async loadConfig(plugin) {
755
581
  const configFile = path.join(this.matterbridge.matterbridgeDirectory, `${plugin.name}.config.json`);
756
582
  try {
@@ -758,8 +584,6 @@ export class PluginManager {
758
584
  const data = await fs.readFile(configFile, 'utf8');
759
585
  const config = JSON.parse(data);
760
586
  this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
761
- // this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
762
- // The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
763
587
  config.name = plugin.name;
764
588
  config.type = plugin.type;
765
589
  if (config.debug === undefined)
@@ -784,7 +608,6 @@ export class PluginManager {
784
608
  try {
785
609
  await fs.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
786
610
  this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
787
- // this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
788
611
  return config;
789
612
  }
790
613
  catch (err) {
@@ -801,18 +624,6 @@ export class PluginManager {
801
624
  return { name: plugin.name, type: plugin.type, debug: false, unregisterOnShutdown: false };
802
625
  }
803
626
  }
804
- /**
805
- * Saves the configuration of a plugin to a file.
806
- *
807
- * This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
808
- * If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
809
- * is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
810
- * the error and rejects the promise.
811
- *
812
- * @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
813
- * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
814
- * @throws {Error} If the plugin's configuration is not found.
815
- */
816
627
  async saveConfigFromPlugin(plugin) {
817
628
  if (!plugin.platform?.config) {
818
629
  this.log.error(`Error saving config file for plugin ${plg}${plugin.name}${er}: config not found`);
@@ -822,7 +633,6 @@ export class PluginManager {
822
633
  try {
823
634
  await fs.writeFile(configFile, JSON.stringify(plugin.platform.config, null, 2), 'utf8');
824
635
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
825
- // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
826
636
  return Promise.resolve();
827
637
  }
828
638
  catch (err) {
@@ -830,19 +640,6 @@ export class PluginManager {
830
640
  return Promise.reject(err);
831
641
  }
832
642
  }
833
- /**
834
- * Saves the configuration of a plugin from a JSON object to a file.
835
- *
836
- * This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
837
- * It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
838
- * the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
839
- * successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
840
- * during the file write operation, it logs the error and returns.
841
- *
842
- * @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
843
- * @param {PlatformConfig} config - The configuration data to be saved.
844
- * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
845
- */
846
643
  async saveConfigFromJson(plugin, config) {
847
644
  if (!config.name || !config.type || config.name !== plugin.name) {
848
645
  this.log.error(`Error saving config file for plugin ${plg}${plugin.name}${er}. Wrong config data content:${rs}\n`, config);
@@ -853,24 +650,12 @@ export class PluginManager {
853
650
  await fs.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
854
651
  plugin.configJson = config;
855
652
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
856
- // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
857
653
  }
858
654
  catch (err) {
859
655
  this.log.error(`Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err}`);
860
656
  return;
861
657
  }
862
658
  }
863
- /**
864
- * Loads the schema for a plugin.
865
- *
866
- * This method attempts to load the schema file for the specified plugin. If the schema file is found,
867
- * it reads and parses the file, updates the schema's title and description, and logs the process.
868
- * It also attempts to delete any old schema file from the matterbridge directory. If the schema file
869
- * is not found, it logs the event and loads a default schema for the plugin.
870
- *
871
- * @param {RegisteredPlugin} plugin - The plugin whose schema is to be loaded.
872
- * @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
873
- */
874
659
  async loadSchema(plugin) {
875
660
  let schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
876
661
  try {
@@ -880,8 +665,6 @@ export class PluginManager {
880
665
  schema.title = plugin.description;
881
666
  schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
882
667
  this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
883
- // this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
884
- // Delete the schema file from old position
885
668
  schemaFile = path.join(this.matterbridge.matterbridgeDirectory, `${plugin.name}.schema.json`);
886
669
  try {
887
670
  await fs.unlink(schemaFile);
@@ -897,16 +680,6 @@ export class PluginManager {
897
680
  return this.getDefaultSchema(plugin);
898
681
  }
899
682
  }
900
- /**
901
- * Returns the default schema for a plugin.
902
- *
903
- * This method generates a default schema object for the specified plugin. The schema includes
904
- * metadata such as the plugin's title, description, version, and author. It also defines the
905
- * properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
906
- *
907
- * @param {RegisteredPlugin} plugin - The plugin for which the default schema is to be generated.
908
- * @returns {PlatformSchema} The default schema object for the plugin.
909
- */
910
683
  getDefaultSchema(plugin) {
911
684
  return {
912
685
  title: plugin.description,
@@ -937,4 +710,3 @@ export class PluginManager {
937
710
  };
938
711
  }
939
712
  }
940
- //# sourceMappingURL=pluginManager.js.map
@@ -1,2 +1 @@
1
1
  export * from 'node-persist-manager';
2
- //# sourceMappingURL=export.js.map