matterbridge 3.2.0 → 3.2.1-dev-20250802-516a522

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 (257) hide show
  1. package/CHANGELOG.md +21 -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/batteryStorage.js +1 -48
  8. package/dist/devices/dishwasher.js +3 -78
  9. package/dist/devices/evse.js +10 -74
  10. package/dist/devices/export.js +0 -2
  11. package/dist/devices/extractorHood.js +0 -42
  12. package/dist/devices/heatPump.js +2 -50
  13. package/dist/devices/laundryDryer.js +6 -83
  14. package/dist/devices/laundryWasher.js +7 -91
  15. package/dist/devices/roboticVacuumCleaner.js +7 -93
  16. package/dist/devices/solarPower.js +0 -38
  17. package/dist/devices/waterHeater.js +2 -82
  18. package/dist/dgram/coap.js +13 -126
  19. package/dist/dgram/dgram.js +2 -113
  20. package/dist/dgram/mb_coap.js +3 -41
  21. package/dist/dgram/mb_mdns.js +13 -51
  22. package/dist/dgram/mdns.js +137 -298
  23. package/dist/dgram/multicast.js +1 -60
  24. package/dist/dgram/unicast.js +0 -54
  25. package/dist/frontend.js +23 -448
  26. package/dist/globalMatterbridge.js +0 -47
  27. package/dist/helpers.js +0 -53
  28. package/dist/index.js +1 -30
  29. package/dist/logger/export.js +0 -1
  30. package/dist/matter/behaviors.js +0 -2
  31. package/dist/matter/clusters.js +0 -2
  32. package/dist/matter/devices.js +0 -2
  33. package/dist/matter/endpoints.js +0 -2
  34. package/dist/matter/export.js +0 -3
  35. package/dist/matter/types.js +0 -3
  36. package/dist/matterbridge.js +50 -805
  37. package/dist/matterbridgeAccessoryPlatform.js +0 -36
  38. package/dist/matterbridgeBehaviors.js +5 -65
  39. package/dist/matterbridgeDeviceTypes.js +15 -579
  40. package/dist/matterbridgeDynamicPlatform.js +0 -36
  41. package/dist/matterbridgeEndpoint.js +55 -1234
  42. package/dist/matterbridgeEndpointHelpers.js +12 -344
  43. package/dist/matterbridgePlatform.js +35 -248
  44. package/dist/matterbridgeTypes.js +0 -25
  45. package/dist/pluginManager.js +3 -249
  46. package/dist/shelly.js +7 -168
  47. package/dist/storage/export.js +0 -1
  48. package/dist/update.js +0 -69
  49. package/dist/utils/colorUtils.js +2 -263
  50. package/dist/utils/commandLine.js +0 -54
  51. package/dist/utils/copyDirectory.js +1 -38
  52. package/dist/utils/createDirectory.js +0 -33
  53. package/dist/utils/createZip.js +2 -47
  54. package/dist/utils/deepCopy.js +0 -39
  55. package/dist/utils/deepEqual.js +1 -72
  56. package/dist/utils/error.js +0 -41
  57. package/dist/utils/export.js +0 -1
  58. package/dist/utils/hex.js +0 -123
  59. package/dist/utils/isvalid.js +0 -101
  60. package/dist/utils/network.js +5 -94
  61. package/dist/utils/spawn.js +0 -40
  62. package/dist/utils/wait.js +9 -62
  63. package/docs/404.html +107 -0
  64. package/docs/HomeAssistant.svg +2 -0
  65. package/docs/Shelly.svg +1 -0
  66. package/docs/Somfy.svg +1 -0
  67. package/docs/Zigbee2MQTT.svg +1 -0
  68. package/docs/_config.yml +86 -0
  69. package/docs/bmc-button.svg +22 -0
  70. package/docs/index.html +774 -0
  71. package/docs/matterbridge.svg +50 -0
  72. package/docs/robots.txt +4 -0
  73. package/npm-shrinkwrap.json +45 -45
  74. package/package.json +5 -3
  75. package/dist/cli.d.ts +0 -26
  76. package/dist/cli.d.ts.map +0 -1
  77. package/dist/cli.js.map +0 -1
  78. package/dist/cliEmitter.d.ts +0 -34
  79. package/dist/cliEmitter.d.ts.map +0 -1
  80. package/dist/cliEmitter.js.map +0 -1
  81. package/dist/clusters/export.d.ts +0 -2
  82. package/dist/clusters/export.d.ts.map +0 -1
  83. package/dist/clusters/export.js.map +0 -1
  84. package/dist/defaultConfigSchema.d.ts +0 -28
  85. package/dist/defaultConfigSchema.d.ts.map +0 -1
  86. package/dist/defaultConfigSchema.js.map +0 -1
  87. package/dist/deviceManager.d.ts +0 -112
  88. package/dist/deviceManager.d.ts.map +0 -1
  89. package/dist/deviceManager.js.map +0 -1
  90. package/dist/devices/batteryStorage.d.ts +0 -48
  91. package/dist/devices/batteryStorage.d.ts.map +0 -1
  92. package/dist/devices/batteryStorage.js.map +0 -1
  93. package/dist/devices/dishwasher.d.ts +0 -91
  94. package/dist/devices/dishwasher.d.ts.map +0 -1
  95. package/dist/devices/dishwasher.js.map +0 -1
  96. package/dist/devices/evse.d.ts +0 -75
  97. package/dist/devices/evse.d.ts.map +0 -1
  98. package/dist/devices/evse.js.map +0 -1
  99. package/dist/devices/export.d.ts +0 -11
  100. package/dist/devices/export.d.ts.map +0 -1
  101. package/dist/devices/export.js.map +0 -1
  102. package/dist/devices/extractorHood.d.ts +0 -46
  103. package/dist/devices/extractorHood.d.ts.map +0 -1
  104. package/dist/devices/extractorHood.js.map +0 -1
  105. package/dist/devices/heatPump.d.ts +0 -47
  106. package/dist/devices/heatPump.d.ts.map +0 -1
  107. package/dist/devices/heatPump.js.map +0 -1
  108. package/dist/devices/laundryDryer.d.ts +0 -87
  109. package/dist/devices/laundryDryer.d.ts.map +0 -1
  110. package/dist/devices/laundryDryer.js.map +0 -1
  111. package/dist/devices/laundryWasher.d.ts +0 -242
  112. package/dist/devices/laundryWasher.d.ts.map +0 -1
  113. package/dist/devices/laundryWasher.js.map +0 -1
  114. package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
  115. package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
  116. package/dist/devices/roboticVacuumCleaner.js.map +0 -1
  117. package/dist/devices/solarPower.d.ts +0 -40
  118. package/dist/devices/solarPower.d.ts.map +0 -1
  119. package/dist/devices/solarPower.js.map +0 -1
  120. package/dist/devices/waterHeater.d.ts +0 -111
  121. package/dist/devices/waterHeater.d.ts.map +0 -1
  122. package/dist/devices/waterHeater.js.map +0 -1
  123. package/dist/dgram/coap.d.ts +0 -205
  124. package/dist/dgram/coap.d.ts.map +0 -1
  125. package/dist/dgram/coap.js.map +0 -1
  126. package/dist/dgram/dgram.d.ts +0 -140
  127. package/dist/dgram/dgram.d.ts.map +0 -1
  128. package/dist/dgram/dgram.js.map +0 -1
  129. package/dist/dgram/mb_coap.d.ts +0 -24
  130. package/dist/dgram/mb_coap.d.ts.map +0 -1
  131. package/dist/dgram/mb_coap.js.map +0 -1
  132. package/dist/dgram/mb_mdns.d.ts +0 -24
  133. package/dist/dgram/mb_mdns.d.ts.map +0 -1
  134. package/dist/dgram/mb_mdns.js.map +0 -1
  135. package/dist/dgram/mdns.d.ts +0 -288
  136. package/dist/dgram/mdns.d.ts.map +0 -1
  137. package/dist/dgram/mdns.js.map +0 -1
  138. package/dist/dgram/multicast.d.ts +0 -65
  139. package/dist/dgram/multicast.d.ts.map +0 -1
  140. package/dist/dgram/multicast.js.map +0 -1
  141. package/dist/dgram/unicast.d.ts +0 -56
  142. package/dist/dgram/unicast.d.ts.map +0 -1
  143. package/dist/dgram/unicast.js.map +0 -1
  144. package/dist/frontend.d.ts +0 -313
  145. package/dist/frontend.d.ts.map +0 -1
  146. package/dist/frontend.js.map +0 -1
  147. package/dist/globalMatterbridge.d.ts +0 -59
  148. package/dist/globalMatterbridge.d.ts.map +0 -1
  149. package/dist/globalMatterbridge.js.map +0 -1
  150. package/dist/helpers.d.ts +0 -48
  151. package/dist/helpers.d.ts.map +0 -1
  152. package/dist/helpers.js.map +0 -1
  153. package/dist/index.d.ts +0 -33
  154. package/dist/index.d.ts.map +0 -1
  155. package/dist/index.js.map +0 -1
  156. package/dist/logger/export.d.ts +0 -2
  157. package/dist/logger/export.d.ts.map +0 -1
  158. package/dist/logger/export.js.map +0 -1
  159. package/dist/matter/behaviors.d.ts +0 -2
  160. package/dist/matter/behaviors.d.ts.map +0 -1
  161. package/dist/matter/behaviors.js.map +0 -1
  162. package/dist/matter/clusters.d.ts +0 -2
  163. package/dist/matter/clusters.d.ts.map +0 -1
  164. package/dist/matter/clusters.js.map +0 -1
  165. package/dist/matter/devices.d.ts +0 -2
  166. package/dist/matter/devices.d.ts.map +0 -1
  167. package/dist/matter/devices.js.map +0 -1
  168. package/dist/matter/endpoints.d.ts +0 -2
  169. package/dist/matter/endpoints.d.ts.map +0 -1
  170. package/dist/matter/endpoints.js.map +0 -1
  171. package/dist/matter/export.d.ts +0 -5
  172. package/dist/matter/export.d.ts.map +0 -1
  173. package/dist/matter/export.js.map +0 -1
  174. package/dist/matter/types.d.ts +0 -3
  175. package/dist/matter/types.d.ts.map +0 -1
  176. package/dist/matter/types.js.map +0 -1
  177. package/dist/matterbridge.d.ts +0 -463
  178. package/dist/matterbridge.d.ts.map +0 -1
  179. package/dist/matterbridge.js.map +0 -1
  180. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
  181. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  182. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  183. package/dist/matterbridgeBehaviors.d.ts +0 -1351
  184. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  185. package/dist/matterbridgeBehaviors.js.map +0 -1
  186. package/dist/matterbridgeDeviceTypes.d.ts +0 -709
  187. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  188. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  189. package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
  190. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  191. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  192. package/dist/matterbridgeEndpoint.d.ts +0 -1354
  193. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  194. package/dist/matterbridgeEndpoint.js.map +0 -1
  195. package/dist/matterbridgeEndpointHelpers.d.ts +0 -406
  196. package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
  197. package/dist/matterbridgeEndpointHelpers.js.map +0 -1
  198. package/dist/matterbridgePlatform.d.ts +0 -310
  199. package/dist/matterbridgePlatform.d.ts.map +0 -1
  200. package/dist/matterbridgePlatform.js.map +0 -1
  201. package/dist/matterbridgeTypes.d.ts +0 -197
  202. package/dist/matterbridgeTypes.d.ts.map +0 -1
  203. package/dist/matterbridgeTypes.js.map +0 -1
  204. package/dist/pluginManager.d.ts +0 -270
  205. package/dist/pluginManager.d.ts.map +0 -1
  206. package/dist/pluginManager.js.map +0 -1
  207. package/dist/shelly.d.ts +0 -174
  208. package/dist/shelly.d.ts.map +0 -1
  209. package/dist/shelly.js.map +0 -1
  210. package/dist/storage/export.d.ts +0 -2
  211. package/dist/storage/export.d.ts.map +0 -1
  212. package/dist/storage/export.js.map +0 -1
  213. package/dist/update.d.ts +0 -75
  214. package/dist/update.d.ts.map +0 -1
  215. package/dist/update.js.map +0 -1
  216. package/dist/utils/colorUtils.d.ts +0 -117
  217. package/dist/utils/colorUtils.d.ts.map +0 -1
  218. package/dist/utils/colorUtils.js.map +0 -1
  219. package/dist/utils/commandLine.d.ts +0 -59
  220. package/dist/utils/commandLine.d.ts.map +0 -1
  221. package/dist/utils/commandLine.js.map +0 -1
  222. package/dist/utils/copyDirectory.d.ts +0 -33
  223. package/dist/utils/copyDirectory.d.ts.map +0 -1
  224. package/dist/utils/copyDirectory.js.map +0 -1
  225. package/dist/utils/createDirectory.d.ts +0 -34
  226. package/dist/utils/createDirectory.d.ts.map +0 -1
  227. package/dist/utils/createDirectory.js.map +0 -1
  228. package/dist/utils/createZip.d.ts +0 -39
  229. package/dist/utils/createZip.d.ts.map +0 -1
  230. package/dist/utils/createZip.js.map +0 -1
  231. package/dist/utils/deepCopy.d.ts +0 -32
  232. package/dist/utils/deepCopy.d.ts.map +0 -1
  233. package/dist/utils/deepCopy.js.map +0 -1
  234. package/dist/utils/deepEqual.d.ts +0 -54
  235. package/dist/utils/deepEqual.d.ts.map +0 -1
  236. package/dist/utils/deepEqual.js.map +0 -1
  237. package/dist/utils/error.d.ts +0 -44
  238. package/dist/utils/error.d.ts.map +0 -1
  239. package/dist/utils/error.js.map +0 -1
  240. package/dist/utils/export.d.ts +0 -12
  241. package/dist/utils/export.d.ts.map +0 -1
  242. package/dist/utils/export.js.map +0 -1
  243. package/dist/utils/hex.d.ts +0 -89
  244. package/dist/utils/hex.d.ts.map +0 -1
  245. package/dist/utils/hex.js.map +0 -1
  246. package/dist/utils/isvalid.d.ts +0 -103
  247. package/dist/utils/isvalid.d.ts.map +0 -1
  248. package/dist/utils/isvalid.js.map +0 -1
  249. package/dist/utils/network.d.ts +0 -84
  250. package/dist/utils/network.d.ts.map +0 -1
  251. package/dist/utils/network.js.map +0 -1
  252. package/dist/utils/spawn.d.ts +0 -33
  253. package/dist/utils/spawn.d.ts.map +0 -1
  254. package/dist/utils/spawn.js.map +0 -1
  255. package/dist/utils/wait.d.ts +0 -56
  256. package/dist/utils/wait.d.ts.map +0 -1
  257. package/dist/utils/wait.js.map +0 -1
@@ -1,82 +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
- // Node AnsiLogger module
2
+ import { Descriptor } from '@matter/main/clusters/descriptor';
3
+ import { BridgedDeviceBasicInformation } from '@matter/main/clusters/bridged-device-basic-information';
27
4
  import { CYAN, db, er, nf, wr } from 'node-ansi-logger';
28
- // Node Storage module
29
5
  import { NodeStorageManager } from 'node-persist-manager';
30
6
  import { checkNotLatinCharacters } from './matterbridgeEndpointHelpers.js';
7
+ import { bridgedNode } from './matterbridgeDeviceTypes.js';
31
8
  import { isValidArray, isValidObject, isValidString } from './utils/export.js';
32
- /**
33
- * Represents the base Matterbridge platform. It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
34
- *
35
- */
36
9
  export class MatterbridgePlatform {
37
- /** The Matterbridge instance of this Platform. */
38
10
  matterbridge;
39
- /** The logger instance for this platform. */
40
11
  log;
41
- /** The configuration for this platform. */
42
12
  config = {};
43
- /** The name of the platform. Will be set by the loadPlugin() method using the package.json value. */
44
13
  name = '';
45
- /** The type of the platform. Will be set by the extending classes. */
46
14
  type = '';
47
- /** The version of the platform. Will be set by the loadPlugin() method using the package.json value */
48
15
  version = '1.0.0';
49
- /** Platform node storage manager. */
50
16
  storage;
51
- /** Platform context storage. */
52
17
  context;
53
- // Device and entity select in the plugin config UI
54
18
  selectDevice = new Map();
55
19
  selectEntity = new Map();
56
- // Promises for storage
57
20
  _contextReady;
58
21
  _selectDeviceContextReady;
59
22
  _selectEntityContextReady;
60
- /** The ready promise for the platform, which resolves when the platform is fully initialized. */
61
23
  ready;
62
- /** Registered MatterbridgeEndpoint Map by uniqueId */
63
24
  _registeredEndpoints = new Map();
64
- /** Registered MatterbridgeEndpoint Map by deviceName */
65
25
  _registeredEndpointsByName = new Map();
66
- /**
67
- * Creates an instance of the base MatterbridgePlatform.
68
- * It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
69
- * Each plugin must extend the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
70
- *
71
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
72
- * @param {AnsiLogger} log - The logger instance.
73
- * @param {PlatformConfig} config - The platform configuration.
74
- */
75
26
  constructor(matterbridge, log, config) {
76
27
  this.matterbridge = matterbridge;
77
28
  this.log = log;
78
29
  this.config = config;
79
- // create the NodeStorageManager for the plugin platform
80
30
  if (!isValidString(this.config.name, 1))
81
31
  throw new Error('Platform: the plugin name is missing or invalid.');
82
32
  this.log.debug(`Creating storage for plugin ${this.config.name} in ${path.join(this.matterbridge.matterbridgeDirectory, this.config.name)}`);
@@ -87,14 +37,12 @@ export class MatterbridgePlatform {
87
37
  logging: false,
88
38
  forgiveParseErrors: true,
89
39
  });
90
- // create the context storage for the plugin platform
91
40
  this.log.debug(`Creating context for plugin ${this.config.name}`);
92
41
  this._contextReady = this.storage.createStorage('context').then((context) => {
93
42
  this.context = context;
94
43
  this.log.debug(`Created context for plugin ${this.config.name}`);
95
44
  return;
96
45
  });
97
- // create the selectDevice storage for the plugin platform
98
46
  this.log.debug(`Loading selectDevice for plugin ${this.config.name}`);
99
47
  this._selectDeviceContextReady = this.storage.createStorage('selectDevice').then(async (context) => {
100
48
  const selectDevice = await context.get('selectDevice', []);
@@ -103,7 +51,6 @@ export class MatterbridgePlatform {
103
51
  this.log.debug(`Loaded ${this.selectDevice.size} selectDevice for plugin ${this.config.name}`);
104
52
  return;
105
53
  });
106
- // create the selectEntity storage for the plugin platform
107
54
  this.log.debug(`Loading selectEntity for plugin ${this.config.name}`);
108
55
  this._selectEntityContextReady = this.storage.createStorage('selectEntity').then(async (context) => {
109
56
  const selectEntity = await context.get('selectEntity', []);
@@ -112,156 +59,89 @@ export class MatterbridgePlatform {
112
59
  this.log.debug(`Loaded ${this.selectEntity.size} selectEntity for plugin ${this.config.name}`);
113
60
  return;
114
61
  });
115
- // Create the `ready` promise for the platform
116
62
  this.ready = Promise.all([this._contextReady, this._selectDeviceContextReady, this._selectEntityContextReady]).then(() => {
117
63
  this.log.debug(`MatterbridgePlatform for plugin ${this.config.name} is fully initialized`);
118
64
  return;
119
65
  });
120
66
  }
121
- /**
122
- * This method must be overridden in the extended class.
123
- * It is called when the platform is started.
124
- * Use this method to create the MatterbridgeEndpoints and call this.registerDevice().
125
- *
126
- * @param {string} [reason] - The reason for starting.
127
- * @throws {Error} - Throws an error if the method is not overridden.
128
- */
129
67
  async onStart(reason) {
130
68
  this.log.error('Plugins must override onStart.', reason);
131
69
  throw new Error('Plugins must override onStart.');
132
70
  }
133
- /**
134
- * This method can be overridden in the extended class. In this case always call super.onConfigure() to save the select and run checkEndpointNumbers().
135
- * It is called after the platform has started.
136
- * 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
137
- * matter storage (i.e. the onOff attribute of the OnOff cluster).
138
- */
139
71
  async onConfigure() {
140
72
  this.log.debug(`Configuring platform ${this.name}`);
141
- // Save the selectDevice and selectEntity
142
73
  await this.saveSelects();
143
- // Check and update the endpoint numbers
144
74
  await this.checkEndpointNumbers();
145
75
  }
146
- /**
147
- * 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.
148
- * It is called when the platform is shutting down.
149
- * Use this method to clean up any resources you used in the constructor or onStart.
150
- *
151
- * @param {string} [reason] - The reason for shutting down.
152
- */
153
76
  async onShutdown(reason) {
154
77
  this.log.debug(`Shutting down platform ${this.name}`, reason);
155
- // Save the selectDevice and selectEntity
156
78
  await this.saveSelects();
157
- // Check and update the endpoint numbers
158
79
  await this.checkEndpointNumbers();
159
- // Cleanup memory
160
80
  this.selectDevice.clear();
161
81
  this.selectEntity.clear();
162
82
  this._registeredEndpoints.clear();
163
83
  this._registeredEndpointsByName.clear();
164
- // Close the storage
165
84
  await this.context?.close();
166
85
  this.context = undefined;
167
86
  await this.storage?.close();
168
87
  }
169
- /**
170
- * Called when the logger level is changed.
171
- *
172
- * @param {LogLevel} logLevel The new logger level.
173
- */
174
88
  async onChangeLoggerLevel(logLevel) {
175
89
  this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
176
90
  }
177
- /**
178
- * Called when a plugin config includes an action button or an action button with text field.
179
- *
180
- * @param {string} action The action triggered by the button in plugin config.
181
- * @param {string} value The value of the field of the action button.
182
- * @param {string} id The id of the schema associated with the action.
183
- * @param {PlatformConfig} formData The changed form data of the plugin.
184
- *
185
- * @remarks
186
- * This method can be overridden in the extended class.
187
- *
188
- * Use this method to handle the action defined in the plugin schema:
189
- * ```json
190
- * "addDevice": {
191
- * "description": "Manually add a device that has not been discovered with mdns:",
192
- * "type": "boolean",
193
- * "buttonText": "ADD", // The text on the button. This is used when the action doesn't include a text field.
194
- * "buttonField": "ADD", // The text on the button. This is used when the action includes a text field.
195
- * "buttonClose": false, // optional, default is false. When true, the dialog will close after the action is sent.
196
- * "buttonSave": false, // optional, default is false. When true, the dialog will close and trigger the restart required after the action is sent.
197
- * "textPlaceholder": "Enter the device IP address", // optional: the placeholder text for the text field.
198
- * "default": false
199
- * },
200
- * ```
201
- */
202
91
  async onAction(action, value, id, formData) {
203
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);
204
93
  }
205
- /**
206
- * Called when the plugin config has been updated.
207
- *
208
- * @param {PlatformConfig} config The new plugin config.
209
- */
210
94
  async onConfigChanged(config) {
211
95
  this.log.debug(`The plugin ${CYAN}${config.name}${db} doesn't override onConfigChanged. Received new config.`);
212
96
  }
213
- /**
214
- * Retrieves the devices registered with the platform.
215
- *
216
- * @returns {MatterbridgeEndpoint[]} The registered devices.
217
- */
218
97
  getDevices() {
219
98
  return Array.from(this._registeredEndpoints.values());
220
99
  }
221
- /**
222
- * Checks if a device with this name is already registered in the platform.
223
- *
224
- * @param {string} deviceName - The device name to check.
225
- * @returns {boolean} True if the device is already registered, false otherwise.
226
- */
227
100
  hasDeviceName(deviceName) {
228
101
  return this._registeredEndpointsByName.has(deviceName);
229
102
  }
230
- /**
231
- * Registers a device with the Matterbridge platform.
232
- *
233
- * @param {MatterbridgeEndpoint} device - The device to register.
234
- */
235
103
  async registerDevice(device) {
236
104
  device.plugin = this.name;
237
- if (device.deviceName && this._registeredEndpointsByName.has(device.deviceName)) {
105
+ if (!device.uniqueId) {
106
+ this.log.error(`Device with name ${CYAN}${device.deviceName}${er} has no uniqueId. Did you forget to call createDefaultBasicInformationClusterServer() or createDefaultBridgedDeviceBasicInformationClusterServer()? The device will not be added.`);
107
+ return;
108
+ }
109
+ if (!device.deviceName) {
110
+ this.log.error(`Device with uniqueId ${CYAN}${device.uniqueId}${er} has no deviceName. The device will not be added.`);
111
+ return;
112
+ }
113
+ if (!device.serialNumber) {
114
+ this.log.error(`Device with uniqueId ${CYAN}${device.uniqueId}${er} has no serialNumber. The device will not be added.`);
115
+ return;
116
+ }
117
+ if (this._registeredEndpointsByName.has(device.deviceName)) {
238
118
  this.log.error(`Device with name ${CYAN}${device.deviceName}${er} is already registered. The device will not be added. Please change the device name.`);
239
119
  return;
240
120
  }
241
- if (device.deviceName && checkNotLatinCharacters(device.deviceName)) {
121
+ if (checkNotLatinCharacters(device.deviceName)) {
242
122
  this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has non latin characters.`);
243
123
  }
244
- /* TODO: Do we need to handle the childbridged mode with DynamicPlatform here if the implementation forgets to call createDefaultBridgedDeviceBasicInformationClusterServer?
245
- if (this.matterbridge.bridgeMode === 'childbridge' && this.type === 'DynamicPlatform' && device.mode === undefined) {
246
- const options = device.getClusterServerOptions(Descriptor.Cluster.id);
247
- if (options) {
248
- const deviceTypeList = options.deviceTypeList as { deviceType: number; revision: number }[];
249
- deviceTypeList.push({ deviceType: bridgedNode.code, revision: bridgedNode.revision });
250
- }
251
- device.createDefaultBridgedDeviceBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productName, softwareVersion, softwareVersionString, hardwareVersion, hardwareVersionString);
124
+ if (device.mode === undefined && (this.matterbridge.bridgeMode === 'bridge' || (this.matterbridge.bridgeMode === 'childbridge' && this.type === 'DynamicPlatform'))) {
125
+ if (!device.deviceTypes.has(bridgedNode.code)) {
126
+ this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has no bridgedNode device type. Adding it...`);
127
+ device.deviceTypes.set(bridgedNode.code, bridgedNode);
128
+ const options = device.getClusterServerOptions(Descriptor.Cluster.id);
129
+ if (options) {
130
+ const deviceTypeList = options.deviceTypeList;
131
+ if (!deviceTypeList.find((dt) => dt.deviceType === bridgedNode.code)) {
132
+ deviceTypeList.push({ deviceType: bridgedNode.code, revision: bridgedNode.revision });
133
+ }
134
+ }
135
+ }
136
+ if (!device.hasClusterServer(BridgedDeviceBasicInformation.Cluster.id)) {
137
+ this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has no BridgedDeviceBasicInformation cluster. Adding it...`);
138
+ device.createDefaultBridgedDeviceBasicInformationClusterServer(device.deviceName, device.serialNumber, device.vendorId, device.vendorName, device.productName, device.softwareVersion, device.softwareVersionString, device.hardwareVersion, device.hardwareVersionString);
139
+ }
252
140
  }
253
- */
254
141
  await this.matterbridge.addBridgedEndpoint(this.name, device);
255
- if (device.uniqueId)
256
- this._registeredEndpoints.set(device.uniqueId, device);
257
- if (device.deviceName)
258
- this._registeredEndpointsByName.set(device.deviceName, device);
142
+ this._registeredEndpoints.set(device.uniqueId, device);
143
+ this._registeredEndpointsByName.set(device.deviceName, device);
259
144
  }
260
- /**
261
- * Unregisters a device registered with the Matterbridge platform.
262
- *
263
- * @param {MatterbridgeEndpoint} device - The device to unregister.
264
- */
265
145
  async unregisterDevice(device) {
266
146
  await this.matterbridge.removeBridgedEndpoint(this.name, device);
267
147
  if (device.uniqueId)
@@ -269,24 +149,11 @@ export class MatterbridgePlatform {
269
149
  if (device.deviceName)
270
150
  this._registeredEndpointsByName.delete(device.deviceName);
271
151
  }
272
- /**
273
- * Unregisters all devices registered with the Matterbridge platform.
274
- *
275
- * @param {number} [delay] - The delay in milliseconds between removing each bridged endpoint (default: 0).
276
- */
277
152
  async unregisterAllDevices(delay = 0) {
278
153
  await this.matterbridge.removeAllBridgedEndpoints(this.name, delay);
279
154
  this._registeredEndpoints.clear();
280
155
  this._registeredEndpointsByName.clear();
281
156
  }
282
- /**
283
- * Saves the select devices and entities to storage.
284
- *
285
- * This method saves the current state of `selectDevice` and `selectEntity` maps to their respective storage.
286
- * It logs the number of items being saved and ensures that the storage is properly closed after saving.
287
- *
288
- * @returns {Promise<void>} A promise that resolves when the save operation is complete.
289
- */
290
157
  async saveSelects() {
291
158
  if (this.storage) {
292
159
  this.log.debug(`Saving ${this.selectDevice.size} selectDevice...`);
@@ -299,36 +166,15 @@ export class MatterbridgePlatform {
299
166
  await selectEntity.close();
300
167
  }
301
168
  }
302
- /**
303
- * Clears all the select device and entity maps.
304
- *
305
- * @returns {void}
306
- */
307
169
  async clearSelect() {
308
170
  this.selectDevice.clear();
309
171
  this.selectEntity.clear();
310
172
  await this.saveSelects();
311
173
  }
312
- /**
313
- * Clears the select for a single device.
314
- *
315
- * @param {string} serial - The serial of the device to clear.
316
- * @returns {void}
317
- */
318
174
  async clearDeviceSelect(serial) {
319
175
  this.selectDevice.delete(serial);
320
176
  await this.saveSelects();
321
177
  }
322
- /**
323
- * Set the select device in the platform map.
324
- *
325
- * @param {string} serial - The serial number of the device.
326
- * @param {string} name - The name of the device.
327
- * @param {string} [configUrl] - The configuration URL of the device.
328
- * @param {string} [icon] - The icon of the device: 'wifi', 'ble', 'hub'
329
- * @param {Array<{ name: string; description: string; icon?: string }>} [entities] - The entities associated with the device.
330
- * @returns {void}
331
- */
332
178
  setSelectDevice(serial, name, configUrl, icon, entities) {
333
179
  const device = this.selectDevice.get(serial);
334
180
  if (device) {
@@ -345,15 +191,6 @@ export class MatterbridgePlatform {
345
191
  this.selectDevice.set(serial, { serial, name, configUrl, icon, entities });
346
192
  }
347
193
  }
348
- /**
349
- * Set the select device entity in the platform map.
350
- *
351
- * @param {string} serial - The serial number of the device.
352
- * @param {string} entityName - The name of the entity.
353
- * @param {string} entityDescription - The description of the entity.
354
- * @param {string} [entityIcon] - The icon of the entity: 'wifi', 'ble', 'hub', 'component', 'matter'
355
- * @returns {void}
356
- */
357
194
  setSelectDeviceEntity(serial, entityName, entityDescription, entityIcon) {
358
195
  const device = this.selectDevice.get(serial);
359
196
  if (device) {
@@ -363,11 +200,6 @@ export class MatterbridgePlatform {
363
200
  device.entities.push({ name: entityName, description: entityDescription, icon: entityIcon });
364
201
  }
365
202
  }
366
- /**
367
- * Retrieves the select devices from the platform map.
368
- *
369
- * @returns {{ pluginName: string; serial: string; name: string; configUrl?: string; icon?: string; entities?: { name: string; description: string; icon?: string }[] }[]} The selected devices array.
370
- */
371
203
  getSelectDevices() {
372
204
  const selectDevices = [];
373
205
  for (const device of this.selectDevice.values()) {
@@ -375,22 +207,9 @@ export class MatterbridgePlatform {
375
207
  }
376
208
  return selectDevices;
377
209
  }
378
- /**
379
- * Set the select entity in the platform map.
380
- *
381
- * @param {string} name - The entity name.
382
- * @param {string} description - The entity description.
383
- * @param {string} [icon] - The entity icon: 'wifi', 'ble', 'hub', 'component', 'matter'
384
- * @returns {void}
385
- */
386
210
  setSelectEntity(name, description, icon) {
387
211
  this.selectEntity.set(name, { name, description, icon });
388
212
  }
389
- /**
390
- * Retrieve the select entities.
391
- *
392
- * @returns {{ pluginName: string; name: string; description: string; icon?: string }[]} The select entities array.
393
- */
394
213
  getSelectEntities() {
395
214
  const selectEntities = [];
396
215
  for (const entity of this.selectEntity.values()) {
@@ -398,12 +217,6 @@ export class MatterbridgePlatform {
398
217
  }
399
218
  return selectEntities;
400
219
  }
401
- /**
402
- * Verifies if the Matterbridge version meets the required version.
403
- *
404
- * @param {string} requiredVersion - The required version to compare against.
405
- * @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
406
- */
407
220
  verifyMatterbridgeVersion(requiredVersion) {
408
221
  const compareVersions = (matterbridgeVersion, requiredVersion) => {
409
222
  const stripTag = (v) => {
@@ -428,14 +241,6 @@ export class MatterbridgePlatform {
428
241
  return false;
429
242
  return true;
430
243
  }
431
- /**
432
- * Validates if a device is allowed based on the whitelist and blacklist configurations.
433
- * The blacklist has priority over the whitelist.
434
- *
435
- * @param {string | string[]} device - The device name(s) to validate.
436
- * @param {boolean} [log] - Whether to log the validation result.
437
- * @returns {boolean} - Returns true if the device is allowed, false otherwise.
438
- */
439
244
  validateDevice(device, log = true) {
440
245
  if (!Array.isArray(device))
441
246
  device = [device];
@@ -465,14 +270,6 @@ export class MatterbridgePlatform {
465
270
  this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
466
271
  return false;
467
272
  }
468
- /**
469
- * Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
470
- *
471
- * @param {string} device - The device to which the entity belongs.
472
- * @param {string} entity - The entity to validate.
473
- * @param {boolean} [log] - Whether to log the validation result.
474
- * @returns {boolean} - Returns true if the entity is allowed, false otherwise.
475
- */
476
273
  validateEntity(device, entity, log = true) {
477
274
  if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
478
275
  if (log)
@@ -491,15 +288,6 @@ export class MatterbridgePlatform {
491
288
  }
492
289
  return true;
493
290
  }
494
- /**
495
- * Checks and updates the endpoint numbers for Matterbridge devices.
496
- *
497
- * This method retrieves the list of Matterbridge devices and their child endpoints,
498
- * compares their current endpoint numbers with the stored ones, and updates the storage
499
- * if there are any changes. It logs the changes and updates the endpoint numbers accordingly.
500
- *
501
- * @returns {Promise<number>} The size of the updated endpoint map, or -1 if storage is not available.
502
- */
503
291
  async checkEndpointNumbers() {
504
292
  if (!this.storage)
505
293
  return -1;
@@ -540,4 +328,3 @@ export class MatterbridgePlatform {
540
328
  return endpointMap.size;
541
329
  }
542
330
  }
543
- //# 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