matterbridge 3.2.6 → 3.2.7-dev-20250908-3bb699e

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 (279) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cli.js +2 -91
  3. package/dist/cliEmitter.js +0 -30
  4. package/dist/clusters/export.js +0 -2
  5. package/dist/defaultConfigSchema.js +3 -24
  6. package/dist/deviceManager.js +1 -94
  7. package/dist/devices/airConditioner.js +0 -57
  8. package/dist/devices/batteryStorage.js +1 -48
  9. package/dist/devices/cooktop.js +0 -55
  10. package/dist/devices/dishwasher.js +0 -57
  11. package/dist/devices/evse.js +10 -74
  12. package/dist/devices/export.js +0 -5
  13. package/dist/devices/extractorHood.js +0 -42
  14. package/dist/devices/heatPump.js +2 -50
  15. package/dist/devices/laundryDryer.js +3 -62
  16. package/dist/devices/laundryWasher.js +4 -70
  17. package/dist/devices/microwaveOven.js +5 -88
  18. package/dist/devices/oven.js +0 -85
  19. package/dist/devices/refrigerator.js +0 -102
  20. package/dist/devices/roboticVacuumCleaner.js +9 -100
  21. package/dist/devices/solarPower.js +0 -38
  22. package/dist/devices/speaker.js +0 -80
  23. package/dist/devices/temperatureControl.js +3 -25
  24. package/dist/devices/waterHeater.js +2 -82
  25. package/dist/dgram/coap.js +13 -126
  26. package/dist/dgram/dgram.js +2 -114
  27. package/dist/dgram/mb_coap.js +3 -41
  28. package/dist/dgram/mb_mdns.js +15 -80
  29. package/dist/dgram/mdns.js +137 -299
  30. package/dist/dgram/multicast.js +1 -62
  31. package/dist/dgram/unicast.js +0 -54
  32. package/dist/frontend.js +24 -450
  33. package/dist/globalMatterbridge.js +0 -47
  34. package/dist/helpers.js +0 -53
  35. package/dist/index.js +1 -30
  36. package/dist/jest-utils/jestHelpers.js +2 -124
  37. package/dist/logger/export.js +0 -1
  38. package/dist/matter/behaviors.js +0 -2
  39. package/dist/matter/clusters.js +0 -2
  40. package/dist/matter/devices.js +0 -2
  41. package/dist/matter/endpoints.js +0 -2
  42. package/dist/matter/export.js +0 -3
  43. package/dist/matter/types.js +0 -3
  44. package/dist/matterbridge.js +49 -780
  45. package/dist/matterbridgeAccessoryPlatform.js +0 -36
  46. package/dist/matterbridgeBehaviors.js +5 -65
  47. package/dist/matterbridgeDeviceTypes.js +17 -630
  48. package/dist/matterbridgeDynamicPlatform.js +0 -36
  49. package/dist/matterbridgeEndpoint.js +54 -1301
  50. package/dist/matterbridgeEndpointHelpers.js +12 -345
  51. package/dist/matterbridgePlatform.js +1 -305
  52. package/dist/matterbridgeTypes.js +0 -25
  53. package/dist/pluginManager.js +5 -251
  54. package/dist/shelly.js +7 -168
  55. package/dist/storage/export.js +0 -1
  56. package/dist/update.js +0 -69
  57. package/dist/utils/colorUtils.js +2 -97
  58. package/dist/utils/commandLine.js +0 -54
  59. package/dist/utils/copyDirectory.js +1 -38
  60. package/dist/utils/createDirectory.js +0 -33
  61. package/dist/utils/createZip.js +2 -47
  62. package/dist/utils/deepCopy.js +0 -39
  63. package/dist/utils/deepEqual.js +1 -72
  64. package/dist/utils/error.js +0 -41
  65. package/dist/utils/export.js +0 -1
  66. package/dist/utils/hex.js +0 -124
  67. package/dist/utils/isvalid.js +0 -101
  68. package/dist/utils/network.js +6 -92
  69. package/dist/utils/spawn.js +0 -40
  70. package/dist/utils/wait.js +8 -60
  71. package/npm-shrinkwrap.json +2 -2
  72. package/package.json +1 -2
  73. package/dist/cli.d.ts +0 -26
  74. package/dist/cli.d.ts.map +0 -1
  75. package/dist/cli.js.map +0 -1
  76. package/dist/cliEmitter.d.ts +0 -34
  77. package/dist/cliEmitter.d.ts.map +0 -1
  78. package/dist/cliEmitter.js.map +0 -1
  79. package/dist/clusters/export.d.ts +0 -2
  80. package/dist/clusters/export.d.ts.map +0 -1
  81. package/dist/clusters/export.js.map +0 -1
  82. package/dist/defaultConfigSchema.d.ts +0 -28
  83. package/dist/defaultConfigSchema.d.ts.map +0 -1
  84. package/dist/defaultConfigSchema.js.map +0 -1
  85. package/dist/deviceManager.d.ts +0 -112
  86. package/dist/deviceManager.d.ts.map +0 -1
  87. package/dist/deviceManager.js.map +0 -1
  88. package/dist/devices/airConditioner.d.ts +0 -98
  89. package/dist/devices/airConditioner.d.ts.map +0 -1
  90. package/dist/devices/airConditioner.js.map +0 -1
  91. package/dist/devices/batteryStorage.d.ts +0 -48
  92. package/dist/devices/batteryStorage.d.ts.map +0 -1
  93. package/dist/devices/batteryStorage.js.map +0 -1
  94. package/dist/devices/cooktop.d.ts +0 -60
  95. package/dist/devices/cooktop.d.ts.map +0 -1
  96. package/dist/devices/cooktop.js.map +0 -1
  97. package/dist/devices/dishwasher.d.ts +0 -71
  98. package/dist/devices/dishwasher.d.ts.map +0 -1
  99. package/dist/devices/dishwasher.js.map +0 -1
  100. package/dist/devices/evse.d.ts +0 -75
  101. package/dist/devices/evse.d.ts.map +0 -1
  102. package/dist/devices/evse.js.map +0 -1
  103. package/dist/devices/export.d.ts +0 -17
  104. package/dist/devices/export.d.ts.map +0 -1
  105. package/dist/devices/export.js.map +0 -1
  106. package/dist/devices/extractorHood.d.ts +0 -46
  107. package/dist/devices/extractorHood.d.ts.map +0 -1
  108. package/dist/devices/extractorHood.js.map +0 -1
  109. package/dist/devices/heatPump.d.ts +0 -47
  110. package/dist/devices/heatPump.d.ts.map +0 -1
  111. package/dist/devices/heatPump.js.map +0 -1
  112. package/dist/devices/laundryDryer.d.ts +0 -67
  113. package/dist/devices/laundryDryer.d.ts.map +0 -1
  114. package/dist/devices/laundryDryer.js.map +0 -1
  115. package/dist/devices/laundryWasher.d.ts +0 -81
  116. package/dist/devices/laundryWasher.d.ts.map +0 -1
  117. package/dist/devices/laundryWasher.js.map +0 -1
  118. package/dist/devices/microwaveOven.d.ts +0 -168
  119. package/dist/devices/microwaveOven.d.ts.map +0 -1
  120. package/dist/devices/microwaveOven.js.map +0 -1
  121. package/dist/devices/oven.d.ts +0 -105
  122. package/dist/devices/oven.d.ts.map +0 -1
  123. package/dist/devices/oven.js.map +0 -1
  124. package/dist/devices/refrigerator.d.ts +0 -118
  125. package/dist/devices/refrigerator.d.ts.map +0 -1
  126. package/dist/devices/refrigerator.js.map +0 -1
  127. package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
  128. package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
  129. package/dist/devices/roboticVacuumCleaner.js.map +0 -1
  130. package/dist/devices/solarPower.d.ts +0 -40
  131. package/dist/devices/solarPower.d.ts.map +0 -1
  132. package/dist/devices/solarPower.js.map +0 -1
  133. package/dist/devices/speaker.d.ts +0 -83
  134. package/dist/devices/speaker.d.ts.map +0 -1
  135. package/dist/devices/speaker.js.map +0 -1
  136. package/dist/devices/temperatureControl.d.ts +0 -166
  137. package/dist/devices/temperatureControl.d.ts.map +0 -1
  138. package/dist/devices/temperatureControl.js.map +0 -1
  139. package/dist/devices/waterHeater.d.ts +0 -111
  140. package/dist/devices/waterHeater.d.ts.map +0 -1
  141. package/dist/devices/waterHeater.js.map +0 -1
  142. package/dist/dgram/coap.d.ts +0 -205
  143. package/dist/dgram/coap.d.ts.map +0 -1
  144. package/dist/dgram/coap.js.map +0 -1
  145. package/dist/dgram/dgram.d.ts +0 -141
  146. package/dist/dgram/dgram.d.ts.map +0 -1
  147. package/dist/dgram/dgram.js.map +0 -1
  148. package/dist/dgram/mb_coap.d.ts +0 -24
  149. package/dist/dgram/mb_coap.d.ts.map +0 -1
  150. package/dist/dgram/mb_coap.js.map +0 -1
  151. package/dist/dgram/mb_mdns.d.ts +0 -24
  152. package/dist/dgram/mb_mdns.d.ts.map +0 -1
  153. package/dist/dgram/mb_mdns.js.map +0 -1
  154. package/dist/dgram/mdns.d.ts +0 -290
  155. package/dist/dgram/mdns.d.ts.map +0 -1
  156. package/dist/dgram/mdns.js.map +0 -1
  157. package/dist/dgram/multicast.d.ts +0 -67
  158. package/dist/dgram/multicast.d.ts.map +0 -1
  159. package/dist/dgram/multicast.js.map +0 -1
  160. package/dist/dgram/unicast.d.ts +0 -56
  161. package/dist/dgram/unicast.d.ts.map +0 -1
  162. package/dist/dgram/unicast.js.map +0 -1
  163. package/dist/frontend.d.ts +0 -313
  164. package/dist/frontend.d.ts.map +0 -1
  165. package/dist/frontend.js.map +0 -1
  166. package/dist/globalMatterbridge.d.ts +0 -59
  167. package/dist/globalMatterbridge.d.ts.map +0 -1
  168. package/dist/globalMatterbridge.js.map +0 -1
  169. package/dist/helpers.d.ts +0 -48
  170. package/dist/helpers.d.ts.map +0 -1
  171. package/dist/helpers.js.map +0 -1
  172. package/dist/index.d.ts +0 -33
  173. package/dist/index.d.ts.map +0 -1
  174. package/dist/index.js.map +0 -1
  175. package/dist/jest-utils/jestHelpers.d.ts +0 -103
  176. package/dist/jest-utils/jestHelpers.d.ts.map +0 -1
  177. package/dist/jest-utils/jestHelpers.js.map +0 -1
  178. package/dist/logger/export.d.ts +0 -2
  179. package/dist/logger/export.d.ts.map +0 -1
  180. package/dist/logger/export.js.map +0 -1
  181. package/dist/matter/behaviors.d.ts +0 -2
  182. package/dist/matter/behaviors.d.ts.map +0 -1
  183. package/dist/matter/behaviors.js.map +0 -1
  184. package/dist/matter/clusters.d.ts +0 -2
  185. package/dist/matter/clusters.d.ts.map +0 -1
  186. package/dist/matter/clusters.js.map +0 -1
  187. package/dist/matter/devices.d.ts +0 -2
  188. package/dist/matter/devices.d.ts.map +0 -1
  189. package/dist/matter/devices.js.map +0 -1
  190. package/dist/matter/endpoints.d.ts +0 -2
  191. package/dist/matter/endpoints.d.ts.map +0 -1
  192. package/dist/matter/endpoints.js.map +0 -1
  193. package/dist/matter/export.d.ts +0 -5
  194. package/dist/matter/export.d.ts.map +0 -1
  195. package/dist/matter/export.js.map +0 -1
  196. package/dist/matter/types.d.ts +0 -3
  197. package/dist/matter/types.d.ts.map +0 -1
  198. package/dist/matter/types.js.map +0 -1
  199. package/dist/matterbridge.d.ts +0 -457
  200. package/dist/matterbridge.d.ts.map +0 -1
  201. package/dist/matterbridge.js.map +0 -1
  202. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
  203. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  204. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  205. package/dist/matterbridgeBehaviors.d.ts +0 -1351
  206. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  207. package/dist/matterbridgeBehaviors.js.map +0 -1
  208. package/dist/matterbridgeDeviceTypes.d.ts +0 -761
  209. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  210. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  211. package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
  212. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  213. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  214. package/dist/matterbridgeEndpoint.d.ts +0 -1438
  215. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  216. package/dist/matterbridgeEndpoint.js.map +0 -1
  217. package/dist/matterbridgeEndpointHelpers.d.ts +0 -407
  218. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  219. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  220. package/dist/matterbridgePlatform.d.ts +0 -379
  221. package/dist/matterbridgePlatform.d.ts.map +0 -1
  222. package/dist/matterbridgePlatform.js.map +0 -1
  223. package/dist/matterbridgeTypes.d.ts +0 -198
  224. package/dist/matterbridgeTypes.d.ts.map +0 -1
  225. package/dist/matterbridgeTypes.js.map +0 -1
  226. package/dist/pluginManager.d.ts +0 -270
  227. package/dist/pluginManager.d.ts.map +0 -1
  228. package/dist/pluginManager.js.map +0 -1
  229. package/dist/shelly.d.ts +0 -174
  230. package/dist/shelly.d.ts.map +0 -1
  231. package/dist/shelly.js.map +0 -1
  232. package/dist/storage/export.d.ts +0 -2
  233. package/dist/storage/export.d.ts.map +0 -1
  234. package/dist/storage/export.js.map +0 -1
  235. package/dist/update.d.ts +0 -75
  236. package/dist/update.d.ts.map +0 -1
  237. package/dist/update.js.map +0 -1
  238. package/dist/utils/colorUtils.d.ts +0 -99
  239. package/dist/utils/colorUtils.d.ts.map +0 -1
  240. package/dist/utils/colorUtils.js.map +0 -1
  241. package/dist/utils/commandLine.d.ts +0 -59
  242. package/dist/utils/commandLine.d.ts.map +0 -1
  243. package/dist/utils/commandLine.js.map +0 -1
  244. package/dist/utils/copyDirectory.d.ts +0 -33
  245. package/dist/utils/copyDirectory.d.ts.map +0 -1
  246. package/dist/utils/copyDirectory.js.map +0 -1
  247. package/dist/utils/createDirectory.d.ts +0 -34
  248. package/dist/utils/createDirectory.d.ts.map +0 -1
  249. package/dist/utils/createDirectory.js.map +0 -1
  250. package/dist/utils/createZip.d.ts +0 -39
  251. package/dist/utils/createZip.d.ts.map +0 -1
  252. package/dist/utils/createZip.js.map +0 -1
  253. package/dist/utils/deepCopy.d.ts +0 -32
  254. package/dist/utils/deepCopy.d.ts.map +0 -1
  255. package/dist/utils/deepCopy.js.map +0 -1
  256. package/dist/utils/deepEqual.d.ts +0 -54
  257. package/dist/utils/deepEqual.d.ts.map +0 -1
  258. package/dist/utils/deepEqual.js.map +0 -1
  259. package/dist/utils/error.d.ts +0 -44
  260. package/dist/utils/error.d.ts.map +0 -1
  261. package/dist/utils/error.js.map +0 -1
  262. package/dist/utils/export.d.ts +0 -13
  263. package/dist/utils/export.d.ts.map +0 -1
  264. package/dist/utils/export.js.map +0 -1
  265. package/dist/utils/hex.d.ts +0 -89
  266. package/dist/utils/hex.d.ts.map +0 -1
  267. package/dist/utils/hex.js.map +0 -1
  268. package/dist/utils/isvalid.d.ts +0 -103
  269. package/dist/utils/isvalid.d.ts.map +0 -1
  270. package/dist/utils/isvalid.js.map +0 -1
  271. package/dist/utils/network.d.ts +0 -84
  272. package/dist/utils/network.d.ts.map +0 -1
  273. package/dist/utils/network.js.map +0 -1
  274. package/dist/utils/spawn.d.ts +0 -33
  275. package/dist/utils/spawn.d.ts.map +0 -1
  276. package/dist/utils/spawn.js.map +0 -1
  277. package/dist/utils/wait.d.ts +0 -54
  278. package/dist/utils/wait.d.ts.map +0 -1
  279. 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.2.0
8
- * @license Apache-2.0
9
- *
10
- * Copyright 2024, 2025, 2026 Luca Liguori.
11
- *
12
- * Licensed under the Apache License, Version 2.0 (the "License");
13
- * you may not use this file except in compliance with the License.
14
- * You may obtain a copy of the License at
15
- *
16
- * http://www.apache.org/licenses/LICENSE-2.0
17
- *
18
- * Unless required by applicable law or agreed to in writing, software
19
- * distributed under the License is distributed on an "AS IS" BASIS,
20
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- * See the License for the specific language governing permissions and
22
- * limitations under the License.
23
- */
24
- // Node.js import
25
1
  import EventEmitter from 'node:events';
26
- // AnsiLogger module
27
2
  import { AnsiLogger, UNDERLINE, UNDERLINEOFF, BLUE, db, er, nf, nt, rs, wr } from 'node-ansi-logger';
28
3
  import { plg, typ } from './matterbridgeTypes.js';
29
4
  import { logError } from './utils/error.js';
@@ -34,7 +9,7 @@ export class PluginManager extends EventEmitter {
34
9
  constructor(matterbridge) {
35
10
  super();
36
11
  this.matterbridge = matterbridge;
37
- this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: matterbridge.log.logLevel });
12
+ this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: matterbridge.log.logLevel });
38
13
  this.log.debug('Matterbridge plugin manager starting...');
39
14
  }
40
15
  get length() {
@@ -78,37 +53,19 @@ export class PluginManager extends EventEmitter {
78
53
  set logLevel(logLevel) {
79
54
  this.log.logLevel = logLevel;
80
55
  }
81
- /**
82
- * Loads registered plugins from storage.
83
- *
84
- * This method retrieves an array of registered plugins from the storage and converts it
85
- * into a map where the plugin names are the keys and the plugin objects are the values.
86
- *
87
- * @returns {Promise<RegisteredPlugin[]>} A promise that resolves to an array of registered plugins.
88
- */
89
56
  async loadFromStorage() {
90
57
  if (!this.matterbridge.nodeContext) {
91
58
  throw new Error('loadFromStorage: node context is not available.');
92
59
  }
93
- // Load the array from storage and convert it to a map
94
60
  const pluginsArray = await this.matterbridge.nodeContext.get('plugins', []);
95
61
  for (const plugin of pluginsArray)
96
62
  this._plugins.set(plugin.name, plugin);
97
63
  return pluginsArray;
98
64
  }
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
65
  async saveToStorage() {
108
66
  if (!this.matterbridge.nodeContext) {
109
67
  throw new Error('loadFromStorage: node context is not available.');
110
68
  }
111
- // Convert the map to an array
112
69
  const plugins = [];
113
70
  const pluginArrayFromMap = Array.from(this._plugins.values());
114
71
  for (const plugin of pluginArrayFromMap) {
@@ -126,21 +83,13 @@ export class PluginManager extends EventEmitter {
126
83
  this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
127
84
  return plugins.length;
128
85
  }
129
- /**
130
- * Resolves the name of a plugin by loading and parsing its package.json file.
131
- *
132
- * @param {string} pluginPath - The path to the plugin or the path to the plugin's package.json file.
133
- * @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.
134
- */
135
86
  async resolve(pluginPath) {
136
87
  const { default: path } = await import('node:path');
137
88
  const { promises } = await import('node:fs');
138
89
  if (!pluginPath.endsWith('package.json'))
139
90
  pluginPath = path.join(pluginPath, 'package.json');
140
- // Resolve the package.json of the plugin
141
91
  let packageJsonPath = path.resolve(pluginPath);
142
92
  this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
143
- // Check if the package.json file exists
144
93
  try {
145
94
  await promises.access(packageJsonPath);
146
95
  }
@@ -150,9 +99,7 @@ export class PluginManager extends EventEmitter {
150
99
  this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
151
100
  }
152
101
  try {
153
- // Load the package.json of the plugin
154
102
  const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
155
- // Check for main issues
156
103
  if (!packageJson.name) {
157
104
  this.log.error(`Package.json name not found at ${packageJsonPath}`);
158
105
  return null;
@@ -165,7 +112,6 @@ export class PluginManager extends EventEmitter {
165
112
  this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
166
113
  return null;
167
114
  }
168
- // Check for @project-chip and @matter packages in dependencies and devDependencies
169
115
  const checkForProjectChipPackages = (dependencies) => {
170
116
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
171
117
  };
@@ -187,7 +133,6 @@ export class PluginManager extends EventEmitter {
187
133
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
188
134
  return null;
189
135
  }
190
- // Check for matterbridge package in dependencies and devDependencies
191
136
  const checkForMatterbridgePackage = (dependencies) => {
192
137
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
193
138
  };
@@ -217,12 +162,6 @@ export class PluginManager extends EventEmitter {
217
162
  return null;
218
163
  }
219
164
  }
220
- /**
221
- * Get the author of a plugin from its package.json.
222
- *
223
- * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
224
- * @returns {string} The author of the plugin, or 'Unknown author' if not found.
225
- */
226
165
  getAuthor(packageJson) {
227
166
  if (packageJson.author && typeof packageJson.author === 'string')
228
167
  return packageJson.author;
@@ -230,12 +169,6 @@ export class PluginManager extends EventEmitter {
230
169
  return packageJson.author.name;
231
170
  return 'Unknown author';
232
171
  }
233
- /**
234
- * Get the homepage of a plugin from its package.json.
235
- *
236
- * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
237
- * @returns {string | undefined} The homepage of the plugin, or undefined if not found.
238
- */
239
172
  getHomepage(packageJson) {
240
173
  if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
241
174
  return packageJson.homepage.replace('git+', '').replace('.git', '');
@@ -244,14 +177,7 @@ export class PluginManager extends EventEmitter {
244
177
  return packageJson.repository.url.replace('git+', '').replace('.git', '');
245
178
  }
246
179
  }
247
- /**
248
- * Get the help URL of a plugin from its package.json.
249
- *
250
- * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
251
- * @returns {string | undefined} The URL to the help page or to the README file, or undefined if not found.
252
- */
253
180
  getHelp(packageJson) {
254
- // If there's a help field that looks like a URL, return it.
255
181
  if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
256
182
  return packageJson.help;
257
183
  }
@@ -262,14 +188,7 @@ export class PluginManager extends EventEmitter {
262
188
  return packageJson.homepage.replace('git+', '').replace('.git', '');
263
189
  }
264
190
  }
265
- /**
266
- * Get the changelog URL of a plugin from its package.json.
267
- *
268
- * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
269
- * @returns {string | undefined} The URL to the CHANGELOG file, or undefined if not found.
270
- */
271
191
  getChangelog(packageJson) {
272
- // If there's a changelog field that looks like a URL, return it.
273
192
  if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
274
193
  return packageJson.changelog;
275
194
  }
@@ -280,13 +199,6 @@ export class PluginManager extends EventEmitter {
280
199
  return packageJson.homepage.replace('git+', '').replace('.git', '');
281
200
  }
282
201
  }
283
- /**
284
- * Get the first funding URL(s) of a plugin from its package.json.
285
- *
286
- * @param {Record<string, any>} packageJson - The package.json object of the plugin.
287
- * @returns {string | undefined} The first funding URLs, or undefined if not found.
288
- */
289
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
290
202
  getFunding(packageJson) {
291
203
  const funding = packageJson.funding;
292
204
  if (!funding)
@@ -295,25 +207,16 @@ export class PluginManager extends EventEmitter {
295
207
  return;
296
208
  if (typeof funding === 'string' && funding.startsWith('http'))
297
209
  return funding;
298
- // Normalize funding into an array.
299
210
  const fundingEntries = Array.isArray(funding) ? funding : [funding];
300
211
  for (const entry of fundingEntries) {
301
212
  if (entry && typeof entry === 'string' && entry.startsWith('http')) {
302
- // If the funding entry is a string, assume it is a URL.
303
213
  return entry;
304
214
  }
305
215
  else if (entry && typeof entry === 'object' && typeof entry.url === 'string' && entry.url.startsWith('http')) {
306
- // If it's an object with a 'url' property, use that.
307
216
  return entry.url;
308
217
  }
309
218
  }
310
219
  }
311
- /**
312
- * Loads and parse the plugin package.json and returns it.
313
- *
314
- * @param {RegisteredPlugin} plugin - The plugin to load the package from.
315
- * @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.
316
- */
317
220
  async parse(plugin) {
318
221
  const { promises } = await import('node:fs');
319
222
  try {
@@ -343,7 +246,6 @@ export class PluginManager extends EventEmitter {
343
246
  plugin.funding = this.getFunding(packageJson);
344
247
  if (!plugin.type)
345
248
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
346
- // Check for @project-chip and @matter packages in dependencies and devDependencies
347
249
  const checkForProjectChipPackages = (dependencies) => {
348
250
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
349
251
  };
@@ -365,7 +267,6 @@ export class PluginManager extends EventEmitter {
365
267
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
366
268
  return null;
367
269
  }
368
- // Check for matterbridge package in dependencies and devDependencies
369
270
  const checkForMatterbridgePackage = (dependencies) => {
370
271
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
371
272
  };
@@ -395,16 +296,6 @@ export class PluginManager extends EventEmitter {
395
296
  return null;
396
297
  }
397
298
  }
398
- /**
399
- * Enables a plugin by its name or path.
400
- *
401
- * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
402
- * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
403
- * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
404
- *
405
- * @param {string} nameOrPath - The name or path of the plugin to enable.
406
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
407
- */
408
299
  async enable(nameOrPath) {
409
300
  const { promises } = await import('node:fs');
410
301
  if (!nameOrPath)
@@ -440,16 +331,6 @@ export class PluginManager extends EventEmitter {
440
331
  return null;
441
332
  }
442
333
  }
443
- /**
444
- * Enables a plugin by its name or path.
445
- *
446
- * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
447
- * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
448
- * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
449
- *
450
- * @param {string} nameOrPath - The name or path of the plugin to enable.
451
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
452
- */
453
334
  async disable(nameOrPath) {
454
335
  const { promises } = await import('node:fs');
455
336
  if (!nameOrPath)
@@ -485,16 +366,6 @@ export class PluginManager extends EventEmitter {
485
366
  return null;
486
367
  }
487
368
  }
488
- /**
489
- * Removes a plugin by its name or path.
490
- *
491
- * This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
492
- * It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
493
- * the plugin's `package.json` file to retrieve its name and remove it.
494
- *
495
- * @param {string} nameOrPath - The name or path of the plugin to remove.
496
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
497
- */
498
369
  async remove(nameOrPath) {
499
370
  const { promises } = await import('node:fs');
500
371
  if (!nameOrPath)
@@ -530,17 +401,6 @@ export class PluginManager extends EventEmitter {
530
401
  return null;
531
402
  }
532
403
  }
533
- /**
534
- * Adds a plugin by its name or path.
535
- *
536
- * This method adds a plugin to the plugins map and saves the updated plugin information to storage.
537
- * It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
538
- * registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
539
- * and saves the updated plugin information to storage.
540
- *
541
- * @param {string} nameOrPath - The name or path of the plugin to add.
542
- * @returns {Promise<RegisteredPlugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
543
- */
544
404
  async add(nameOrPath) {
545
405
  const { promises } = await import('node:fs');
546
406
  if (!nameOrPath)
@@ -569,7 +429,6 @@ export class PluginManager extends EventEmitter {
569
429
  await this.saveToStorage();
570
430
  const plugin = this._plugins.get(packageJson.name);
571
431
  this.emit('added', packageJson.name);
572
- // istanbul ignore next
573
432
  return plugin || null;
574
433
  }
575
434
  catch (err) {
@@ -577,15 +436,6 @@ export class PluginManager extends EventEmitter {
577
436
  return null;
578
437
  }
579
438
  }
580
- /**
581
- * Loads a plugin and returns the corresponding MatterbridgePlatform instance.
582
- *
583
- * @param {RegisteredPlugin} plugin - The plugin to load.
584
- * @param {boolean} start - Optional flag indicating whether to start the plugin after loading. Default is false.
585
- * @param {string} message - Optional message to pass to the plugin when starting.
586
- * @param {boolean} configure - Optional flag indicating whether to configure the plugin after loading. Default is false.
587
- * @returns {Promise<MatterbridgePlatform | undefined>} A Promise that resolves to the loaded MatterbridgePlatform instance or undefined.
588
- */
589
439
  async load(plugin, start = false, message = '', configure = false) {
590
440
  const { promises } = await import('node:fs');
591
441
  const { default: path } = await import('node:path');
@@ -599,20 +449,15 @@ export class PluginManager extends EventEmitter {
599
449
  }
600
450
  this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
601
451
  try {
602
- // Load the package.json of the plugin
603
452
  const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
604
- // Resolve the main module path relative to package.json
605
453
  const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
606
- // Dynamically import the plugin
607
454
  const { pathToFileURL } = await import('node:url');
608
455
  const pluginUrl = pathToFileURL(pluginEntry);
609
456
  this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
610
457
  const pluginInstance = await import(pluginUrl.href);
611
458
  this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
612
- // Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
613
459
  if (pluginInstance.default) {
614
460
  const config = await this.loadConfig(plugin);
615
- // 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.
616
461
  plugin.name = packageJson.name;
617
462
  plugin.description = packageJson.description ?? 'No description';
618
463
  plugin.version = packageJson.version;
@@ -621,7 +466,7 @@ export class PluginManager extends EventEmitter {
621
466
  plugin.schemaJson = await this.loadSchema(plugin);
622
467
  config.name = plugin.name;
623
468
  config.version = packageJson.version;
624
- const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: config.debug ? "debug" /* LogLevel.DEBUG */ : this.matterbridge.log.logLevel });
469
+ const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
625
470
  const platform = pluginInstance.default(this.matterbridge, log, config);
626
471
  config.type = platform.type;
627
472
  platform.name = packageJson.name;
@@ -640,7 +485,7 @@ export class PluginManager extends EventEmitter {
640
485
  plugin.loaded = true;
641
486
  plugin.registeredDevices = 0;
642
487
  plugin.addedDevices = 0;
643
- await this.saveToStorage(); // Save the plugin to storage
488
+ await this.saveToStorage();
644
489
  this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
645
490
  this.emit('loaded', plugin.name);
646
491
  if (start)
@@ -660,14 +505,6 @@ export class PluginManager extends EventEmitter {
660
505
  }
661
506
  return undefined;
662
507
  }
663
- /**
664
- * Starts a plugin.
665
- *
666
- * @param {RegisteredPlugin} plugin - The plugin to start.
667
- * @param {string} [message] - Optional message to pass to the plugin's onStart method.
668
- * @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
669
- * @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
670
- */
671
508
  async start(plugin, message, configure = false) {
672
509
  if (!plugin.loaded) {
673
510
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -698,12 +535,6 @@ export class PluginManager extends EventEmitter {
698
535
  }
699
536
  return undefined;
700
537
  }
701
- /**
702
- * Configures a plugin.
703
- *
704
- * @param {RegisteredPlugin} plugin - The plugin to configure.
705
- * @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
706
- */
707
538
  async configure(plugin) {
708
539
  if (!plugin.loaded) {
709
540
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -735,18 +566,6 @@ export class PluginManager extends EventEmitter {
735
566
  }
736
567
  return undefined;
737
568
  }
738
- /**
739
- * Shuts down a plugin.
740
- *
741
- * This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
742
- * It logs the shutdown process and optionally removes all devices associated with the plugin.
743
- *
744
- * @param {RegisteredPlugin} plugin - The plugin to shut down.
745
- * @param {string} [reason] - The reason for shutting down the plugin.
746
- * @param {boolean} [removeAllDevices] - Whether to remove all devices associated with the plugin.
747
- * @param {boolean} [force] - Whether to force the shutdown even if the plugin is not loaded or started.
748
- * @returns {Promise<RegisteredPlugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
749
- */
750
569
  async shutdown(plugin, reason, removeAllDevices = false, force = false) {
751
570
  this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
752
571
  if (!plugin.loaded) {
@@ -790,15 +609,6 @@ export class PluginManager extends EventEmitter {
790
609
  }
791
610
  return undefined;
792
611
  }
793
- /**
794
- * Loads the configuration for a plugin.
795
- * If the configuration file exists, it reads the file and returns the parsed JSON data.
796
- * If the configuration file does not exist, it creates a new file with default configuration and returns it.
797
- * If any error occurs during file access or creation, it logs an error and return un empty config.
798
- *
799
- * @param {RegisteredPlugin} plugin - The plugin for which to load the configuration.
800
- * @returns {Promise<PlatformConfig>} A promise that resolves to the loaded or created configuration.
801
- */
802
612
  async loadConfig(plugin) {
803
613
  const { default: path } = await import('node:path');
804
614
  const { promises } = await import('node:fs');
@@ -810,8 +620,6 @@ export class PluginManager extends EventEmitter {
810
620
  const data = await promises.readFile(configFile, 'utf8');
811
621
  const config = JSON.parse(data);
812
622
  this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
813
- // this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
814
- // The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
815
623
  config.name = plugin.name;
816
624
  config.type = plugin.type;
817
625
  if (config.debug === undefined)
@@ -833,8 +641,6 @@ export class PluginManager extends EventEmitter {
833
641
  }
834
642
  catch (_err) {
835
643
  this.log.debug(`Default config file ${defaultConfigFile} for plugin ${plg}${plugin.name}${db} does not exist, creating new config file...`);
836
- // TODO: Remove this when all these plugins have their own default config file
837
- // istanbul ignore next if
838
644
  if (plugin.name === 'matterbridge-zigbee2mqtt')
839
645
  config = zigbee2mqtt_config;
840
646
  else if (plugin.name === 'matterbridge-somfy-tahoma')
@@ -842,12 +648,11 @@ export class PluginManager extends EventEmitter {
842
648
  else if (plugin.name === 'matterbridge-shelly')
843
649
  config = shelly_config;
844
650
  else
845
- config = { name: plugin.name, type: plugin.type, debug: false, unregisterOnShutdown: false };
651
+ config = { name: plugin.name, type: plugin.type, version: '1.0.0', debug: false, unregisterOnShutdown: false };
846
652
  }
847
653
  try {
848
654
  await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
849
655
  this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
850
- // this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
851
656
  return config;
852
657
  }
853
658
  catch (err) {
@@ -857,23 +662,10 @@ export class PluginManager extends EventEmitter {
857
662
  }
858
663
  else {
859
664
  logError(this.log, `Error accessing config file ${configFile} for plugin ${plg}${plugin.name}${er}`, err);
860
- return { name: plugin.name, type: plugin.type, debug: false, unregisterOnShutdown: false };
665
+ return { name: plugin.name, type: plugin.type, version: '1.0.0', debug: false, unregisterOnShutdown: false };
861
666
  }
862
667
  }
863
668
  }
864
- /**
865
- * Saves the configuration of a plugin to a file.
866
- *
867
- * This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
868
- * If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
869
- * is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
870
- * the error and rejects the promise.
871
- *
872
- * @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
873
- * @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
874
- * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
875
- * @throws {Error} If the plugin's configuration is not found.
876
- */
877
669
  async saveConfigFromPlugin(plugin, restartRequired = false) {
878
670
  const { default: path } = await import('node:path');
879
671
  const { promises } = await import('node:fs');
@@ -888,7 +680,6 @@ export class PluginManager extends EventEmitter {
888
680
  if (restartRequired)
889
681
  plugin.restartRequired = true;
890
682
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
891
- // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
892
683
  return Promise.resolve();
893
684
  }
894
685
  catch (err) {
@@ -896,20 +687,6 @@ export class PluginManager extends EventEmitter {
896
687
  return Promise.reject(err);
897
688
  }
898
689
  }
899
- /**
900
- * Saves the configuration of a plugin from a JSON object to a file.
901
- *
902
- * This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
903
- * It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
904
- * the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
905
- * successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
906
- * during the file write operation, it logs the error and returns.
907
- *
908
- * @param {RegisteredPlugin} plugin - The plugin whose configuration is to be saved.
909
- * @param {PlatformConfig} config - The configuration data to be saved.
910
- * @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
911
- * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
912
- */
913
690
  async saveConfigFromJson(plugin, config, restartRequired = false) {
914
691
  const { default: path } = await import('node:path');
915
692
  const { promises } = await import('node:fs');
@@ -928,23 +705,12 @@ export class PluginManager extends EventEmitter {
928
705
  plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
929
706
  }
930
707
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
931
- // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
932
708
  }
933
709
  catch (err) {
934
710
  logError(this.log, `Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}`, err);
935
711
  return;
936
712
  }
937
713
  }
938
- /**
939
- * Loads the schema for a plugin.
940
- *
941
- * This method attempts to load the schema file for the specified plugin. If the schema file is found,
942
- * it reads and parses the file, updates the schema's title and description, and logs the process.
943
- * If the schema file is not found, it logs the event and loads a default schema for the plugin.
944
- *
945
- * @param {RegisteredPlugin} plugin - The plugin whose schema is to be loaded.
946
- * @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
947
- */
948
714
  async loadSchema(plugin) {
949
715
  const { promises } = await import('node:fs');
950
716
  const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
@@ -955,7 +721,6 @@ export class PluginManager extends EventEmitter {
955
721
  schema.title = plugin.description;
956
722
  schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
957
723
  this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
958
- // this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
959
724
  return schema;
960
725
  }
961
726
  catch (_err) {
@@ -963,16 +728,6 @@ export class PluginManager extends EventEmitter {
963
728
  return this.getDefaultSchema(plugin);
964
729
  }
965
730
  }
966
- /**
967
- * Returns the default schema for a plugin.
968
- *
969
- * This method generates a default schema object for the specified plugin. The schema includes
970
- * metadata such as the plugin's title, description, version, and author. It also defines the
971
- * properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
972
- *
973
- * @param {RegisteredPlugin} plugin - The plugin for which the default schema is to be generated.
974
- * @returns {PlatformSchema} The default schema object for the plugin.
975
- */
976
731
  getDefaultSchema(plugin) {
977
732
  return {
978
733
  title: plugin.description,
@@ -1003,4 +758,3 @@ export class PluginManager extends EventEmitter {
1003
758
  };
1004
759
  }
1005
760
  }
1006
- //# sourceMappingURL=pluginManager.js.map