matterbridge 3.3.4-dev-20251021-7651f57 → 3.3.4

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 (304) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/README-SERVICE-LOCAL.md +226 -0
  3. package/dist/broadcastServer.d.ts +112 -0
  4. package/dist/broadcastServer.d.ts.map +1 -0
  5. package/dist/broadcastServer.js +100 -6
  6. package/dist/broadcastServer.js.map +1 -0
  7. package/dist/broadcastServerTypes.d.ts +793 -0
  8. package/dist/broadcastServerTypes.d.ts.map +1 -0
  9. package/dist/broadcastServerTypes.js +24 -0
  10. package/dist/broadcastServerTypes.js.map +1 -0
  11. package/dist/cli.d.ts +30 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +100 -2
  14. package/dist/cli.js.map +1 -0
  15. package/dist/cliEmitter.d.ts +50 -0
  16. package/dist/cliEmitter.d.ts.map +1 -0
  17. package/dist/cliEmitter.js +37 -0
  18. package/dist/cliEmitter.js.map +1 -0
  19. package/dist/cliHistory.d.ts +48 -0
  20. package/dist/cliHistory.d.ts.map +1 -0
  21. package/dist/cliHistory.js +38 -0
  22. package/dist/cliHistory.js.map +1 -0
  23. package/dist/clusters/export.d.ts +2 -0
  24. package/dist/clusters/export.d.ts.map +1 -0
  25. package/dist/clusters/export.js +2 -0
  26. package/dist/clusters/export.js.map +1 -0
  27. package/dist/defaultConfigSchema.d.ts +28 -0
  28. package/dist/defaultConfigSchema.d.ts.map +1 -0
  29. package/dist/defaultConfigSchema.js +24 -0
  30. package/dist/defaultConfigSchema.js.map +1 -0
  31. package/dist/deviceManager.d.ts +117 -0
  32. package/dist/deviceManager.d.ts.map +1 -0
  33. package/dist/deviceManager.js +126 -3
  34. package/dist/deviceManager.js.map +1 -0
  35. package/dist/devices/airConditioner.d.ts +98 -0
  36. package/dist/devices/airConditioner.d.ts.map +1 -0
  37. package/dist/devices/airConditioner.js +57 -0
  38. package/dist/devices/airConditioner.js.map +1 -0
  39. package/dist/devices/batteryStorage.d.ts +48 -0
  40. package/dist/devices/batteryStorage.d.ts.map +1 -0
  41. package/dist/devices/batteryStorage.js +48 -1
  42. package/dist/devices/batteryStorage.js.map +1 -0
  43. package/dist/devices/cooktop.d.ts +60 -0
  44. package/dist/devices/cooktop.d.ts.map +1 -0
  45. package/dist/devices/cooktop.js +55 -0
  46. package/dist/devices/cooktop.js.map +1 -0
  47. package/dist/devices/dishwasher.d.ts +71 -0
  48. package/dist/devices/dishwasher.d.ts.map +1 -0
  49. package/dist/devices/dishwasher.js +57 -0
  50. package/dist/devices/dishwasher.js.map +1 -0
  51. package/dist/devices/evse.d.ts +76 -0
  52. package/dist/devices/evse.d.ts.map +1 -0
  53. package/dist/devices/evse.js +74 -10
  54. package/dist/devices/evse.js.map +1 -0
  55. package/dist/devices/export.d.ts +17 -0
  56. package/dist/devices/export.d.ts.map +1 -0
  57. package/dist/devices/export.js +5 -0
  58. package/dist/devices/export.js.map +1 -0
  59. package/dist/devices/extractorHood.d.ts +46 -0
  60. package/dist/devices/extractorHood.d.ts.map +1 -0
  61. package/dist/devices/extractorHood.js +42 -0
  62. package/dist/devices/extractorHood.js.map +1 -0
  63. package/dist/devices/heatPump.d.ts +47 -0
  64. package/dist/devices/heatPump.d.ts.map +1 -0
  65. package/dist/devices/heatPump.js +50 -2
  66. package/dist/devices/heatPump.js.map +1 -0
  67. package/dist/devices/laundryDryer.d.ts +67 -0
  68. package/dist/devices/laundryDryer.d.ts.map +1 -0
  69. package/dist/devices/laundryDryer.js +62 -3
  70. package/dist/devices/laundryDryer.js.map +1 -0
  71. package/dist/devices/laundryWasher.d.ts +81 -0
  72. package/dist/devices/laundryWasher.d.ts.map +1 -0
  73. package/dist/devices/laundryWasher.js +70 -4
  74. package/dist/devices/laundryWasher.js.map +1 -0
  75. package/dist/devices/microwaveOven.d.ts +168 -0
  76. package/dist/devices/microwaveOven.d.ts.map +1 -0
  77. package/dist/devices/microwaveOven.js +88 -5
  78. package/dist/devices/microwaveOven.js.map +1 -0
  79. package/dist/devices/oven.d.ts +105 -0
  80. package/dist/devices/oven.d.ts.map +1 -0
  81. package/dist/devices/oven.js +85 -0
  82. package/dist/devices/oven.js.map +1 -0
  83. package/dist/devices/refrigerator.d.ts +118 -0
  84. package/dist/devices/refrigerator.d.ts.map +1 -0
  85. package/dist/devices/refrigerator.js +102 -0
  86. package/dist/devices/refrigerator.js.map +1 -0
  87. package/dist/devices/roboticVacuumCleaner.d.ts +112 -0
  88. package/dist/devices/roboticVacuumCleaner.d.ts.map +1 -0
  89. package/dist/devices/roboticVacuumCleaner.js +100 -9
  90. package/dist/devices/roboticVacuumCleaner.js.map +1 -0
  91. package/dist/devices/solarPower.d.ts +40 -0
  92. package/dist/devices/solarPower.d.ts.map +1 -0
  93. package/dist/devices/solarPower.js +38 -0
  94. package/dist/devices/solarPower.js.map +1 -0
  95. package/dist/devices/speaker.d.ts +87 -0
  96. package/dist/devices/speaker.d.ts.map +1 -0
  97. package/dist/devices/speaker.js +84 -0
  98. package/dist/devices/speaker.js.map +1 -0
  99. package/dist/devices/temperatureControl.d.ts +166 -0
  100. package/dist/devices/temperatureControl.d.ts.map +1 -0
  101. package/dist/devices/temperatureControl.js +24 -3
  102. package/dist/devices/temperatureControl.js.map +1 -0
  103. package/dist/devices/waterHeater.d.ts +111 -0
  104. package/dist/devices/waterHeater.d.ts.map +1 -0
  105. package/dist/devices/waterHeater.js +82 -2
  106. package/dist/devices/waterHeater.js.map +1 -0
  107. package/dist/dgram/coap.d.ts +205 -0
  108. package/dist/dgram/coap.d.ts.map +1 -0
  109. package/dist/dgram/coap.js +126 -13
  110. package/dist/dgram/coap.js.map +1 -0
  111. package/dist/dgram/dgram.d.ts +141 -0
  112. package/dist/dgram/dgram.d.ts.map +1 -0
  113. package/dist/dgram/dgram.js +114 -2
  114. package/dist/dgram/dgram.js.map +1 -0
  115. package/dist/dgram/mb_coap.d.ts +24 -0
  116. package/dist/dgram/mb_coap.d.ts.map +1 -0
  117. package/dist/dgram/mb_coap.js +41 -3
  118. package/dist/dgram/mb_coap.js.map +1 -0
  119. package/dist/dgram/mb_mdns.d.ts +24 -0
  120. package/dist/dgram/mb_mdns.d.ts.map +1 -0
  121. package/dist/dgram/mb_mdns.js +80 -15
  122. package/dist/dgram/mb_mdns.js.map +1 -0
  123. package/dist/dgram/mdns.d.ts +290 -0
  124. package/dist/dgram/mdns.d.ts.map +1 -0
  125. package/dist/dgram/mdns.js +299 -137
  126. package/dist/dgram/mdns.js.map +1 -0
  127. package/dist/dgram/multicast.d.ts +67 -0
  128. package/dist/dgram/multicast.d.ts.map +1 -0
  129. package/dist/dgram/multicast.js +62 -1
  130. package/dist/dgram/multicast.js.map +1 -0
  131. package/dist/dgram/unicast.d.ts +56 -0
  132. package/dist/dgram/unicast.d.ts.map +1 -0
  133. package/dist/dgram/unicast.js +54 -0
  134. package/dist/dgram/unicast.js.map +1 -0
  135. package/dist/frontend.d.ts +235 -0
  136. package/dist/frontend.d.ts.map +1 -0
  137. package/dist/frontend.js +441 -39
  138. package/dist/frontend.js.map +1 -0
  139. package/dist/frontendTypes.d.ts +529 -0
  140. package/dist/frontendTypes.d.ts.map +1 -0
  141. package/dist/frontendTypes.js +45 -0
  142. package/dist/frontendTypes.js.map +1 -0
  143. package/dist/helpers.d.ts +48 -0
  144. package/dist/helpers.d.ts.map +1 -0
  145. package/dist/helpers.js +53 -0
  146. package/dist/helpers.js.map +1 -0
  147. package/dist/index.d.ts +33 -0
  148. package/dist/index.d.ts.map +1 -0
  149. package/dist/index.js +25 -0
  150. package/dist/index.js.map +1 -0
  151. package/dist/logger/export.d.ts +2 -0
  152. package/dist/logger/export.d.ts.map +1 -0
  153. package/dist/logger/export.js +1 -0
  154. package/dist/logger/export.js.map +1 -0
  155. package/dist/matter/behaviors.d.ts +2 -0
  156. package/dist/matter/behaviors.d.ts.map +1 -0
  157. package/dist/matter/behaviors.js +2 -0
  158. package/dist/matter/behaviors.js.map +1 -0
  159. package/dist/matter/clusters.d.ts +2 -0
  160. package/dist/matter/clusters.d.ts.map +1 -0
  161. package/dist/matter/clusters.js +2 -0
  162. package/dist/matter/clusters.js.map +1 -0
  163. package/dist/matter/devices.d.ts +2 -0
  164. package/dist/matter/devices.d.ts.map +1 -0
  165. package/dist/matter/devices.js +2 -0
  166. package/dist/matter/devices.js.map +1 -0
  167. package/dist/matter/endpoints.d.ts +2 -0
  168. package/dist/matter/endpoints.d.ts.map +1 -0
  169. package/dist/matter/endpoints.js +2 -0
  170. package/dist/matter/endpoints.js.map +1 -0
  171. package/dist/matter/export.d.ts +5 -0
  172. package/dist/matter/export.d.ts.map +1 -0
  173. package/dist/matter/export.js +3 -0
  174. package/dist/matter/export.js.map +1 -0
  175. package/dist/matter/types.d.ts +3 -0
  176. package/dist/matter/types.d.ts.map +1 -0
  177. package/dist/matter/types.js +3 -0
  178. package/dist/matter/types.js.map +1 -0
  179. package/dist/matterbridge.d.ts +475 -0
  180. package/dist/matterbridge.d.ts.map +1 -0
  181. package/dist/matterbridge.js +833 -51
  182. package/dist/matterbridge.js.map +1 -0
  183. package/dist/matterbridgeAccessoryPlatform.d.ts +42 -0
  184. package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
  185. package/dist/matterbridgeAccessoryPlatform.js +37 -0
  186. package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
  187. package/dist/matterbridgeBehaviors.d.ts +2404 -0
  188. package/dist/matterbridgeBehaviors.d.ts.map +1 -0
  189. package/dist/matterbridgeBehaviors.js +68 -5
  190. package/dist/matterbridgeBehaviors.js.map +1 -0
  191. package/dist/matterbridgeDeviceTypes.d.ts +770 -0
  192. package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
  193. package/dist/matterbridgeDeviceTypes.js +638 -17
  194. package/dist/matterbridgeDeviceTypes.js.map +1 -0
  195. package/dist/matterbridgeDynamicPlatform.d.ts +42 -0
  196. package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
  197. package/dist/matterbridgeDynamicPlatform.js +37 -0
  198. package/dist/matterbridgeDynamicPlatform.js.map +1 -0
  199. package/dist/matterbridgeEndpoint.d.ts +1550 -0
  200. package/dist/matterbridgeEndpoint.d.ts.map +1 -0
  201. package/dist/matterbridgeEndpoint.js +1403 -53
  202. package/dist/matterbridgeEndpoint.js.map +1 -0
  203. package/dist/matterbridgeEndpointHelpers.d.ts +758 -0
  204. package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
  205. package/dist/matterbridgeEndpointHelpers.js +464 -19
  206. package/dist/matterbridgeEndpointHelpers.js.map +1 -0
  207. package/dist/matterbridgePlatform.d.ts +402 -0
  208. package/dist/matterbridgePlatform.d.ts.map +1 -0
  209. package/dist/matterbridgePlatform.js +341 -1
  210. package/dist/matterbridgePlatform.js.map +1 -0
  211. package/dist/matterbridgeTypes.d.ts +226 -0
  212. package/dist/matterbridgeTypes.d.ts.map +1 -0
  213. package/dist/matterbridgeTypes.js +26 -0
  214. package/dist/matterbridgeTypes.js.map +1 -0
  215. package/dist/pluginManager.d.ts +347 -0
  216. package/dist/pluginManager.d.ts.map +1 -0
  217. package/dist/pluginManager.js +320 -4
  218. package/dist/pluginManager.js.map +1 -0
  219. package/dist/shelly.d.ts +174 -0
  220. package/dist/shelly.d.ts.map +1 -0
  221. package/dist/shelly.js +168 -7
  222. package/dist/shelly.js.map +1 -0
  223. package/dist/storage/export.d.ts +2 -0
  224. package/dist/storage/export.d.ts.map +1 -0
  225. package/dist/storage/export.js +1 -0
  226. package/dist/storage/export.js.map +1 -0
  227. package/dist/update.d.ts +75 -0
  228. package/dist/update.d.ts.map +1 -0
  229. package/dist/update.js +69 -0
  230. package/dist/update.js.map +1 -0
  231. package/dist/utils/colorUtils.d.ts +99 -0
  232. package/dist/utils/colorUtils.d.ts.map +1 -0
  233. package/dist/utils/colorUtils.js +97 -2
  234. package/dist/utils/colorUtils.js.map +1 -0
  235. package/dist/utils/commandLine.d.ts +66 -0
  236. package/dist/utils/commandLine.d.ts.map +1 -0
  237. package/dist/utils/commandLine.js +60 -0
  238. package/dist/utils/commandLine.js.map +1 -0
  239. package/dist/utils/copyDirectory.d.ts +33 -0
  240. package/dist/utils/copyDirectory.d.ts.map +1 -0
  241. package/dist/utils/copyDirectory.js +38 -1
  242. package/dist/utils/copyDirectory.js.map +1 -0
  243. package/dist/utils/createDirectory.d.ts +34 -0
  244. package/dist/utils/createDirectory.d.ts.map +1 -0
  245. package/dist/utils/createDirectory.js +33 -0
  246. package/dist/utils/createDirectory.js.map +1 -0
  247. package/dist/utils/createZip.d.ts +39 -0
  248. package/dist/utils/createZip.d.ts.map +1 -0
  249. package/dist/utils/createZip.js +47 -2
  250. package/dist/utils/createZip.js.map +1 -0
  251. package/dist/utils/deepCopy.d.ts +32 -0
  252. package/dist/utils/deepCopy.d.ts.map +1 -0
  253. package/dist/utils/deepCopy.js +39 -0
  254. package/dist/utils/deepCopy.js.map +1 -0
  255. package/dist/utils/deepEqual.d.ts +54 -0
  256. package/dist/utils/deepEqual.d.ts.map +1 -0
  257. package/dist/utils/deepEqual.js +72 -1
  258. package/dist/utils/deepEqual.js.map +1 -0
  259. package/dist/utils/error.d.ts +44 -0
  260. package/dist/utils/error.d.ts.map +1 -0
  261. package/dist/utils/error.js +43 -1
  262. package/dist/utils/error.js.map +1 -0
  263. package/dist/utils/export.d.ts +13 -0
  264. package/dist/utils/export.d.ts.map +1 -0
  265. package/dist/utils/export.js +1 -0
  266. package/dist/utils/export.js.map +1 -0
  267. package/dist/utils/format.d.ts +53 -0
  268. package/dist/utils/format.d.ts.map +1 -0
  269. package/dist/utils/format.js +49 -0
  270. package/dist/utils/format.js.map +1 -0
  271. package/dist/utils/hex.d.ts +89 -0
  272. package/dist/utils/hex.d.ts.map +1 -0
  273. package/dist/utils/hex.js +124 -0
  274. package/dist/utils/hex.js.map +1 -0
  275. package/dist/utils/inspector.d.ts +87 -0
  276. package/dist/utils/inspector.d.ts.map +1 -0
  277. package/dist/utils/inspector.js +69 -1
  278. package/dist/utils/inspector.js.map +1 -0
  279. package/dist/utils/isvalid.d.ts +103 -0
  280. package/dist/utils/isvalid.d.ts.map +1 -0
  281. package/dist/utils/isvalid.js +101 -0
  282. package/dist/utils/isvalid.js.map +1 -0
  283. package/dist/utils/jestHelpers.d.ts +139 -0
  284. package/dist/utils/jestHelpers.d.ts.map +1 -0
  285. package/dist/utils/jestHelpers.js +153 -3
  286. package/dist/utils/jestHelpers.js.map +1 -0
  287. package/dist/utils/network.d.ts +101 -0
  288. package/dist/utils/network.d.ts.map +1 -0
  289. package/dist/utils/network.js +96 -5
  290. package/dist/utils/network.js.map +1 -0
  291. package/dist/utils/spawn.d.ts +35 -0
  292. package/dist/utils/spawn.d.ts.map +1 -0
  293. package/dist/utils/spawn.js +71 -0
  294. package/dist/utils/spawn.js.map +1 -0
  295. package/dist/utils/tracker.d.ts +108 -0
  296. package/dist/utils/tracker.d.ts.map +1 -0
  297. package/dist/utils/tracker.js +64 -1
  298. package/dist/utils/tracker.js.map +1 -0
  299. package/dist/utils/wait.d.ts +54 -0
  300. package/dist/utils/wait.d.ts.map +1 -0
  301. package/dist/utils/wait.js +60 -8
  302. package/dist/utils/wait.js.map +1 -0
  303. package/npm-shrinkwrap.json +5 -5
  304. package/package.json +2 -1
@@ -1,17 +1,50 @@
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
1
25
  import EventEmitter from 'node:events';
26
+ // AnsiLogger module
2
27
  import { AnsiLogger, UNDERLINE, UNDERLINEOFF, BLUE, db, er, nf, nt, rs, wr, debugStringify, CYAN } from 'node-ansi-logger';
3
28
  import { plg, typ } from './matterbridgeTypes.js';
4
29
  import { inspectError, logError } from './utils/error.js';
5
30
  import { BroadcastServer } from './broadcastServer.js';
31
+ /**
32
+ * Manages Matterbridge plugins.
33
+ */
6
34
  export class PluginManager extends EventEmitter {
7
35
  _plugins = new Map();
8
36
  matterbridge;
9
37
  log;
10
38
  server;
39
+ /**
40
+ * Creates an instance of PluginManager.
41
+ *
42
+ * @param {Matterbridge} matterbridge - The Matterbridge instance.
43
+ */
11
44
  constructor(matterbridge) {
12
45
  super();
13
46
  this.matterbridge = matterbridge;
14
- this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4, logLevel: matterbridge.log.logLevel });
47
+ this.log = new AnsiLogger({ logName: 'PluginManager', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: matterbridge.log.logLevel });
15
48
  this.log.debug('Matterbridge plugin manager starting...');
16
49
  this.server = new BroadcastServer('plugins', this.log);
17
50
  this.server.on('broadcast_message', this.msgHandler.bind(this));
@@ -49,32 +82,73 @@ export class PluginManager extends EventEmitter {
49
82
  this.server.respond({ ...msg, response: { packageName: msg.params.packageName, success: await this.uninstall(msg.params.packageName) } });
50
83
  break;
51
84
  default:
52
- this.log.warn(`Unknown broadcast message ${CYAN}${msg.type}${wr} from ${CYAN}${msg.src}${wr}`);
85
+ this.log.debug(`Unknown broadcast message ${CYAN}${msg.type}${db} from ${CYAN}${msg.src}${db}`);
53
86
  }
54
87
  }
55
88
  }
89
+ /**
90
+ * Gets the number of plugins.
91
+ *
92
+ * @returns {number} The number of plugins.
93
+ */
56
94
  get length() {
57
95
  return this._plugins.size;
58
96
  }
97
+ /**
98
+ * Gets the number of plugins.
99
+ *
100
+ * @returns {number} The number of plugins.
101
+ */
59
102
  get size() {
60
103
  return this._plugins.size;
61
104
  }
105
+ /**
106
+ * Checks if a plugin with the specified name exists.
107
+ *
108
+ * @param {string} name - The name of the plugin.
109
+ * @returns {boolean} True if the plugin exists, false otherwise.
110
+ */
62
111
  has(name) {
63
112
  return this._plugins.has(name);
64
113
  }
114
+ /**
115
+ * Gets a plugin by its name.
116
+ *
117
+ * @param {string} name - The name of the plugin.
118
+ * @returns {Plugin | undefined} The plugin, or undefined if not found.
119
+ */
65
120
  get(name) {
66
121
  return this._plugins.get(name);
67
122
  }
123
+ /**
124
+ * Adds a plugin to the manager.
125
+ *
126
+ * @param {Plugin} plugin - The plugin to add.
127
+ * @returns {Plugin} The added plugin.
128
+ */
68
129
  set(plugin) {
69
130
  this._plugins.set(plugin.name, plugin);
70
131
  return plugin;
71
132
  }
133
+ /**
134
+ * Clears all plugins from the manager.
135
+ */
72
136
  clear() {
73
137
  this._plugins.clear();
74
138
  }
139
+ /**
140
+ * Gets an array of all plugins.
141
+ *
142
+ * @returns {Plugin[]} An array of all plugins.
143
+ */
75
144
  array() {
76
145
  return Array.from(this._plugins.values());
77
146
  }
147
+ /**
148
+ * Gets an array of all plugins suitable for serialization.
149
+ *
150
+ * @returns {ApiPlugin[]} An array of all plugins.
151
+ */
78
152
  baseArray() {
79
153
  const basePlugins = [];
80
154
  for (const plugin of this._plugins.values()) {
@@ -108,9 +182,20 @@ export class PluginManager extends EventEmitter {
108
182
  }
109
183
  return basePlugins;
110
184
  }
185
+ /**
186
+ * Gets an iterator for the plugins.
187
+ *
188
+ * @returns {IterableIterator<Plugin>} An iterator for the plugins.
189
+ */
111
190
  [Symbol.iterator]() {
112
191
  return this._plugins.values();
113
192
  }
193
+ /**
194
+ * Executes a provided function once for each plugin.
195
+ *
196
+ * @param {Function} callback - The function to execute for each plugin.
197
+ * @returns {Promise<void>}
198
+ */
114
199
  async forEach(callback) {
115
200
  if (this.size === 0)
116
201
  return;
@@ -124,22 +209,39 @@ export class PluginManager extends EventEmitter {
124
209
  });
125
210
  await Promise.all(tasks);
126
211
  }
212
+ /**
213
+ * Sets the log level for the plugin manager.
214
+ *
215
+ * @param {LogLevel} logLevel - The log level to set.
216
+ */
127
217
  set logLevel(logLevel) {
128
218
  this.log.logLevel = logLevel;
129
219
  }
220
+ /**
221
+ * Loads registered plugins from storage.
222
+ *
223
+ * @returns {Promise<StoragePlugin[]>} A promise that resolves to an array of registered plugins.
224
+ */
130
225
  async loadFromStorage() {
131
226
  if (!this.matterbridge.nodeContext) {
132
227
  throw new Error('loadFromStorage: node context is not available.');
133
228
  }
229
+ // Load the array from storage and convert it to a map
134
230
  const pluginsArray = await this.matterbridge.nodeContext.get('plugins', []);
135
231
  for (const plugin of pluginsArray)
136
232
  this._plugins.set(plugin.name, plugin);
137
233
  return pluginsArray;
138
234
  }
235
+ /**
236
+ * Saves registered plugins to storage.
237
+ *
238
+ * @returns {Promise<number>} A promise that resolves to the number of registered plugins.
239
+ */
139
240
  async saveToStorage() {
140
241
  if (!this.matterbridge.nodeContext) {
141
242
  throw new Error('loadFromStorage: node context is not available.');
142
243
  }
244
+ // Convert the map to an array
143
245
  const plugins = [];
144
246
  for (const plugin of this.array()) {
145
247
  plugins.push({
@@ -156,13 +258,21 @@ export class PluginManager extends EventEmitter {
156
258
  this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
157
259
  return plugins.length;
158
260
  }
261
+ /**
262
+ * Resolves the name of a plugin by loading and parsing its package.json file.
263
+ *
264
+ * @param {string} pluginPath - The path to the plugin or the path to the plugin's package.json file.
265
+ * @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.
266
+ */
159
267
  async resolve(pluginPath) {
160
268
  const { default: path } = await import('node:path');
161
269
  const { promises } = await import('node:fs');
162
270
  if (!pluginPath.endsWith('package.json'))
163
271
  pluginPath = path.join(pluginPath, 'package.json');
272
+ // Resolve the package.json of the plugin
164
273
  let packageJsonPath = path.resolve(pluginPath);
165
274
  this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
275
+ // Check if the package.json file exists
166
276
  try {
167
277
  await promises.access(packageJsonPath);
168
278
  }
@@ -172,7 +282,9 @@ export class PluginManager extends EventEmitter {
172
282
  this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
173
283
  }
174
284
  try {
285
+ // Load the package.json of the plugin
175
286
  const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
287
+ // Check for main issues
176
288
  if (!packageJson.name) {
177
289
  this.log.error(`Package.json name not found at ${packageJsonPath}`);
178
290
  return null;
@@ -185,6 +297,7 @@ export class PluginManager extends EventEmitter {
185
297
  this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
186
298
  return null;
187
299
  }
300
+ // Check for @project-chip and @matter packages in dependencies and devDependencies
188
301
  const checkForProjectChipPackages = (dependencies) => {
189
302
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
190
303
  };
@@ -206,6 +319,7 @@ export class PluginManager extends EventEmitter {
206
319
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
207
320
  return null;
208
321
  }
322
+ // Check for matterbridge package in dependencies and devDependencies
209
323
  const checkForMatterbridgePackage = (dependencies) => {
210
324
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
211
325
  };
@@ -235,6 +349,12 @@ export class PluginManager extends EventEmitter {
235
349
  return null;
236
350
  }
237
351
  }
352
+ /**
353
+ * Installs a package globally using npm.
354
+ *
355
+ * @param {string} packageName - The name of the package to install.
356
+ * @returns {Promise<boolean>} A promise that resolves to true if the installation was successful, false otherwise.
357
+ */
238
358
  async install(packageName) {
239
359
  const { spawnCommand } = await import('./utils/spawn.js');
240
360
  try {
@@ -261,6 +381,12 @@ export class PluginManager extends EventEmitter {
261
381
  return false;
262
382
  }
263
383
  }
384
+ /**
385
+ * Uninstalls a package globally using npm.
386
+ *
387
+ * @param {string} packageName - The name of the package to uninstall.
388
+ * @returns {Promise<boolean>} A promise that resolves to true if the uninstallation was successful, false otherwise.
389
+ */
264
390
  async uninstall(packageName) {
265
391
  const { spawnCommand } = await import('./utils/spawn.js');
266
392
  packageName = packageName.replace(/@.*$/, '');
@@ -281,6 +407,12 @@ export class PluginManager extends EventEmitter {
281
407
  return false;
282
408
  }
283
409
  }
410
+ /**
411
+ * Get the author of a plugin from its package.json.
412
+ *
413
+ * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
414
+ * @returns {string} The author of the plugin, or 'Unknown author' if not found.
415
+ */
284
416
  getAuthor(packageJson) {
285
417
  if (packageJson.author && typeof packageJson.author === 'string')
286
418
  return packageJson.author;
@@ -288,6 +420,12 @@ export class PluginManager extends EventEmitter {
288
420
  return packageJson.author.name;
289
421
  return 'Unknown author';
290
422
  }
423
+ /**
424
+ * Get the homepage of a plugin from its package.json.
425
+ *
426
+ * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
427
+ * @returns {string | undefined} The homepage of the plugin, or undefined if not found.
428
+ */
291
429
  getHomepage(packageJson) {
292
430
  if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
293
431
  return packageJson.homepage.replace('git+', '').replace('.git', '');
@@ -296,7 +434,14 @@ export class PluginManager extends EventEmitter {
296
434
  return packageJson.repository.url.replace('git+', '').replace('.git', '');
297
435
  }
298
436
  }
437
+ /**
438
+ * Get the help URL of a plugin from its package.json.
439
+ *
440
+ * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
441
+ * @returns {string | undefined} The URL to the help page or to the README file, or undefined if not found.
442
+ */
299
443
  getHelp(packageJson) {
444
+ // If there's a help field that looks like a URL, return it.
300
445
  if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
301
446
  return packageJson.help;
302
447
  }
@@ -307,7 +452,14 @@ export class PluginManager extends EventEmitter {
307
452
  return packageJson.homepage.replace('git+', '').replace('.git', '');
308
453
  }
309
454
  }
455
+ /**
456
+ * Get the changelog URL of a plugin from its package.json.
457
+ *
458
+ * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
459
+ * @returns {string | undefined} The URL to the CHANGELOG file, or undefined if not found.
460
+ */
310
461
  getChangelog(packageJson) {
462
+ // If there's a changelog field that looks like a URL, return it.
311
463
  if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
312
464
  return packageJson.changelog;
313
465
  }
@@ -318,6 +470,13 @@ export class PluginManager extends EventEmitter {
318
470
  return packageJson.homepage.replace('git+', '').replace('.git', '');
319
471
  }
320
472
  }
473
+ /**
474
+ * Get the first funding URL(s) of a plugin from its package.json.
475
+ *
476
+ * @param {Record<string, any>} packageJson - The package.json object of the plugin.
477
+ * @returns {string | undefined} The first funding URLs, or undefined if not found.
478
+ */
479
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
321
480
  getFunding(packageJson) {
322
481
  const funding = packageJson.funding;
323
482
  if (!funding)
@@ -326,16 +485,25 @@ export class PluginManager extends EventEmitter {
326
485
  return;
327
486
  if (typeof funding === 'string' && funding.startsWith('http'))
328
487
  return funding;
488
+ // Normalize funding into an array.
329
489
  const fundingEntries = Array.isArray(funding) ? funding : [funding];
330
490
  for (const entry of fundingEntries) {
331
491
  if (entry && typeof entry === 'string' && entry.startsWith('http')) {
492
+ // If the funding entry is a string, assume it is a URL.
332
493
  return entry;
333
494
  }
334
495
  else if (entry && typeof entry === 'object' && typeof entry.url === 'string' && entry.url.startsWith('http')) {
496
+ // If it's an object with a 'url' property, use that.
335
497
  return entry.url;
336
498
  }
337
499
  }
338
500
  }
501
+ /**
502
+ * Loads and parses the plugin package.json and returns it.
503
+ *
504
+ * @param {Plugin} plugin - The plugin to load the package from.
505
+ * @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.
506
+ */
339
507
  async parse(plugin) {
340
508
  const { promises } = await import('node:fs');
341
509
  try {
@@ -365,6 +533,7 @@ export class PluginManager extends EventEmitter {
365
533
  plugin.funding = this.getFunding(packageJson);
366
534
  if (!plugin.type)
367
535
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
536
+ // Check for @project-chip and @matter packages in dependencies and devDependencies
368
537
  const checkForProjectChipPackages = (dependencies) => {
369
538
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
370
539
  };
@@ -386,6 +555,7 @@ export class PluginManager extends EventEmitter {
386
555
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
387
556
  return null;
388
557
  }
558
+ // Check for matterbridge package in dependencies and devDependencies
389
559
  const checkForMatterbridgePackage = (dependencies) => {
390
560
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
391
561
  };
@@ -415,6 +585,16 @@ export class PluginManager extends EventEmitter {
415
585
  return null;
416
586
  }
417
587
  }
588
+ /**
589
+ * Enables a plugin by its name or path.
590
+ *
591
+ * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
592
+ * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
593
+ * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
594
+ *
595
+ * @param {string} nameOrPath - The name or path of the plugin to enable.
596
+ * @returns {Promise<Plugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
597
+ */
418
598
  async enable(nameOrPath) {
419
599
  const { promises } = await import('node:fs');
420
600
  if (!nameOrPath)
@@ -450,6 +630,16 @@ export class PluginManager extends EventEmitter {
450
630
  return null;
451
631
  }
452
632
  }
633
+ /**
634
+ * Enables a plugin by its name or path.
635
+ *
636
+ * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
637
+ * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
638
+ * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
639
+ *
640
+ * @param {string} nameOrPath - The name or path of the plugin to enable.
641
+ * @returns {Promise<Plugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
642
+ */
453
643
  async disable(nameOrPath) {
454
644
  const { promises } = await import('node:fs');
455
645
  if (!nameOrPath)
@@ -485,6 +675,16 @@ export class PluginManager extends EventEmitter {
485
675
  return null;
486
676
  }
487
677
  }
678
+ /**
679
+ * Removes a plugin by its name or path.
680
+ *
681
+ * This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
682
+ * It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
683
+ * the plugin's `package.json` file to retrieve its name and remove it.
684
+ *
685
+ * @param {string} nameOrPath - The name or path of the plugin to remove.
686
+ * @returns {Promise<Plugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
687
+ */
488
688
  async remove(nameOrPath) {
489
689
  const { promises } = await import('node:fs');
490
690
  if (!nameOrPath)
@@ -520,6 +720,17 @@ export class PluginManager extends EventEmitter {
520
720
  return null;
521
721
  }
522
722
  }
723
+ /**
724
+ * Adds a plugin by its name or path.
725
+ *
726
+ * This method adds a plugin to the plugins map and saves the updated plugin information to storage.
727
+ * It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
728
+ * registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
729
+ * and saves the updated plugin information to storage.
730
+ *
731
+ * @param {string} nameOrPath - The name or path of the plugin to add.
732
+ * @returns {Promise<Plugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
733
+ */
523
734
  async add(nameOrPath) {
524
735
  const { promises } = await import('node:fs');
525
736
  if (!nameOrPath)
@@ -559,6 +770,15 @@ export class PluginManager extends EventEmitter {
559
770
  return null;
560
771
  }
561
772
  }
773
+ /**
774
+ * Loads a plugin and returns the corresponding MatterbridgePlatform instance.
775
+ *
776
+ * @param {Plugin} plugin - The plugin to load.
777
+ * @param {boolean} start - Optional flag indicating whether to start the plugin after loading. Default is false.
778
+ * @param {string} message - Optional message to pass to the plugin when starting.
779
+ * @param {boolean} configure - Optional flag indicating whether to configure the plugin after loading. Default is false.
780
+ * @returns {Promise<MatterbridgePlatform | undefined>} A Promise that resolves to the loaded MatterbridgePlatform instance or undefined.
781
+ */
562
782
  async load(plugin, start = false, message = '', configure = false) {
563
783
  const { promises } = await import('node:fs');
564
784
  const { default: path } = await import('node:path');
@@ -572,15 +792,20 @@ export class PluginManager extends EventEmitter {
572
792
  }
573
793
  this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
574
794
  try {
795
+ // Load the package.json of the plugin
575
796
  const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
797
+ // Resolve the main module path relative to package.json
576
798
  const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
799
+ // Dynamically import the plugin
577
800
  const { pathToFileURL } = await import('node:url');
578
801
  const pluginUrl = pathToFileURL(pluginEntry);
579
802
  this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
580
803
  const pluginInstance = await import(pluginUrl.href);
581
804
  this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
805
+ // Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
582
806
  if (pluginInstance.default) {
583
807
  const config = await this.loadConfig(plugin);
808
+ // 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.
584
809
  plugin.name = packageJson.name;
585
810
  plugin.description = packageJson.description ?? 'No description';
586
811
  plugin.version = packageJson.version;
@@ -589,7 +814,7 @@ export class PluginManager extends EventEmitter {
589
814
  plugin.schemaJson = await this.loadSchema(plugin);
590
815
  config.name = plugin.name;
591
816
  config.version = packageJson.version;
592
- const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
817
+ const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: config.debug ? "debug" /* LogLevel.DEBUG */ : this.matterbridge.log.logLevel });
593
818
  const platform = pluginInstance.default(this.matterbridge, log, config);
594
819
  config.type = platform.type;
595
820
  platform.name = packageJson.name;
@@ -607,7 +832,7 @@ export class PluginManager extends EventEmitter {
607
832
  plugin.platform = platform;
608
833
  plugin.loaded = true;
609
834
  plugin.registeredDevices = 0;
610
- await this.saveToStorage();
835
+ await this.saveToStorage(); // Save the plugin to storage
611
836
  this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
612
837
  this.emit('loaded', plugin.name);
613
838
  if (start)
@@ -627,6 +852,14 @@ export class PluginManager extends EventEmitter {
627
852
  }
628
853
  return undefined;
629
854
  }
855
+ /**
856
+ * Starts a plugin.
857
+ *
858
+ * @param {Plugin} plugin - The plugin to start.
859
+ * @param {string} [message] - Optional message to pass to the plugin's onStart method.
860
+ * @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
861
+ * @returns {Promise<Plugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
862
+ */
630
863
  async start(plugin, message, configure = false) {
631
864
  if (!plugin.loaded) {
632
865
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -657,6 +890,12 @@ export class PluginManager extends EventEmitter {
657
890
  }
658
891
  return undefined;
659
892
  }
893
+ /**
894
+ * Configures a plugin.
895
+ *
896
+ * @param {Plugin} plugin - The plugin to configure.
897
+ * @returns {Promise<Plugin | undefined>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
898
+ */
660
899
  async configure(plugin) {
661
900
  if (!plugin.loaded) {
662
901
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -688,6 +927,18 @@ export class PluginManager extends EventEmitter {
688
927
  }
689
928
  return undefined;
690
929
  }
930
+ /**
931
+ * Shuts down a plugin.
932
+ *
933
+ * This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
934
+ * It logs the shutdown process and optionally removes all devices associated with the plugin.
935
+ *
936
+ * @param {Plugin} plugin - The plugin to shut down.
937
+ * @param {string} [reason] - The reason for shutting down the plugin.
938
+ * @param {boolean} [removeAllDevices] - Whether to remove all devices associated with the plugin.
939
+ * @param {boolean} [force] - Whether to force the shutdown even if the plugin is not loaded or started.
940
+ * @returns {Promise<Plugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
941
+ */
691
942
  async shutdown(plugin, reason, removeAllDevices = false, force = false) {
692
943
  this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
693
944
  if (!plugin.loaded) {
@@ -730,6 +981,15 @@ export class PluginManager extends EventEmitter {
730
981
  }
731
982
  return undefined;
732
983
  }
984
+ /**
985
+ * Loads the configuration for a plugin.
986
+ * If the configuration file exists, it reads the file and returns the parsed JSON data.
987
+ * If the configuration file does not exist, it creates a new file with default configuration and returns it.
988
+ * If any error occurs during file access or creation, it logs an error and return un empty config.
989
+ *
990
+ * @param {Plugin} plugin - The plugin for which to load the configuration.
991
+ * @returns {Promise<PlatformConfig>} A promise that resolves to the loaded or created configuration.
992
+ */
733
993
  async loadConfig(plugin) {
734
994
  const { default: path } = await import('node:path');
735
995
  const { promises } = await import('node:fs');
@@ -741,6 +1001,8 @@ export class PluginManager extends EventEmitter {
741
1001
  const data = await promises.readFile(configFile, 'utf8');
742
1002
  const config = JSON.parse(data);
743
1003
  this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
1004
+ // this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
1005
+ // The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
744
1006
  config.name = plugin.name;
745
1007
  config.type = plugin.type;
746
1008
  if (config.debug === undefined)
@@ -762,6 +1024,8 @@ export class PluginManager extends EventEmitter {
762
1024
  }
763
1025
  catch (_err) {
764
1026
  this.log.debug(`Default config file ${defaultConfigFile} for plugin ${plg}${plugin.name}${db} does not exist, creating new config file...`);
1027
+ // TODO: Remove this when all these plugins have their own default config file
1028
+ // istanbul ignore next if
765
1029
  if (plugin.name === 'matterbridge-zigbee2mqtt')
766
1030
  config = zigbee2mqtt_config;
767
1031
  else if (plugin.name === 'matterbridge-somfy-tahoma')
@@ -774,6 +1038,7 @@ export class PluginManager extends EventEmitter {
774
1038
  try {
775
1039
  await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
776
1040
  this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
1041
+ // this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
777
1042
  return config;
778
1043
  }
779
1044
  catch (err) {
@@ -787,6 +1052,19 @@ export class PluginManager extends EventEmitter {
787
1052
  }
788
1053
  }
789
1054
  }
1055
+ /**
1056
+ * Saves the configuration of a plugin to a file.
1057
+ *
1058
+ * This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
1059
+ * If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
1060
+ * is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
1061
+ * the error and rejects the promise.
1062
+ *
1063
+ * @param {Plugin} plugin - The plugin whose configuration is to be saved.
1064
+ * @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
1065
+ * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
1066
+ * @throws {Error} If the plugin's configuration is not found.
1067
+ */
790
1068
  async saveConfigFromPlugin(plugin, restartRequired = false) {
791
1069
  const { default: path } = await import('node:path');
792
1070
  const { promises } = await import('node:fs');
@@ -801,6 +1079,7 @@ export class PluginManager extends EventEmitter {
801
1079
  if (restartRequired)
802
1080
  plugin.restartRequired = true;
803
1081
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
1082
+ // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
804
1083
  return Promise.resolve();
805
1084
  }
806
1085
  catch (err) {
@@ -808,6 +1087,20 @@ export class PluginManager extends EventEmitter {
808
1087
  return Promise.reject(err);
809
1088
  }
810
1089
  }
1090
+ /**
1091
+ * Saves the configuration of a plugin from a JSON object to a file.
1092
+ *
1093
+ * This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
1094
+ * It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
1095
+ * the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
1096
+ * successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
1097
+ * during the file write operation, it logs the error and returns.
1098
+ *
1099
+ * @param {Plugin} plugin - The plugin whose configuration is to be saved.
1100
+ * @param {PlatformConfig} config - The configuration data to be saved.
1101
+ * @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
1102
+ * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
1103
+ */
811
1104
  async saveConfigFromJson(plugin, config, restartRequired = false) {
812
1105
  const { default: path } = await import('node:path');
813
1106
  const { promises } = await import('node:fs');
@@ -826,12 +1119,23 @@ export class PluginManager extends EventEmitter {
826
1119
  plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
827
1120
  }
828
1121
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
1122
+ // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
829
1123
  }
830
1124
  catch (err) {
831
1125
  logError(this.log, `Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}`, err);
832
1126
  return;
833
1127
  }
834
1128
  }
1129
+ /**
1130
+ * Loads the schema for a plugin.
1131
+ *
1132
+ * This method attempts to load the schema file for the specified plugin. If the schema file is found,
1133
+ * it reads and parses the file, updates the schema's title and description, and logs the process.
1134
+ * If the schema file is not found, it logs the event and loads a default schema for the plugin.
1135
+ *
1136
+ * @param {Plugin} plugin - The plugin whose schema is to be loaded.
1137
+ * @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
1138
+ */
835
1139
  async loadSchema(plugin) {
836
1140
  const { promises } = await import('node:fs');
837
1141
  const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
@@ -842,6 +1146,7 @@ export class PluginManager extends EventEmitter {
842
1146
  schema.title = plugin.description;
843
1147
  schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
844
1148
  this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
1149
+ // this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
845
1150
  return schema;
846
1151
  }
847
1152
  catch (_err) {
@@ -849,6 +1154,16 @@ export class PluginManager extends EventEmitter {
849
1154
  return this.getDefaultSchema(plugin);
850
1155
  }
851
1156
  }
1157
+ /**
1158
+ * Returns the default schema for a plugin.
1159
+ *
1160
+ * This method generates a default schema object for the specified plugin. The schema includes
1161
+ * metadata such as the plugin's title, description, version, and author. It also defines the
1162
+ * properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
1163
+ *
1164
+ * @param {Plugin} plugin - The plugin for which the default schema is to be generated.
1165
+ * @returns {PlatformSchema} The default schema object for the plugin.
1166
+ */
852
1167
  getDefaultSchema(plugin) {
853
1168
  return {
854
1169
  title: plugin.description,
@@ -879,3 +1194,4 @@ export class PluginManager extends EventEmitter {
879
1194
  };
880
1195
  }
881
1196
  }
1197
+ //# sourceMappingURL=pluginManager.js.map