matterbridge 3.3.5-dev-20251031-3482891 → 3.3.5

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