matterbridge 3.4.2 → 3.4.3-dev-20251207-3ce5a0e

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