matterbridge 3.3.6 → 3.3.7-dev-20251104-7c779b9

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 (306) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/broadcastServer.js +1 -92
  3. package/dist/broadcastServerTypes.js +0 -24
  4. package/dist/cli.js +1 -97
  5. package/dist/cliEmitter.js +0 -37
  6. package/dist/cliHistory.js +0 -38
  7. package/dist/clusters/export.js +0 -2
  8. package/dist/defaultConfigSchema.js +0 -24
  9. package/dist/deviceManager.js +1 -124
  10. package/dist/devices/airConditioner.js +0 -57
  11. package/dist/devices/batteryStorage.js +1 -48
  12. package/dist/devices/cooktop.js +0 -55
  13. package/dist/devices/dishwasher.js +0 -57
  14. package/dist/devices/evse.js +10 -74
  15. package/dist/devices/export.js +0 -5
  16. package/dist/devices/extractorHood.js +0 -42
  17. package/dist/devices/heatPump.js +2 -50
  18. package/dist/devices/laundryDryer.js +3 -62
  19. package/dist/devices/laundryWasher.js +4 -70
  20. package/dist/devices/microwaveOven.js +5 -88
  21. package/dist/devices/oven.js +0 -85
  22. package/dist/devices/refrigerator.js +0 -102
  23. package/dist/devices/roboticVacuumCleaner.js +9 -100
  24. package/dist/devices/solarPower.js +0 -38
  25. package/dist/devices/speaker.js +0 -84
  26. package/dist/devices/temperatureControl.js +3 -24
  27. package/dist/devices/waterHeater.js +2 -82
  28. package/dist/dgram/coap.js +13 -126
  29. package/dist/dgram/dgram.js +2 -114
  30. package/dist/dgram/mb_coap.js +3 -41
  31. package/dist/dgram/mb_mdns.js +15 -80
  32. package/dist/dgram/mdns.js +137 -299
  33. package/dist/dgram/multicast.js +1 -62
  34. package/dist/dgram/unicast.js +0 -54
  35. package/dist/frontend.js +55 -451
  36. package/dist/frontendTypes.js +0 -45
  37. package/dist/helpers.js +0 -53
  38. package/dist/index.js +0 -25
  39. package/dist/logger/export.js +0 -1
  40. package/dist/matter/behaviors.js +0 -2
  41. package/dist/matter/clusters.js +0 -2
  42. package/dist/matter/devices.js +0 -2
  43. package/dist/matter/endpoints.js +0 -2
  44. package/dist/matter/export.js +0 -3
  45. package/dist/matter/types.js +0 -3
  46. package/dist/matterbridge.js +66 -841
  47. package/dist/matterbridgeAccessoryPlatform.js +0 -37
  48. package/dist/matterbridgeBehaviors.js +5 -68
  49. package/dist/matterbridgeDeviceTypes.js +17 -638
  50. package/dist/matterbridgeDynamicPlatform.js +0 -37
  51. package/dist/matterbridgeEndpoint.js +52 -1408
  52. package/dist/matterbridgeEndpointHelpers.js +19 -464
  53. package/dist/matterbridgePlatform.js +1 -341
  54. package/dist/matterbridgeTypes.js +0 -26
  55. package/dist/pluginManager.js +3 -319
  56. package/dist/shelly.js +7 -168
  57. package/dist/storage/export.js +0 -1
  58. package/dist/update.js +0 -69
  59. package/dist/utils/colorUtils.js +2 -97
  60. package/dist/utils/commandLine.js +0 -60
  61. package/dist/utils/copyDirectory.js +1 -38
  62. package/dist/utils/createDirectory.js +0 -33
  63. package/dist/utils/createZip.js +2 -47
  64. package/dist/utils/deepCopy.js +0 -39
  65. package/dist/utils/deepEqual.js +1 -72
  66. package/dist/utils/error.js +0 -41
  67. package/dist/utils/export.js +0 -1
  68. package/dist/utils/format.js +0 -49
  69. package/dist/utils/hex.js +0 -124
  70. package/dist/utils/inspector.js +1 -69
  71. package/dist/utils/isvalid.js +0 -101
  72. package/dist/utils/jestHelpers.js +3 -153
  73. package/dist/utils/network.js +5 -96
  74. package/dist/utils/spawn.js +0 -71
  75. package/dist/utils/tracker.js +1 -64
  76. package/dist/utils/wait.js +8 -60
  77. package/frontend/build/assets/index.css +1 -1
  78. package/frontend/build/assets/index.js +4 -4
  79. package/frontend/package.json +1 -1
  80. package/npm-shrinkwrap.json +2 -2
  81. package/package.json +1 -2
  82. package/dist/broadcastServer.d.ts +0 -112
  83. package/dist/broadcastServer.d.ts.map +0 -1
  84. package/dist/broadcastServer.js.map +0 -1
  85. package/dist/broadcastServerTypes.d.ts +0 -803
  86. package/dist/broadcastServerTypes.d.ts.map +0 -1
  87. package/dist/broadcastServerTypes.js.map +0 -1
  88. package/dist/cli.d.ts +0 -30
  89. package/dist/cli.d.ts.map +0 -1
  90. package/dist/cli.js.map +0 -1
  91. package/dist/cliEmitter.d.ts +0 -50
  92. package/dist/cliEmitter.d.ts.map +0 -1
  93. package/dist/cliEmitter.js.map +0 -1
  94. package/dist/cliHistory.d.ts +0 -48
  95. package/dist/cliHistory.d.ts.map +0 -1
  96. package/dist/cliHistory.js.map +0 -1
  97. package/dist/clusters/export.d.ts +0 -2
  98. package/dist/clusters/export.d.ts.map +0 -1
  99. package/dist/clusters/export.js.map +0 -1
  100. package/dist/defaultConfigSchema.d.ts +0 -28
  101. package/dist/defaultConfigSchema.d.ts.map +0 -1
  102. package/dist/defaultConfigSchema.js.map +0 -1
  103. package/dist/deviceManager.d.ts +0 -117
  104. package/dist/deviceManager.d.ts.map +0 -1
  105. package/dist/deviceManager.js.map +0 -1
  106. package/dist/devices/airConditioner.d.ts +0 -98
  107. package/dist/devices/airConditioner.d.ts.map +0 -1
  108. package/dist/devices/airConditioner.js.map +0 -1
  109. package/dist/devices/batteryStorage.d.ts +0 -48
  110. package/dist/devices/batteryStorage.d.ts.map +0 -1
  111. package/dist/devices/batteryStorage.js.map +0 -1
  112. package/dist/devices/cooktop.d.ts +0 -60
  113. package/dist/devices/cooktop.d.ts.map +0 -1
  114. package/dist/devices/cooktop.js.map +0 -1
  115. package/dist/devices/dishwasher.d.ts +0 -71
  116. package/dist/devices/dishwasher.d.ts.map +0 -1
  117. package/dist/devices/dishwasher.js.map +0 -1
  118. package/dist/devices/evse.d.ts +0 -76
  119. package/dist/devices/evse.d.ts.map +0 -1
  120. package/dist/devices/evse.js.map +0 -1
  121. package/dist/devices/export.d.ts +0 -17
  122. package/dist/devices/export.d.ts.map +0 -1
  123. package/dist/devices/export.js.map +0 -1
  124. package/dist/devices/extractorHood.d.ts +0 -46
  125. package/dist/devices/extractorHood.d.ts.map +0 -1
  126. package/dist/devices/extractorHood.js.map +0 -1
  127. package/dist/devices/heatPump.d.ts +0 -47
  128. package/dist/devices/heatPump.d.ts.map +0 -1
  129. package/dist/devices/heatPump.js.map +0 -1
  130. package/dist/devices/laundryDryer.d.ts +0 -67
  131. package/dist/devices/laundryDryer.d.ts.map +0 -1
  132. package/dist/devices/laundryDryer.js.map +0 -1
  133. package/dist/devices/laundryWasher.d.ts +0 -81
  134. package/dist/devices/laundryWasher.d.ts.map +0 -1
  135. package/dist/devices/laundryWasher.js.map +0 -1
  136. package/dist/devices/microwaveOven.d.ts +0 -168
  137. package/dist/devices/microwaveOven.d.ts.map +0 -1
  138. package/dist/devices/microwaveOven.js.map +0 -1
  139. package/dist/devices/oven.d.ts +0 -105
  140. package/dist/devices/oven.d.ts.map +0 -1
  141. package/dist/devices/oven.js.map +0 -1
  142. package/dist/devices/refrigerator.d.ts +0 -118
  143. package/dist/devices/refrigerator.d.ts.map +0 -1
  144. package/dist/devices/refrigerator.js.map +0 -1
  145. package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
  146. package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
  147. package/dist/devices/roboticVacuumCleaner.js.map +0 -1
  148. package/dist/devices/solarPower.d.ts +0 -40
  149. package/dist/devices/solarPower.d.ts.map +0 -1
  150. package/dist/devices/solarPower.js.map +0 -1
  151. package/dist/devices/speaker.d.ts +0 -87
  152. package/dist/devices/speaker.d.ts.map +0 -1
  153. package/dist/devices/speaker.js.map +0 -1
  154. package/dist/devices/temperatureControl.d.ts +0 -166
  155. package/dist/devices/temperatureControl.d.ts.map +0 -1
  156. package/dist/devices/temperatureControl.js.map +0 -1
  157. package/dist/devices/waterHeater.d.ts +0 -111
  158. package/dist/devices/waterHeater.d.ts.map +0 -1
  159. package/dist/devices/waterHeater.js.map +0 -1
  160. package/dist/dgram/coap.d.ts +0 -205
  161. package/dist/dgram/coap.d.ts.map +0 -1
  162. package/dist/dgram/coap.js.map +0 -1
  163. package/dist/dgram/dgram.d.ts +0 -141
  164. package/dist/dgram/dgram.d.ts.map +0 -1
  165. package/dist/dgram/dgram.js.map +0 -1
  166. package/dist/dgram/mb_coap.d.ts +0 -24
  167. package/dist/dgram/mb_coap.d.ts.map +0 -1
  168. package/dist/dgram/mb_coap.js.map +0 -1
  169. package/dist/dgram/mb_mdns.d.ts +0 -24
  170. package/dist/dgram/mb_mdns.d.ts.map +0 -1
  171. package/dist/dgram/mb_mdns.js.map +0 -1
  172. package/dist/dgram/mdns.d.ts +0 -290
  173. package/dist/dgram/mdns.d.ts.map +0 -1
  174. package/dist/dgram/mdns.js.map +0 -1
  175. package/dist/dgram/multicast.d.ts +0 -67
  176. package/dist/dgram/multicast.d.ts.map +0 -1
  177. package/dist/dgram/multicast.js.map +0 -1
  178. package/dist/dgram/unicast.d.ts +0 -56
  179. package/dist/dgram/unicast.d.ts.map +0 -1
  180. package/dist/dgram/unicast.js.map +0 -1
  181. package/dist/frontend.d.ts +0 -236
  182. package/dist/frontend.d.ts.map +0 -1
  183. package/dist/frontend.js.map +0 -1
  184. package/dist/frontendTypes.d.ts +0 -529
  185. package/dist/frontendTypes.d.ts.map +0 -1
  186. package/dist/frontendTypes.js.map +0 -1
  187. package/dist/helpers.d.ts +0 -48
  188. package/dist/helpers.d.ts.map +0 -1
  189. package/dist/helpers.js.map +0 -1
  190. package/dist/index.d.ts +0 -33
  191. package/dist/index.d.ts.map +0 -1
  192. package/dist/index.js.map +0 -1
  193. package/dist/logger/export.d.ts +0 -2
  194. package/dist/logger/export.d.ts.map +0 -1
  195. package/dist/logger/export.js.map +0 -1
  196. package/dist/matter/behaviors.d.ts +0 -2
  197. package/dist/matter/behaviors.d.ts.map +0 -1
  198. package/dist/matter/behaviors.js.map +0 -1
  199. package/dist/matter/clusters.d.ts +0 -2
  200. package/dist/matter/clusters.d.ts.map +0 -1
  201. package/dist/matter/clusters.js.map +0 -1
  202. package/dist/matter/devices.d.ts +0 -2
  203. package/dist/matter/devices.d.ts.map +0 -1
  204. package/dist/matter/devices.js.map +0 -1
  205. package/dist/matter/endpoints.d.ts +0 -2
  206. package/dist/matter/endpoints.d.ts.map +0 -1
  207. package/dist/matter/endpoints.js.map +0 -1
  208. package/dist/matter/export.d.ts +0 -5
  209. package/dist/matter/export.d.ts.map +0 -1
  210. package/dist/matter/export.js.map +0 -1
  211. package/dist/matter/types.d.ts +0 -3
  212. package/dist/matter/types.d.ts.map +0 -1
  213. package/dist/matter/types.js.map +0 -1
  214. package/dist/matterbridge.d.ts +0 -476
  215. package/dist/matterbridge.d.ts.map +0 -1
  216. package/dist/matterbridge.js.map +0 -1
  217. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
  218. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  219. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  220. package/dist/matterbridgeBehaviors.d.ts +0 -2404
  221. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  222. package/dist/matterbridgeBehaviors.js.map +0 -1
  223. package/dist/matterbridgeDeviceTypes.d.ts +0 -770
  224. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  225. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  226. package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
  227. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  228. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  229. package/dist/matterbridgeEndpoint.d.ts +0 -1556
  230. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  231. package/dist/matterbridgeEndpoint.js.map +0 -1
  232. package/dist/matterbridgeEndpointHelpers.d.ts +0 -758
  233. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  234. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  235. package/dist/matterbridgePlatform.d.ts +0 -402
  236. package/dist/matterbridgePlatform.d.ts.map +0 -1
  237. package/dist/matterbridgePlatform.js.map +0 -1
  238. package/dist/matterbridgeTypes.d.ts +0 -226
  239. package/dist/matterbridgeTypes.d.ts.map +0 -1
  240. package/dist/matterbridgeTypes.js.map +0 -1
  241. package/dist/pluginManager.d.ts +0 -347
  242. package/dist/pluginManager.d.ts.map +0 -1
  243. package/dist/pluginManager.js.map +0 -1
  244. package/dist/shelly.d.ts +0 -174
  245. package/dist/shelly.d.ts.map +0 -1
  246. package/dist/shelly.js.map +0 -1
  247. package/dist/storage/export.d.ts +0 -2
  248. package/dist/storage/export.d.ts.map +0 -1
  249. package/dist/storage/export.js.map +0 -1
  250. package/dist/update.d.ts +0 -75
  251. package/dist/update.d.ts.map +0 -1
  252. package/dist/update.js.map +0 -1
  253. package/dist/utils/colorUtils.d.ts +0 -101
  254. package/dist/utils/colorUtils.d.ts.map +0 -1
  255. package/dist/utils/colorUtils.js.map +0 -1
  256. package/dist/utils/commandLine.d.ts +0 -66
  257. package/dist/utils/commandLine.d.ts.map +0 -1
  258. package/dist/utils/commandLine.js.map +0 -1
  259. package/dist/utils/copyDirectory.d.ts +0 -33
  260. package/dist/utils/copyDirectory.d.ts.map +0 -1
  261. package/dist/utils/copyDirectory.js.map +0 -1
  262. package/dist/utils/createDirectory.d.ts +0 -34
  263. package/dist/utils/createDirectory.d.ts.map +0 -1
  264. package/dist/utils/createDirectory.js.map +0 -1
  265. package/dist/utils/createZip.d.ts +0 -39
  266. package/dist/utils/createZip.d.ts.map +0 -1
  267. package/dist/utils/createZip.js.map +0 -1
  268. package/dist/utils/deepCopy.d.ts +0 -32
  269. package/dist/utils/deepCopy.d.ts.map +0 -1
  270. package/dist/utils/deepCopy.js.map +0 -1
  271. package/dist/utils/deepEqual.d.ts +0 -54
  272. package/dist/utils/deepEqual.d.ts.map +0 -1
  273. package/dist/utils/deepEqual.js.map +0 -1
  274. package/dist/utils/error.d.ts +0 -44
  275. package/dist/utils/error.d.ts.map +0 -1
  276. package/dist/utils/error.js.map +0 -1
  277. package/dist/utils/export.d.ts +0 -13
  278. package/dist/utils/export.d.ts.map +0 -1
  279. package/dist/utils/export.js.map +0 -1
  280. package/dist/utils/format.d.ts +0 -53
  281. package/dist/utils/format.d.ts.map +0 -1
  282. package/dist/utils/format.js.map +0 -1
  283. package/dist/utils/hex.d.ts +0 -89
  284. package/dist/utils/hex.d.ts.map +0 -1
  285. package/dist/utils/hex.js.map +0 -1
  286. package/dist/utils/inspector.d.ts +0 -87
  287. package/dist/utils/inspector.d.ts.map +0 -1
  288. package/dist/utils/inspector.js.map +0 -1
  289. package/dist/utils/isvalid.d.ts +0 -103
  290. package/dist/utils/isvalid.d.ts.map +0 -1
  291. package/dist/utils/isvalid.js.map +0 -1
  292. package/dist/utils/jestHelpers.d.ts +0 -139
  293. package/dist/utils/jestHelpers.d.ts.map +0 -1
  294. package/dist/utils/jestHelpers.js.map +0 -1
  295. package/dist/utils/network.d.ts +0 -101
  296. package/dist/utils/network.d.ts.map +0 -1
  297. package/dist/utils/network.js.map +0 -1
  298. package/dist/utils/spawn.d.ts +0 -35
  299. package/dist/utils/spawn.d.ts.map +0 -1
  300. package/dist/utils/spawn.js.map +0 -1
  301. package/dist/utils/tracker.d.ts +0 -108
  302. package/dist/utils/tracker.d.ts.map +0 -1
  303. package/dist/utils/tracker.js.map +0 -1
  304. package/dist/utils/wait.d.ts +0 -54
  305. package/dist/utils/wait.d.ts.map +0 -1
  306. package/dist/utils/wait.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.3.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
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';
@@ -36,54 +9,27 @@ import { checkNotLatinCharacters } from './matterbridgeEndpointHelpers.js';
36
9
  import { bridgedNode } from './matterbridgeDeviceTypes.js';
37
10
  import { isValidArray, isValidObject, isValidString } from './utils/isvalid.js';
38
11
  import { addVirtualDevice } from './helpers.js';
39
- /**
40
- * Represents the base Matterbridge platform. It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
41
- *
42
- */
43
12
  export class MatterbridgePlatform {
44
- /** The Matterbridge instance of this Platform. */
45
13
  matterbridge;
46
- /** The logger instance for this platform. */
47
14
  log;
48
- /** The configuration for this platform. */
49
15
  config;
50
- /** The name of the platform. Will be set by the loadPlugin() method using the package.json value. */
51
16
  name = '';
52
- /** The type of the platform. Will be set by the extending classes. */
53
17
  type = 'AnyPlatform';
54
- /** The version of the platform. Will be set by the loadPlugin() method using the package.json value */
55
18
  version = '1.0.0';
56
- /** Platform node storage manager in the matterbridgeDirectory. */
57
19
  storage;
58
- /** Platform context in the storage of matterbridgeDirectory. Use await platform.ready to access it early. */
59
20
  context;
60
- // Device and entity select in the plugin config UI
61
21
  selectDevice = new Map();
62
22
  selectEntity = new Map();
63
- // Promises for platform initialization. They are grouped in platform.ready with Promise.all.
64
23
  contextReady;
65
24
  selectDeviceContextReady;
66
25
  selectEntityContextReady;
67
- /** The ready promise for the platform, which resolves when the platform is fully initialized (including context and selects). */
68
26
  ready;
69
- /** Registered MatterbridgeEndpoint Map keyed by uniqueId */
70
27
  registeredEndpointsByUniqueId = new Map();
71
- /** Registered MatterbridgeEndpoint Map keyed by deviceName */
72
28
  registeredEndpointsByName = new Map();
73
- /**
74
- * Creates an instance of the base MatterbridgePlatform.
75
- * It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
76
- * Each plugin must extend the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
77
- *
78
- * @param {PlatformMatterbridge} matterbridge - The Matterbridge instance.
79
- * @param {AnsiLogger} log - The logger instance.
80
- * @param {PlatformConfig} config - The platform configuration.
81
- */
82
29
  constructor(matterbridge, log, config) {
83
30
  this.matterbridge = matterbridge;
84
31
  this.log = log;
85
32
  this.config = config;
86
- // create the NodeStorageManager for the plugin platform
87
33
  if (!isValidString(this.config.name, 1))
88
34
  throw new Error('Platform: the plugin name is missing or invalid.');
89
35
  this.log.debug(`Creating storage for plugin ${this.config.name} in ${path.join(this.matterbridge.matterbridgeDirectory, this.config.name)}`);
@@ -94,14 +40,12 @@ export class MatterbridgePlatform {
94
40
  logging: false,
95
41
  forgiveParseErrors: true,
96
42
  });
97
- // create the context storage for the plugin platform
98
43
  this.log.debug(`Creating context for plugin ${this.config.name}`);
99
44
  this.contextReady = this.storage.createStorage('context').then((context) => {
100
45
  this.context = context;
101
46
  this.log.debug(`Created context for plugin ${this.config.name}`);
102
47
  return;
103
48
  });
104
- // create the selectDevice storage for the plugin platform
105
49
  this.log.debug(`Loading selectDevice for plugin ${this.config.name}`);
106
50
  this.selectDeviceContextReady = this.storage.createStorage('selectDevice').then(async (context) => {
107
51
  const selectDevice = await context.get('selectDevice', []);
@@ -110,7 +54,6 @@ export class MatterbridgePlatform {
110
54
  this.log.debug(`Loaded ${this.selectDevice.size} selectDevice for plugin ${this.config.name}`);
111
55
  return;
112
56
  });
113
- // create the selectEntity storage for the plugin platform
114
57
  this.log.debug(`Loading selectEntity for plugin ${this.config.name}`);
115
58
  this.selectEntityContextReady = this.storage.createStorage('selectEntity').then(async (context) => {
116
59
  const selectEntity = await context.get('selectEntity', []);
@@ -119,165 +62,59 @@ export class MatterbridgePlatform {
119
62
  this.log.debug(`Loaded ${this.selectEntity.size} selectEntity for plugin ${this.config.name}`);
120
63
  return;
121
64
  });
122
- // Create the `ready` promise for the platform
123
65
  this.ready = Promise.all([this.contextReady, this.selectDeviceContextReady, this.selectEntityContextReady]).then(() => {
124
66
  this.log.debug(`MatterbridgePlatform for plugin ${this.config.name} is fully initialized`);
125
67
  return;
126
68
  });
127
69
  }
128
- /**
129
- * This method shall be overridden in the extended class.
130
- * It is called when the platform is started.
131
- * Use this method to create the MatterbridgeEndpoints and call this.registerDevice().
132
- *
133
- * @param {string} [reason] - The reason for starting.
134
- * @throws {Error} - Throws an error if the method is not overridden.
135
- */
136
70
  async onStart(reason) {
137
71
  this.log.error('Plugins must override onStart.', reason);
138
72
  throw new Error('Plugins must override onStart.');
139
73
  }
140
- /**
141
- * This method can be overridden in the extended class. In this case always call super.onConfigure() to save the select and run checkEndpointNumbers().
142
- * It is called after the platform has started.
143
- * 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
144
- * matter storage (i.e. the onOff attribute of the OnOff cluster).
145
- */
146
74
  async onConfigure() {
147
75
  this.log.debug(`Configuring platform ${this.name}`);
148
- // Save the selectDevice and selectEntity
149
76
  await this.saveSelects();
150
- // Check and update the endpoint numbers
151
77
  await this.checkEndpointNumbers();
152
78
  }
153
- /**
154
- * 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.
155
- * It is called when the platform is shutting down.
156
- * Use this method to clean up any resources you used in the constructor or onStart.
157
- *
158
- * @param {string} [reason] - The reason for shutting down.
159
- */
160
79
  async onShutdown(reason) {
161
80
  this.log.debug(`Shutting down platform ${this.name}`, reason);
162
- // Save the selectDevice and selectEntity
163
81
  await this.saveSelects();
164
- // Check and update the endpoint numbers
165
82
  await this.checkEndpointNumbers();
166
- // Cleanup memory
167
83
  this.selectDevice.clear();
168
84
  this.selectEntity.clear();
169
85
  this.registeredEndpointsByUniqueId.clear();
170
86
  this.registeredEndpointsByName.clear();
171
- // Close the storage
172
87
  await this.context?.close();
173
88
  this.context = undefined;
174
89
  await this.storage?.close();
175
90
  }
176
- /**
177
- * Called when the logger level is changed.
178
- *
179
- * @param {LogLevel} logLevel The new logger level.
180
- */
181
91
  async onChangeLoggerLevel(logLevel) {
182
92
  this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
183
93
  }
184
- /**
185
- * Called when a plugin config includes an action button or an action button with text field.
186
- *
187
- * @param {string} action The action triggered by the button in plugin config.
188
- * @param {string} value The value of the field of the action button.
189
- * @param {string} id The id of the schema associated with the action.
190
- * @param {PlatformConfig} formData The changed form data of the plugin.
191
- *
192
- * @remarks
193
- * This method can be overridden in the extended class.
194
- *
195
- * Use this method to handle the action defined in the plugin schema:
196
- * ```json
197
- * "addDevice": {
198
- * "description": "Manually add a device that has not been discovered with mdns:",
199
- * "type": "boolean",
200
- * "buttonText": "ADD", // The text on the button. This is used when the action doesn't include a text field.
201
- * "buttonField": "ADD", // The text on the button. This is used when the action includes a text field.
202
- * "buttonClose": false, // optional, default is false. When true, the dialog will close after the action is sent.
203
- * "buttonSave": false, // optional, default is false. When true, the dialog will close and trigger the restart required after the action is sent.
204
- * "textPlaceholder": "Enter the device IP address", // optional: the placeholder text for the text field.
205
- * "default": false
206
- * },
207
- * ```
208
- */
209
94
  async onAction(action, value, id, formData) {
210
95
  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);
211
96
  }
212
- /**
213
- * Called when the plugin config has been updated.
214
- *
215
- * @param {PlatformConfig} config The new plugin config.
216
- */
217
97
  async onConfigChanged(config) {
218
98
  this.log.debug(`The plugin ${CYAN}${config.name}${db} doesn't override onConfigChanged. Received new config.`);
219
99
  }
220
- /**
221
- * Save the platform configuration to the platform config JSON.
222
- *
223
- * @param {PlatformConfig} [config] - The platform configuration to save.
224
- * @returns {void}
225
- */
226
100
  saveConfig(config) {
227
- // TODO: replace with a message to the matterbridge thread
228
101
  const plugin = this.matterbridge.plugins.get(this.name);
229
102
  if (!plugin) {
230
103
  throw new Error(`Plugin ${this.name} not found`);
231
104
  }
232
- this.matterbridge.plugins.saveConfigFromJson(plugin, config); // No await as it's not necessary to wait
105
+ this.matterbridge.plugins.saveConfigFromJson(plugin, config);
233
106
  }
234
- /**
235
- * Sends a restart required message to the frontend.
236
- *
237
- * @param {boolean} [snackbar] - If true, shows a snackbar notification. Default is true.
238
- * @param {boolean} [fixed] - If true, shows a fixed notification. Default is false.
239
- * @returns {void}
240
- */
241
107
  wssSendRestartRequired(snackbar = true, fixed = false) {
242
- // TODO: replace with a message to the frontend thread
243
108
  this.matterbridge.frontend.wssSendRestartRequired(snackbar, fixed);
244
109
  }
245
- /**
246
- * Retrieves the devices registered with the platform.
247
- *
248
- * @returns {MatterbridgeEndpoint[]} The registered devices.
249
- */
250
110
  getDevices() {
251
111
  return Array.from(this.registeredEndpointsByUniqueId.values());
252
112
  }
253
- /**
254
- * Checks if a device with this name is already registered in the platform.
255
- *
256
- * @param {string} deviceName - The device name to check.
257
- * @returns {boolean} True if the device is already registered, false otherwise.
258
- */
259
113
  hasDeviceName(deviceName) {
260
114
  return this.registeredEndpointsByName.has(deviceName);
261
115
  }
262
- /**
263
- * Registers a virtual device with the platform aggregator endpoint.
264
- *
265
- * The virtual device is created as an instance of `Endpoint` with the provided device type.
266
- * When the virtual device is turned on, the provided callback function is executed.
267
- * The onOff state of the virtual device always reverts to false when the device is turned on.
268
- *
269
- * @param { string } name - The name of the virtual device.
270
- * @param { 'light' | 'outlet' | 'switch' | 'mounted_switch' } type - The type of the virtual device.
271
- * @param { () => Promise<void> } callback - The callback to call when the virtual device is turned on.
272
- *
273
- * @returns {Promise<void>} A promise that resolves when the virtual device is registered.
274
- *
275
- * @remarks
276
- * The virtual devices don't show up in the device list of the frontend.
277
- */
278
116
  async registerVirtualDevice(name, type, callback) {
279
117
  let aggregator;
280
- // TODO: replace with a message to the matterbridge thread
281
118
  if (this.matterbridge.bridgeMode === 'bridge') {
282
119
  aggregator = this.matterbridge.aggregatorNode;
283
120
  }
@@ -294,25 +131,6 @@ export class MatterbridgePlatform {
294
131
  }
295
132
  }
296
133
  }
297
- /**
298
- * Registers a device with the Matterbridge platform and performs validation checks.
299
- *
300
- * This method also checks if the implementation called createDefaultBasicInformationClusterServer() instead of createDefaultBridgedDeviceBasicInformationClusterServer().
301
- *
302
- * This is correct with Accessory platforms so we check if we are running in bridge mode and add the bridgedNode and the BridgedDeviceBasicInformation cluster.
303
- *
304
- * If we are in bridge mode, we add the bridgedNode device type and the BridgedDeviceBasicInformation cluster.
305
- *
306
- * If we are in childbridge mode and the plugin is a 'DynamicPlatform', we add the bridgedNode device type and the BridgedDeviceBasicInformation cluster.
307
- *
308
- * if we are in childbridge mode and the plugin is a 'AccessoryPlatform', the device is not bridged so no action is taken.
309
- *
310
- * If the device.mode = 'server', the device is not bridged so no action is taken.
311
- *
312
- * If the device.mode = 'matter', the device is not bridged so no action is taken.
313
- *
314
- * @param {MatterbridgeEndpoint} device - The device to register.
315
- */
316
134
  async registerDevice(device) {
317
135
  device.plugin = this.name;
318
136
  if (!device.uniqueId) {
@@ -334,9 +152,7 @@ export class MatterbridgePlatform {
334
152
  if (checkNotLatinCharacters(device.deviceName)) {
335
153
  this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has non latin characters.`);
336
154
  }
337
- // Validate bridgedNode and BridgedDeviceBasicInformation cluster
338
155
  if (device.mode === undefined && (this.matterbridge.bridgeMode === 'bridge' || (this.matterbridge.bridgeMode === 'childbridge' && this.type === 'DynamicPlatform'))) {
339
- // If the device is a bridged device, we add the bridgedNode to the deviceTypes map and to the Descriptor Cluster options
340
156
  if (!device.deviceTypes.has(bridgedNode.code)) {
341
157
  this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has no bridgedNode device type. Adding it...`);
342
158
  device.deviceTypes.set(bridgedNode.code, bridgedNode);
@@ -348,49 +164,27 @@ export class MatterbridgePlatform {
348
164
  }
349
165
  }
350
166
  }
351
- // If the device is a bridged device, we add the BridgedDeviceBasicInformation cluster
352
167
  if (!device.hasClusterServer(BridgedDeviceBasicInformation.Cluster.id)) {
353
168
  this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has no BridgedDeviceBasicInformation cluster. Adding it...`);
354
169
  device.createDefaultBridgedDeviceBasicInformationClusterServer(device.deviceName, device.serialNumber, device.vendorId, device.vendorName, device.productName, device.softwareVersion, device.softwareVersionString, device.hardwareVersion, device.hardwareVersionString);
355
170
  }
356
171
  }
357
- // TODO: replace with a message to the matterbridge thread
358
172
  await this.matterbridge.addBridgedEndpoint(this.name, device);
359
173
  this.registeredEndpointsByUniqueId.set(device.uniqueId, device);
360
174
  this.registeredEndpointsByName.set(device.deviceName, device);
361
175
  }
362
- /**
363
- * Unregisters a device registered with the Matterbridge platform.
364
- *
365
- * @param {MatterbridgeEndpoint} device - The device to unregister.
366
- */
367
176
  async unregisterDevice(device) {
368
- // TODO: replace with a message to the matterbridge thread
369
177
  await this.matterbridge.removeBridgedEndpoint(this.name, device);
370
178
  if (device.uniqueId)
371
179
  this.registeredEndpointsByUniqueId.delete(device.uniqueId);
372
180
  if (device.deviceName)
373
181
  this.registeredEndpointsByName.delete(device.deviceName);
374
182
  }
375
- /**
376
- * Unregisters all devices registered with the Matterbridge platform.
377
- *
378
- * @param {number} [delay] - The delay in milliseconds between removing each bridged endpoint (default: 0).
379
- */
380
183
  async unregisterAllDevices(delay = 0) {
381
- // TODO: replace with a message to the matterbridge thread
382
184
  await this.matterbridge.removeAllBridgedEndpoints(this.name, delay);
383
185
  this.registeredEndpointsByUniqueId.clear();
384
186
  this.registeredEndpointsByName.clear();
385
187
  }
386
- /**
387
- * Saves the select devices and entities to storage.
388
- *
389
- * This method saves the current state of `selectDevice` and `selectEntity` maps to their respective storage.
390
- * It logs the number of items being saved and ensures that the storage is properly closed after saving.
391
- *
392
- * @returns {Promise<void>} A promise that resolves when the save operation is complete.
393
- */
394
188
  async saveSelects() {
395
189
  if (this.storage) {
396
190
  this.log.debug(`Saving ${this.selectDevice.size} selectDevice...`);
@@ -403,60 +197,19 @@ export class MatterbridgePlatform {
403
197
  await selectEntity.close();
404
198
  }
405
199
  }
406
- /**
407
- * Clears all the select device and entity maps.
408
- *
409
- * @returns {void}
410
- */
411
200
  async clearSelect() {
412
201
  this.selectDevice.clear();
413
202
  this.selectEntity.clear();
414
203
  await this.saveSelects();
415
204
  }
416
- /**
417
- * Clears the select for a single device.
418
- *
419
- * @param {string} serial - The serial of the device to clear.
420
- * @returns {void}
421
- */
422
205
  async clearDeviceSelect(serial) {
423
206
  this.selectDevice.delete(serial);
424
207
  await this.saveSelects();
425
208
  }
426
- /**
427
- * Clears the select for a single entity.
428
- *
429
- * @param {string} name - The name of the entity to clear.
430
- * @returns {void}
431
- */
432
209
  async clearEntitySelect(name) {
433
210
  this.selectEntity.delete(name);
434
211
  await this.saveSelects();
435
212
  }
436
- /**
437
- * Set the select device in the platform map.
438
- *
439
- * @param {string} serial - The serial number of the device.
440
- * @param {string} name - The name of the device.
441
- * @param {string} [configUrl] - The configuration URL of the device.
442
- * @param {string} [icon] - The icon of the device: 'wifi', 'ble', 'hub'
443
- * @param {Array<{ name: string; description: string; icon?: string }>} [entities] - The entities associated with the device.
444
- * @returns {void}
445
- *
446
- * @remarks
447
- * In the schema use selectFrom: 'serial' or 'name'
448
- * ```json
449
- * "whiteList": {
450
- * "description": "Only the devices in the list will be exposed.",
451
- * "type": "array",
452
- * "items": {
453
- * "type": "string"
454
- * },
455
- * "uniqueItems": true,
456
- * "selectFrom": "name"
457
- * },
458
- * ```
459
- */
460
213
  setSelectDevice(serial, name, configUrl, icon, entities) {
461
214
  const device = this.selectDevice.get(serial);
462
215
  if (device) {
@@ -473,35 +226,6 @@ export class MatterbridgePlatform {
473
226
  this.selectDevice.set(serial, { serial, name, configUrl, icon, entities });
474
227
  }
475
228
  }
476
- /**
477
- * Set the select device entity in the platform map.
478
- *
479
- * @param {string} serial - The serial number of the device.
480
- * @param {string} entityName - The name of the entity.
481
- * @param {string} entityDescription - The description of the entity.
482
- * @param {string} [entityIcon] - The icon of the entity: 'wifi', 'ble', 'hub', 'component', 'matter'
483
- * @returns {void}
484
- *
485
- * @remarks
486
- * In the schema use selectDeviceEntityFrom: 'name' or 'description'
487
- * ```json
488
- * "deviceEntityBlackList": {
489
- * "description": "List of entities not to be exposed for a single device.",
490
- * "type": "object",
491
- * "uniqueItems": true,
492
- * "selectFrom": "name",
493
- * "additionalProperties": {
494
- * "description": "List of entities not to be exposed for this device.",
495
- * "type": "array",
496
- * "items": {
497
- * "type": "string"
498
- * },
499
- * "uniqueItems": true,
500
- * "selectDeviceEntityFrom": "name"
501
- * }
502
- * },
503
- * ```
504
- */
505
229
  setSelectDeviceEntity(serial, entityName, entityDescription, entityIcon) {
506
230
  const device = this.selectDevice.get(serial);
507
231
  if (device) {
@@ -511,11 +235,6 @@ export class MatterbridgePlatform {
511
235
  device.entities.push({ name: entityName, description: entityDescription, icon: entityIcon });
512
236
  }
513
237
  }
514
- /**
515
- * Retrieves the select devices from the platform map.
516
- *
517
- * @returns {ApiSelectDevice[]} The selected devices array.
518
- */
519
238
  getSelectDevices() {
520
239
  const selectDevices = [];
521
240
  for (const device of this.selectDevice.values()) {
@@ -523,36 +242,9 @@ export class MatterbridgePlatform {
523
242
  }
524
243
  return selectDevices;
525
244
  }
526
- /**
527
- * Set the select entity in the platform map.
528
- *
529
- * @param {string} name - The entity name.
530
- * @param {string} description - The entity description.
531
- * @param {string} [icon] - The entity icon: 'wifi', 'ble', 'hub', 'component', 'matter'
532
- * @returns {void}
533
- *
534
- * @remarks
535
- * In the schema use selectEntityFrom: 'name' or 'description'
536
- * ```json
537
- * "entityBlackList": {
538
- * "description": "The entities in the list will not be exposed.",
539
- * "type": "array",
540
- * "items": {
541
- * "type": "string"
542
- * },
543
- * "uniqueItems": true,
544
- * "selectEntityFrom": "name"
545
- * },
546
- * ```
547
- */
548
245
  setSelectEntity(name, description, icon) {
549
246
  this.selectEntity.set(name, { name, description, icon });
550
247
  }
551
- /**
552
- * Retrieve the select entities.
553
- *
554
- * @returns {ApiSelectEntity[]} The select entities array.
555
- */
556
248
  getSelectEntities() {
557
249
  const selectEntities = [];
558
250
  for (const entity of this.selectEntity.values()) {
@@ -560,12 +252,6 @@ export class MatterbridgePlatform {
560
252
  }
561
253
  return selectEntities;
562
254
  }
563
- /**
564
- * Verifies if the Matterbridge version meets the required version.
565
- *
566
- * @param {string} requiredVersion - The required version to compare against.
567
- * @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
568
- */
569
255
  verifyMatterbridgeVersion(requiredVersion) {
570
256
  const compareVersions = (matterbridgeVersion, requiredVersion) => {
571
257
  const stripTag = (v) => {
@@ -590,14 +276,6 @@ export class MatterbridgePlatform {
590
276
  return false;
591
277
  return true;
592
278
  }
593
- /**
594
- * Validates if a device is allowed based on the whitelist and blacklist configurations.
595
- * The blacklist has priority over the whitelist.
596
- *
597
- * @param {string | string[]} device - The device name(s) to validate.
598
- * @param {boolean} [log] - Whether to log the validation result.
599
- * @returns {boolean} - Returns true if the device is allowed, false otherwise.
600
- */
601
279
  validateDevice(device, log = true) {
602
280
  if (!Array.isArray(device))
603
281
  device = [device];
@@ -627,14 +305,6 @@ export class MatterbridgePlatform {
627
305
  this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
628
306
  return false;
629
307
  }
630
- /**
631
- * Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
632
- *
633
- * @param {string} device - The device to which the entity belongs.
634
- * @param {string} entity - The entity to validate.
635
- * @param {boolean} [log] - Whether to log the validation result.
636
- * @returns {boolean} - Returns true if the entity is allowed, false otherwise.
637
- */
638
308
  validateEntity(device, entity, log = true) {
639
309
  if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
640
310
  if (log)
@@ -653,15 +323,6 @@ export class MatterbridgePlatform {
653
323
  }
654
324
  return true;
655
325
  }
656
- /**
657
- * Checks and updates the endpoint numbers for Matterbridge devices.
658
- *
659
- * This method retrieves the list of Matterbridge devices and their child endpoints,
660
- * compares their current endpoint numbers with the stored ones, and updates the storage
661
- * if there are any changes. It logs the changes and updates the endpoint numbers accordingly.
662
- *
663
- * @returns {Promise<number>} The size of the updated endpoint map, or -1 if storage is not available.
664
- */
665
326
  async checkEndpointNumbers() {
666
327
  if (!this.storage)
667
328
  return -1;
@@ -702,4 +363,3 @@ export class MatterbridgePlatform {
702
363
  return endpointMap.size;
703
364
  }
704
365
  }
705
- //# sourceMappingURL=matterbridgePlatform.js.map
@@ -1,35 +1,9 @@
1
- /**
2
- * This file contains the types for Matterbridge.
3
- *
4
- * @file matterbridgeTypes.ts
5
- * @author Luca Liguori
6
- * @created 2024-07-12
7
- * @version 1.0.2
8
- * @license Apache-2.0
9
- *
10
- * Copyright 2023, 2024, 2025 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
- // Default colors
25
1
  export const plg = '\u001B[38;5;33m';
26
2
  export const dev = '\u001B[38;5;79m';
27
3
  export const typ = '\u001B[38;5;207m';
28
- // Default names
29
4
  export const MATTERBRIDGE_LOGGER_FILE = 'matterbridge.log';
30
5
  export const MATTER_LOGGER_FILE = 'matter.log';
31
6
  export const NODE_STORAGE_DIR = 'storage';
32
7
  export const MATTER_STORAGE_NAME = 'matterstorage';
33
8
  export const MATTERBRIDGE_DIAGNOSTIC_FILE = 'diagnostic.log';
34
9
  export const MATTERBRIDGE_HISTORY_FILE = 'history.html';
35
- //# sourceMappingURL=matterbridgeTypes.js.map