matterbridge 3.4.2 → 3.4.3-dev-20251207-3ce5a0e

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 (332) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README-SERVICE-LOCAL.md +3 -3
  3. package/README-SERVICE-OPT.md +3 -5
  4. package/README.md +8 -14
  5. package/dist/broadcastServer.js +0 -119
  6. package/dist/broadcastServerTypes.js +0 -24
  7. package/dist/cli.js +3 -97
  8. package/dist/cliEmitter.js +0 -37
  9. package/dist/cliHistory.js +0 -38
  10. package/dist/clusters/export.js +0 -2
  11. package/dist/deviceManager.js +1 -113
  12. package/dist/devices/airConditioner.js +0 -57
  13. package/dist/devices/batteryStorage.js +1 -48
  14. package/dist/devices/cooktop.js +0 -56
  15. package/dist/devices/dishwasher.js +0 -57
  16. package/dist/devices/evse.js +10 -74
  17. package/dist/devices/export.js +0 -5
  18. package/dist/devices/extractorHood.js +0 -43
  19. package/dist/devices/heatPump.js +2 -50
  20. package/dist/devices/laundryDryer.js +3 -62
  21. package/dist/devices/laundryWasher.js +4 -70
  22. package/dist/devices/microwaveOven.js +5 -88
  23. package/dist/devices/oven.js +0 -85
  24. package/dist/devices/refrigerator.js +0 -102
  25. package/dist/devices/roboticVacuumCleaner.js +9 -100
  26. package/dist/devices/solarPower.js +0 -38
  27. package/dist/devices/speaker.js +0 -84
  28. package/dist/devices/temperatureControl.js +3 -24
  29. package/dist/devices/waterHeater.js +2 -82
  30. package/dist/dgram/coap.js +13 -126
  31. package/dist/dgram/dgram.js +2 -114
  32. package/dist/dgram/mb_coap.js +3 -41
  33. package/dist/dgram/mb_mdns.js +15 -80
  34. package/dist/dgram/mdns.js +137 -299
  35. package/dist/dgram/multicast.js +1 -62
  36. package/dist/dgram/unicast.js +0 -54
  37. package/dist/frontend.js +35 -455
  38. package/dist/frontendTypes.js +0 -45
  39. package/dist/helpers.js +0 -53
  40. package/dist/index.js +0 -25
  41. package/dist/jestutils/export.js +0 -1
  42. package/dist/jestutils/jestHelpers.js +14 -371
  43. package/dist/logger/export.js +0 -1
  44. package/dist/matter/behaviors.js +0 -2
  45. package/dist/matter/clusters.js +0 -2
  46. package/dist/matter/devices.js +0 -2
  47. package/dist/matter/endpoints.js +0 -2
  48. package/dist/matter/export.js +0 -3
  49. package/dist/matter/types.js +0 -3
  50. package/dist/matterNode.js +8 -369
  51. package/dist/matterbridge.js +54 -817
  52. package/dist/matterbridgeAccessoryPlatform.js +0 -38
  53. package/dist/matterbridgeBehaviors.js +5 -68
  54. package/dist/matterbridgeDeviceTypes.js +14 -635
  55. package/dist/matterbridgeDynamicPlatform.js +0 -38
  56. package/dist/matterbridgeEndpoint.js +53 -1444
  57. package/dist/matterbridgeEndpointHelpers.js +20 -483
  58. package/dist/matterbridgeEndpointTypes.js +0 -25
  59. package/dist/matterbridgePlatform.js +1 -451
  60. package/dist/matterbridgeTypes.js +0 -26
  61. package/dist/pluginManager.js +5 -341
  62. package/dist/shelly.js +7 -178
  63. package/dist/storage/export.js +0 -1
  64. package/dist/update.js +1 -93
  65. package/dist/utils/colorUtils.js +2 -97
  66. package/dist/utils/commandLine.js +0 -60
  67. package/dist/utils/copyDirectory.js +0 -37
  68. package/dist/utils/createDirectory.js +0 -33
  69. package/dist/utils/createZip.js +2 -47
  70. package/dist/utils/deepCopy.js +0 -39
  71. package/dist/utils/deepEqual.js +1 -72
  72. package/dist/utils/error.js +0 -42
  73. package/dist/utils/export.js +0 -1
  74. package/dist/utils/format.js +0 -49
  75. package/dist/utils/hex.js +0 -124
  76. package/dist/utils/inspector.js +1 -69
  77. package/dist/utils/isvalid.js +0 -101
  78. package/dist/utils/network.js +5 -96
  79. package/dist/utils/spawn.js +1 -71
  80. package/dist/utils/tracker.js +1 -64
  81. package/dist/utils/wait.js +8 -60
  82. package/dist/workerGlobalPrefix.js +5 -37
  83. package/dist/workerTypes.js +0 -24
  84. package/dist/workers.js +4 -68
  85. package/frontend/build/assets/index.js +4 -4
  86. package/frontend/build/assets/vendor_mui.js +1 -1
  87. package/frontend/package.json +1 -1
  88. package/npm-shrinkwrap.json +8 -7
  89. package/package.json +3 -4
  90. package/scripts/marked.mjs +132 -0
  91. package/scripts/markedFooter.html +42 -0
  92. package/scripts/markedHeader.html +78 -0
  93. package/dist/broadcastServer.d.ts +0 -144
  94. package/dist/broadcastServer.d.ts.map +0 -1
  95. package/dist/broadcastServer.js.map +0 -1
  96. package/dist/broadcastServerTypes.d.ts +0 -841
  97. package/dist/broadcastServerTypes.d.ts.map +0 -1
  98. package/dist/broadcastServerTypes.js.map +0 -1
  99. package/dist/cli.d.ts +0 -30
  100. package/dist/cli.d.ts.map +0 -1
  101. package/dist/cli.js.map +0 -1
  102. package/dist/cliEmitter.d.ts +0 -50
  103. package/dist/cliEmitter.d.ts.map +0 -1
  104. package/dist/cliEmitter.js.map +0 -1
  105. package/dist/cliHistory.d.ts +0 -48
  106. package/dist/cliHistory.d.ts.map +0 -1
  107. package/dist/cliHistory.js.map +0 -1
  108. package/dist/clusters/export.d.ts +0 -2
  109. package/dist/clusters/export.d.ts.map +0 -1
  110. package/dist/clusters/export.js.map +0 -1
  111. package/dist/deviceManager.d.ts +0 -135
  112. package/dist/deviceManager.d.ts.map +0 -1
  113. package/dist/deviceManager.js.map +0 -1
  114. package/dist/devices/airConditioner.d.ts +0 -98
  115. package/dist/devices/airConditioner.d.ts.map +0 -1
  116. package/dist/devices/airConditioner.js.map +0 -1
  117. package/dist/devices/batteryStorage.d.ts +0 -48
  118. package/dist/devices/batteryStorage.d.ts.map +0 -1
  119. package/dist/devices/batteryStorage.js.map +0 -1
  120. package/dist/devices/cooktop.d.ts +0 -61
  121. package/dist/devices/cooktop.d.ts.map +0 -1
  122. package/dist/devices/cooktop.js.map +0 -1
  123. package/dist/devices/dishwasher.d.ts +0 -71
  124. package/dist/devices/dishwasher.d.ts.map +0 -1
  125. package/dist/devices/dishwasher.js.map +0 -1
  126. package/dist/devices/evse.d.ts +0 -76
  127. package/dist/devices/evse.d.ts.map +0 -1
  128. package/dist/devices/evse.js.map +0 -1
  129. package/dist/devices/export.d.ts +0 -17
  130. package/dist/devices/export.d.ts.map +0 -1
  131. package/dist/devices/export.js.map +0 -1
  132. package/dist/devices/extractorHood.d.ts +0 -46
  133. package/dist/devices/extractorHood.d.ts.map +0 -1
  134. package/dist/devices/extractorHood.js.map +0 -1
  135. package/dist/devices/heatPump.d.ts +0 -47
  136. package/dist/devices/heatPump.d.ts.map +0 -1
  137. package/dist/devices/heatPump.js.map +0 -1
  138. package/dist/devices/laundryDryer.d.ts +0 -67
  139. package/dist/devices/laundryDryer.d.ts.map +0 -1
  140. package/dist/devices/laundryDryer.js.map +0 -1
  141. package/dist/devices/laundryWasher.d.ts +0 -81
  142. package/dist/devices/laundryWasher.d.ts.map +0 -1
  143. package/dist/devices/laundryWasher.js.map +0 -1
  144. package/dist/devices/microwaveOven.d.ts +0 -168
  145. package/dist/devices/microwaveOven.d.ts.map +0 -1
  146. package/dist/devices/microwaveOven.js.map +0 -1
  147. package/dist/devices/oven.d.ts +0 -105
  148. package/dist/devices/oven.d.ts.map +0 -1
  149. package/dist/devices/oven.js.map +0 -1
  150. package/dist/devices/refrigerator.d.ts +0 -118
  151. package/dist/devices/refrigerator.d.ts.map +0 -1
  152. package/dist/devices/refrigerator.js.map +0 -1
  153. package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
  154. package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
  155. package/dist/devices/roboticVacuumCleaner.js.map +0 -1
  156. package/dist/devices/solarPower.d.ts +0 -40
  157. package/dist/devices/solarPower.d.ts.map +0 -1
  158. package/dist/devices/solarPower.js.map +0 -1
  159. package/dist/devices/speaker.d.ts +0 -87
  160. package/dist/devices/speaker.d.ts.map +0 -1
  161. package/dist/devices/speaker.js.map +0 -1
  162. package/dist/devices/temperatureControl.d.ts +0 -166
  163. package/dist/devices/temperatureControl.d.ts.map +0 -1
  164. package/dist/devices/temperatureControl.js.map +0 -1
  165. package/dist/devices/waterHeater.d.ts +0 -111
  166. package/dist/devices/waterHeater.d.ts.map +0 -1
  167. package/dist/devices/waterHeater.js.map +0 -1
  168. package/dist/dgram/coap.d.ts +0 -205
  169. package/dist/dgram/coap.d.ts.map +0 -1
  170. package/dist/dgram/coap.js.map +0 -1
  171. package/dist/dgram/dgram.d.ts +0 -141
  172. package/dist/dgram/dgram.d.ts.map +0 -1
  173. package/dist/dgram/dgram.js.map +0 -1
  174. package/dist/dgram/mb_coap.d.ts +0 -24
  175. package/dist/dgram/mb_coap.d.ts.map +0 -1
  176. package/dist/dgram/mb_coap.js.map +0 -1
  177. package/dist/dgram/mb_mdns.d.ts +0 -24
  178. package/dist/dgram/mb_mdns.d.ts.map +0 -1
  179. package/dist/dgram/mb_mdns.js.map +0 -1
  180. package/dist/dgram/mdns.d.ts +0 -290
  181. package/dist/dgram/mdns.d.ts.map +0 -1
  182. package/dist/dgram/mdns.js.map +0 -1
  183. package/dist/dgram/multicast.d.ts +0 -67
  184. package/dist/dgram/multicast.d.ts.map +0 -1
  185. package/dist/dgram/multicast.js.map +0 -1
  186. package/dist/dgram/unicast.d.ts +0 -56
  187. package/dist/dgram/unicast.d.ts.map +0 -1
  188. package/dist/dgram/unicast.js.map +0 -1
  189. package/dist/frontend.d.ts +0 -238
  190. package/dist/frontend.d.ts.map +0 -1
  191. package/dist/frontend.js.map +0 -1
  192. package/dist/frontendTypes.d.ts +0 -529
  193. package/dist/frontendTypes.d.ts.map +0 -1
  194. package/dist/frontendTypes.js.map +0 -1
  195. package/dist/helpers.d.ts +0 -48
  196. package/dist/helpers.d.ts.map +0 -1
  197. package/dist/helpers.js.map +0 -1
  198. package/dist/index.d.ts +0 -34
  199. package/dist/index.d.ts.map +0 -1
  200. package/dist/index.js.map +0 -1
  201. package/dist/jestutils/export.d.ts +0 -2
  202. package/dist/jestutils/export.d.ts.map +0 -1
  203. package/dist/jestutils/export.js.map +0 -1
  204. package/dist/jestutils/jestHelpers.d.ts +0 -345
  205. package/dist/jestutils/jestHelpers.d.ts.map +0 -1
  206. package/dist/jestutils/jestHelpers.js.map +0 -1
  207. package/dist/logger/export.d.ts +0 -2
  208. package/dist/logger/export.d.ts.map +0 -1
  209. package/dist/logger/export.js.map +0 -1
  210. package/dist/matter/behaviors.d.ts +0 -2
  211. package/dist/matter/behaviors.d.ts.map +0 -1
  212. package/dist/matter/behaviors.js.map +0 -1
  213. package/dist/matter/clusters.d.ts +0 -2
  214. package/dist/matter/clusters.d.ts.map +0 -1
  215. package/dist/matter/clusters.js.map +0 -1
  216. package/dist/matter/devices.d.ts +0 -2
  217. package/dist/matter/devices.d.ts.map +0 -1
  218. package/dist/matter/devices.js.map +0 -1
  219. package/dist/matter/endpoints.d.ts +0 -2
  220. package/dist/matter/endpoints.d.ts.map +0 -1
  221. package/dist/matter/endpoints.js.map +0 -1
  222. package/dist/matter/export.d.ts +0 -5
  223. package/dist/matter/export.d.ts.map +0 -1
  224. package/dist/matter/export.js.map +0 -1
  225. package/dist/matter/types.d.ts +0 -3
  226. package/dist/matter/types.d.ts.map +0 -1
  227. package/dist/matter/types.js.map +0 -1
  228. package/dist/matterNode.d.ts +0 -342
  229. package/dist/matterNode.d.ts.map +0 -1
  230. package/dist/matterNode.js.map +0 -1
  231. package/dist/matterbridge.d.ts +0 -492
  232. package/dist/matterbridge.d.ts.map +0 -1
  233. package/dist/matterbridge.js.map +0 -1
  234. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -41
  235. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  236. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  237. package/dist/matterbridgeBehaviors.d.ts +0 -2404
  238. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  239. package/dist/matterbridgeBehaviors.js.map +0 -1
  240. package/dist/matterbridgeDeviceTypes.d.ts +0 -698
  241. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  242. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  243. package/dist/matterbridgeDynamicPlatform.d.ts +0 -41
  244. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  245. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  246. package/dist/matterbridgeEndpoint.d.ts +0 -1507
  247. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  248. package/dist/matterbridgeEndpoint.js.map +0 -1
  249. package/dist/matterbridgeEndpointHelpers.d.ts +0 -787
  250. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  251. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  252. package/dist/matterbridgeEndpointTypes.d.ts +0 -166
  253. package/dist/matterbridgeEndpointTypes.d.ts.map +0 -1
  254. package/dist/matterbridgeEndpointTypes.js.map +0 -1
  255. package/dist/matterbridgePlatform.d.ts +0 -539
  256. package/dist/matterbridgePlatform.d.ts.map +0 -1
  257. package/dist/matterbridgePlatform.js.map +0 -1
  258. package/dist/matterbridgeTypes.d.ts +0 -251
  259. package/dist/matterbridgeTypes.d.ts.map +0 -1
  260. package/dist/matterbridgeTypes.js.map +0 -1
  261. package/dist/pluginManager.d.ts +0 -372
  262. package/dist/pluginManager.d.ts.map +0 -1
  263. package/dist/pluginManager.js.map +0 -1
  264. package/dist/shelly.d.ts +0 -181
  265. package/dist/shelly.d.ts.map +0 -1
  266. package/dist/shelly.js.map +0 -1
  267. package/dist/storage/export.d.ts +0 -2
  268. package/dist/storage/export.d.ts.map +0 -1
  269. package/dist/storage/export.js.map +0 -1
  270. package/dist/update.d.ts +0 -84
  271. package/dist/update.d.ts.map +0 -1
  272. package/dist/update.js.map +0 -1
  273. package/dist/utils/colorUtils.d.ts +0 -101
  274. package/dist/utils/colorUtils.d.ts.map +0 -1
  275. package/dist/utils/colorUtils.js.map +0 -1
  276. package/dist/utils/commandLine.d.ts +0 -66
  277. package/dist/utils/commandLine.d.ts.map +0 -1
  278. package/dist/utils/commandLine.js.map +0 -1
  279. package/dist/utils/copyDirectory.d.ts +0 -35
  280. package/dist/utils/copyDirectory.d.ts.map +0 -1
  281. package/dist/utils/copyDirectory.js.map +0 -1
  282. package/dist/utils/createDirectory.d.ts +0 -34
  283. package/dist/utils/createDirectory.d.ts.map +0 -1
  284. package/dist/utils/createDirectory.js.map +0 -1
  285. package/dist/utils/createZip.d.ts +0 -39
  286. package/dist/utils/createZip.d.ts.map +0 -1
  287. package/dist/utils/createZip.js.map +0 -1
  288. package/dist/utils/deepCopy.d.ts +0 -32
  289. package/dist/utils/deepCopy.d.ts.map +0 -1
  290. package/dist/utils/deepCopy.js.map +0 -1
  291. package/dist/utils/deepEqual.d.ts +0 -54
  292. package/dist/utils/deepEqual.d.ts.map +0 -1
  293. package/dist/utils/deepEqual.js.map +0 -1
  294. package/dist/utils/error.d.ts +0 -45
  295. package/dist/utils/error.d.ts.map +0 -1
  296. package/dist/utils/error.js.map +0 -1
  297. package/dist/utils/export.d.ts +0 -13
  298. package/dist/utils/export.d.ts.map +0 -1
  299. package/dist/utils/export.js.map +0 -1
  300. package/dist/utils/format.d.ts +0 -53
  301. package/dist/utils/format.d.ts.map +0 -1
  302. package/dist/utils/format.js.map +0 -1
  303. package/dist/utils/hex.d.ts +0 -89
  304. package/dist/utils/hex.d.ts.map +0 -1
  305. package/dist/utils/hex.js.map +0 -1
  306. package/dist/utils/inspector.d.ts +0 -87
  307. package/dist/utils/inspector.d.ts.map +0 -1
  308. package/dist/utils/inspector.js.map +0 -1
  309. package/dist/utils/isvalid.d.ts +0 -103
  310. package/dist/utils/isvalid.d.ts.map +0 -1
  311. package/dist/utils/isvalid.js.map +0 -1
  312. package/dist/utils/network.d.ts +0 -111
  313. package/dist/utils/network.d.ts.map +0 -1
  314. package/dist/utils/network.js.map +0 -1
  315. package/dist/utils/spawn.d.ts +0 -33
  316. package/dist/utils/spawn.d.ts.map +0 -1
  317. package/dist/utils/spawn.js.map +0 -1
  318. package/dist/utils/tracker.d.ts +0 -108
  319. package/dist/utils/tracker.d.ts.map +0 -1
  320. package/dist/utils/tracker.js.map +0 -1
  321. package/dist/utils/wait.d.ts +0 -54
  322. package/dist/utils/wait.d.ts.map +0 -1
  323. package/dist/utils/wait.js.map +0 -1
  324. package/dist/workerGlobalPrefix.d.ts +0 -25
  325. package/dist/workerGlobalPrefix.d.ts.map +0 -1
  326. package/dist/workerGlobalPrefix.js.map +0 -1
  327. package/dist/workerTypes.d.ts +0 -52
  328. package/dist/workerTypes.d.ts.map +0 -1
  329. package/dist/workerTypes.js.map +0 -1
  330. package/dist/workers.d.ts +0 -69
  331. package/dist/workers.d.ts.map +0 -1
  332. package/dist/workers.js.map +0 -1
@@ -1,37 +1,9 @@
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.3.5
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, debugStringify, CYAN } from 'node-ansi-logger';
28
3
  import { plg, typ } from './matterbridgeTypes.js';
29
4
  import { inspectError, logError } from './utils/error.js';
30
5
  import { hasParameter } from './utils/commandLine.js';
31
6
  import { BroadcastServer } from './broadcastServer.js';
32
- /**
33
- * Manages Matterbridge plugins.
34
- */
35
7
  export class PluginManager extends EventEmitter {
36
8
  matterbridge;
37
9
  _plugins = new Map();
@@ -39,15 +11,10 @@ export class PluginManager extends EventEmitter {
39
11
  server;
40
12
  debug = hasParameter('debug') || hasParameter('verbose');
41
13
  verbose = hasParameter('verbose');
42
- /**
43
- * Creates an instance of PluginManager.
44
- *
45
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
46
- */
47
14
  constructor(matterbridge) {
48
15
  super();
49
16
  this.matterbridge = matterbridge;
50
- this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: hasParameter('debug') ? "debug" /* LogLevel.DEBUG */ : "info" /* LogLevel.INFO */ });
17
+ this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: hasParameter('debug') ? "debug" : "info" });
51
18
  this.log.debug('Matterbridge plugin manager starting...');
52
19
  this.server = new BroadcastServer('plugins', this.log);
53
20
  this.server.on('broadcast_message', this.msgHandler.bind(this));
@@ -220,7 +187,7 @@ export class PluginManager extends EventEmitter {
220
187
  {
221
188
  const plugin = this.get(msg.params.name);
222
189
  if (plugin) {
223
- this.saveConfigFromJson(plugin, msg.params.config, msg.params.restartRequired); // No await as it's not necessary to wait
190
+ this.saveConfigFromJson(plugin, msg.params.config, msg.params.restartRequired);
224
191
  this.server.respond({ ...msg, result: { success: true } });
225
192
  }
226
193
  else {
@@ -258,62 +225,25 @@ export class PluginManager extends EventEmitter {
258
225
  }
259
226
  }
260
227
  }
261
- /**
262
- * Gets the number of plugins.
263
- *
264
- * @returns {number} The number of plugins.
265
- */
266
228
  get length() {
267
229
  return this._plugins.size;
268
230
  }
269
- /**
270
- * Gets the number of plugins.
271
- *
272
- * @returns {number} The number of plugins.
273
- */
274
231
  get size() {
275
232
  return this._plugins.size;
276
233
  }
277
- /**
278
- * Checks if a plugin with the specified name exists.
279
- *
280
- * @param {string} name - The name of the plugin.
281
- * @returns {boolean} True if the plugin exists, false otherwise.
282
- */
283
234
  has(name) {
284
235
  return this._plugins.has(name);
285
236
  }
286
- /**
287
- * Gets a plugin by its name.
288
- *
289
- * @param {string} name - The name of the plugin.
290
- * @returns {Plugin | undefined} The plugin, or undefined if not found.
291
- */
292
237
  get(name) {
293
238
  return this._plugins.get(name);
294
239
  }
295
- /**
296
- * Adds a plugin to the manager.
297
- *
298
- * @param {Plugin} plugin - The plugin to add.
299
- * @returns {Plugin} The added plugin.
300
- */
301
240
  set(plugin) {
302
241
  this._plugins.set(plugin.name, plugin);
303
242
  return plugin;
304
243
  }
305
- /**
306
- * Clears all plugins from the manager.
307
- */
308
244
  clear() {
309
245
  this._plugins.clear();
310
246
  }
311
- /**
312
- * Converts a plugin or API plugin to a storage plugin.
313
- *
314
- * @param {Plugin | ApiPlugin} plugin - The plugin or API plugin to convert.
315
- * @returns {StoragePlugin} The converted storage plugin.
316
- */
317
247
  toStoragePlugin(plugin) {
318
248
  return {
319
249
  name: plugin.name,
@@ -325,12 +255,6 @@ export class PluginManager extends EventEmitter {
325
255
  enabled: plugin.enabled,
326
256
  };
327
257
  }
328
- /**
329
- * Converts a plugin to an API plugin.
330
- *
331
- * @param {Plugin} plugin - The plugin to convert.
332
- * @returns {ApiPlugin} The converted API plugin.
333
- */
334
258
  toApiPlugin(plugin) {
335
259
  return {
336
260
  name: plugin.name,
@@ -360,19 +284,9 @@ export class PluginManager extends EventEmitter {
360
284
  matter: plugin.serverNode ? this.matterbridge.getServerNodeData(plugin.serverNode) : undefined,
361
285
  };
362
286
  }
363
- /**
364
- * Gets an array of all plugins.
365
- *
366
- * @returns {Plugin[]} An array of all plugins.
367
- */
368
287
  array() {
369
288
  return Array.from(this._plugins.values());
370
289
  }
371
- /**
372
- * Gets a StoragePlugin array of all plugins suitable for serialization.
373
- *
374
- * @returns {StoragePlugin[]} An array of all plugins.
375
- */
376
290
  storagePluginArray() {
377
291
  const storagePlugins = [];
378
292
  for (const plugin of this._plugins.values()) {
@@ -380,11 +294,6 @@ export class PluginManager extends EventEmitter {
380
294
  }
381
295
  return storagePlugins;
382
296
  }
383
- /**
384
- * Gets an ApiPlugin array of all plugins suitable for serialization.
385
- *
386
- * @returns {ApiPlugin[]} An array of all plugins.
387
- */
388
297
  apiPluginArray() {
389
298
  const apiPlugins = [];
390
299
  for (const plugin of this._plugins.values()) {
@@ -392,20 +301,9 @@ export class PluginManager extends EventEmitter {
392
301
  }
393
302
  return apiPlugins;
394
303
  }
395
- /**
396
- * Gets an iterator for the plugins.
397
- *
398
- * @returns {IterableIterator<Plugin>} An iterator for the plugins.
399
- */
400
304
  [Symbol.iterator]() {
401
305
  return this._plugins.values();
402
306
  }
403
- /**
404
- * Executes a provided function once for each plugin.
405
- *
406
- * @param {Function} callback - The function to execute for each plugin.
407
- * @returns {Promise<void>}
408
- */
409
307
  async forEach(callback) {
410
308
  if (this.size === 0)
411
309
  return;
@@ -419,40 +317,23 @@ export class PluginManager extends EventEmitter {
419
317
  });
420
318
  await Promise.all(tasks);
421
319
  }
422
- /**
423
- * Sets the log level for the plugin manager.
424
- *
425
- * @param {LogLevel} logLevel - The log level to set.
426
- */
427
320
  set logLevel(logLevel) {
428
321
  this.log.logLevel = logLevel;
429
322
  }
430
- /**
431
- * Loads registered plugins from storage.
432
- *
433
- * @returns {Promise<StoragePlugin[]>} A promise that resolves to an array of registered plugins.
434
- */
435
323
  async loadFromStorage() {
436
324
  if (!this.matterbridge.nodeContext) {
437
325
  throw new Error('loadFromStorage: node context is not available.');
438
326
  }
439
- // Load the array from storage and convert it to a map
440
327
  const pluginsArray = await this.matterbridge.nodeContext.get('plugins', []);
441
328
  for (const plugin of pluginsArray)
442
329
  this._plugins.set(plugin.name, plugin);
443
330
  this.log.debug(`Loaded ${BLUE}${pluginsArray.length}${db} plugins from storage`);
444
331
  return pluginsArray;
445
332
  }
446
- /**
447
- * Saves registered plugins to storage.
448
- *
449
- * @returns {Promise<number>} A promise that resolves to the number of registered plugins.
450
- */
451
333
  async saveToStorage() {
452
334
  if (!this.matterbridge.nodeContext) {
453
335
  throw new Error('loadFromStorage: node context is not available.');
454
336
  }
455
- // Convert the map to an array
456
337
  const plugins = [];
457
338
  for (const plugin of this.array()) {
458
339
  plugins.push({
@@ -469,22 +350,13 @@ export class PluginManager extends EventEmitter {
469
350
  this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
470
351
  return plugins.length;
471
352
  }
472
- /**
473
- * Resolves the name of a plugin by loading and parsing its package.json file.
474
- * It will first try to resolve the path as is, then in the global modules directory, and finally in the matterbridge plugin directory.
475
- *
476
- * @param {string} nameOrPath - The name of the plugin or the path to the plugin's package.json file.
477
- * @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.
478
- */
479
353
  async resolve(nameOrPath) {
480
354
  const { default: path } = await import('node:path');
481
355
  const { promises } = await import('node:fs');
482
356
  if (!nameOrPath.endsWith('package.json'))
483
357
  nameOrPath = path.join(nameOrPath, 'package.json');
484
- // Resolve the package.json of the plugin
485
358
  let packageJsonPath = path.resolve(nameOrPath);
486
359
  this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
487
- // Check if the package.json file exists at the specified path or next try in the global modules directory
488
360
  try {
489
361
  await promises.access(packageJsonPath);
490
362
  }
@@ -493,7 +365,6 @@ export class PluginManager extends EventEmitter {
493
365
  packageJsonPath = path.join(this.matterbridge.globalModulesDirectory, nameOrPath);
494
366
  this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
495
367
  }
496
- // Check if the package.json file exists at the global modules directory or next try in the matterbridge plugin directory
497
368
  try {
498
369
  await promises.access(packageJsonPath);
499
370
  }
@@ -503,9 +374,7 @@ export class PluginManager extends EventEmitter {
503
374
  this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
504
375
  }
505
376
  try {
506
- // Load the package.json of the plugin or fails if even not found in the matterbridge plugin directory
507
377
  const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
508
- // Check for main issues
509
378
  if (!packageJson.name) {
510
379
  this.log.error(`Package.json name not found at ${packageJsonPath}`);
511
380
  return null;
@@ -518,7 +387,6 @@ export class PluginManager extends EventEmitter {
518
387
  this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
519
388
  return null;
520
389
  }
521
- // Check for @project-chip and @matter packages in dependencies and devDependencies
522
390
  const checkForProjectChipPackages = (dependencies) => {
523
391
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
524
392
  };
@@ -540,7 +408,6 @@ export class PluginManager extends EventEmitter {
540
408
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
541
409
  return null;
542
410
  }
543
- // Check for matterbridge package in dependencies and devDependencies
544
411
  const checkForMatterbridgePackage = (dependencies) => {
545
412
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
546
413
  };
@@ -570,19 +437,13 @@ export class PluginManager extends EventEmitter {
570
437
  return null;
571
438
  }
572
439
  }
573
- /**
574
- * Installs a package globally using npm.
575
- *
576
- * @param {string} packageName - The name of the package to install.
577
- * @returns {Promise<boolean>} A promise that resolves to true if the installation was successful, false otherwise.
578
- */
579
440
  async install(packageName) {
580
441
  this.log.debug(`Installing plugin ${plg}${packageName}${db}...`);
581
442
  const { spawnCommand } = await import('./utils/spawn.js');
582
443
  if (await spawnCommand('npm', ['install', '-g', packageName, '--omit=dev', '--verbose'], 'install', packageName)) {
583
444
  this.matterbridge.restartRequired = true;
584
445
  this.matterbridge.fixedRestartRequired = true;
585
- packageName = packageName.replace(/@.*$/, ''); // Remove @version if present
446
+ packageName = packageName.replace(/@.*$/, '');
586
447
  if (packageName !== 'matterbridge') {
587
448
  if (!this.has(packageName))
588
449
  await this.add(packageName);
@@ -603,12 +464,6 @@ export class PluginManager extends EventEmitter {
603
464
  return false;
604
465
  }
605
466
  }
606
- /**
607
- * Uninstalls a package globally using npm.
608
- *
609
- * @param {string} packageName - The name of the package to uninstall.
610
- * @returns {Promise<boolean>} A promise that resolves to true if the uninstallation was successful, false otherwise.
611
- */
612
467
  async uninstall(packageName) {
613
468
  this.log.debug(`Uninstalling plugin ${plg}${packageName}${db}...`);
614
469
  const { spawnCommand } = await import('./utils/spawn.js');
@@ -630,12 +485,6 @@ export class PluginManager extends EventEmitter {
630
485
  return false;
631
486
  }
632
487
  }
633
- /**
634
- * Get the author of a plugin from its package.json.
635
- *
636
- * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
637
- * @returns {string} The author of the plugin, or 'Unknown author' if not found.
638
- */
639
488
  getAuthor(packageJson) {
640
489
  if (packageJson.author && typeof packageJson.author === 'string')
641
490
  return packageJson.author;
@@ -643,12 +492,6 @@ export class PluginManager extends EventEmitter {
643
492
  return packageJson.author.name;
644
493
  return 'Unknown author';
645
494
  }
646
- /**
647
- * Get the homepage of a plugin from its package.json.
648
- *
649
- * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
650
- * @returns {string | undefined} The homepage of the plugin, or undefined if not found.
651
- */
652
495
  getHomepage(packageJson) {
653
496
  if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
654
497
  return packageJson.homepage.replace('git+', '').replace('.git', '');
@@ -657,14 +500,7 @@ export class PluginManager extends EventEmitter {
657
500
  return packageJson.repository.url.replace('git+', '').replace('.git', '');
658
501
  }
659
502
  }
660
- /**
661
- * Get the help URL of a plugin from its package.json.
662
- *
663
- * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
664
- * @returns {string | undefined} The URL to the help page or to the README file, or undefined if not found.
665
- */
666
503
  getHelp(packageJson) {
667
- // If there's a help field that looks like a URL, return it.
668
504
  if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
669
505
  return packageJson.help;
670
506
  }
@@ -675,14 +511,7 @@ export class PluginManager extends EventEmitter {
675
511
  return packageJson.homepage.replace('git+', '').replace('.git', '');
676
512
  }
677
513
  }
678
- /**
679
- * Get the changelog URL of a plugin from its package.json.
680
- *
681
- * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
682
- * @returns {string | undefined} The URL to the CHANGELOG file, or undefined if not found.
683
- */
684
514
  getChangelog(packageJson) {
685
- // If there's a changelog field that looks like a URL, return it.
686
515
  if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
687
516
  return packageJson.changelog;
688
517
  }
@@ -693,13 +522,6 @@ export class PluginManager extends EventEmitter {
693
522
  return packageJson.homepage.replace('git+', '').replace('.git', '');
694
523
  }
695
524
  }
696
- /**
697
- * Get the first funding URL(s) of a plugin from its package.json.
698
- *
699
- * @param {Record<string, any>} packageJson - The package.json object of the plugin.
700
- * @returns {string | undefined} The first funding URLs, or undefined if not found.
701
- */
702
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
703
525
  getFunding(packageJson) {
704
526
  const funding = packageJson.funding;
705
527
  if (!funding)
@@ -708,27 +530,16 @@ export class PluginManager extends EventEmitter {
708
530
  return;
709
531
  if (typeof funding === 'string' && funding.startsWith('http'))
710
532
  return funding;
711
- // Normalize funding into an array.
712
533
  const fundingEntries = Array.isArray(funding) ? funding : [funding];
713
534
  for (const entry of fundingEntries) {
714
535
  if (entry && typeof entry === 'string' && entry.startsWith('http')) {
715
- // If the funding entry is a string, assume it is a URL.
716
536
  return entry;
717
537
  }
718
538
  else if (entry && typeof entry === 'object' && typeof entry.url === 'string' && entry.url.startsWith('http')) {
719
- // If it's an object with a 'url' property, use that.
720
539
  return entry.url;
721
540
  }
722
541
  }
723
542
  }
724
- /**
725
- * Parses the plugin package.json and returns it.
726
- * It will also log warnings and errors for missing or invalid fields.
727
- * It will return null if critical errors are found.
728
- *
729
- * @param {Plugin | PluginName} plugin - The plugin to load the package from.
730
- * @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.
731
- */
732
543
  async parse(plugin) {
733
544
  const { promises } = await import('node:fs');
734
545
  if (typeof plugin === 'string') {
@@ -766,7 +577,6 @@ export class PluginManager extends EventEmitter {
766
577
  plugin.funding = this.getFunding(packageJson);
767
578
  if (!plugin.type)
768
579
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
769
- // Check for @project-chip and @matter packages in dependencies and devDependencies
770
580
  const checkForProjectChipPackages = (dependencies) => {
771
581
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
772
582
  };
@@ -788,7 +598,6 @@ export class PluginManager extends EventEmitter {
788
598
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
789
599
  return null;
790
600
  }
791
- // Check for matterbridge package in dependencies and devDependencies
792
601
  const checkForMatterbridgePackage = (dependencies) => {
793
602
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
794
603
  };
@@ -818,16 +627,6 @@ export class PluginManager extends EventEmitter {
818
627
  return null;
819
628
  }
820
629
  }
821
- /**
822
- * Enables a plugin by its name or path.
823
- *
824
- * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
825
- * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
826
- * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
827
- *
828
- * @param {string} nameOrPath - The name or path of the plugin to enable.
829
- * @returns {Promise<Plugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
830
- */
831
630
  async enable(nameOrPath) {
832
631
  const { promises } = await import('node:fs');
833
632
  if (!nameOrPath)
@@ -863,16 +662,6 @@ export class PluginManager extends EventEmitter {
863
662
  return null;
864
663
  }
865
664
  }
866
- /**
867
- * Disables a plugin by its name or path.
868
- *
869
- * This method disables a plugin by setting its `enabled` property to `false` and saving the updated
870
- * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
871
- * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and disable it.
872
- *
873
- * @param {string} nameOrPath - The name or path of the plugin to enable.
874
- * @returns {Promise<Plugin | null>} A promise that resolves to the disabled plugin object, or null if the plugin could not be disabled.
875
- */
876
665
  async disable(nameOrPath) {
877
666
  const { promises } = await import('node:fs');
878
667
  if (!nameOrPath)
@@ -908,16 +697,6 @@ export class PluginManager extends EventEmitter {
908
697
  return null;
909
698
  }
910
699
  }
911
- /**
912
- * Removes a plugin by its name or path.
913
- *
914
- * This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
915
- * It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
916
- * the plugin's `package.json` file to retrieve its name and remove it.
917
- *
918
- * @param {string} nameOrPath - The name or path of the plugin to remove.
919
- * @returns {Promise<Plugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
920
- */
921
700
  async remove(nameOrPath) {
922
701
  const { promises } = await import('node:fs');
923
702
  if (!nameOrPath)
@@ -953,17 +732,6 @@ export class PluginManager extends EventEmitter {
953
732
  return null;
954
733
  }
955
734
  }
956
- /**
957
- * Adds a plugin by its name or path.
958
- *
959
- * This method adds a plugin to the plugins map and saves the updated plugin information to storage.
960
- * It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
961
- * registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
962
- * and saves the updated plugin information to storage.
963
- *
964
- * @param {string} nameOrPath - The name or path of the plugin to add.
965
- * @returns {Promise<Plugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
966
- */
967
735
  async add(nameOrPath) {
968
736
  const { promises } = await import('node:fs');
969
737
  if (!nameOrPath)
@@ -1003,15 +771,6 @@ export class PluginManager extends EventEmitter {
1003
771
  return null;
1004
772
  }
1005
773
  }
1006
- /**
1007
- * Loads a plugin and returns the corresponding MatterbridgePlatform instance.
1008
- *
1009
- * @param {Plugin | PluginName} plugin - The plugin to load.
1010
- * @param {boolean} start - Optional flag indicating whether to start the plugin after loading. Default is false.
1011
- * @param {string} message - Optional message to pass to the plugin when starting.
1012
- * @param {boolean} configure - Optional flag indicating whether to configure the plugin after loading. Default is false.
1013
- * @returns {Promise<MatterbridgePlatform | undefined>} A Promise that resolves to the loaded MatterbridgePlatform instance or undefined.
1014
- */
1015
774
  async load(plugin, start = false, message = '', configure = false) {
1016
775
  const { promises } = await import('node:fs');
1017
776
  const { default: path } = await import('node:path');
@@ -1033,20 +792,15 @@ export class PluginManager extends EventEmitter {
1033
792
  }
1034
793
  this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
1035
794
  try {
1036
- // Load the package.json of the plugin
1037
795
  const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
1038
- // Resolve the main module path relative to package.json
1039
796
  const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
1040
- // Dynamically import the plugin
1041
797
  const { pathToFileURL } = await import('node:url');
1042
798
  const pluginUrl = pathToFileURL(pluginEntry);
1043
799
  this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
1044
800
  const pluginInstance = (await import(pluginUrl.href));
1045
801
  this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
1046
- // Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
1047
802
  if (pluginInstance.default) {
1048
803
  const config = await this.loadConfig(plugin);
1049
- // 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.
1050
804
  plugin.name = packageJson.name;
1051
805
  plugin.description = packageJson.description ?? 'No description';
1052
806
  plugin.version = packageJson.version;
@@ -1055,14 +809,13 @@ export class PluginManager extends EventEmitter {
1055
809
  plugin.schemaJson = await this.loadSchema(plugin);
1056
810
  config.name = packageJson.name;
1057
811
  config.version = packageJson.version;
1058
- const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: config.debug ? "debug" /* LogLevel.DEBUG */ : this.matterbridge.logLevel });
812
+ const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.logLevel });
1059
813
  const platform = pluginInstance.default(this.matterbridge, log, config);
1060
814
  config.type = platform.type;
1061
815
  platform.name = packageJson.name;
1062
816
  platform.config = config;
1063
817
  platform.version = packageJson.version;
1064
818
  platform.isLoaded = true;
1065
- // @ts-expect-error - setMatterNode is intentionally private
1066
819
  platform.setMatterNode?.(this.matterbridge.addBridgedEndpoint.bind(this.matterbridge), this.matterbridge.removeBridgedEndpoint.bind(this.matterbridge), this.matterbridge.removeAllBridgedEndpoints.bind(this.matterbridge), this.matterbridge.addVirtualEndpoint.bind(this.matterbridge));
1067
820
  plugin.name = packageJson.name;
1068
821
  plugin.description = packageJson.description ?? 'No description';
@@ -1076,7 +829,7 @@ export class PluginManager extends EventEmitter {
1076
829
  plugin.platform = platform;
1077
830
  plugin.loaded = true;
1078
831
  plugin.registeredDevices = 0;
1079
- await this.saveToStorage(); // Save the plugin to storage
832
+ await this.saveToStorage();
1080
833
  this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
1081
834
  this.emit('loaded', plugin.name);
1082
835
  if (start)
@@ -1096,14 +849,6 @@ export class PluginManager extends EventEmitter {
1096
849
  }
1097
850
  return undefined;
1098
851
  }
1099
- /**
1100
- * Starts a plugin.
1101
- *
1102
- * @param {Plugin | PluginName} plugin - The plugin to start.
1103
- * @param {string} [message] - Optional message to pass to the plugin's onStart method.
1104
- * @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
1105
- * @returns {Promise<Plugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
1106
- */
1107
852
  async start(plugin, message, configure = false) {
1108
853
  if (typeof plugin === 'string') {
1109
854
  const p = this._plugins.get(plugin);
@@ -1143,12 +888,6 @@ export class PluginManager extends EventEmitter {
1143
888
  }
1144
889
  return undefined;
1145
890
  }
1146
- /**
1147
- * Configures a plugin.
1148
- *
1149
- * @param {Plugin | PluginName} plugin - The plugin to configure.
1150
- * @returns {Promise<Plugin | undefined>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
1151
- */
1152
891
  async configure(plugin) {
1153
892
  if (typeof plugin === 'string') {
1154
893
  const p = this._plugins.get(plugin);
@@ -1189,18 +928,6 @@ export class PluginManager extends EventEmitter {
1189
928
  }
1190
929
  return undefined;
1191
930
  }
1192
- /**
1193
- * Shuts down a plugin.
1194
- *
1195
- * This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
1196
- * It logs the shutdown process and optionally removes all devices associated with the plugin.
1197
- *
1198
- * @param {Plugin | PluginName} plugin - The plugin to shut down.
1199
- * @param {string} [reason] - The reason for shutting down the plugin.
1200
- * @param {boolean} [removeAllDevices] - Whether to remove all devices associated with the plugin.
1201
- * @param {boolean} [force] - Whether to force the shutdown even if the plugin is not loaded or started.
1202
- * @returns {Promise<Plugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
1203
- */
1204
931
  async shutdown(plugin, reason, removeAllDevices = false, force = false) {
1205
932
  if (typeof plugin === 'string') {
1206
933
  const p = this._plugins.get(plugin);
@@ -1257,15 +984,6 @@ export class PluginManager extends EventEmitter {
1257
984
  }
1258
985
  return undefined;
1259
986
  }
1260
- /**
1261
- * Loads the configuration for a plugin.
1262
- * If the configuration file exists, it reads the file and returns the parsed JSON data.
1263
- * If the configuration file does not exist, it creates a new file with default configuration and returns it.
1264
- * If any error occurs during file access or creation, it logs an error and return un empty config.
1265
- *
1266
- * @param {Plugin} plugin - The plugin for which to load the configuration.
1267
- * @returns {Promise<PlatformConfig>} A promise that resolves to the loaded or created configuration.
1268
- */
1269
987
  async loadConfig(plugin) {
1270
988
  const { default: path } = await import('node:path');
1271
989
  const { promises } = await import('node:fs');
@@ -1276,8 +994,6 @@ export class PluginManager extends EventEmitter {
1276
994
  const data = await promises.readFile(configFile, 'utf8');
1277
995
  const config = JSON.parse(data);
1278
996
  this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
1279
- // this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
1280
- // The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
1281
997
  config.name = plugin.name;
1282
998
  config.type = plugin.type;
1283
999
  if (config.debug === undefined)
@@ -1304,7 +1020,6 @@ export class PluginManager extends EventEmitter {
1304
1020
  try {
1305
1021
  await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
1306
1022
  this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
1307
- // this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
1308
1023
  return config;
1309
1024
  }
1310
1025
  catch (err) {
@@ -1318,19 +1033,6 @@ export class PluginManager extends EventEmitter {
1318
1033
  }
1319
1034
  }
1320
1035
  }
1321
- /**
1322
- * Saves the configuration of a plugin to a file.
1323
- *
1324
- * This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
1325
- * If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
1326
- * is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
1327
- * the error and rejects the promise.
1328
- *
1329
- * @param {Plugin} plugin - The plugin whose configuration is to be saved.
1330
- * @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
1331
- * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
1332
- * @throws {Error} If the plugin's configuration is not found.
1333
- */
1334
1036
  async saveConfigFromPlugin(plugin, restartRequired = false) {
1335
1037
  const { default: path } = await import('node:path');
1336
1038
  const { promises } = await import('node:fs');
@@ -1345,7 +1047,6 @@ export class PluginManager extends EventEmitter {
1345
1047
  if (restartRequired)
1346
1048
  plugin.restartRequired = true;
1347
1049
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
1348
- // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
1349
1050
  return Promise.resolve();
1350
1051
  }
1351
1052
  catch (err) {
@@ -1353,20 +1054,6 @@ export class PluginManager extends EventEmitter {
1353
1054
  return Promise.reject(err);
1354
1055
  }
1355
1056
  }
1356
- /**
1357
- * Saves the configuration of a plugin from a JSON object to a file.
1358
- *
1359
- * This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
1360
- * It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
1361
- * the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
1362
- * successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
1363
- * during the file write operation, it logs the error and returns.
1364
- *
1365
- * @param {Plugin} plugin - The plugin whose configuration is to be saved.
1366
- * @param {PlatformConfig} config - The configuration data to be saved.
1367
- * @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
1368
- * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
1369
- */
1370
1057
  async saveConfigFromJson(plugin, config, restartRequired = false) {
1371
1058
  const { default: path } = await import('node:path');
1372
1059
  const { promises } = await import('node:fs');
@@ -1385,23 +1072,12 @@ export class PluginManager extends EventEmitter {
1385
1072
  plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
1386
1073
  }
1387
1074
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
1388
- // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
1389
1075
  }
1390
1076
  catch (err) {
1391
1077
  logError(this.log, `Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}`, err);
1392
1078
  return;
1393
1079
  }
1394
1080
  }
1395
- /**
1396
- * Loads the schema for a plugin.
1397
- *
1398
- * This method attempts to load the schema file for the specified plugin. If the schema file is found,
1399
- * it reads and parses the file, updates the schema's title and description, and logs the process.
1400
- * If the schema file is not found, it logs the event and loads a default schema for the plugin.
1401
- *
1402
- * @param {Plugin} plugin - The plugin whose schema is to be loaded.
1403
- * @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
1404
- */
1405
1081
  async loadSchema(plugin) {
1406
1082
  const { promises } = await import('node:fs');
1407
1083
  const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
@@ -1412,7 +1088,6 @@ export class PluginManager extends EventEmitter {
1412
1088
  schema.title = plugin.description;
1413
1089
  schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
1414
1090
  this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
1415
- // this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
1416
1091
  return schema;
1417
1092
  }
1418
1093
  catch (_err) {
@@ -1420,16 +1095,6 @@ export class PluginManager extends EventEmitter {
1420
1095
  return this.getDefaultSchema(plugin);
1421
1096
  }
1422
1097
  }
1423
- /**
1424
- * Returns the default schema for a plugin.
1425
- *
1426
- * This method generates a default schema object for the specified plugin. The schema includes
1427
- * metadata such as the plugin's title, description, version, and author. It also defines the
1428
- * properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
1429
- *
1430
- * @param {Plugin} plugin - The plugin for which the default schema is to be generated.
1431
- * @returns {PlatformSchema} The default schema object for the plugin.
1432
- */
1433
1098
  getDefaultSchema(plugin) {
1434
1099
  return {
1435
1100
  title: plugin.description,
@@ -1460,4 +1125,3 @@ export class PluginManager extends EventEmitter {
1460
1125
  };
1461
1126
  }
1462
1127
  }
1463
- //# sourceMappingURL=pluginManager.js.map