matterbridge 3.3.3-dev-20251017-2e6040a → 3.3.3

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 (291) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/broadcastServer.d.ts +105 -0
  3. package/dist/broadcastServer.d.ts.map +1 -0
  4. package/dist/broadcastServer.js +86 -1
  5. package/dist/broadcastServer.js.map +1 -0
  6. package/dist/broadcastServerTypes.d.ts +719 -0
  7. package/dist/broadcastServerTypes.d.ts.map +1 -0
  8. package/dist/broadcastServerTypes.js +24 -0
  9. package/dist/broadcastServerTypes.js.map +1 -0
  10. package/dist/cli.d.ts +26 -0
  11. package/dist/cli.d.ts.map +1 -0
  12. package/dist/cli.js +135 -5
  13. package/dist/cli.js.map +1 -0
  14. package/dist/cliEmitter.d.ts +50 -0
  15. package/dist/cliEmitter.d.ts.map +1 -0
  16. package/dist/cliEmitter.js +37 -0
  17. package/dist/cliEmitter.js.map +1 -0
  18. package/dist/cliHistory.d.ts +74 -0
  19. package/dist/cliHistory.d.ts.map +1 -0
  20. package/dist/cliHistory.js +44 -0
  21. package/dist/cliHistory.js.map +1 -0
  22. package/dist/clusters/export.d.ts +2 -0
  23. package/dist/clusters/export.d.ts.map +1 -0
  24. package/dist/clusters/export.js +2 -0
  25. package/dist/clusters/export.js.map +1 -0
  26. package/dist/defaultConfigSchema.d.ts +28 -0
  27. package/dist/defaultConfigSchema.d.ts.map +1 -0
  28. package/dist/defaultConfigSchema.js +24 -0
  29. package/dist/defaultConfigSchema.js.map +1 -0
  30. package/dist/deviceManager.d.ts +117 -0
  31. package/dist/deviceManager.d.ts.map +1 -0
  32. package/dist/deviceManager.js +124 -1
  33. package/dist/deviceManager.js.map +1 -0
  34. package/dist/devices/airConditioner.d.ts +98 -0
  35. package/dist/devices/airConditioner.d.ts.map +1 -0
  36. package/dist/devices/airConditioner.js +57 -0
  37. package/dist/devices/airConditioner.js.map +1 -0
  38. package/dist/devices/batteryStorage.d.ts +48 -0
  39. package/dist/devices/batteryStorage.d.ts.map +1 -0
  40. package/dist/devices/batteryStorage.js +48 -1
  41. package/dist/devices/batteryStorage.js.map +1 -0
  42. package/dist/devices/cooktop.d.ts +60 -0
  43. package/dist/devices/cooktop.d.ts.map +1 -0
  44. package/dist/devices/cooktop.js +55 -0
  45. package/dist/devices/cooktop.js.map +1 -0
  46. package/dist/devices/dishwasher.d.ts +71 -0
  47. package/dist/devices/dishwasher.d.ts.map +1 -0
  48. package/dist/devices/dishwasher.js +57 -0
  49. package/dist/devices/dishwasher.js.map +1 -0
  50. package/dist/devices/evse.d.ts +75 -0
  51. package/dist/devices/evse.d.ts.map +1 -0
  52. package/dist/devices/evse.js +74 -10
  53. package/dist/devices/evse.js.map +1 -0
  54. package/dist/devices/export.d.ts +17 -0
  55. package/dist/devices/export.d.ts.map +1 -0
  56. package/dist/devices/export.js +5 -0
  57. package/dist/devices/export.js.map +1 -0
  58. package/dist/devices/extractorHood.d.ts +46 -0
  59. package/dist/devices/extractorHood.d.ts.map +1 -0
  60. package/dist/devices/extractorHood.js +42 -0
  61. package/dist/devices/extractorHood.js.map +1 -0
  62. package/dist/devices/heatPump.d.ts +47 -0
  63. package/dist/devices/heatPump.d.ts.map +1 -0
  64. package/dist/devices/heatPump.js +50 -2
  65. package/dist/devices/heatPump.js.map +1 -0
  66. package/dist/devices/laundryDryer.d.ts +67 -0
  67. package/dist/devices/laundryDryer.d.ts.map +1 -0
  68. package/dist/devices/laundryDryer.js +62 -3
  69. package/dist/devices/laundryDryer.js.map +1 -0
  70. package/dist/devices/laundryWasher.d.ts +81 -0
  71. package/dist/devices/laundryWasher.d.ts.map +1 -0
  72. package/dist/devices/laundryWasher.js +70 -4
  73. package/dist/devices/laundryWasher.js.map +1 -0
  74. package/dist/devices/microwaveOven.d.ts +168 -0
  75. package/dist/devices/microwaveOven.d.ts.map +1 -0
  76. package/dist/devices/microwaveOven.js +88 -5
  77. package/dist/devices/microwaveOven.js.map +1 -0
  78. package/dist/devices/oven.d.ts +105 -0
  79. package/dist/devices/oven.d.ts.map +1 -0
  80. package/dist/devices/oven.js +85 -0
  81. package/dist/devices/oven.js.map +1 -0
  82. package/dist/devices/refrigerator.d.ts +118 -0
  83. package/dist/devices/refrigerator.d.ts.map +1 -0
  84. package/dist/devices/refrigerator.js +102 -0
  85. package/dist/devices/refrigerator.js.map +1 -0
  86. package/dist/devices/roboticVacuumCleaner.d.ts +112 -0
  87. package/dist/devices/roboticVacuumCleaner.d.ts.map +1 -0
  88. package/dist/devices/roboticVacuumCleaner.js +100 -9
  89. package/dist/devices/roboticVacuumCleaner.js.map +1 -0
  90. package/dist/devices/solarPower.d.ts +40 -0
  91. package/dist/devices/solarPower.d.ts.map +1 -0
  92. package/dist/devices/solarPower.js +38 -0
  93. package/dist/devices/solarPower.js.map +1 -0
  94. package/dist/devices/speaker.d.ts +87 -0
  95. package/dist/devices/speaker.d.ts.map +1 -0
  96. package/dist/devices/speaker.js +84 -0
  97. package/dist/devices/speaker.js.map +1 -0
  98. package/dist/devices/temperatureControl.d.ts +166 -0
  99. package/dist/devices/temperatureControl.d.ts.map +1 -0
  100. package/dist/devices/temperatureControl.js +25 -3
  101. package/dist/devices/temperatureControl.js.map +1 -0
  102. package/dist/devices/waterHeater.d.ts +111 -0
  103. package/dist/devices/waterHeater.d.ts.map +1 -0
  104. package/dist/devices/waterHeater.js +82 -2
  105. package/dist/devices/waterHeater.js.map +1 -0
  106. package/dist/dgram/coap.d.ts +205 -0
  107. package/dist/dgram/coap.d.ts.map +1 -0
  108. package/dist/dgram/coap.js +126 -13
  109. package/dist/dgram/coap.js.map +1 -0
  110. package/dist/dgram/dgram.d.ts +141 -0
  111. package/dist/dgram/dgram.d.ts.map +1 -0
  112. package/dist/dgram/dgram.js +114 -2
  113. package/dist/dgram/dgram.js.map +1 -0
  114. package/dist/dgram/mb_coap.d.ts +24 -0
  115. package/dist/dgram/mb_coap.d.ts.map +1 -0
  116. package/dist/dgram/mb_coap.js +41 -3
  117. package/dist/dgram/mb_coap.js.map +1 -0
  118. package/dist/dgram/mb_mdns.d.ts +24 -0
  119. package/dist/dgram/mb_mdns.d.ts.map +1 -0
  120. package/dist/dgram/mb_mdns.js +80 -15
  121. package/dist/dgram/mb_mdns.js.map +1 -0
  122. package/dist/dgram/mdns.d.ts +290 -0
  123. package/dist/dgram/mdns.d.ts.map +1 -0
  124. package/dist/dgram/mdns.js +299 -137
  125. package/dist/dgram/mdns.js.map +1 -0
  126. package/dist/dgram/multicast.d.ts +67 -0
  127. package/dist/dgram/multicast.d.ts.map +1 -0
  128. package/dist/dgram/multicast.js +62 -1
  129. package/dist/dgram/multicast.js.map +1 -0
  130. package/dist/dgram/unicast.d.ts +56 -0
  131. package/dist/dgram/unicast.d.ts.map +1 -0
  132. package/dist/dgram/unicast.js +54 -0
  133. package/dist/dgram/unicast.js.map +1 -0
  134. package/dist/frontend.d.ts +235 -0
  135. package/dist/frontend.d.ts.map +1 -0
  136. package/dist/frontend.js +415 -29
  137. package/dist/frontend.js.map +1 -0
  138. package/dist/frontendTypes.d.ts +529 -0
  139. package/dist/frontendTypes.d.ts.map +1 -0
  140. package/dist/frontendTypes.js +45 -0
  141. package/dist/frontendTypes.js.map +1 -0
  142. package/dist/helpers.d.ts +48 -0
  143. package/dist/helpers.d.ts.map +1 -0
  144. package/dist/helpers.js +53 -0
  145. package/dist/helpers.js.map +1 -0
  146. package/dist/index.d.ts +33 -0
  147. package/dist/index.d.ts.map +1 -0
  148. package/dist/index.js +25 -0
  149. package/dist/index.js.map +1 -0
  150. package/dist/logger/export.d.ts +2 -0
  151. package/dist/logger/export.d.ts.map +1 -0
  152. package/dist/logger/export.js +1 -0
  153. package/dist/logger/export.js.map +1 -0
  154. package/dist/matter/behaviors.d.ts +2 -0
  155. package/dist/matter/behaviors.d.ts.map +1 -0
  156. package/dist/matter/behaviors.js +2 -0
  157. package/dist/matter/behaviors.js.map +1 -0
  158. package/dist/matter/clusters.d.ts +2 -0
  159. package/dist/matter/clusters.d.ts.map +1 -0
  160. package/dist/matter/clusters.js +2 -0
  161. package/dist/matter/clusters.js.map +1 -0
  162. package/dist/matter/devices.d.ts +2 -0
  163. package/dist/matter/devices.d.ts.map +1 -0
  164. package/dist/matter/devices.js +2 -0
  165. package/dist/matter/devices.js.map +1 -0
  166. package/dist/matter/endpoints.d.ts +2 -0
  167. package/dist/matter/endpoints.d.ts.map +1 -0
  168. package/dist/matter/endpoints.js +2 -0
  169. package/dist/matter/endpoints.js.map +1 -0
  170. package/dist/matter/export.d.ts +5 -0
  171. package/dist/matter/export.d.ts.map +1 -0
  172. package/dist/matter/export.js +3 -0
  173. package/dist/matter/export.js.map +1 -0
  174. package/dist/matter/types.d.ts +3 -0
  175. package/dist/matter/types.d.ts.map +1 -0
  176. package/dist/matter/types.js +3 -0
  177. package/dist/matter/types.js.map +1 -0
  178. package/dist/matterbridge.d.ts +469 -0
  179. package/dist/matterbridge.d.ts.map +1 -0
  180. package/dist/matterbridge.js +795 -45
  181. package/dist/matterbridge.js.map +1 -0
  182. package/dist/matterbridgeAccessoryPlatform.d.ts +42 -0
  183. package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
  184. package/dist/matterbridgeAccessoryPlatform.js +36 -0
  185. package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
  186. package/dist/matterbridgeBehaviors.d.ts +2399 -0
  187. package/dist/matterbridgeBehaviors.d.ts.map +1 -0
  188. package/dist/matterbridgeBehaviors.js +71 -5
  189. package/dist/matterbridgeBehaviors.js.map +1 -0
  190. package/dist/matterbridgeDeviceTypes.d.ts +761 -0
  191. package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
  192. package/dist/matterbridgeDeviceTypes.js +630 -17
  193. package/dist/matterbridgeDeviceTypes.js.map +1 -0
  194. package/dist/matterbridgeDynamicPlatform.d.ts +42 -0
  195. package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
  196. package/dist/matterbridgeDynamicPlatform.js +36 -0
  197. package/dist/matterbridgeDynamicPlatform.js.map +1 -0
  198. package/dist/matterbridgeEndpoint.d.ts +1545 -0
  199. package/dist/matterbridgeEndpoint.d.ts.map +1 -0
  200. package/dist/matterbridgeEndpoint.js +1412 -58
  201. package/dist/matterbridgeEndpoint.js.map +1 -0
  202. package/dist/matterbridgeEndpointHelpers.d.ts +560 -0
  203. package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
  204. package/dist/matterbridgeEndpointHelpers.js +368 -10
  205. package/dist/matterbridgeEndpointHelpers.js.map +1 -0
  206. package/dist/matterbridgePlatform.d.ts +402 -0
  207. package/dist/matterbridgePlatform.d.ts.map +1 -0
  208. package/dist/matterbridgePlatform.js +341 -1
  209. package/dist/matterbridgePlatform.js.map +1 -0
  210. package/dist/matterbridgeTypes.d.ts +209 -0
  211. package/dist/matterbridgeTypes.d.ts.map +1 -0
  212. package/dist/matterbridgeTypes.js +26 -0
  213. package/dist/matterbridgeTypes.js.map +1 -0
  214. package/dist/pluginManager.d.ts +353 -0
  215. package/dist/pluginManager.d.ts.map +1 -0
  216. package/dist/pluginManager.js +325 -3
  217. package/dist/pluginManager.js.map +1 -0
  218. package/dist/shelly.d.ts +174 -0
  219. package/dist/shelly.d.ts.map +1 -0
  220. package/dist/shelly.js +168 -7
  221. package/dist/shelly.js.map +1 -0
  222. package/dist/storage/export.d.ts +2 -0
  223. package/dist/storage/export.d.ts.map +1 -0
  224. package/dist/storage/export.js +1 -0
  225. package/dist/storage/export.js.map +1 -0
  226. package/dist/update.d.ts +75 -0
  227. package/dist/update.d.ts.map +1 -0
  228. package/dist/update.js +69 -0
  229. package/dist/update.js.map +1 -0
  230. package/dist/utils/colorUtils.d.ts +99 -0
  231. package/dist/utils/colorUtils.d.ts.map +1 -0
  232. package/dist/utils/colorUtils.js +97 -2
  233. package/dist/utils/colorUtils.js.map +1 -0
  234. package/dist/utils/commandLine.d.ts +59 -0
  235. package/dist/utils/commandLine.d.ts.map +1 -0
  236. package/dist/utils/commandLine.js +54 -0
  237. package/dist/utils/commandLine.js.map +1 -0
  238. package/dist/utils/copyDirectory.d.ts +33 -0
  239. package/dist/utils/copyDirectory.d.ts.map +1 -0
  240. package/dist/utils/copyDirectory.js +38 -1
  241. package/dist/utils/copyDirectory.js.map +1 -0
  242. package/dist/utils/createDirectory.d.ts +34 -0
  243. package/dist/utils/createDirectory.d.ts.map +1 -0
  244. package/dist/utils/createDirectory.js +33 -0
  245. package/dist/utils/createDirectory.js.map +1 -0
  246. package/dist/utils/createZip.d.ts +39 -0
  247. package/dist/utils/createZip.d.ts.map +1 -0
  248. package/dist/utils/createZip.js +47 -2
  249. package/dist/utils/createZip.js.map +1 -0
  250. package/dist/utils/deepCopy.d.ts +32 -0
  251. package/dist/utils/deepCopy.d.ts.map +1 -0
  252. package/dist/utils/deepCopy.js +39 -0
  253. package/dist/utils/deepCopy.js.map +1 -0
  254. package/dist/utils/deepEqual.d.ts +54 -0
  255. package/dist/utils/deepEqual.d.ts.map +1 -0
  256. package/dist/utils/deepEqual.js +72 -1
  257. package/dist/utils/deepEqual.js.map +1 -0
  258. package/dist/utils/error.d.ts +44 -0
  259. package/dist/utils/error.d.ts.map +1 -0
  260. package/dist/utils/error.js +41 -0
  261. package/dist/utils/error.js.map +1 -0
  262. package/dist/utils/export.d.ts +13 -0
  263. package/dist/utils/export.d.ts.map +1 -0
  264. package/dist/utils/export.js +1 -0
  265. package/dist/utils/export.js.map +1 -0
  266. package/dist/utils/hex.d.ts +89 -0
  267. package/dist/utils/hex.d.ts.map +1 -0
  268. package/dist/utils/hex.js +124 -0
  269. package/dist/utils/hex.js.map +1 -0
  270. package/dist/utils/isvalid.d.ts +103 -0
  271. package/dist/utils/isvalid.d.ts.map +1 -0
  272. package/dist/utils/isvalid.js +101 -0
  273. package/dist/utils/isvalid.js.map +1 -0
  274. package/dist/utils/jestHelpers.d.ts +137 -0
  275. package/dist/utils/jestHelpers.d.ts.map +1 -0
  276. package/dist/utils/jestHelpers.js +153 -3
  277. package/dist/utils/jestHelpers.js.map +1 -0
  278. package/dist/utils/network.d.ts +115 -0
  279. package/dist/utils/network.d.ts.map +1 -0
  280. package/dist/utils/network.js +108 -5
  281. package/dist/utils/network.js.map +1 -0
  282. package/dist/utils/spawn.d.ts +35 -0
  283. package/dist/utils/spawn.d.ts.map +1 -0
  284. package/dist/utils/spawn.js +71 -0
  285. package/dist/utils/spawn.js.map +1 -0
  286. package/dist/utils/wait.d.ts +54 -0
  287. package/dist/utils/wait.d.ts.map +1 -0
  288. package/dist/utils/wait.js +60 -8
  289. package/dist/utils/wait.js.map +1 -0
  290. package/npm-shrinkwrap.json +2 -2
  291. 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));
@@ -53,28 +86,69 @@ export class PluginManager extends EventEmitter {
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,45 @@ 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
+ * This method retrieves an array of registered plugins from the storage and converts it
224
+ * into a map where the plugin names are the keys and the plugin objects are the values.
225
+ *
226
+ * @returns {Promise<Plugin[]>} A promise that resolves to an array of registered plugins.
227
+ */
130
228
  async loadFromStorage() {
131
229
  if (!this.matterbridge.nodeContext) {
132
230
  throw new Error('loadFromStorage: node context is not available.');
133
231
  }
232
+ // Load the array from storage and convert it to a map
134
233
  const pluginsArray = await this.matterbridge.nodeContext.get('plugins', []);
135
234
  for (const plugin of pluginsArray)
136
235
  this._plugins.set(plugin.name, plugin);
137
236
  return pluginsArray;
138
237
  }
238
+ /**
239
+ * Loads registered plugins from storage.
240
+ *
241
+ * This method retrieves an array of registered plugins from the storage and converts it
242
+ * into a map where the plugin names are the keys and the plugin objects are the values.
243
+ *
244
+ * @returns {Promise<Plugin[]>} A promise that resolves to an array of registered plugins.
245
+ */
139
246
  async saveToStorage() {
140
247
  if (!this.matterbridge.nodeContext) {
141
248
  throw new Error('loadFromStorage: node context is not available.');
142
249
  }
250
+ // Convert the map to an array
143
251
  const plugins = [];
144
252
  for (const plugin of this.array()) {
145
253
  plugins.push({
@@ -156,13 +264,21 @@ export class PluginManager extends EventEmitter {
156
264
  this.log.debug(`Saved ${BLUE}${plugins.length}${db} plugins to storage`);
157
265
  return plugins.length;
158
266
  }
267
+ /**
268
+ * Resolves the name of a plugin by loading and parsing its package.json file.
269
+ *
270
+ * @param {string} pluginPath - The path to the plugin or the path to the plugin's package.json file.
271
+ * @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.
272
+ */
159
273
  async resolve(pluginPath) {
160
274
  const { default: path } = await import('node:path');
161
275
  const { promises } = await import('node:fs');
162
276
  if (!pluginPath.endsWith('package.json'))
163
277
  pluginPath = path.join(pluginPath, 'package.json');
278
+ // Resolve the package.json of the plugin
164
279
  let packageJsonPath = path.resolve(pluginPath);
165
280
  this.log.debug(`Resolving plugin path ${plg}${packageJsonPath}${db}`);
281
+ // Check if the package.json file exists
166
282
  try {
167
283
  await promises.access(packageJsonPath);
168
284
  }
@@ -172,7 +288,9 @@ export class PluginManager extends EventEmitter {
172
288
  this.log.debug(`Trying at ${plg}${packageJsonPath}${db}`);
173
289
  }
174
290
  try {
291
+ // Load the package.json of the plugin
175
292
  const packageJson = JSON.parse(await promises.readFile(packageJsonPath, 'utf8'));
293
+ // Check for main issues
176
294
  if (!packageJson.name) {
177
295
  this.log.error(`Package.json name not found at ${packageJsonPath}`);
178
296
  return null;
@@ -185,6 +303,7 @@ export class PluginManager extends EventEmitter {
185
303
  this.log.error(`Plugin at ${packageJsonPath} has no main entrypoint in package.json`);
186
304
  return null;
187
305
  }
306
+ // Check for @project-chip and @matter packages in dependencies and devDependencies
188
307
  const checkForProjectChipPackages = (dependencies) => {
189
308
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
190
309
  };
@@ -206,6 +325,7 @@ export class PluginManager extends EventEmitter {
206
325
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
207
326
  return null;
208
327
  }
328
+ // Check for matterbridge package in dependencies and devDependencies
209
329
  const checkForMatterbridgePackage = (dependencies) => {
210
330
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
211
331
  };
@@ -235,6 +355,12 @@ export class PluginManager extends EventEmitter {
235
355
  return null;
236
356
  }
237
357
  }
358
+ /**
359
+ * Installs a package globally using npm.
360
+ *
361
+ * @param {string} packageName - The name of the package to install.
362
+ * @returns {Promise<boolean>} A promise that resolves to true if the installation was successful, false otherwise.
363
+ */
238
364
  async install(packageName) {
239
365
  const { spawnCommand } = await import('./utils/spawn.js');
240
366
  try {
@@ -261,6 +387,12 @@ export class PluginManager extends EventEmitter {
261
387
  return false;
262
388
  }
263
389
  }
390
+ /**
391
+ * Uninstalls a package globally using npm.
392
+ *
393
+ * @param {string} packageName - The name of the package to uninstall.
394
+ * @returns {Promise<boolean>} A promise that resolves to true if the uninstallation was successful, false otherwise.
395
+ */
264
396
  async uninstall(packageName) {
265
397
  const { spawnCommand } = await import('./utils/spawn.js');
266
398
  packageName = packageName.replace(/@.*$/, '');
@@ -281,6 +413,12 @@ export class PluginManager extends EventEmitter {
281
413
  return false;
282
414
  }
283
415
  }
416
+ /**
417
+ * Get the author of a plugin from its package.json.
418
+ *
419
+ * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
420
+ * @returns {string} The author of the plugin, or 'Unknown author' if not found.
421
+ */
284
422
  getAuthor(packageJson) {
285
423
  if (packageJson.author && typeof packageJson.author === 'string')
286
424
  return packageJson.author;
@@ -288,6 +426,12 @@ export class PluginManager extends EventEmitter {
288
426
  return packageJson.author.name;
289
427
  return 'Unknown author';
290
428
  }
429
+ /**
430
+ * Get the homepage of a plugin from its package.json.
431
+ *
432
+ * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
433
+ * @returns {string | undefined} The homepage of the plugin, or undefined if not found.
434
+ */
291
435
  getHomepage(packageJson) {
292
436
  if (packageJson.homepage && typeof packageJson.homepage === 'string' && packageJson.homepage.includes('http')) {
293
437
  return packageJson.homepage.replace('git+', '').replace('.git', '');
@@ -296,7 +440,14 @@ export class PluginManager extends EventEmitter {
296
440
  return packageJson.repository.url.replace('git+', '').replace('.git', '');
297
441
  }
298
442
  }
443
+ /**
444
+ * Get the help URL of a plugin from its package.json.
445
+ *
446
+ * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
447
+ * @returns {string | undefined} The URL to the help page or to the README file, or undefined if not found.
448
+ */
299
449
  getHelp(packageJson) {
450
+ // If there's a help field that looks like a URL, return it.
300
451
  if (packageJson.help && typeof packageJson.help === 'string' && packageJson.help.startsWith('http')) {
301
452
  return packageJson.help;
302
453
  }
@@ -307,7 +458,14 @@ export class PluginManager extends EventEmitter {
307
458
  return packageJson.homepage.replace('git+', '').replace('.git', '');
308
459
  }
309
460
  }
461
+ /**
462
+ * Get the changelog URL of a plugin from its package.json.
463
+ *
464
+ * @param {Record<string, string | number | Record<string, string | number | object>>} packageJson - The package.json object of the plugin.
465
+ * @returns {string | undefined} The URL to the CHANGELOG file, or undefined if not found.
466
+ */
310
467
  getChangelog(packageJson) {
468
+ // If there's a changelog field that looks like a URL, return it.
311
469
  if (packageJson.changelog && typeof packageJson.changelog === 'string' && packageJson.changelog.startsWith('http')) {
312
470
  return packageJson.changelog;
313
471
  }
@@ -318,6 +476,13 @@ export class PluginManager extends EventEmitter {
318
476
  return packageJson.homepage.replace('git+', '').replace('.git', '');
319
477
  }
320
478
  }
479
+ /**
480
+ * Get the first funding URL(s) of a plugin from its package.json.
481
+ *
482
+ * @param {Record<string, any>} packageJson - The package.json object of the plugin.
483
+ * @returns {string | undefined} The first funding URLs, or undefined if not found.
484
+ */
485
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
321
486
  getFunding(packageJson) {
322
487
  const funding = packageJson.funding;
323
488
  if (!funding)
@@ -326,16 +491,25 @@ export class PluginManager extends EventEmitter {
326
491
  return;
327
492
  if (typeof funding === 'string' && funding.startsWith('http'))
328
493
  return funding;
494
+ // Normalize funding into an array.
329
495
  const fundingEntries = Array.isArray(funding) ? funding : [funding];
330
496
  for (const entry of fundingEntries) {
331
497
  if (entry && typeof entry === 'string' && entry.startsWith('http')) {
498
+ // If the funding entry is a string, assume it is a URL.
332
499
  return entry;
333
500
  }
334
501
  else if (entry && typeof entry === 'object' && typeof entry.url === 'string' && entry.url.startsWith('http')) {
502
+ // If it's an object with a 'url' property, use that.
335
503
  return entry.url;
336
504
  }
337
505
  }
338
506
  }
507
+ /**
508
+ * Loads and parses the plugin package.json and returns it.
509
+ *
510
+ * @param {Plugin} plugin - The plugin to load the package from.
511
+ * @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.
512
+ */
339
513
  async parse(plugin) {
340
514
  const { promises } = await import('node:fs');
341
515
  try {
@@ -365,6 +539,7 @@ export class PluginManager extends EventEmitter {
365
539
  plugin.funding = this.getFunding(packageJson);
366
540
  if (!plugin.type)
367
541
  this.log.warn(`Plugin ${plg}${plugin.name}${wr} has no type`);
542
+ // Check for @project-chip and @matter packages in dependencies and devDependencies
368
543
  const checkForProjectChipPackages = (dependencies) => {
369
544
  return Object.keys(dependencies).filter((pkg) => pkg.startsWith('@project-chip') || pkg.startsWith('@matter'));
370
545
  };
@@ -386,6 +561,7 @@ export class PluginManager extends EventEmitter {
386
561
  this.log.error(`Please open an issue on the plugin repository to remove them.`);
387
562
  return null;
388
563
  }
564
+ // Check for matterbridge package in dependencies and devDependencies
389
565
  const checkForMatterbridgePackage = (dependencies) => {
390
566
  return Object.keys(dependencies).filter((pkg) => pkg === 'matterbridge');
391
567
  };
@@ -415,6 +591,16 @@ export class PluginManager extends EventEmitter {
415
591
  return null;
416
592
  }
417
593
  }
594
+ /**
595
+ * Enables a plugin by its name or path.
596
+ *
597
+ * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
598
+ * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
599
+ * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
600
+ *
601
+ * @param {string} nameOrPath - The name or path of the plugin to enable.
602
+ * @returns {Promise<Plugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
603
+ */
418
604
  async enable(nameOrPath) {
419
605
  const { promises } = await import('node:fs');
420
606
  if (!nameOrPath)
@@ -450,6 +636,16 @@ export class PluginManager extends EventEmitter {
450
636
  return null;
451
637
  }
452
638
  }
639
+ /**
640
+ * Enables a plugin by its name or path.
641
+ *
642
+ * This method enables a plugin by setting its `enabled` property to `true` and saving the updated
643
+ * plugin information to storage. It first checks if the plugin is already registered in the `_plugins` map.
644
+ * If not, it attempts to resolve the plugin's `package.json` file to retrieve its name and enable it.
645
+ *
646
+ * @param {string} nameOrPath - The name or path of the plugin to enable.
647
+ * @returns {Promise<Plugin | null>} A promise that resolves to the enabled plugin object, or null if the plugin could not be enabled.
648
+ */
453
649
  async disable(nameOrPath) {
454
650
  const { promises } = await import('node:fs');
455
651
  if (!nameOrPath)
@@ -485,6 +681,16 @@ export class PluginManager extends EventEmitter {
485
681
  return null;
486
682
  }
487
683
  }
684
+ /**
685
+ * Removes a plugin by its name or path.
686
+ *
687
+ * This method removes a plugin from the `_plugins` map and saves the updated plugin information to storage.
688
+ * It first checks if the plugin is already registered in the `_plugins` map. If not, it attempts to resolve
689
+ * the plugin's `package.json` file to retrieve its name and remove it.
690
+ *
691
+ * @param {string} nameOrPath - The name or path of the plugin to remove.
692
+ * @returns {Promise<Plugin | null>} A promise that resolves to the removed plugin object, or null if the plugin could not be removed.
693
+ */
488
694
  async remove(nameOrPath) {
489
695
  const { promises } = await import('node:fs');
490
696
  if (!nameOrPath)
@@ -520,6 +726,17 @@ export class PluginManager extends EventEmitter {
520
726
  return null;
521
727
  }
522
728
  }
729
+ /**
730
+ * Adds a plugin by its name or path.
731
+ *
732
+ * This method adds a plugin to the plugins map and saves the updated plugin information to storage.
733
+ * It first resolves the plugin's `package.json` file to retrieve its details. If the plugin is already
734
+ * registered, it logs an info message and returns null. Otherwise, it registers the plugin, enables it,
735
+ * and saves the updated plugin information to storage.
736
+ *
737
+ * @param {string} nameOrPath - The name or path of the plugin to add.
738
+ * @returns {Promise<Plugin | null>} A promise that resolves to the added plugin object, or null if the plugin could not be added.
739
+ */
523
740
  async add(nameOrPath) {
524
741
  const { promises } = await import('node:fs');
525
742
  if (!nameOrPath)
@@ -559,6 +776,15 @@ export class PluginManager extends EventEmitter {
559
776
  return null;
560
777
  }
561
778
  }
779
+ /**
780
+ * Loads a plugin and returns the corresponding MatterbridgePlatform instance.
781
+ *
782
+ * @param {Plugin} plugin - The plugin to load.
783
+ * @param {boolean} start - Optional flag indicating whether to start the plugin after loading. Default is false.
784
+ * @param {string} message - Optional message to pass to the plugin when starting.
785
+ * @param {boolean} configure - Optional flag indicating whether to configure the plugin after loading. Default is false.
786
+ * @returns {Promise<MatterbridgePlatform | undefined>} A Promise that resolves to the loaded MatterbridgePlatform instance or undefined.
787
+ */
562
788
  async load(plugin, start = false, message = '', configure = false) {
563
789
  const { promises } = await import('node:fs');
564
790
  const { default: path } = await import('node:path');
@@ -572,15 +798,20 @@ export class PluginManager extends EventEmitter {
572
798
  }
573
799
  this.log.info(`Loading plugin ${plg}${plugin.name}${nf} type ${typ}${plugin.type}${nf}`);
574
800
  try {
801
+ // Load the package.json of the plugin
575
802
  const packageJson = JSON.parse(await promises.readFile(plugin.path, 'utf8'));
803
+ // Resolve the main module path relative to package.json
576
804
  const pluginEntry = path.resolve(path.dirname(plugin.path), packageJson.main);
805
+ // Dynamically import the plugin
577
806
  const { pathToFileURL } = await import('node:url');
578
807
  const pluginUrl = pathToFileURL(pluginEntry);
579
808
  this.log.debug(`Importing plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
580
809
  const pluginInstance = await import(pluginUrl.href);
581
810
  this.log.debug(`Imported plugin ${plg}${plugin.name}${db} from ${pluginUrl.href}`);
811
+ // Call the default export function of the plugin, passing this MatterBridge instance, the log and the config
582
812
  if (pluginInstance.default) {
583
813
  const config = await this.loadConfig(plugin);
814
+ // 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
815
  plugin.name = packageJson.name;
585
816
  plugin.description = packageJson.description ?? 'No description';
586
817
  plugin.version = packageJson.version;
@@ -589,7 +820,7 @@ export class PluginManager extends EventEmitter {
589
820
  plugin.schemaJson = await this.loadSchema(plugin);
590
821
  config.name = plugin.name;
591
822
  config.version = packageJson.version;
592
- const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4, logLevel: config.debug ? "debug" : this.matterbridge.log.logLevel });
823
+ const log = new AnsiLogger({ logName: plugin.description, logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: config.debug ? "debug" /* LogLevel.DEBUG */ : this.matterbridge.log.logLevel });
593
824
  const platform = pluginInstance.default(this.matterbridge, log, config);
594
825
  config.type = platform.type;
595
826
  platform.name = packageJson.name;
@@ -607,7 +838,7 @@ export class PluginManager extends EventEmitter {
607
838
  plugin.platform = platform;
608
839
  plugin.loaded = true;
609
840
  plugin.registeredDevices = 0;
610
- await this.saveToStorage();
841
+ await this.saveToStorage(); // Save the plugin to storage
611
842
  this.log.notice(`Loaded plugin ${plg}${plugin.name}${nt} type ${typ}${platform.type}${nt} (entrypoint ${UNDERLINE}${pluginEntry}${UNDERLINEOFF})`);
612
843
  this.emit('loaded', plugin.name);
613
844
  if (start)
@@ -627,6 +858,14 @@ export class PluginManager extends EventEmitter {
627
858
  }
628
859
  return undefined;
629
860
  }
861
+ /**
862
+ * Starts a plugin.
863
+ *
864
+ * @param {Plugin} plugin - The plugin to start.
865
+ * @param {string} [message] - Optional message to pass to the plugin's onStart method.
866
+ * @param {boolean} [configure] - Indicates whether to configure the plugin after starting (default false).
867
+ * @returns {Promise<Plugin | undefined>} A promise that resolves when the plugin is started successfully, or rejects with an error if starting the plugin fails.
868
+ */
630
869
  async start(plugin, message, configure = false) {
631
870
  if (!plugin.loaded) {
632
871
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -657,6 +896,12 @@ export class PluginManager extends EventEmitter {
657
896
  }
658
897
  return undefined;
659
898
  }
899
+ /**
900
+ * Configures a plugin.
901
+ *
902
+ * @param {Plugin} plugin - The plugin to configure.
903
+ * @returns {Promise<Plugin | undefined>} A promise that resolves when the plugin is configured successfully, or rejects with an error if configuration fails.
904
+ */
660
905
  async configure(plugin) {
661
906
  if (!plugin.loaded) {
662
907
  this.log.error(`Plugin ${plg}${plugin.name}${er} not loaded`);
@@ -688,6 +933,18 @@ export class PluginManager extends EventEmitter {
688
933
  }
689
934
  return undefined;
690
935
  }
936
+ /**
937
+ * Shuts down a plugin.
938
+ *
939
+ * This method shuts down a plugin by calling its `onShutdown` method and resetting its state.
940
+ * It logs the shutdown process and optionally removes all devices associated with the plugin.
941
+ *
942
+ * @param {Plugin} plugin - The plugin to shut down.
943
+ * @param {string} [reason] - The reason for shutting down the plugin.
944
+ * @param {boolean} [removeAllDevices] - Whether to remove all devices associated with the plugin.
945
+ * @param {boolean} [force] - Whether to force the shutdown even if the plugin is not loaded or started.
946
+ * @returns {Promise<Plugin | undefined>} A promise that resolves to the shut down plugin object, or undefined if the shutdown failed.
947
+ */
691
948
  async shutdown(plugin, reason, removeAllDevices = false, force = false) {
692
949
  this.log.debug(`Shutting down plugin ${plg}${plugin.name}${db}`);
693
950
  if (!plugin.loaded) {
@@ -730,6 +987,15 @@ export class PluginManager extends EventEmitter {
730
987
  }
731
988
  return undefined;
732
989
  }
990
+ /**
991
+ * Loads the configuration for a plugin.
992
+ * If the configuration file exists, it reads the file and returns the parsed JSON data.
993
+ * If the configuration file does not exist, it creates a new file with default configuration and returns it.
994
+ * If any error occurs during file access or creation, it logs an error and return un empty config.
995
+ *
996
+ * @param {Plugin} plugin - The plugin for which to load the configuration.
997
+ * @returns {Promise<PlatformConfig>} A promise that resolves to the loaded or created configuration.
998
+ */
733
999
  async loadConfig(plugin) {
734
1000
  const { default: path } = await import('node:path');
735
1001
  const { promises } = await import('node:fs');
@@ -741,6 +1007,8 @@ export class PluginManager extends EventEmitter {
741
1007
  const data = await promises.readFile(configFile, 'utf8');
742
1008
  const config = JSON.parse(data);
743
1009
  this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
1010
+ // this.log.debug(`Loaded config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
1011
+ // The first time a plugin is added to the system, the config file is created with the plugin name and type "AnyPlatform".
744
1012
  config.name = plugin.name;
745
1013
  config.type = plugin.type;
746
1014
  if (config.debug === undefined)
@@ -762,6 +1030,8 @@ export class PluginManager extends EventEmitter {
762
1030
  }
763
1031
  catch (_err) {
764
1032
  this.log.debug(`Default config file ${defaultConfigFile} for plugin ${plg}${plugin.name}${db} does not exist, creating new config file...`);
1033
+ // TODO: Remove this when all these plugins have their own default config file
1034
+ // istanbul ignore next if
765
1035
  if (plugin.name === 'matterbridge-zigbee2mqtt')
766
1036
  config = zigbee2mqtt_config;
767
1037
  else if (plugin.name === 'matterbridge-somfy-tahoma')
@@ -774,6 +1044,7 @@ export class PluginManager extends EventEmitter {
774
1044
  try {
775
1045
  await promises.writeFile(configFile, JSON.stringify(config, null, 2), 'utf8');
776
1046
  this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.`);
1047
+ // this.log.debug(`Created config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
777
1048
  return config;
778
1049
  }
779
1050
  catch (err) {
@@ -787,6 +1058,19 @@ export class PluginManager extends EventEmitter {
787
1058
  }
788
1059
  }
789
1060
  }
1061
+ /**
1062
+ * Saves the configuration of a plugin to a file.
1063
+ *
1064
+ * This method saves the configuration of the specified plugin to a JSON file in the matterbridge directory.
1065
+ * If the plugin's configuration is not found, it logs an error and rejects the promise. If the configuration
1066
+ * is successfully saved, it logs a debug message. If an error occurs during the file write operation, it logs
1067
+ * the error and rejects the promise.
1068
+ *
1069
+ * @param {Plugin} plugin - The plugin whose configuration is to be saved.
1070
+ * @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
1071
+ * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or rejects if an error occurs.
1072
+ * @throws {Error} If the plugin's configuration is not found.
1073
+ */
790
1074
  async saveConfigFromPlugin(plugin, restartRequired = false) {
791
1075
  const { default: path } = await import('node:path');
792
1076
  const { promises } = await import('node:fs');
@@ -801,6 +1085,7 @@ export class PluginManager extends EventEmitter {
801
1085
  if (restartRequired)
802
1086
  plugin.restartRequired = true;
803
1087
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
1088
+ // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, plugin.platform.config);
804
1089
  return Promise.resolve();
805
1090
  }
806
1091
  catch (err) {
@@ -808,6 +1093,20 @@ export class PluginManager extends EventEmitter {
808
1093
  return Promise.reject(err);
809
1094
  }
810
1095
  }
1096
+ /**
1097
+ * Saves the configuration of a plugin from a JSON object to a file.
1098
+ *
1099
+ * This method saves the provided configuration of the specified plugin to a JSON file in the matterbridge directory.
1100
+ * It first checks if the configuration data is valid by ensuring it contains the correct name and type, and matches
1101
+ * the plugin's name. If the configuration data is invalid, it logs an error and returns. If the configuration is
1102
+ * successfully saved, it updates the plugin's `configJson` property and logs a debug message. If an error occurs
1103
+ * during the file write operation, it logs the error and returns.
1104
+ *
1105
+ * @param {Plugin} plugin - The plugin whose configuration is to be saved.
1106
+ * @param {PlatformConfig} config - The configuration data to be saved.
1107
+ * @param {boolean} [restartRequired] - Indicates whether a restart is required after saving the configuration.
1108
+ * @returns {Promise<void>} A promise that resolves when the configuration is successfully saved, or returns if an error occurs.
1109
+ */
811
1110
  async saveConfigFromJson(plugin, config, restartRequired = false) {
812
1111
  const { default: path } = await import('node:path');
813
1112
  const { promises } = await import('node:fs');
@@ -826,12 +1125,23 @@ export class PluginManager extends EventEmitter {
826
1125
  plugin.platform.onConfigChanged(config).catch((err) => this.log.error(`Error calling onConfigChanged for plugin ${plg}${plugin.name}${er}: ${err}`));
827
1126
  }
828
1127
  this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}`);
1128
+ // this.log.debug(`Saved config file ${configFile} for plugin ${plg}${plugin.name}${db}.\nConfig:${rs}\n`, config);
829
1129
  }
830
1130
  catch (err) {
831
1131
  logError(this.log, `Error saving config file ${configFile} for plugin ${plg}${plugin.name}${er}`, err);
832
1132
  return;
833
1133
  }
834
1134
  }
1135
+ /**
1136
+ * Loads the schema for a plugin.
1137
+ *
1138
+ * This method attempts to load the schema file for the specified plugin. If the schema file is found,
1139
+ * it reads and parses the file, updates the schema's title and description, and logs the process.
1140
+ * If the schema file is not found, it logs the event and loads a default schema for the plugin.
1141
+ *
1142
+ * @param {Plugin} plugin - The plugin whose schema is to be loaded.
1143
+ * @returns {Promise<PlatformSchema>} A promise that resolves to the loaded schema object, or the default schema if the schema file is not found.
1144
+ */
835
1145
  async loadSchema(plugin) {
836
1146
  const { promises } = await import('node:fs');
837
1147
  const schemaFile = plugin.path.replace('package.json', `${plugin.name}.schema.json`);
@@ -842,6 +1152,7 @@ export class PluginManager extends EventEmitter {
842
1152
  schema.title = plugin.description;
843
1153
  schema.description = plugin.name + ' v. ' + plugin.version + ' by ' + plugin.author;
844
1154
  this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.`);
1155
+ // this.log.debug(`Loaded schema file ${schemaFile} for plugin ${plg}${plugin.name}${db}.\nSchema:${rs}\n`, schema);
845
1156
  return schema;
846
1157
  }
847
1158
  catch (_err) {
@@ -849,6 +1160,16 @@ export class PluginManager extends EventEmitter {
849
1160
  return this.getDefaultSchema(plugin);
850
1161
  }
851
1162
  }
1163
+ /**
1164
+ * Returns the default schema for a plugin.
1165
+ *
1166
+ * This method generates a default schema object for the specified plugin. The schema includes
1167
+ * metadata such as the plugin's title, description, version, and author. It also defines the
1168
+ * properties of the schema, including the plugin's name, type, debug flag, and unregisterOnShutdown flag.
1169
+ *
1170
+ * @param {Plugin} plugin - The plugin for which the default schema is to be generated.
1171
+ * @returns {PlatformSchema} The default schema object for the plugin.
1172
+ */
852
1173
  getDefaultSchema(plugin) {
853
1174
  return {
854
1175
  title: plugin.description,
@@ -879,3 +1200,4 @@ export class PluginManager extends EventEmitter {
879
1200
  };
880
1201
  }
881
1202
  }
1203
+ //# sourceMappingURL=pluginManager.js.map