matterbridge 3.1.2 → 3.1.3-dev-20250714-c9b85b3

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