matterbridge 3.1.0 → 3.1.1-dev-20250629-f14b886

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 (188) hide show
  1. package/CHANGELOG.md +17 -4
  2. package/README-DEV.md +14 -2
  3. package/dist/cli.js +2 -91
  4. package/dist/clusters/export.js +0 -2
  5. package/dist/defaultConfigSchema.js +0 -24
  6. package/dist/deviceManager.js +1 -94
  7. package/dist/devices/export.js +0 -2
  8. package/dist/evse.js +9 -70
  9. package/dist/frontend.js +16 -413
  10. package/dist/globalMatterbridge.js +0 -47
  11. package/dist/helpers.js +0 -53
  12. package/dist/index.js +1 -32
  13. package/dist/laundryWasher.js +7 -92
  14. package/dist/logger/export.js +0 -1
  15. package/dist/matter/behaviors.js +0 -2
  16. package/dist/matter/clusters.js +0 -2
  17. package/dist/matter/devices.js +0 -2
  18. package/dist/matter/endpoints.js +0 -2
  19. package/dist/matter/export.js +0 -3
  20. package/dist/matter/types.js +0 -3
  21. package/dist/matterbridge.js +50 -797
  22. package/dist/matterbridgeAccessoryPlatform.js +0 -36
  23. package/dist/matterbridgeBehaviors.js +1 -55
  24. package/dist/matterbridgeDeviceTypes.js +15 -579
  25. package/dist/matterbridgeDynamicPlatform.js +0 -36
  26. package/dist/matterbridgeEndpoint.js +40 -1022
  27. package/dist/matterbridgeEndpointHelpers.js +12 -322
  28. package/dist/matterbridgePlatform.js +0 -233
  29. package/dist/matterbridgeTypes.js +0 -25
  30. package/dist/pluginManager.js +3 -269
  31. package/dist/roboticVacuumCleaner.js +6 -83
  32. package/dist/shelly.js +7 -168
  33. package/dist/storage/export.js +0 -1
  34. package/dist/update.js +0 -54
  35. package/dist/utils/colorUtils.js +2 -263
  36. package/dist/utils/commandLine.js +0 -54
  37. package/dist/utils/copyDirectory.js +1 -38
  38. package/dist/utils/createDirectory.js +0 -33
  39. package/dist/utils/createZip.js +2 -47
  40. package/dist/utils/deepCopy.js +0 -39
  41. package/dist/utils/deepEqual.js +1 -72
  42. package/dist/utils/export.js +0 -1
  43. package/dist/utils/hex.js +0 -58
  44. package/dist/utils/isvalid.js +0 -101
  45. package/dist/utils/network.js +5 -83
  46. package/dist/utils/spawn.js +0 -18
  47. package/dist/utils/wait.js +9 -62
  48. package/dist/waterHeater.js +2 -77
  49. package/npm-shrinkwrap.json +2 -2
  50. package/package.json +1 -2
  51. package/dist/cli.d.ts +0 -29
  52. package/dist/cli.d.ts.map +0 -1
  53. package/dist/cli.js.map +0 -1
  54. package/dist/clusters/export.d.ts +0 -2
  55. package/dist/clusters/export.d.ts.map +0 -1
  56. package/dist/clusters/export.js.map +0 -1
  57. package/dist/defaultConfigSchema.d.ts +0 -28
  58. package/dist/defaultConfigSchema.d.ts.map +0 -1
  59. package/dist/defaultConfigSchema.js.map +0 -1
  60. package/dist/deviceManager.d.ts +0 -112
  61. package/dist/deviceManager.d.ts.map +0 -1
  62. package/dist/deviceManager.js.map +0 -1
  63. package/dist/devices/export.d.ts +0 -5
  64. package/dist/devices/export.d.ts.map +0 -1
  65. package/dist/devices/export.js.map +0 -1
  66. package/dist/evse.d.ts +0 -72
  67. package/dist/evse.d.ts.map +0 -1
  68. package/dist/evse.js.map +0 -1
  69. package/dist/frontend.d.ts +0 -285
  70. package/dist/frontend.d.ts.map +0 -1
  71. package/dist/frontend.js.map +0 -1
  72. package/dist/globalMatterbridge.d.ts +0 -59
  73. package/dist/globalMatterbridge.d.ts.map +0 -1
  74. package/dist/globalMatterbridge.js.map +0 -1
  75. package/dist/helpers.d.ts +0 -48
  76. package/dist/helpers.d.ts.map +0 -1
  77. package/dist/helpers.js.map +0 -1
  78. package/dist/index.d.ts +0 -38
  79. package/dist/index.d.ts.map +0 -1
  80. package/dist/index.js.map +0 -1
  81. package/dist/laundryWasher.d.ts +0 -243
  82. package/dist/laundryWasher.d.ts.map +0 -1
  83. package/dist/laundryWasher.js.map +0 -1
  84. package/dist/logger/export.d.ts +0 -2
  85. package/dist/logger/export.d.ts.map +0 -1
  86. package/dist/logger/export.js.map +0 -1
  87. package/dist/matter/behaviors.d.ts +0 -2
  88. package/dist/matter/behaviors.d.ts.map +0 -1
  89. package/dist/matter/behaviors.js.map +0 -1
  90. package/dist/matter/clusters.d.ts +0 -2
  91. package/dist/matter/clusters.d.ts.map +0 -1
  92. package/dist/matter/clusters.js.map +0 -1
  93. package/dist/matter/devices.d.ts +0 -2
  94. package/dist/matter/devices.d.ts.map +0 -1
  95. package/dist/matter/devices.js.map +0 -1
  96. package/dist/matter/endpoints.d.ts +0 -2
  97. package/dist/matter/endpoints.d.ts.map +0 -1
  98. package/dist/matter/endpoints.js.map +0 -1
  99. package/dist/matter/export.d.ts +0 -5
  100. package/dist/matter/export.d.ts.map +0 -1
  101. package/dist/matter/export.js.map +0 -1
  102. package/dist/matter/types.d.ts +0 -3
  103. package/dist/matter/types.d.ts.map +0 -1
  104. package/dist/matter/types.js.map +0 -1
  105. package/dist/matterbridge.d.ts +0 -450
  106. package/dist/matterbridge.d.ts.map +0 -1
  107. package/dist/matterbridge.js.map +0 -1
  108. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
  109. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  110. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  111. package/dist/matterbridgeBehaviors.d.ts +0 -1334
  112. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  113. package/dist/matterbridgeBehaviors.js.map +0 -1
  114. package/dist/matterbridgeDeviceTypes.d.ts +0 -709
  115. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  116. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  117. package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
  118. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  119. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  120. package/dist/matterbridgeEndpoint.d.ts +0 -1173
  121. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  122. package/dist/matterbridgeEndpoint.js.map +0 -1
  123. package/dist/matterbridgeEndpointHelpers.d.ts +0 -3198
  124. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  125. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  126. package/dist/matterbridgePlatform.d.ts +0 -310
  127. package/dist/matterbridgePlatform.d.ts.map +0 -1
  128. package/dist/matterbridgePlatform.js.map +0 -1
  129. package/dist/matterbridgeTypes.d.ts +0 -184
  130. package/dist/matterbridgeTypes.d.ts.map +0 -1
  131. package/dist/matterbridgeTypes.js.map +0 -1
  132. package/dist/pluginManager.d.ts +0 -291
  133. package/dist/pluginManager.d.ts.map +0 -1
  134. package/dist/pluginManager.js.map +0 -1
  135. package/dist/roboticVacuumCleaner.d.ts +0 -104
  136. package/dist/roboticVacuumCleaner.d.ts.map +0 -1
  137. package/dist/roboticVacuumCleaner.js.map +0 -1
  138. package/dist/shelly.d.ts +0 -174
  139. package/dist/shelly.d.ts.map +0 -1
  140. package/dist/shelly.js.map +0 -1
  141. package/dist/storage/export.d.ts +0 -2
  142. package/dist/storage/export.d.ts.map +0 -1
  143. package/dist/storage/export.js.map +0 -1
  144. package/dist/update.d.ts +0 -59
  145. package/dist/update.d.ts.map +0 -1
  146. package/dist/update.js.map +0 -1
  147. package/dist/utils/colorUtils.d.ts +0 -117
  148. package/dist/utils/colorUtils.d.ts.map +0 -1
  149. package/dist/utils/colorUtils.js.map +0 -1
  150. package/dist/utils/commandLine.d.ts +0 -59
  151. package/dist/utils/commandLine.d.ts.map +0 -1
  152. package/dist/utils/commandLine.js.map +0 -1
  153. package/dist/utils/copyDirectory.d.ts +0 -33
  154. package/dist/utils/copyDirectory.d.ts.map +0 -1
  155. package/dist/utils/copyDirectory.js.map +0 -1
  156. package/dist/utils/createDirectory.d.ts +0 -34
  157. package/dist/utils/createDirectory.d.ts.map +0 -1
  158. package/dist/utils/createDirectory.js.map +0 -1
  159. package/dist/utils/createZip.d.ts +0 -39
  160. package/dist/utils/createZip.d.ts.map +0 -1
  161. package/dist/utils/createZip.js.map +0 -1
  162. package/dist/utils/deepCopy.d.ts +0 -32
  163. package/dist/utils/deepCopy.d.ts.map +0 -1
  164. package/dist/utils/deepCopy.js.map +0 -1
  165. package/dist/utils/deepEqual.d.ts +0 -54
  166. package/dist/utils/deepEqual.d.ts.map +0 -1
  167. package/dist/utils/deepEqual.js.map +0 -1
  168. package/dist/utils/export.d.ts +0 -12
  169. package/dist/utils/export.d.ts.map +0 -1
  170. package/dist/utils/export.js.map +0 -1
  171. package/dist/utils/hex.d.ts +0 -49
  172. package/dist/utils/hex.d.ts.map +0 -1
  173. package/dist/utils/hex.js.map +0 -1
  174. package/dist/utils/isvalid.d.ts +0 -103
  175. package/dist/utils/isvalid.d.ts.map +0 -1
  176. package/dist/utils/isvalid.js.map +0 -1
  177. package/dist/utils/network.d.ts +0 -76
  178. package/dist/utils/network.d.ts.map +0 -1
  179. package/dist/utils/network.js.map +0 -1
  180. package/dist/utils/spawn.d.ts +0 -14
  181. package/dist/utils/spawn.d.ts.map +0 -1
  182. package/dist/utils/spawn.js.map +0 -1
  183. package/dist/utils/wait.d.ts +0 -56
  184. package/dist/utils/wait.d.ts.map +0 -1
  185. package/dist/utils/wait.js.map +0 -1
  186. package/dist/waterHeater.d.ts +0 -106
  187. package/dist/waterHeater.d.ts.map +0 -1
  188. package/dist/waterHeater.js.map +0 -1
@@ -1,29 +1,4 @@
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.1.2
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 } from 'node-ansi-logger';
28
3
  import { plg, typ } from './matterbridgeTypes.js';
29
4
  export class PluginManager extends EventEmitter {
@@ -34,9 +9,8 @@ export class PluginManager extends EventEmitter {
34
9
  constructor(matterbridge) {
35
10
  super();
36
11
  this.matterbridge = matterbridge;
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
12
  this.nodeContext = matterbridge.nodeContext;
39
- this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: matterbridge.log.logLevel });
13
+ this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: matterbridge.log.logLevel });
40
14
  this.log.debug('Matterbridge plugin manager starting...');
41
15
  }
42
16
  get length() {
@@ -73,7 +47,6 @@ export class PluginManager extends EventEmitter {
73
47
  }
74
48
  catch (err) {
75
49
  this.log.error(`Error processing forEach plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
76
- // throw error;
77
50
  }
78
51
  });
79
52
  await Promise.all(tasks);
@@ -81,31 +54,13 @@ export class PluginManager extends EventEmitter {
81
54
  set logLevel(logLevel) {
82
55
  this.log.logLevel = logLevel;
83
56
  }
84
- /**
85
- * Loads registered plugins from storage.
86
- *
87
- * This method retrieves an array of registered plugins from the storage and converts it
88
- * into a map where the plugin names are the keys and the plugin objects are the values.
89
- *
90
- * @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
91
- */
92
57
  async loadFromStorage() {
93
- // Load the array from storage and convert it to a map
94
58
  const pluginsArray = await this.nodeContext.get('plugins', []);
95
59
  for (const plugin of pluginsArray)
96
60
  this._plugins.set(plugin.name, plugin);
97
61
  return pluginsArray;
98
62
  }
99
- /**
100
- * Loads registered plugins from storage.
101
- *
102
- * This method retrieves an array of registered plugins from the storage and converts it
103
- * into a map where the plugin names are the keys and the plugin objects are the values.
104
- *
105
- * @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
106
- */
107
63
  async saveToStorage() {
108
- // Convert the map to an array
109
64
  const plugins = [];
110
65
  const pluginArrayFromMap = Array.from(this._plugins.values());
111
66
  for (const plugin of pluginArrayFromMap) {
@@ -125,21 +80,13 @@ export class PluginManager extends EventEmitter {
125
80
  this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
126
81
  return plugins.length;
127
82
  }
128
- /**
129
- * Resolves the name of a plugin by loading and parsing its package.json file.
130
- *
131
- * @param {string} pluginPath - The path to the plugin or the path to the plugin's package.json file.
132
- * @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.
133
- */
134
83
  async resolve(pluginPath) {
135
84
  const { default: path } = await import('node:path');
136
85
  const { promises } = await import('node:fs');
137
86
  if (!pluginPath.endsWith('package.json'))
138
87
  pluginPath = path.join(pluginPath, 'package.json');
139
- // Resolve the package.json of the plugin
140
88
  let packageJsonPath = path.resolve(pluginPath);
141
89
  this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
142
- // Check if the package.json file exists
143
90
  try {
144
91
  await promises.access(packageJsonPath);
145
92
  }
@@ -149,9 +96,7 @@ export class PluginManager extends EventEmitter {
149
96
  this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
150
97
  }
151
98
  try {
152
- // Load the package.json of the plugin
153
99
  const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
154
- // Check for main issues
155
100
  if (!packageJson.name) {
156
101
  this.log.error(`Package.json name not found at ${packageJsonPath}`);
157
102
  return null;
@@ -164,7 +109,6 @@ export class PluginManager extends EventEmitter {
164
109
  this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
165
110
  return null;
166
111
  }
167
- // Check for @project-chip and @matter packages in dependencies and devDependencies
168
112
  const checkForProjectChipPackages = (dependencies) => {
169
113
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
170
114
  };
@@ -186,7 +130,6 @@ export class PluginManager extends EventEmitter {
186
130
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
187
131
  return null;
188
132
  }
189
- // Check for matterbridge package in dependencies and devDependencies
190
133
  const checkForMatterbridgePackage = (dependencies) => {
191
134
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
192
135
  };
@@ -216,12 +159,6 @@ export class PluginManager extends EventEmitter {
216
159
  return null;
217
160
  }
218
161
  }
219
- /**
220
- * Get the author of a plugin from its package.json.
221
- *
222
- * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
223
- * @returns {string} The author of the plugin, or 'Unknown author' if not found.
224
- */
225
162
  getAuthor(packageJson) {
226
163
  if (packageJson.author && typeof packageJson.author === 'string')
227
164
  return packageJson.author;
@@ -229,12 +166,6 @@ export class PluginManager extends EventEmitter {
229
166
  return packageJson.author.name;
230
167
  return 'Unknown author';
231
168
  }
232
- /**
233
- * Get the homepage of a plugin from its package.json.
234
- *
235
- * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
236
- * @returns {string | undefined} The homepage of the plugin, or undefined if not found.
237
- */
238
169
  getHomepage(packageJson) {
239
170
  if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
240
171
  return packageJson.homepage.replace('git+', '').replace('.git', '');
@@ -243,14 +174,7 @@ export class PluginManager extends EventEmitter {
243
174
  return packageJson.repository.url.replace('git+', '').replace('.git', '');
244
175
  }
245
176
  }
246
- /**
247
- * Get the help URL of a plugin from its package.json.
248
- *
249
- * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
250
- * @returns {string | undefined} The URL to the help page or to the README file, or undefined if not found.
251
- */
252
177
  getHelp(packageJson) {
253
- // If there's a help field that looks like a URL, return it.
254
178
  if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
255
179
  return packageJson.help;
256
180
  }
@@ -261,14 +185,7 @@ export class PluginManager extends EventEmitter {
261
185
  return packageJson.homepage.replace('git+', '').replace('.git', '');
262
186
  }
263
187
  }
264
- /**
265
- * Get the changelog URL of a plugin from its package.json.
266
- *
267
- * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
268
- * @returns {string | undefined} The URL to the CHANGELOG file, or undefined if not found.
269
- */
270
188
  getChangelog(packageJson) {
271
- // If there's a changelog field that looks like a URL, return it.
272
189
  if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
273
190
  return packageJson.changelog;
274
191
  }
@@ -279,13 +196,6 @@ export class PluginManager extends EventEmitter {
279
196
  return packageJson.homepage.replace('git+', '').replace('.git', '');
280
197
  }
281
198
  }
282
- /**
283
- * Get the first funding URL(s) of a plugin from its package.json.
284
- *
285
- * @param {Record<string, any>} packageJson - The package.json object of the plugin.
286
- * @returns {string | undefined} The first funding URLs, or undefined if not found.
287
- */
288
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
289
199
  getFunding(packageJson) {
290
200
  const funding = packageJson.funding;
291
201
  if (!funding)
@@ -294,25 +204,16 @@ export class PluginManager extends EventEmitter {
294
204
  return;
295
205
  if (typeof funding === 'string' && funding.startsWith('http'))
296
206
  return funding;
297
- // Normalize funding into an array.
298
207
  const fundingEntries = Array.isArray(funding) ? funding : [funding];
299
208
  for (const entry of fundingEntries) {
300
209
  if (entry && typeof entry === 'string' && entry.startsWith('http')) {
301
- // If the funding entry is a string, assume it is a URL.
302
210
  return entry;
303
211
  }
304
212
  else if (entry && typeof entry === 'object' && typeof entry.url === 'string' && entry.url.startsWith('http')) {
305
- // If it's an object with a 'url' property, use that.
306
213
  return entry.url;
307
214
  }
308
215
  }
309
216
  }
310
- /**
311
- * Loads and parse the plugin package.json and returns it.
312
- *
313
- * @param {RegisteredPlugin} plugin - The plugin to load the package from.
314
- * @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.
315
- */
316
217
  async parse(plugin) {
317
218
  const { promises } = await import('node:fs');
318
219
  try {
@@ -344,7 +245,6 @@ export class PluginManager extends EventEmitter {
344
245
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no path`);
345
246
  if (!plugin.type)
346
247
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
347
- // Check for @project-chip and @matter packages in dependencies and devDependencies
348
248
  const checkForProjectChipPackages = (dependencies) => {
349
249
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
350
250
  };
@@ -366,7 +266,6 @@ export class PluginManager extends EventEmitter {
366
266
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
367
267
  return null;
368
268
  }
369
- // Check for matterbridge package in dependencies and devDependencies
370
269
  const checkForMatterbridgePackage = (dependencies) => {
371
270
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
372
271
  };
@@ -396,16 +295,6 @@ export class PluginManager extends EventEmitter {
396
295
  return null;
397
296
  }
398
297
  }
399
- /**
400
- * Enables a plugin by its name or path.
401
- *
402
- * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
403
- * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
404
- * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
405
- *
406
- * @param {string} nameOrPath - The name or path of the plugin to enable.
407
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
408
- */
409
298
  async enable(nameOrPath) {
410
299
  const { promises } = await import('node:fs');
411
300
  if (!nameOrPath)
@@ -441,16 +330,6 @@ export class PluginManager extends EventEmitter {
441
330
  return null;
442
331
  }
443
332
  }
444
- /**
445
- * Enables a plugin by its name or path.
446
- *
447
- * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
448
- * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
449
- * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
450
- *
451
- * @param {string} nameOrPath - The name or path of the plugin to enable.
452
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
453
- */
454
333
  async disable(nameOrPath) {
455
334
  const { promises } = await import('node:fs');
456
335
  if (!nameOrPath)
@@ -486,16 +365,6 @@ export class PluginManager extends EventEmitter {
486
365
  return null;
487
366
  }
488
367
  }
489
- /**
490
- * Removes a plugin by its name or path.
491
- *
492
- * This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
493
- * It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
494
- * the plugin's `package.json` file to retrieve its name and remove it.
495
- *
496
- * @param {string} nameOrPath - The name or path of the plugin to remove.
497
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
498
- */
499
368
  async remove(nameOrPath) {
500
369
  const { promises } = await import('node:fs');
501
370
  if (!nameOrPath)
@@ -531,17 +400,6 @@ export class PluginManager extends EventEmitter {
531
400
  return null;
532
401
  }
533
402
  }
534
- /**
535
- * Adds a plugin by its name or path.
536
- *
537
- * This method adds a plugin to the plugins map and saves the updated plugin information to storage.
538
- * It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
539
- * registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
540
- * and saves the updated plugin information to storage.
541
- *
542
- * @param {string} nameOrPath - The name or path of the plugin to add.
543
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
544
- */
545
403
  async add(nameOrPath) {
546
404
  const { promises } = await import('node:fs');
547
405
  if (!nameOrPath)
@@ -577,15 +435,6 @@ export class PluginManager extends EventEmitter {
577
435
  return null;
578
436
  }
579
437
  }
580
- /**
581
- * Installs a plugin by its name.
582
- *
583
- * This method first uninstalls any existing version of the plugin, then installs the plugin globally using npm.
584
- * It logs the installation process and retrieves the installed version of the plugin.
585
- *
586
- * @param {string} name - The name of the plugin to install.
587
- * @returns {Promise<string | undefined>} A promise that resolves to the installed version of the plugin, or undefined if the installation failed.
588
- */
589
438
  async install(name) {
590
439
  const { exec } = await import('node:child_process');
591
440
  await this.uninstall(name);
@@ -600,14 +449,11 @@ export class PluginManager extends EventEmitter {
600
449
  else {
601
450
  this.log.info(`Installed plugin ${plg}${name}${nf}`);
602
451
  this.log.debug(`Installed plugin ${plg}${name}${db}: ${stdout}`);
603
- // Get the installed version
604
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
605
452
  exec(`npm list -g ${name} --depth=0`, (listError, listStdout, listStderr) => {
606
453
  if (listError) {
607
454
  this.log.error(`List error: ${listError}`);
608
455
  resolve(undefined);
609
456
  }
610
- // Clean the output to get only the package name and version
611
457
  const lines = listStdout.split('\n');
612
458
  const versionLine = lines.find((line) => line.includes(`${name}@`));
613
459
  if (versionLine) {
@@ -624,15 +470,6 @@ export class PluginManager extends EventEmitter {
624
470
  });
625
471
  });
626
472
  }
627
- /**
628
- * Uninstalls a plugin by its name.
629
- *
630
- * This method uninstalls a globally installed plugin using npm. It logs the uninstallation process
631
- * and returns the name of the uninstalled plugin if successful, or undefined if the uninstallation failed.
632
- *
633
- * @param {string} name - The name of the plugin to uninstall.
634
- * @returns {Promise<string | undefined>} A promise that resolves to the name of the uninstalled plugin, or undefined if the uninstallation failed.
635
- */
636
473
  async uninstall(name) {
637
474
  const { exec } = await import('node:child_process');
638
475
  this.log.info(`Uninstalling plugin ${plg}${name}${nf}`);
@@ -652,15 +489,6 @@ export class PluginManager extends EventEmitter {
652
489
  });
653
490
  });
654
491
  }
655
- /**
656
- * Loads a plugin and returns the corresponding MatterbridgePlatform instance.
657
- *
658
- * @param {RegisteredPlugin} plugin - The plugin to load.
659
- * @param {boolean} start - Optional flag indicating whether to start the plugin after loading. Default is false.
660
- * @param {string} message - Optional message to pass to the plugin when starting.
661
- * @param {boolean} configure - Optional flag indicating whether to configure the plugin after loading. Default is false.
662
- * @returns {Promise<MatterbridgePlatform | undefined>} A Promise that resolves to the loaded MatterbridgePlatform instance or undefined.
663
- */
664
492
  async load(plugin, start = false, message = '', configure = false) {
665
493
  const { promises } = await import('node:fs');
666
494
  const { default: path } = await import('node:path');
@@ -674,20 +502,15 @@ export class PluginManager extends EventEmitter {
674
502
  }
675
503
  this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
676
504
  try {
677
- // Load the package.json of the plugin
678
505
  const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
679
- // Resolve the main module path relative to package.json
680
506
  const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
681
- // Dynamically import the plugin
682
507
  const { pathToFileURL } = await import('node:url');
683
508
  const pluginUrl = pathToFileURL(pluginEntry);
684
509
  this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
685
510
  const pluginInstance = await import(pluginUrl.href);
686
511
  this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
687
- // Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
688
512
  if (pluginInstance.default) {
689
513
  const config = await this.loadConfig(plugin);
690
- // 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.
691
514
  plugin.name = packageJson.name;
692
515
  plugin.description = packageJson.description ?? 'No description';
693
516
  plugin.version = packageJson.version;
@@ -696,7 +519,7 @@ export class PluginManager extends EventEmitter {
696
519
  plugin.schemaJson = await this.loadSchema(plugin);
697
520
  config.name = plugin.name;
698
521
  config.version = packageJson.version;
699
- const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: config.debug ? "debug" /* LogLevel.DEBUG */ : this.matterbridge.log.logLevel });
522
+ const log = new AnsiLogger({ logName: plugin.description ?? 'No description', logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
700
523
  const platform = pluginInstance.default(this.matterbridge, log, config);
701
524
  config.type = platform.type;
702
525
  platform.name = packageJson.name;
@@ -715,7 +538,7 @@ export class PluginManager extends EventEmitter {
715
538
  plugin.loaded = true;
716
539
  plugin.registeredDevices = 0;
717
540
  plugin.addedDevices = 0;
718
- await this.saveToStorage(); // Save the plugin to storage
541
+ await this.saveToStorage();
719
542
  this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
720
543
  this.emit('loaded', plugin.name);
721
544
  if (start)
@@ -735,14 +558,6 @@ export class PluginManager extends EventEmitter {
735
558
  }
736
559
  return undefined;
737
560
  }
738
- /**
739
- * Starts a plugin.
740
- *
741
- * @param {RegisteredPlugin} plugin - The plugin to start.
742
- * @param {string} [message] - Optional message to pass to the plugin's onStart method.
743
- * @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
744
- * @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
745
- */
746
561
  async start(plugin, message, configure = false) {
747
562
  if (!plugin.loaded) {
748
563
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -773,12 +588,6 @@ export class PluginManager extends EventEmitter {
773
588
  }
774
589
  return undefined;
775
590
  }
776
- /**
777
- * Configures a plugin.
778
- *
779
- * @param {RegisteredPlugin} plugin - The plugin to configure.
780
- * @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
781
- */
782
591
  async configure(plugin) {
783
592
  if (!plugin.loaded) {
784
593
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -810,18 +619,6 @@ export class PluginManager extends EventEmitter {
810
619
  }
811
620
  return undefined;
812
621
  }
813
- /**
814
- * Shuts down a plugin.
815
- *
816
- * This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
817
- * It logs the shutdown process and optionally removes all devices associated with the plugin.
818
- *
819
- * @param {RegisteredPlugin} plugin - The plugin to shut down.
820
- * @param {string} [reason] - The reason for shutting down the plugin.
821
- * @param {boolean} [removeAllDevices] - Whether to remove all devices associated with the plugin.
822
- * @param {boolean} [force] - Whether to force the shutdown even if the plugin is not loaded or started.
823
- * @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
824
- */
825
622
  async shutdown(plugin, reason, removeAllDevices = false, force = false) {
826
623
  this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
827
624
  if (!plugin.loaded) {
@@ -865,15 +662,6 @@ export class PluginManager extends EventEmitter {
865
662
  }
866
663
  return undefined;
867
664
  }
868
- /**
869
- * Loads the configuration for a plugin.
870
- * If the configuration file exists, it reads the file and returns the parsed JSON data.
871
- * If the configuration file does not exist, it creates a new file with default configuration and returns it.
872
- * If any error occurs during file access or creation, it logs an error and return un empty config.
873
- *
874
- * @param {RegisteredPlugin} plugin - The plugin for which to load the configuration.
875
- * @returns {Promise<PlatformConfig>} A promise that resolves to the loaded or created configuration.
876
- */
877
665
  async loadConfig(plugin) {
878
666
  const { default: path } = await import('node:path');
879
667
  const { promises } = await import('node:fs');
@@ -884,8 +672,6 @@ export class PluginManager extends EventEmitter {
884
672
  const data = await promises.readFile(configFile, 'utf8');
885
673
  const config = JSON.parse(data);
886
674
  this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
887
- // this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
888
- // The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
889
675
  config.name = plugin.name;
890
676
  config.type = plugin.type;
891
677
  if (config.debug === undefined)
@@ -909,7 +695,6 @@ export class PluginManager extends EventEmitter {
909
695
  try {
910
696
  await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
911
697
  this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
912
- // this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
913
698
  return config;
914
699
  }
915
700
  catch (err) {
@@ -923,19 +708,6 @@ export class PluginManager extends EventEmitter {
923
708
  }
924
709
  }
925
710
  }
926
- /**
927
- * Saves the configuration of a plugin to a file.
928
- *
929
- * This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
930
- * If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
931
- * is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
932
- * the error and rejects the promise.
933
- *
934
- * @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
935
- * @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
936
- * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
937
- * @throws {Error} If the plugin's configuration is not found.
938
- */
939
711
  async saveConfigFromPlugin(plugin, restartRequired = false) {
940
712
  const { default: path } = await import('node:path');
941
713
  const { promises } = await import('node:fs');
@@ -950,7 +722,6 @@ export class PluginManager extends EventEmitter {
950
722
  if (restartRequired)
951
723
  plugin.restartRequired = true;
952
724
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
953
- // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
954
725
  return Promise.resolve();
955
726
  }
956
727
  catch (err) {
@@ -958,20 +729,6 @@ export class PluginManager extends EventEmitter {
958
729
  return Promise.reject(err);
959
730
  }
960
731
  }
961
- /**
962
- * Saves the configuration of a plugin from a JSON object to a file.
963
- *
964
- * This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
965
- * It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
966
- * the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
967
- * successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
968
- * during the file write operation, it logs the error and returns.
969
- *
970
- * @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
971
- * @param {PlatformConfig} config - The configuration data to be saved.
972
- * @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
973
- * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
974
- */
975
732
  async saveConfigFromJson(plugin, config, restartRequired = false) {
976
733
  const { default: path } = await import('node:path');
977
734
  const { promises } = await import('node:fs');
@@ -990,23 +747,12 @@ export class PluginManager extends EventEmitter {
990
747
  plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
991
748
  }
992
749
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
993
- // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
994
750
  }
995
751
  catch (err) {
996
752
  this.log.error(`Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}: ${err instanceof Error ? err.message + '\n' + err.stack : err}`);
997
753
  return;
998
754
  }
999
755
  }
1000
- /**
1001
- * Loads the schema for a plugin.
1002
- *
1003
- * This method attempts to load the schema file for the specified plugin. If the schema file is found,
1004
- * it reads and parses the file, updates the schema's title and description, and logs the process.
1005
- * If the schema file is not found, it logs the event and loads a default schema for the plugin.
1006
- *
1007
- * @param {RegisteredPlugin} plugin - The plugin whose schema is to be loaded.
1008
- * @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
1009
- */
1010
756
  async loadSchema(plugin) {
1011
757
  const { promises } = await import('node:fs');
1012
758
  const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
@@ -1017,7 +763,6 @@ export class PluginManager extends EventEmitter {
1017
763
  schema.title = plugin.description;
1018
764
  schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
1019
765
  this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
1020
- // this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
1021
766
  return schema;
1022
767
  }
1023
768
  catch (_err) {
@@ -1025,16 +770,6 @@ export class PluginManager extends EventEmitter {
1025
770
  return this.getDefaultSchema(plugin);
1026
771
  }
1027
772
  }
1028
- /**
1029
- * Returns the default schema for a plugin.
1030
- *
1031
- * This method generates a default schema object for the specified plugin. The schema includes
1032
- * metadata such as the plugin's title, description, version, and author. It also defines the
1033
- * properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
1034
- *
1035
- * @param {RegisteredPlugin} plugin - The plugin for which the default schema is to be generated.
1036
- * @returns {PlatformSchema} The default schema object for the plugin.
1037
- */
1038
773
  getDefaultSchema(plugin) {
1039
774
  return {
1040
775
  title: plugin.description,
@@ -1065,4 +800,3 @@ export class PluginManager extends EventEmitter {
1065
800
  };
1066
801
  }
1067
802
  }
1068
- //# sourceMappingURL=pluginManager.js.map