matterbridge 3.3.0 → 3.3.1-dev-20251007-4e5eaac

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