matterbridge 3.2.9 → 3.3.0-dev-20250928-3d2b558

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