matterbridge 2.0.0-edge1 → 2.1.0-dev.1

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 (82) hide show
  1. package/CHANGELOG.md +36 -3
  2. package/README.md +1 -1
  3. package/dist/cli.js +0 -26
  4. package/dist/cluster/export.js +0 -2
  5. package/dist/defaultConfigSchema.js +0 -23
  6. package/dist/deviceManager.js +2 -27
  7. package/dist/frontend.js +99 -245
  8. package/dist/index.js +2 -33
  9. package/dist/logger/export.js +0 -1
  10. package/dist/matter/export.js +0 -7
  11. package/dist/matterbridge.js +99 -710
  12. package/dist/matterbridgeAccessoryPlatform.js +0 -33
  13. package/dist/matterbridgeBehaviors.js +42 -32
  14. package/dist/matterbridgeDeviceTypes.js +90 -84
  15. package/dist/matterbridgeDynamicPlatform.js +0 -33
  16. package/dist/matterbridgeEndpoint.js +992 -2454
  17. package/dist/matterbridgePlatform.js +11 -130
  18. package/dist/matterbridgeTypes.js +0 -25
  19. package/dist/pluginManager.js +7 -251
  20. package/dist/storage/export.js +0 -1
  21. package/dist/utils/colorUtils.js +2 -205
  22. package/dist/utils/export.js +0 -1
  23. package/dist/utils/utils.js +10 -255
  24. package/frontend/build/asset-manifest.json +3 -3
  25. package/frontend/build/index.html +1 -1
  26. package/frontend/build/static/js/{main.ea28015b.js → main.26dbf9b9.js} +3 -3
  27. package/frontend/build/static/js/main.26dbf9b9.js.map +1 -0
  28. package/npm-shrinkwrap.json +97 -79
  29. package/package.json +2 -4
  30. package/dist/cli.d.ts.map +0 -1
  31. package/dist/cli.js.map +0 -1
  32. package/dist/cluster/export.d.ts.map +0 -1
  33. package/dist/cluster/export.js.map +0 -1
  34. package/dist/defaultConfigSchema.d.ts.map +0 -1
  35. package/dist/defaultConfigSchema.js.map +0 -1
  36. package/dist/deviceManager.d.ts +0 -46
  37. package/dist/deviceManager.d.ts.map +0 -1
  38. package/dist/deviceManager.js.map +0 -1
  39. package/dist/frontend.d.ts +0 -98
  40. package/dist/frontend.d.ts.map +0 -1
  41. package/dist/frontend.js.map +0 -1
  42. package/dist/index.d.ts.map +0 -1
  43. package/dist/index.js.map +0 -1
  44. package/dist/logger/export.d.ts.map +0 -1
  45. package/dist/logger/export.js.map +0 -1
  46. package/dist/matter/export.d.ts.map +0 -1
  47. package/dist/matter/export.js.map +0 -1
  48. package/dist/matterbridge.d.ts +0 -357
  49. package/dist/matterbridge.d.ts.map +0 -1
  50. package/dist/matterbridge.js.map +0 -1
  51. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  52. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  53. package/dist/matterbridgeBehaviors.d.ts +0 -123
  54. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  55. package/dist/matterbridgeBehaviors.js.map +0 -1
  56. package/dist/matterbridgeDeviceTypes.d.ts +0 -109
  57. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  58. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  59. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  60. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  61. package/dist/matterbridgeEndpoint.d.ts +0 -1167
  62. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  63. package/dist/matterbridgeEndpoint.js.map +0 -1
  64. package/dist/matterbridgePlatform.d.ts +0 -154
  65. package/dist/matterbridgePlatform.d.ts.map +0 -1
  66. package/dist/matterbridgePlatform.js.map +0 -1
  67. package/dist/matterbridgeTypes.d.ts.map +0 -1
  68. package/dist/matterbridgeTypes.js.map +0 -1
  69. package/dist/pluginManager.d.ts +0 -238
  70. package/dist/pluginManager.d.ts.map +0 -1
  71. package/dist/pluginManager.js.map +0 -1
  72. package/dist/storage/export.d.ts.map +0 -1
  73. package/dist/storage/export.js.map +0 -1
  74. package/dist/utils/colorUtils.d.ts.map +0 -1
  75. package/dist/utils/colorUtils.js.map +0 -1
  76. package/dist/utils/export.d.ts.map +0 -1
  77. package/dist/utils/export.js.map +0 -1
  78. package/dist/utils/utils.d.ts +0 -221
  79. package/dist/utils/utils.d.ts.map +0 -1
  80. package/dist/utils/utils.js.map +0 -1
  81. package/frontend/build/static/js/main.ea28015b.js.map +0 -1
  82. /package/frontend/build/static/js/{main.ea28015b.js.LICENSE.txt → main.26dbf9b9.js.LICENSE.txt} +0 -0
@@ -1,59 +1,23 @@
1
- /**
2
- * This file contains the class MatterbridgeAccessoryPlatform.
3
- *
4
- * @file matterbridgePlatform.ts
5
- * @author Luca Liguori
6
- * @date 2024-03-21
7
- * @version 1.1.0
8
- *
9
- * Copyright 2024, 2025, 2026 Luca Liguori.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License. *
22
- */
23
- import { MatterbridgeEndpoint } from './matterbridgeEndpoint.js';
24
1
  import { isValidArray, isValidObject, isValidString } from './utils/utils.js';
25
- // AnsiLogger module
26
- import { CYAN, db, nf, wr } from 'node-ansi-logger';
27
- // Storage module
28
- import { NodeStorageManager } from 'node-persist-manager';
29
- // Node.js module
2
+ import { CYAN, db, nf, wr } from './logger/export.js';
3
+ import { NodeStorageManager } from './storage/export.js';
30
4
  import path from 'path';
31
- /**
32
- * Represents the base Matterbridge platform.
33
- *
34
- */
35
5
  export class MatterbridgePlatform {
36
6
  matterbridge;
37
7
  log;
38
8
  config = {};
39
- name = ''; // Will be set by the loadPlugin() method using the package.json value.
40
- type = ''; // Will be set by the extending classes.
41
- version = ''; // Will be set by the loadPlugin() method using the package.json value.
9
+ name = '';
10
+ type = '';
11
+ version = '';
42
12
  storage;
43
13
  context;
44
14
  selectDevice = new Map();
45
15
  selectEntity = new Map();
46
- /**
47
- * Creates an instance of the base MatterbridgePlatform.
48
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
49
- * @param {AnsiLogger} log - The logger instance.
50
- * @param {PlatformConfig} config - The platform configuration.
51
- */
16
+ registeredEndpoints = new Map();
52
17
  constructor(matterbridge, log, config) {
53
18
  this.matterbridge = matterbridge;
54
19
  this.log = log;
55
20
  this.config = config;
56
- // create the NodeStorageManager for the plugin platform
57
21
  if (!isValidString(this.config.name))
58
22
  return;
59
23
  this.log.debug(`Creating storage for plugin ${this.config.name} in ${path.join(this.matterbridge.matterbridgeDirectory, this.config.name)}`);
@@ -65,69 +29,36 @@ export class MatterbridgePlatform {
65
29
  forgiveParseErrors: true,
66
30
  });
67
31
  }
68
- /**
69
- * This method must be overridden in the extended class.
70
- * It is called when the platform is started.
71
- * Use this method to create the MatterbridgeDevice and call this.registerDevice().
72
- * @param {string} [reason] - The reason for starting.
73
- * @throws {Error} - Throws an error if the method is not overridden.
74
- */
75
32
  async onStart(reason) {
76
33
  this.log.error('Plugins must override onStart.', reason);
77
34
  throw new Error('Plugins must override onStart.');
78
35
  }
79
- /**
80
- * This method can be overridden in the extended class.
81
- * It is called after the platform has been commissioned.
82
- * Use this method to perform any configuration of your devices.
83
- */
84
36
  async onConfigure() {
85
37
  this.log.debug(`Configuring platform ${this.name}`);
86
38
  await this.checkEndpointNumbers();
87
39
  }
88
- /**
89
- * This method can be overridden in the extended class.
90
- * It is called when the platform is shutting down.
91
- * Use this method to clean up any resources.
92
- * @param {string} [reason] - The reason for shutting down.
93
- */
94
40
  async onShutdown(reason) {
95
41
  this.log.debug(`Shutting down platform ${this.name}`, reason);
96
42
  await this.checkEndpointNumbers();
97
43
  }
98
- /**
99
- * Sets the logger level and logs a debug message indicating that the plugin doesn't override this method.
100
- * @param {LogLevel} logLevel The new logger level.
101
- */
102
44
  async onChangeLoggerLevel(logLevel) {
103
45
  this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
104
46
  }
105
- /**
106
- * Registers a device with the Matterbridge platform.
107
- * @param {MatterbridgeEndpoint} device - The device to register.
108
- */
109
47
  async registerDevice(device) {
110
48
  device.plugin = this.name;
111
49
  await this.matterbridge.addBridgedEndpoint(this.name, device);
50
+ if (device.uniqueId)
51
+ this.registeredEndpoints.set(device.uniqueId, device);
112
52
  }
113
- /**
114
- * Unregisters a device registered with the Matterbridge platform.
115
- * @param {MatterbridgeEndpoint} device - The device to unregister.
116
- */
117
53
  async unregisterDevice(device) {
118
54
  await this.matterbridge.removeBridgedEndpoint(this.name, device);
55
+ if (device.uniqueId)
56
+ this.registeredEndpoints.delete(device.uniqueId);
119
57
  }
120
- /**
121
- * Unregisters all devices registered with the Matterbridge platform.
122
- */
123
58
  async unregisterAllDevices() {
124
59
  await this.matterbridge.removeAllBridgedEndpoints(this.name);
60
+ this.registeredEndpoints.clear();
125
61
  }
126
- /**
127
- * Verifies if the Matterbridge version meets the required version.
128
- * @param {string} requiredVersion - The required version to compare against.
129
- * @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
130
- */
131
62
  verifyMatterbridgeVersion(requiredVersion) {
132
63
  const compareVersions = (matterbridgeVersion, requiredVersion) => {
133
64
  const stripTag = (v) => {
@@ -152,27 +83,9 @@ export class MatterbridgePlatform {
152
83
  return false;
153
84
  return true;
154
85
  }
155
- /**
156
- * Validates if a device is allowed based on the whitelist and blacklist configurations.
157
- * The blacklist has priority over the whitelist.
158
- *
159
- * @param {string | string[]} device - The device name(s) to validate.
160
- * @param {boolean} [log=true] - Whether to log the validation result.
161
- * @returns {boolean} - Returns true if the device is allowed, false otherwise.
162
- */
163
86
  validateDevice(device, log = true) {
164
87
  return this.validateDeviceWhiteBlackList(device, log);
165
88
  }
166
- /**
167
- * Validates if a device is allowed based on the whitelist and blacklist configurations.
168
- * The blacklist has priority over the whitelist.
169
- *
170
- * @param {string | string[]} device - The device name(s) to validate.
171
- * @param {boolean} [log=true] - Whether to log the validation result.
172
- * @returns {boolean} - Returns true if the device is allowed, false otherwise.
173
- *
174
- * @deprecated This method is deprecated and will be removed in future versions. Use validateDevice instead.
175
- */
176
89
  validateDeviceWhiteBlackList(device, log = true) {
177
90
  if (!Array.isArray(device))
178
91
  device = [device];
@@ -202,27 +115,9 @@ export class MatterbridgePlatform {
202
115
  this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
203
116
  return false;
204
117
  }
205
- /**
206
- * Validates if an entity is allowed based on the entity whitelist and blacklist and the device-entity blacklist configurations.
207
- *
208
- * @param {string} device - The device to which the entity belongs.
209
- * @param {string} entity - The entity to validate.
210
- * @param {boolean} [log=true] - Whether to log the validation result.
211
- * @returns {boolean} - Returns true if the entity is allowed, false otherwise.
212
- */
213
118
  validateEntity(device, entity, log = true) {
214
119
  return this.validateEntityBlackList(device, entity, log);
215
120
  }
216
- /**
217
- * Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
218
- *
219
- * @param {string} device - The device to which the entity belongs.
220
- * @param {string} entity - The entity to validate.
221
- * @param {boolean} [log=true] - Whether to log the validation result.
222
- * @returns {boolean} - Returns true if the entity is allowed, false otherwise.
223
- *
224
- * @deprecated This method is deprecated and will be removed in future versions. Use validateEntity instead.
225
- */
226
121
  validateEntityBlackList(device, entity, log = true) {
227
122
  if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
228
123
  if (log)
@@ -241,15 +136,6 @@ export class MatterbridgePlatform {
241
136
  }
242
137
  return true;
243
138
  }
244
- /**
245
- * Checks and updates the endpoint numbers for Matterbridge devices.
246
- *
247
- * This method retrieves the list of Matterbridge devices and their child endpoints,
248
- * compares their current endpoint numbers with the stored ones, and updates the storage
249
- * if there are any changes. It logs the changes and updates the endpoint numbers accordingly.
250
- *
251
- * @returns {Promise<number>} The size of the updated endpoint map, or -1 if storage is not available.
252
- */
253
139
  async checkEndpointNumbers() {
254
140
  if (!this.storage)
255
141
  return -1;
@@ -288,9 +174,4 @@ export class MatterbridgePlatform {
288
174
  this.log.debug('Endpoint numbers check completed.');
289
175
  return endpointMap.size;
290
176
  }
291
- // Temporary method to create a MatterbridgeDevice before switching to the edge
292
- async _createMutableDevice(definition, options = {}, debug = false) {
293
- return new MatterbridgeEndpoint(definition, options, debug);
294
- }
295
177
  }
296
- //# sourceMappingURL=matterbridgePlatform.js.map
@@ -1,31 +1,6 @@
1
- /**
2
- * This file contains the types for Matterbridge.
3
- *
4
- * @file matterbridgeTypes.ts
5
- * @author Luca Liguori
6
- * @date 2024-07-12
7
- * @version 1.0.2
8
- *
9
- * Copyright 2023, 2024, 2025 Luca Liguori.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License. *
22
- */
23
1
  import { MatterbridgeEndpoint } from './matterbridgeEndpoint.js';
24
- // Default colors
25
2
  export const plg = '\u001B[38;5;33m';
26
3
  export const dev = '\u001B[38;5;79m';
27
4
  export const typ = '\u001B[38;5;207m';
28
- // Define an alias for MatterbridgeEndpoint by extending it
29
5
  export class MatterbridgeDevice extends MatterbridgeEndpoint {
30
6
  }
31
- //# sourceMappingURL=matterbridgeTypes.js.map