matterbridge 3.4.0-dev-20251125-6f11a4f → 3.4.0

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 (317) hide show
  1. package/CHANGELOG.md +3 -2
  2. package/README.md +1 -1
  3. package/dist/broadcastServer.d.ts +115 -0
  4. package/dist/broadcastServer.d.ts.map +1 -0
  5. package/dist/broadcastServer.js +93 -1
  6. package/dist/broadcastServer.js.map +1 -0
  7. package/dist/broadcastServerTypes.d.ts +838 -0
  8. package/dist/broadcastServerTypes.d.ts.map +1 -0
  9. package/dist/broadcastServerTypes.js +24 -0
  10. package/dist/broadcastServerTypes.js.map +1 -0
  11. package/dist/cli.d.ts +30 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +97 -1
  14. package/dist/cli.js.map +1 -0
  15. package/dist/cliEmitter.d.ts +50 -0
  16. package/dist/cliEmitter.d.ts.map +1 -0
  17. package/dist/cliEmitter.js +37 -0
  18. package/dist/cliEmitter.js.map +1 -0
  19. package/dist/cliHistory.d.ts +48 -0
  20. package/dist/cliHistory.d.ts.map +1 -0
  21. package/dist/cliHistory.js +38 -0
  22. package/dist/cliHistory.js.map +1 -0
  23. package/dist/clusters/export.d.ts +2 -0
  24. package/dist/clusters/export.d.ts.map +1 -0
  25. package/dist/clusters/export.js +2 -0
  26. package/dist/clusters/export.js.map +1 -0
  27. package/dist/defaultConfigSchema.d.ts +28 -0
  28. package/dist/defaultConfigSchema.d.ts.map +1 -0
  29. package/dist/defaultConfigSchema.js +24 -0
  30. package/dist/defaultConfigSchema.js.map +1 -0
  31. package/dist/deviceManager.d.ts +135 -0
  32. package/dist/deviceManager.d.ts.map +1 -0
  33. package/dist/deviceManager.js +113 -1
  34. package/dist/deviceManager.js.map +1 -0
  35. package/dist/devices/airConditioner.d.ts +98 -0
  36. package/dist/devices/airConditioner.d.ts.map +1 -0
  37. package/dist/devices/airConditioner.js +57 -0
  38. package/dist/devices/airConditioner.js.map +1 -0
  39. package/dist/devices/batteryStorage.d.ts +48 -0
  40. package/dist/devices/batteryStorage.d.ts.map +1 -0
  41. package/dist/devices/batteryStorage.js +48 -1
  42. package/dist/devices/batteryStorage.js.map +1 -0
  43. package/dist/devices/cooktop.d.ts +61 -0
  44. package/dist/devices/cooktop.d.ts.map +1 -0
  45. package/dist/devices/cooktop.js +56 -0
  46. package/dist/devices/cooktop.js.map +1 -0
  47. package/dist/devices/dishwasher.d.ts +71 -0
  48. package/dist/devices/dishwasher.d.ts.map +1 -0
  49. package/dist/devices/dishwasher.js +57 -0
  50. package/dist/devices/dishwasher.js.map +1 -0
  51. package/dist/devices/evse.d.ts +76 -0
  52. package/dist/devices/evse.d.ts.map +1 -0
  53. package/dist/devices/evse.js +74 -10
  54. package/dist/devices/evse.js.map +1 -0
  55. package/dist/devices/export.d.ts +17 -0
  56. package/dist/devices/export.d.ts.map +1 -0
  57. package/dist/devices/export.js +5 -0
  58. package/dist/devices/export.js.map +1 -0
  59. package/dist/devices/extractorHood.d.ts +46 -0
  60. package/dist/devices/extractorHood.d.ts.map +1 -0
  61. package/dist/devices/extractorHood.js +43 -0
  62. package/dist/devices/extractorHood.js.map +1 -0
  63. package/dist/devices/heatPump.d.ts +47 -0
  64. package/dist/devices/heatPump.d.ts.map +1 -0
  65. package/dist/devices/heatPump.js +50 -2
  66. package/dist/devices/heatPump.js.map +1 -0
  67. package/dist/devices/laundryDryer.d.ts +67 -0
  68. package/dist/devices/laundryDryer.d.ts.map +1 -0
  69. package/dist/devices/laundryDryer.js +62 -3
  70. package/dist/devices/laundryDryer.js.map +1 -0
  71. package/dist/devices/laundryWasher.d.ts +81 -0
  72. package/dist/devices/laundryWasher.d.ts.map +1 -0
  73. package/dist/devices/laundryWasher.js +70 -4
  74. package/dist/devices/laundryWasher.js.map +1 -0
  75. package/dist/devices/microwaveOven.d.ts +168 -0
  76. package/dist/devices/microwaveOven.d.ts.map +1 -0
  77. package/dist/devices/microwaveOven.js +88 -5
  78. package/dist/devices/microwaveOven.js.map +1 -0
  79. package/dist/devices/oven.d.ts +105 -0
  80. package/dist/devices/oven.d.ts.map +1 -0
  81. package/dist/devices/oven.js +85 -0
  82. package/dist/devices/oven.js.map +1 -0
  83. package/dist/devices/refrigerator.d.ts +118 -0
  84. package/dist/devices/refrigerator.d.ts.map +1 -0
  85. package/dist/devices/refrigerator.js +102 -0
  86. package/dist/devices/refrigerator.js.map +1 -0
  87. package/dist/devices/roboticVacuumCleaner.d.ts +112 -0
  88. package/dist/devices/roboticVacuumCleaner.d.ts.map +1 -0
  89. package/dist/devices/roboticVacuumCleaner.js +100 -9
  90. package/dist/devices/roboticVacuumCleaner.js.map +1 -0
  91. package/dist/devices/solarPower.d.ts +40 -0
  92. package/dist/devices/solarPower.d.ts.map +1 -0
  93. package/dist/devices/solarPower.js +38 -0
  94. package/dist/devices/solarPower.js.map +1 -0
  95. package/dist/devices/speaker.d.ts +87 -0
  96. package/dist/devices/speaker.d.ts.map +1 -0
  97. package/dist/devices/speaker.js +84 -0
  98. package/dist/devices/speaker.js.map +1 -0
  99. package/dist/devices/temperatureControl.d.ts +166 -0
  100. package/dist/devices/temperatureControl.d.ts.map +1 -0
  101. package/dist/devices/temperatureControl.js +24 -3
  102. package/dist/devices/temperatureControl.js.map +1 -0
  103. package/dist/devices/waterHeater.d.ts +111 -0
  104. package/dist/devices/waterHeater.d.ts.map +1 -0
  105. package/dist/devices/waterHeater.js +82 -2
  106. package/dist/devices/waterHeater.js.map +1 -0
  107. package/dist/dgram/coap.d.ts +205 -0
  108. package/dist/dgram/coap.d.ts.map +1 -0
  109. package/dist/dgram/coap.js +126 -13
  110. package/dist/dgram/coap.js.map +1 -0
  111. package/dist/dgram/dgram.d.ts +141 -0
  112. package/dist/dgram/dgram.d.ts.map +1 -0
  113. package/dist/dgram/dgram.js +114 -2
  114. package/dist/dgram/dgram.js.map +1 -0
  115. package/dist/dgram/mb_coap.d.ts +24 -0
  116. package/dist/dgram/mb_coap.d.ts.map +1 -0
  117. package/dist/dgram/mb_coap.js +41 -3
  118. package/dist/dgram/mb_coap.js.map +1 -0
  119. package/dist/dgram/mb_mdns.d.ts +24 -0
  120. package/dist/dgram/mb_mdns.d.ts.map +1 -0
  121. package/dist/dgram/mb_mdns.js +80 -15
  122. package/dist/dgram/mb_mdns.js.map +1 -0
  123. package/dist/dgram/mdns.d.ts +290 -0
  124. package/dist/dgram/mdns.d.ts.map +1 -0
  125. package/dist/dgram/mdns.js +299 -137
  126. package/dist/dgram/mdns.js.map +1 -0
  127. package/dist/dgram/multicast.d.ts +67 -0
  128. package/dist/dgram/multicast.d.ts.map +1 -0
  129. package/dist/dgram/multicast.js +62 -1
  130. package/dist/dgram/multicast.js.map +1 -0
  131. package/dist/dgram/unicast.d.ts +56 -0
  132. package/dist/dgram/unicast.d.ts.map +1 -0
  133. package/dist/dgram/unicast.js +54 -0
  134. package/dist/dgram/unicast.js.map +1 -0
  135. package/dist/frontend.d.ts +238 -0
  136. package/dist/frontend.d.ts.map +1 -0
  137. package/dist/frontend.js +455 -35
  138. package/dist/frontend.js.map +1 -0
  139. package/dist/frontendTypes.d.ts +529 -0
  140. package/dist/frontendTypes.d.ts.map +1 -0
  141. package/dist/frontendTypes.js +45 -0
  142. package/dist/frontendTypes.js.map +1 -0
  143. package/dist/helpers.d.ts +48 -0
  144. package/dist/helpers.d.ts.map +1 -0
  145. package/dist/helpers.js +53 -0
  146. package/dist/helpers.js.map +1 -0
  147. package/dist/index.d.ts +34 -0
  148. package/dist/index.d.ts.map +1 -0
  149. package/dist/index.js +25 -0
  150. package/dist/index.js.map +1 -0
  151. package/dist/jestutils/export.d.ts +2 -0
  152. package/dist/jestutils/export.d.ts.map +1 -0
  153. package/dist/jestutils/export.js +1 -0
  154. package/dist/jestutils/export.js.map +1 -0
  155. package/dist/jestutils/jestHelpers.d.ts +303 -0
  156. package/dist/jestutils/jestHelpers.d.ts.map +1 -0
  157. package/dist/jestutils/jestHelpers.js +354 -13
  158. package/dist/jestutils/jestHelpers.js.map +1 -0
  159. package/dist/logger/export.d.ts +2 -0
  160. package/dist/logger/export.d.ts.map +1 -0
  161. package/dist/logger/export.js +1 -0
  162. package/dist/logger/export.js.map +1 -0
  163. package/dist/matter/behaviors.d.ts +2 -0
  164. package/dist/matter/behaviors.d.ts.map +1 -0
  165. package/dist/matter/behaviors.js +2 -0
  166. package/dist/matter/behaviors.js.map +1 -0
  167. package/dist/matter/clusters.d.ts +2 -0
  168. package/dist/matter/clusters.d.ts.map +1 -0
  169. package/dist/matter/clusters.js +2 -0
  170. package/dist/matter/clusters.js.map +1 -0
  171. package/dist/matter/devices.d.ts +2 -0
  172. package/dist/matter/devices.d.ts.map +1 -0
  173. package/dist/matter/devices.js +2 -0
  174. package/dist/matter/devices.js.map +1 -0
  175. package/dist/matter/endpoints.d.ts +2 -0
  176. package/dist/matter/endpoints.d.ts.map +1 -0
  177. package/dist/matter/endpoints.js +2 -0
  178. package/dist/matter/endpoints.js.map +1 -0
  179. package/dist/matter/export.d.ts +5 -0
  180. package/dist/matter/export.d.ts.map +1 -0
  181. package/dist/matter/export.js +3 -0
  182. package/dist/matter/export.js.map +1 -0
  183. package/dist/matter/types.d.ts +3 -0
  184. package/dist/matter/types.d.ts.map +1 -0
  185. package/dist/matter/types.js +3 -0
  186. package/dist/matter/types.js.map +1 -0
  187. package/dist/matterNode.d.ts +342 -0
  188. package/dist/matterNode.d.ts.map +1 -0
  189. package/dist/matterNode.js +369 -8
  190. package/dist/matterNode.js.map +1 -0
  191. package/dist/matterbridge.d.ts +473 -0
  192. package/dist/matterbridge.d.ts.map +1 -0
  193. package/dist/matterbridge.js +787 -46
  194. package/dist/matterbridge.js.map +1 -0
  195. package/dist/matterbridgeAccessoryPlatform.d.ts +41 -0
  196. package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
  197. package/dist/matterbridgeAccessoryPlatform.js +38 -0
  198. package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
  199. package/dist/matterbridgeBehaviors.d.ts +2404 -0
  200. package/dist/matterbridgeBehaviors.d.ts.map +1 -0
  201. package/dist/matterbridgeBehaviors.js +68 -5
  202. package/dist/matterbridgeBehaviors.js.map +1 -0
  203. package/dist/matterbridgeDeviceTypes.d.ts +698 -0
  204. package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
  205. package/dist/matterbridgeDeviceTypes.js +635 -14
  206. package/dist/matterbridgeDeviceTypes.js.map +1 -0
  207. package/dist/matterbridgeDynamicPlatform.d.ts +41 -0
  208. package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
  209. package/dist/matterbridgeDynamicPlatform.js +38 -0
  210. package/dist/matterbridgeDynamicPlatform.js.map +1 -0
  211. package/dist/matterbridgeEndpoint.d.ts +1507 -0
  212. package/dist/matterbridgeEndpoint.d.ts.map +1 -0
  213. package/dist/matterbridgeEndpoint.js +1444 -53
  214. package/dist/matterbridgeEndpoint.js.map +1 -0
  215. package/dist/matterbridgeEndpointHelpers.d.ts +787 -0
  216. package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
  217. package/dist/matterbridgeEndpointHelpers.js +483 -20
  218. package/dist/matterbridgeEndpointHelpers.js.map +1 -0
  219. package/dist/matterbridgeEndpointTypes.d.ts +166 -0
  220. package/dist/matterbridgeEndpointTypes.d.ts.map +1 -0
  221. package/dist/matterbridgeEndpointTypes.js +25 -0
  222. package/dist/matterbridgeEndpointTypes.js.map +1 -0
  223. package/dist/matterbridgePlatform.d.ts +524 -0
  224. package/dist/matterbridgePlatform.d.ts.map +1 -0
  225. package/dist/matterbridgePlatform.js +439 -1
  226. package/dist/matterbridgePlatform.js.map +1 -0
  227. package/dist/matterbridgeTypes.d.ts +251 -0
  228. package/dist/matterbridgeTypes.d.ts.map +1 -0
  229. package/dist/matterbridgeTypes.js +26 -0
  230. package/dist/matterbridgeTypes.js.map +1 -0
  231. package/dist/pluginManager.d.ts +371 -0
  232. package/dist/pluginManager.d.ts.map +1 -0
  233. package/dist/pluginManager.js +340 -5
  234. package/dist/pluginManager.js.map +1 -0
  235. package/dist/shelly.d.ts +174 -0
  236. package/dist/shelly.d.ts.map +1 -0
  237. package/dist/shelly.js +168 -7
  238. package/dist/shelly.js.map +1 -0
  239. package/dist/storage/export.d.ts +2 -0
  240. package/dist/storage/export.d.ts.map +1 -0
  241. package/dist/storage/export.js +1 -0
  242. package/dist/storage/export.js.map +1 -0
  243. package/dist/update.d.ts +75 -0
  244. package/dist/update.d.ts.map +1 -0
  245. package/dist/update.js +69 -0
  246. package/dist/update.js.map +1 -0
  247. package/dist/utils/colorUtils.d.ts +101 -0
  248. package/dist/utils/colorUtils.d.ts.map +1 -0
  249. package/dist/utils/colorUtils.js +97 -2
  250. package/dist/utils/colorUtils.js.map +1 -0
  251. package/dist/utils/commandLine.d.ts +66 -0
  252. package/dist/utils/commandLine.d.ts.map +1 -0
  253. package/dist/utils/commandLine.js +60 -0
  254. package/dist/utils/commandLine.js.map +1 -0
  255. package/dist/utils/copyDirectory.d.ts +35 -0
  256. package/dist/utils/copyDirectory.d.ts.map +1 -0
  257. package/dist/utils/copyDirectory.js +37 -0
  258. package/dist/utils/copyDirectory.js.map +1 -0
  259. package/dist/utils/createDirectory.d.ts +34 -0
  260. package/dist/utils/createDirectory.d.ts.map +1 -0
  261. package/dist/utils/createDirectory.js +33 -0
  262. package/dist/utils/createDirectory.js.map +1 -0
  263. package/dist/utils/createZip.d.ts +39 -0
  264. package/dist/utils/createZip.d.ts.map +1 -0
  265. package/dist/utils/createZip.js +47 -2
  266. package/dist/utils/createZip.js.map +1 -0
  267. package/dist/utils/deepCopy.d.ts +32 -0
  268. package/dist/utils/deepCopy.d.ts.map +1 -0
  269. package/dist/utils/deepCopy.js +39 -0
  270. package/dist/utils/deepCopy.js.map +1 -0
  271. package/dist/utils/deepEqual.d.ts +54 -0
  272. package/dist/utils/deepEqual.d.ts.map +1 -0
  273. package/dist/utils/deepEqual.js +72 -1
  274. package/dist/utils/deepEqual.js.map +1 -0
  275. package/dist/utils/error.d.ts +44 -0
  276. package/dist/utils/error.d.ts.map +1 -0
  277. package/dist/utils/error.js +41 -0
  278. package/dist/utils/error.js.map +1 -0
  279. package/dist/utils/export.d.ts +13 -0
  280. package/dist/utils/export.d.ts.map +1 -0
  281. package/dist/utils/export.js +1 -0
  282. package/dist/utils/export.js.map +1 -0
  283. package/dist/utils/format.d.ts +53 -0
  284. package/dist/utils/format.d.ts.map +1 -0
  285. package/dist/utils/format.js +49 -0
  286. package/dist/utils/format.js.map +1 -0
  287. package/dist/utils/hex.d.ts +89 -0
  288. package/dist/utils/hex.d.ts.map +1 -0
  289. package/dist/utils/hex.js +124 -0
  290. package/dist/utils/hex.js.map +1 -0
  291. package/dist/utils/inspector.d.ts +87 -0
  292. package/dist/utils/inspector.d.ts.map +1 -0
  293. package/dist/utils/inspector.js +69 -1
  294. package/dist/utils/inspector.js.map +1 -0
  295. package/dist/utils/isvalid.d.ts +103 -0
  296. package/dist/utils/isvalid.d.ts.map +1 -0
  297. package/dist/utils/isvalid.js +101 -0
  298. package/dist/utils/isvalid.js.map +1 -0
  299. package/dist/utils/network.d.ts +111 -0
  300. package/dist/utils/network.d.ts.map +1 -0
  301. package/dist/utils/network.js +96 -5
  302. package/dist/utils/network.js.map +1 -0
  303. package/dist/utils/spawn.d.ts +33 -0
  304. package/dist/utils/spawn.d.ts.map +1 -0
  305. package/dist/utils/spawn.js +71 -1
  306. package/dist/utils/spawn.js.map +1 -0
  307. package/dist/utils/tracker.d.ts +108 -0
  308. package/dist/utils/tracker.d.ts.map +1 -0
  309. package/dist/utils/tracker.js +65 -2
  310. package/dist/utils/tracker.js.map +1 -0
  311. package/dist/utils/wait.d.ts +54 -0
  312. package/dist/utils/wait.d.ts.map +1 -0
  313. package/dist/utils/wait.js +60 -8
  314. package/dist/utils/wait.js.map +1 -0
  315. package/marked.ps1 +10 -0
  316. package/npm-shrinkwrap.json +2 -2
  317. package/package.json +2 -1
@@ -1,7 +1,34 @@
1
+ /**
2
+ * This file contains the class MatterbridgePlatform.
3
+ *
4
+ * @file matterbridgePlatform.ts
5
+ * @author Luca Liguori
6
+ * @created 2024-03-21
7
+ * @version 1.4.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
+ // eslint-disable-next-line no-console
1
25
  if (process.argv.includes('--loader') || process.argv.includes('-loader'))
2
26
  console.log('\u001B[32mMatterbridgePlatform loaded.\u001B[40;0m');
27
+ // Node.js modules
3
28
  import path from 'node:path';
29
+ // Node AnsiLogger module
4
30
  import { CYAN, db, er, nf, wr } from 'node-ansi-logger';
31
+ // Node Storage module
5
32
  import { NodeStorageManager } from 'node-persist-manager';
6
33
  import { Descriptor } from '@matter/types/clusters/descriptor';
7
34
  import { BridgedDeviceBasicInformation } from '@matter/types/clusters/bridged-device-basic-information';
@@ -11,29 +38,60 @@ import { isValidArray, isValidObject, isValidString } from './utils/isvalid.js';
11
38
  import { addVirtualDevice } from './helpers.js';
12
39
  import { hasParameter } from './utils/commandLine.js';
13
40
  import { BroadcastServer } from './broadcastServer.js';
41
+ /**
42
+ * Represents the base Matterbridge platform. It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
43
+ *
44
+ */
14
45
  export class MatterbridgePlatform {
46
+ /** The PlatformMatterbridge instance of this Platform. */
15
47
  matterbridge;
48
+ /** The logger instance for this platform. Created by the PluginManager.load() method. */
16
49
  log;
50
+ /** The configuration for this platform. Set by the PluginManager.load() method using the stored config file. */
17
51
  config;
52
+ /** The name of the platform. Set by the PluginManager.load() method using the package.json name value. */
18
53
  name = '';
54
+ /** The type of the platform. Set by the extending classes: MatterbridgeDynamicPlatform and MatterbridgeAccessoryPlatform */
19
55
  type = 'AnyPlatform';
56
+ /** The version of the platform. Set by the PluginManager.load() method using the package.json version value. */
20
57
  version = '1.0.0';
58
+ /** Platform node storage manager created in the matterbridgeDirectory with the plugin name. */
21
59
  #storage;
60
+ /** Platform context in the storage of matterbridgeDirectory. Use await platform.ready to access it early. */
22
61
  context;
62
+ /** Indicates whether the platform is is fully initialized (including context and selects). */
23
63
  isReady = false;
64
+ /** Indicates whether the platform has been loaded. */
24
65
  isLoaded = false;
66
+ /** Indicates whether the platform has been started. */
25
67
  isStarted = false;
68
+ /** Indicates whether the platform has been configured. */
26
69
  isConfigured = false;
70
+ // Device and entity select in the plugin config UI
27
71
  #selectDevices = new Map();
28
72
  #selectEntities = new Map();
73
+ // Promises for platform initialization. They are grouped in MatterbridgePlatform.ready with Promise.all.
29
74
  #contextReady;
30
75
  #selectDeviceContextReady;
31
76
  #selectEntityContextReady;
77
+ /** The ready promise for the platform, which resolves when the platform is fully initialized (including context and selects). Await platform.ready if you access the platform context or select early. */
32
78
  ready;
79
+ /** Registered MatterbridgeEndpoint map keyed by uniqueId */
33
80
  #registeredEndpoints = new Map();
81
+ /** Broadcast server */
34
82
  #server;
35
83
  #debug = hasParameter('debug') || hasParameter('verbose');
36
84
  #verbose = hasParameter('verbose');
85
+ /**
86
+ * Creates an instance of the base MatterbridgePlatform.
87
+ * It is extended by the MatterbridgeDynamicPlatform and MatterbridgeAccessoryPlatform classes.
88
+ * Each plugin must extend the MatterbridgeDynamicPlatform or MatterbridgeAccessoryPlatform class.
89
+ * MatterbridgePlatform cannot be instantiated directly, it can only be extended by the MatterbridgeDynamicPlatform or MatterbridgeAccessoryPlatform class.
90
+ *
91
+ * @param {PlatformMatterbridge} matterbridge - The PlatformMatterbridge instance.
92
+ * @param {AnsiLogger} log - The logger instance.
93
+ * @param {PlatformConfig} config - The platform configuration.
94
+ */
37
95
  constructor(matterbridge, log, config) {
38
96
  this.matterbridge = matterbridge;
39
97
  this.log = log;
@@ -43,6 +101,7 @@ export class MatterbridgePlatform {
43
101
  this.log.debug(`Creating MatterbridgePlatform for plugin ${this.config.name}`);
44
102
  if (this.#verbose)
45
103
  this.log.debug(`Creating MatterbridgePlatform for plugin ${this.config.name} with config:\n${JSON.stringify(this.config, null, 2)}\n`);
104
+ // create the NodeStorageManager for the plugin platform
46
105
  if (!isValidString(this.config.name, 1)) {
47
106
  this.#server.close();
48
107
  throw new Error('Platform: the plugin name is missing or invalid.');
@@ -55,12 +114,14 @@ export class MatterbridgePlatform {
55
114
  logging: false,
56
115
  forgiveParseErrors: true,
57
116
  });
117
+ // create the context storage for the plugin platform
58
118
  this.log.debug(`Creating context for plugin ${this.config.name}`);
59
119
  this.#contextReady = this.#storage.createStorage('context').then((context) => {
60
120
  this.context = context;
61
121
  this.log.debug(`Created context for plugin ${this.config.name}`);
62
122
  return;
63
123
  });
124
+ // create the selectDevice storage for the plugin platform
64
125
  this.log.debug(`Loading selectDevice for plugin ${this.config.name}`);
65
126
  this.#selectDeviceContextReady = this.#storage.createStorage('selectDevice').then(async (context) => {
66
127
  const selectDevice = await context.get('selectDevice', []);
@@ -69,6 +130,7 @@ export class MatterbridgePlatform {
69
130
  this.log.debug(`Loaded ${this.#selectDevices.size} selectDevice for plugin ${this.config.name}`);
70
131
  return;
71
132
  });
133
+ // create the selectEntity storage for the plugin platform
72
134
  this.log.debug(`Loading selectEntity for plugin ${this.config.name}`);
73
135
  this.#selectEntityContextReady = this.#storage.createStorage('selectEntity').then(async (context) => {
74
136
  const selectEntity = await context.get('selectEntity', []);
@@ -77,97 +139,279 @@ export class MatterbridgePlatform {
77
139
  this.log.debug(`Loaded ${this.#selectEntities.size} selectEntity for plugin ${this.config.name}`);
78
140
  return;
79
141
  });
142
+ // Create the `ready` promise for the platform
80
143
  this.ready = Promise.all([this.#contextReady, this.#selectDeviceContextReady, this.#selectEntityContextReady]).then(() => {
81
144
  this.log.debug(`MatterbridgePlatform for plugin ${this.config.name} is fully initialized`);
82
145
  this.isReady = true;
83
146
  return;
84
147
  });
85
148
  }
149
+ /**
150
+ * Destroys the platform, cleaning up memory, closing storage and broadcast server.
151
+ */
86
152
  async destroy() {
87
153
  if (this.#verbose)
88
154
  this.log.debug(`Destroying MatterbridgePlatform for plugin ${this.config.name}`);
155
+ // Cleanup memory
89
156
  this.#selectDevices.clear();
90
157
  this.#selectEntities.clear();
91
158
  this.#registeredEndpoints.clear();
159
+ // Close the storage
92
160
  await this.context?.close();
93
161
  this.context = undefined;
94
162
  await this.#storage?.close();
163
+ // Close the broadcast server
95
164
  this.#server.close();
96
165
  if (this.#verbose)
97
166
  this.log.debug(`Destroyed MatterbridgePlatform for plugin ${this.config.name}`);
98
167
  this.isReady = false;
99
168
  }
169
+ /**
170
+ * This method shall be overridden in the extended class.
171
+ * It is called when the platform is started.
172
+ * Use this method to create the MatterbridgeEndpoints and call this.registerDevice().
173
+ *
174
+ * @param {string} [reason] - The reason for starting.
175
+ * @throws {Error} - Throws an error if the method is not overridden.
176
+ */
100
177
  async onStart(reason) {
101
178
  this.log.error('Plugins must override onStart.', reason);
102
179
  throw new Error('Plugins must override onStart.');
103
180
  }
181
+ /**
182
+ * This method can be overridden in the extended class. In this case always call super.onConfigure() to save the select and run checkEndpointNumbers().
183
+ * It is called after the platform has started.
184
+ * Use this method to perform any configuration of your devices and to override the value of the attributes that are persistent and stored in the
185
+ * matter storage (i.e. the onOff attribute of the OnOff cluster).
186
+ */
104
187
  async onConfigure() {
105
188
  this.log.debug(`Configuring platform ${this.name}`);
189
+ // Save the selectDevice and selectEntity
106
190
  await this.saveSelects();
191
+ // Check and update the endpoint numbers
107
192
  await this.checkEndpointNumbers();
108
193
  }
194
+ /**
195
+ * This method can be overridden in the extended class. In this case always call super.onShutdown() to save the selects, run checkEndpointNumbers() and cleanup memory.
196
+ * It is called when the platform is shutting down.
197
+ * Use this method to clean up any resources you used in the constructor or onStart.
198
+ *
199
+ * @param {string} [reason] - The reason for shutting down.
200
+ */
109
201
  async onShutdown(reason) {
110
202
  this.log.debug(`Shutting down platform ${this.name}`, reason);
203
+ // Save the selectDevice and selectEntity
111
204
  await this.saveSelects();
205
+ // Check and update the endpoint numbers
112
206
  await this.checkEndpointNumbers();
207
+ // Cleanup memory and close storage and broadcast server
113
208
  await this.destroy();
114
209
  }
210
+ /**
211
+ * Called when the logger level is changed.
212
+ *
213
+ * @param {LogLevel} logLevel The new logger level.
214
+ */
115
215
  async onChangeLoggerLevel(logLevel) {
116
216
  this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
117
217
  }
218
+ /**
219
+ * Called when a plugin config includes an action button or an action button with text field.
220
+ *
221
+ * @param {string} action The action triggered by the button in plugin config.
222
+ * @param {string} value The value of the field of the action button.
223
+ * @param {string} id The id of the schema associated with the action.
224
+ * @param {PlatformConfig} formData The changed form data of the plugin.
225
+ *
226
+ * @remarks
227
+ * This method can be overridden in the extended class.
228
+ *
229
+ * @example
230
+ * Use this method to handle the action defined in the plugin schema:
231
+ * ```json
232
+ * "addDevice": {
233
+ * "description": "Manually add a device that has not been discovered with mdns:",
234
+ * "type": "boolean",
235
+ * "buttonText": "ADD", // The text on the button. This is used when the action doesn't include a text field.
236
+ * "buttonField": "ADD", // The text on the button. This is used when the action includes a text field.
237
+ * "buttonClose": false, // optional, default is false. When true, the dialog will close after the action is sent.
238
+ * "buttonSave": false, // optional, default is false. When true, the dialog will close and trigger the restart required after the action is sent.
239
+ * "textPlaceholder": "Enter the device IP address", // optional: the placeholder text for the text field.
240
+ * "default": false
241
+ * },
242
+ * ```
243
+ */
118
244
  async onAction(action, value, id, formData) {
119
245
  this.log.debug(`The plugin ${CYAN}${this.name}${db} doesn't override onAction. Received action ${CYAN}${action}${db}${value ? ' with ' + CYAN + value + db : ''} ${id ? ' for schema ' + CYAN + id + db : ''}`, formData);
120
246
  }
247
+ /**
248
+ * Called when the plugin config has been updated.
249
+ *
250
+ * @param {PlatformConfig} config The new plugin config.
251
+ */
121
252
  async onConfigChanged(config) {
122
253
  this.log.debug(`The plugin ${CYAN}${config.name}${db} doesn't override onConfigChanged. Received new config.`);
123
254
  }
255
+ /**
256
+ * Save the platform configuration to the platform config JSON.
257
+ *
258
+ * @param {PlatformConfig} [config] - The platform configuration to save.
259
+ * @returns {void}
260
+ */
124
261
  saveConfig(config) {
125
262
  this.#server.request({ type: 'plugins_saveconfigfromjson', src: 'platform', dst: 'plugins', params: { name: this.name, config } });
126
263
  }
264
+ /**
265
+ * Get the platform schema for the config editor. This will retrieve the schema from the Matterbridge plugin manager.
266
+ *
267
+ * @returns {Promise<PlatformSchema | undefined>} The platform schema.
268
+ */
127
269
  async getSchema() {
128
270
  return (await this.#server.fetch({ type: 'plugins_getschema', src: 'platform', dst: 'plugins', params: { name: this.name } })).response.schema;
129
271
  }
272
+ /**
273
+ * Set the platform schema for the config editor. This will update the schema in the Matterbridge plugin manager but will not change the schema file.
274
+ *
275
+ * @param {PlatformSchema} [schema] - The platform schema to set.
276
+ * @returns {void}
277
+ */
130
278
  setSchema(schema) {
131
279
  this.#server.request({ type: 'plugins_setschema', src: 'platform', dst: 'plugins', params: { name: this.name, schema } });
132
280
  }
281
+ /**
282
+ * Sends a restart required message to the frontend.
283
+ *
284
+ * @param {boolean} [snackbar] - If true, shows a snackbar notification. Default is true.
285
+ * @param {boolean} [fixed] - If true, shows a fixed notification. Default is false.
286
+ * @returns {void}
287
+ */
133
288
  wssSendRestartRequired(snackbar = true, fixed = false) {
134
289
  this.#server.request({ type: 'frontend_restartrequired', src: 'platform', dst: 'frontend', params: { snackbar, fixed } });
135
290
  }
291
+ /**
292
+ * Sends an open snackbar message to all connected clients.
293
+ *
294
+ * @param {string} message - The message to send.
295
+ * @param {number} timeout - The timeout in seconds for the snackbar message. Default is 5 seconds.
296
+ * @param {'info' | 'warning' | 'error' | 'success'} severity - The severity of the message.
297
+ * possible values are: 'info', 'warning', 'error', 'success'. Default is 'info'.
298
+ *
299
+ * @remarks
300
+ * If timeout is 0, the snackbar message will be displayed until closed by the user.
301
+ */
136
302
  wssSendSnackbarMessage(message, timeout, severity) {
137
303
  this.#server.request({ type: 'frontend_snackbarmessage', src: 'platform', dst: 'frontend', params: { message, timeout, severity } });
138
304
  }
305
+ /**
306
+ * Retrieves the number of devices registered with the platform.
307
+ *
308
+ * @returns {number} The number of registered devices.
309
+ */
139
310
  size() {
140
311
  return this.#registeredEndpoints.size;
141
312
  }
313
+ /**
314
+ * Retrieves the devices registered with the platform.
315
+ *
316
+ * @returns {MatterbridgeEndpoint[]} The registered devices.
317
+ */
142
318
  getDevices() {
143
319
  return Array.from(this.#registeredEndpoints.values());
144
320
  }
321
+ /**
322
+ * Retrieves a registered device by its name.
323
+ *
324
+ * @param {string} deviceName - The device name to search for.
325
+ * @returns {MatterbridgeEndpoint | undefined} The registered device or undefined if not found.
326
+ */
145
327
  getDeviceByName(deviceName) {
146
328
  return Array.from(this.#registeredEndpoints.values()).find((device) => device.deviceName === deviceName);
147
329
  }
330
+ /**
331
+ * Retrieves a registered device by its uniqueId.
332
+ *
333
+ * @param {string} uniqueId - The device unique ID to search for.
334
+ * @returns {MatterbridgeEndpoint | undefined} The registered device or undefined if not found.
335
+ */
148
336
  getDeviceByUniqueId(uniqueId) {
149
337
  return Array.from(this.#registeredEndpoints.values()).find((device) => device.uniqueId === uniqueId);
150
338
  }
339
+ /**
340
+ * Retrieves a registered device by its serialNumber.
341
+ *
342
+ * @param {string} serialNumber - The device serial number to search for.
343
+ * @returns {MatterbridgeEndpoint | undefined} The registered device or undefined if not found.
344
+ */
151
345
  getDeviceBySerialNumber(serialNumber) {
152
346
  return Array.from(this.#registeredEndpoints.values()).find((device) => device.serialNumber === serialNumber);
153
347
  }
348
+ /**
349
+ * Retrieves a registered device by its id.
350
+ *
351
+ * @param {string} id - The device id to search for.
352
+ * @returns {MatterbridgeEndpoint | undefined} The registered device or undefined if not found.
353
+ */
154
354
  getDeviceById(id) {
155
355
  return Array.from(this.#registeredEndpoints.values()).find((device) => device.maybeId === id);
156
356
  }
357
+ /**
358
+ * Retrieves a registered device by its originalId.
359
+ *
360
+ * @param {string} originalId - The device originalId to search for.
361
+ * @returns {MatterbridgeEndpoint | undefined} The registered device or undefined if not found.
362
+ */
157
363
  getDeviceByOriginalId(originalId) {
158
364
  return Array.from(this.#registeredEndpoints.values()).find((device) => device.originalId === originalId);
159
365
  }
366
+ /**
367
+ * Retrieves a registered device by its number.
368
+ *
369
+ * @param {EndpointNumber | number} number - The device number to search for.
370
+ * @returns {MatterbridgeEndpoint | undefined} The registered device or undefined if not found.
371
+ */
160
372
  getDeviceByNumber(number) {
161
373
  return Array.from(this.#registeredEndpoints.values()).find((device) => device.maybeNumber === number);
162
374
  }
375
+ /**
376
+ * Checks if a device with this name is already registered in the platform.
377
+ *
378
+ * @param {string} deviceName - The device name to check.
379
+ * @returns {boolean} True if the device is already registered, false otherwise.
380
+ */
163
381
  hasDeviceName(deviceName) {
164
382
  return Array.from(this.#registeredEndpoints.values()).find((device) => device.deviceName === deviceName) !== undefined;
165
- }
383
+ // return this.registeredEndpointsByName.has(deviceName);
384
+ }
385
+ /**
386
+ * Checks if a device with this uniqueId is already registered in the platform.
387
+ *
388
+ * @param {string} deviceUniqueId - The device unique ID to check.
389
+ * @returns {boolean} True if the device is already registered, false otherwise.
390
+ */
166
391
  hasDeviceUniqueId(deviceUniqueId) {
167
392
  return this.#registeredEndpoints.has(deviceUniqueId);
168
393
  }
394
+ /**
395
+ * Registers a virtual device with the Matterbridge platform.
396
+ * Virtual devices are only supported in bridge mode and childbridge mode with a DynamicPlatform.
397
+ *
398
+ * The virtual device is created as an instance of `Endpoint` with the provided device type.
399
+ * When the virtual device is turned on, the provided callback function is executed.
400
+ * The onOff state of the virtual device always reverts to false when the device is turned on.
401
+ *
402
+ * @param { string } name - The name of the virtual device.
403
+ * @param { 'light' | 'outlet' | 'switch' | 'mounted_switch' } type - The type of the virtual device.
404
+ * @param { () => Promise<void> } callback - The callback to call when the virtual device is turned on.
405
+ *
406
+ * @returns {Promise<boolean>} A promise that resolves to true if the virtual device was successfully registered, false otherwise.
407
+ *
408
+ * @remarks
409
+ * The virtual devices don't show up in the device list of the frontend.
410
+ * Type 'switch' is not supported by Alexa and 'mounted_switch' is not supported by Apple Home.
411
+ */
169
412
  async registerVirtualDevice(name, type, callback) {
170
413
  let aggregator;
414
+ // TODO: replace with a message to the matterbridge thread
171
415
  if (this.matterbridge.bridgeMode === 'bridge') {
172
416
  aggregator = this.matterbridge.aggregatorNode;
173
417
  }
@@ -188,6 +432,25 @@ export class MatterbridgePlatform {
188
432
  this.log.warn(`Virtual device ${name} not created. Virtual devices are only supported in bridge mode and childbridge mode with a DynamicPlatform.`);
189
433
  return false;
190
434
  }
435
+ /**
436
+ * Registers a device with the Matterbridge platform and performs validation checks.
437
+ *
438
+ * This method also checks if the implementation called createDefaultBasicInformationClusterServer() instead of createDefaultBridgedDeviceBasicInformationClusterServer().
439
+ *
440
+ * This is correct with Accessory platforms so we check if we are running in bridge mode and add the bridgedNode and the BridgedDeviceBasicInformation cluster.
441
+ *
442
+ * If we are in bridge mode, we add the bridgedNode device type and the BridgedDeviceBasicInformation cluster.
443
+ *
444
+ * If we are in childbridge mode and the plugin is a 'DynamicPlatform', we add the bridgedNode device type and the BridgedDeviceBasicInformation cluster.
445
+ *
446
+ * if we are in childbridge mode and the plugin is a 'AccessoryPlatform', the device is not bridged so no action is taken.
447
+ *
448
+ * If the device.mode = 'server', the device is not bridged so no action is taken.
449
+ *
450
+ * If the device.mode = 'matter', the device is not bridged so no action is taken.
451
+ *
452
+ * @param {MatterbridgeEndpoint} device - The device to register.
453
+ */
191
454
  async registerDevice(device) {
192
455
  device.plugin = this.name;
193
456
  if (!device.uniqueId) {
@@ -209,7 +472,9 @@ export class MatterbridgePlatform {
209
472
  if (checkNotLatinCharacters(device.deviceName)) {
210
473
  this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has non latin characters.`);
211
474
  }
475
+ // Validate bridgedNode and BridgedDeviceBasicInformation cluster
212
476
  if (device.mode === undefined && (this.matterbridge.bridgeMode === 'bridge' || (this.matterbridge.bridgeMode === 'childbridge' && this.type === 'DynamicPlatform'))) {
477
+ // If the device is a bridged device, we add the bridgedNode to the deviceTypes map and to the Descriptor Cluster options
213
478
  if (!device.deviceTypes.has(bridgedNode.code)) {
214
479
  this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has no bridgedNode device type. Adding it...`);
215
480
  device.deviceTypes.set(bridgedNode.code, bridgedNode);
@@ -221,23 +486,45 @@ export class MatterbridgePlatform {
221
486
  }
222
487
  }
223
488
  }
489
+ // If the device is a bridged device, we add the BridgedDeviceBasicInformation cluster
224
490
  if (!device.hasClusterServer(BridgedDeviceBasicInformation.Cluster.id)) {
225
491
  this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has no BridgedDeviceBasicInformation cluster. Adding it...`);
226
492
  device.createDefaultBridgedDeviceBasicInformationClusterServer(device.deviceName, device.serialNumber, device.vendorId, device.vendorName, device.productName, device.softwareVersion, device.softwareVersionString, device.hardwareVersion, device.hardwareVersionString);
227
493
  }
228
494
  }
495
+ // TODO: replace with a message to the matterbridge thread
229
496
  await this.matterbridge.addBridgedEndpoint(this.name, device);
230
497
  this.#registeredEndpoints.set(device.uniqueId, device);
231
498
  }
499
+ /**
500
+ * Unregisters a device registered with the Matterbridge platform.
501
+ *
502
+ * @param {MatterbridgeEndpoint} device - The device to unregister.
503
+ */
232
504
  async unregisterDevice(device) {
505
+ // TODO: replace with a message to the matterbridge thread
233
506
  await this.matterbridge.removeBridgedEndpoint(this.name, device);
234
507
  if (device.uniqueId)
235
508
  this.#registeredEndpoints.delete(device.uniqueId);
236
509
  }
510
+ /**
511
+ * Unregisters all devices registered with the Matterbridge platform.
512
+ *
513
+ * @param {number} [delay] - The delay in milliseconds between removing each bridged endpoint (default: 0).
514
+ */
237
515
  async unregisterAllDevices(delay = 0) {
516
+ // TODO: replace with a message to the matterbridge thread
238
517
  await this.matterbridge.removeAllBridgedEndpoints(this.name, delay);
239
518
  this.#registeredEndpoints.clear();
240
519
  }
520
+ /**
521
+ * Saves the select devices and entities to storage.
522
+ *
523
+ * This method saves the current state of `selectDevice` and `selectEntity` maps to their respective storage.
524
+ * It logs the number of items being saved and ensures that the storage is properly closed after saving.
525
+ *
526
+ * @returns {Promise<void>} A promise that resolves when the save operation is complete.
527
+ */
241
528
  async saveSelects() {
242
529
  if (this.#storage) {
243
530
  this.log.debug(`Saving ${this.#selectDevices.size} selectDevice...`);
@@ -250,19 +537,60 @@ export class MatterbridgePlatform {
250
537
  await selectEntity.close();
251
538
  }
252
539
  }
540
+ /**
541
+ * Clears all the select device and entity maps and saves the changes to the storage.
542
+ *
543
+ * @returns {void}
544
+ */
253
545
  async clearSelect() {
254
546
  this.#selectDevices.clear();
255
547
  this.#selectEntities.clear();
256
548
  await this.saveSelects();
257
549
  }
550
+ /**
551
+ * Clears the select for a single device and saves the changes to the storage.
552
+ *
553
+ * @param {string} serial - The serial of the device to clear.
554
+ * @returns {void}
555
+ */
258
556
  async clearDeviceSelect(serial) {
259
557
  this.#selectDevices.delete(serial);
260
558
  await this.saveSelects();
261
559
  }
560
+ /**
561
+ * Clears the select for a single entity and saves the changes to the storage.
562
+ *
563
+ * @param {string} name - The name of the entity to clear.
564
+ * @returns {void}
565
+ */
262
566
  async clearEntitySelect(name) {
263
567
  this.#selectEntities.delete(name);
264
568
  await this.saveSelects();
265
569
  }
570
+ /**
571
+ * Set the select device in the platform map.
572
+ *
573
+ * @param {string} serial - The serial number of the device.
574
+ * @param {string} name - The name of the device.
575
+ * @param {string} [configUrl] - The configuration URL of the device.
576
+ * @param {string} [icon] - The icon of the device: 'wifi', 'ble', 'hub'
577
+ * @param {Array<{ name: string; description: string; icon?: string }>} [entities] - The entities associated with the device.
578
+ * @returns {void}
579
+ *
580
+ * @remarks
581
+ * In the schema use selectFrom: 'serial' or 'name'
582
+ * ```json
583
+ * "whiteList": {
584
+ * "description": "Only the devices in the list will be exposed.",
585
+ * "type": "array",
586
+ * "items": {
587
+ * "type": "string"
588
+ * },
589
+ * "uniqueItems": true,
590
+ * "selectFrom": "name"
591
+ * },
592
+ * ```
593
+ */
266
594
  setSelectDevice(serial, name, configUrl, icon, entities) {
267
595
  const device = this.#selectDevices.get(serial);
268
596
  if (device) {
@@ -279,9 +607,44 @@ export class MatterbridgePlatform {
279
607
  this.#selectDevices.set(serial, { serial, name, configUrl, icon, entities });
280
608
  }
281
609
  }
610
+ /**
611
+ * Retrieve a select device by serial.
612
+ *
613
+ * @param {string} serial - The serial number of the device.
614
+ * @returns {{ serial: string; name: string; configUrl?: string; icon?: string; entities?: { name: string; description: string; icon?: string }[] } | undefined} The select device or undefined if not found.
615
+ */
282
616
  getSelectDevice(serial) {
283
617
  return this.#selectDevices.get(serial);
284
618
  }
619
+ /**
620
+ * Set the select device entity in the platform map.
621
+ *
622
+ * @param {string} serial - The serial number of the device.
623
+ * @param {string} entityName - The name of the entity.
624
+ * @param {string} entityDescription - The description of the entity.
625
+ * @param {string} [entityIcon] - The icon of the entity: 'wifi', 'ble', 'hub', 'component', 'matter'
626
+ * @returns {void}
627
+ *
628
+ * @remarks
629
+ * In the schema use selectDeviceEntityFrom: 'name' or 'description'
630
+ * ```json
631
+ * "deviceEntityBlackList": {
632
+ * "description": "List of entities not to be exposed for a single device.",
633
+ * "type": "object",
634
+ * "uniqueItems": true,
635
+ * "selectFrom": "name",
636
+ * "additionalProperties": {
637
+ * "description": "List of entities not to be exposed for this device.",
638
+ * "type": "array",
639
+ * "items": {
640
+ * "type": "string"
641
+ * },
642
+ * "uniqueItems": true,
643
+ * "selectDeviceEntityFrom": "name"
644
+ * }
645
+ * },
646
+ * ```
647
+ */
285
648
  setSelectDeviceEntity(serial, entityName, entityDescription, entityIcon) {
286
649
  const device = this.#selectDevices.get(serial);
287
650
  if (device) {
@@ -291,6 +654,11 @@ export class MatterbridgePlatform {
291
654
  device.entities.push({ name: entityName, description: entityDescription, icon: entityIcon });
292
655
  }
293
656
  }
657
+ /**
658
+ * Retrieves the select devices from the platform map.
659
+ *
660
+ * @returns {ApiSelectDevice[]} The selected devices array.
661
+ */
294
662
  getSelectDevices() {
295
663
  const selectDevices = [];
296
664
  for (const device of this.#selectDevices.values()) {
@@ -298,12 +666,45 @@ export class MatterbridgePlatform {
298
666
  }
299
667
  return selectDevices;
300
668
  }
669
+ /**
670
+ * Set the select entity in the platform map.
671
+ *
672
+ * @param {string} name - The entity name.
673
+ * @param {string} description - The entity description.
674
+ * @param {string} [icon] - The entity icon: 'wifi', 'ble', 'hub', 'component', 'matter'
675
+ * @returns {void}
676
+ *
677
+ * @remarks
678
+ * In the schema use selectEntityFrom: 'name' or 'description'
679
+ * ```json
680
+ * "entityBlackList": {
681
+ * "description": "The entities in the list will not be exposed.",
682
+ * "type": "array",
683
+ * "items": {
684
+ * "type": "string"
685
+ * },
686
+ * "uniqueItems": true,
687
+ * "selectEntityFrom": "name"
688
+ * },
689
+ * ```
690
+ */
301
691
  setSelectEntity(name, description, icon) {
302
692
  this.#selectEntities.set(name, { name, description, icon });
303
693
  }
694
+ /**
695
+ * Retrieve a select entity by name.
696
+ *
697
+ * @param {string} name - The name of the entity.
698
+ * @returns {{ name: string; description: string; icon?: string } | undefined} The select entity or undefined if not found.
699
+ */
304
700
  getSelectEntity(name) {
305
701
  return this.#selectEntities.get(name);
306
702
  }
703
+ /**
704
+ * Retrieve the select entities.
705
+ *
706
+ * @returns {ApiSelectEntity[]} The select entities array.
707
+ */
307
708
  getSelectEntities() {
308
709
  const selectEntities = [];
309
710
  for (const entity of this.#selectEntities.values()) {
@@ -311,6 +712,12 @@ export class MatterbridgePlatform {
311
712
  }
312
713
  return selectEntities;
313
714
  }
715
+ /**
716
+ * Verifies if the Matterbridge version meets the required version.
717
+ *
718
+ * @param {string} requiredVersion - The required version to compare against.
719
+ * @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
720
+ */
314
721
  verifyMatterbridgeVersion(requiredVersion) {
315
722
  const compareVersions = (matterbridgeVersion, requiredVersion) => {
316
723
  const stripTag = (v) => {
@@ -335,6 +742,14 @@ export class MatterbridgePlatform {
335
742
  return false;
336
743
  return true;
337
744
  }
745
+ /**
746
+ * Validates if a device is allowed based on the whitelist and blacklist configurations.
747
+ * The blacklist has priority over the whitelist.
748
+ *
749
+ * @param {string | string[]} device - The device name(s) to validate.
750
+ * @param {boolean} [log] - Whether to log the validation result.
751
+ * @returns {boolean} - Returns true if the device is allowed, false otherwise.
752
+ */
338
753
  validateDevice(device, log = true) {
339
754
  if (!Array.isArray(device))
340
755
  device = [device];
@@ -364,6 +779,14 @@ export class MatterbridgePlatform {
364
779
  this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
365
780
  return false;
366
781
  }
782
+ /**
783
+ * Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
784
+ *
785
+ * @param {string} device - The device to which the entity belongs.
786
+ * @param {string} entity - The entity to validate.
787
+ * @param {boolean} [log] - Whether to log the validation result.
788
+ * @returns {boolean} - Returns true if the entity is allowed, false otherwise.
789
+ */
367
790
  validateEntity(device, entity, log = true) {
368
791
  if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
369
792
  if (log)
@@ -382,10 +805,24 @@ export class MatterbridgePlatform {
382
805
  }
383
806
  return true;
384
807
  }
808
+ /**
809
+ * Clears all stored endpoint numbers for checkEndpointNumbers().
810
+ *
811
+ * @returns {Promise<void>} A promise that resolves when the endpoint numbers have been cleared.
812
+ */
385
813
  async clearEndpointNumbers() {
386
814
  const context = await this.#storage.createStorage('endpointNumbers');
387
815
  await context.set('endpointMap', []);
388
816
  }
817
+ /**
818
+ * Checks and updates the endpoint numbers for Matterbridge devices.
819
+ *
820
+ * This method retrieves the list of Matterbridge devices and their child endpoints,
821
+ * compares their current endpoint numbers with the stored ones, and updates the storage
822
+ * if there are any changes. It logs the changes and updates the endpoint numbers accordingly.
823
+ *
824
+ * @returns {Promise<number>} The size of the updated endpoint map, or -1 if storage is not available.
825
+ */
389
826
  async checkEndpointNumbers() {
390
827
  this.log.debug('Checking endpoint numbers...');
391
828
  const context = await this.#storage.createStorage('endpointNumbers');
@@ -424,3 +861,4 @@ export class MatterbridgePlatform {
424
861
  return endpointMap.size;
425
862
  }
426
863
  }
864
+ //# sourceMappingURL=matterbridgePlatform.js.map