matterbridge 1.6.8-dev.2 → 1.6.8-dev.20

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 (95) hide show
  1. package/CHANGELOG.md +23 -4
  2. package/README-DOCKER.md +8 -6
  3. package/README-EDGE.md +76 -0
  4. package/README-SERVICE.md +3 -3
  5. package/README.md +7 -4
  6. package/dist/cli.js +0 -26
  7. package/dist/cluster/export.js +0 -2
  8. package/dist/defaultConfigSchema.js +3 -24
  9. package/dist/deviceManager.js +1 -26
  10. package/dist/index.js +0 -30
  11. package/dist/logger/export.js +0 -1
  12. package/dist/matter/export.js +0 -1
  13. package/dist/matterbridge.js +315 -678
  14. package/dist/matterbridgeAccessoryPlatform.js +0 -33
  15. package/dist/matterbridgeBehaviors.js +1 -29
  16. package/dist/matterbridgeDevice.js +9 -995
  17. package/dist/matterbridgeDeviceTypes.js +11 -82
  18. package/dist/matterbridgeDynamicPlatform.js +0 -33
  19. package/dist/matterbridgeEdge.js +2 -531
  20. package/dist/matterbridgeEndpoint.js +11 -1120
  21. package/dist/matterbridgePlatform.js +69 -95
  22. package/dist/matterbridgeTypes.js +0 -24
  23. package/dist/matterbridgeWebsocket.js +0 -45
  24. package/dist/pluginManager.js +3 -238
  25. package/dist/storage/export.js +0 -1
  26. package/dist/utils/colorUtils.js +2 -205
  27. package/dist/utils/export.js +0 -1
  28. package/dist/utils/utils.js +7 -252
  29. package/frontend/build/asset-manifest.json +6 -6
  30. package/frontend/build/index.html +1 -1
  31. package/frontend/build/static/css/{main.823e08b6.css → main.fa9c13f2.css} +2 -2
  32. package/frontend/build/static/css/main.fa9c13f2.css.map +1 -0
  33. package/frontend/build/static/js/{main.4dd7e165.js → main.f1f06641.js} +15 -15
  34. package/frontend/build/static/js/main.f1f06641.js.map +1 -0
  35. package/npm-shrinkwrap.json +12 -12
  36. package/package.json +1 -1
  37. package/dist/cli.d.ts.map +0 -1
  38. package/dist/cli.js.map +0 -1
  39. package/dist/cluster/export.d.ts.map +0 -1
  40. package/dist/cluster/export.js.map +0 -1
  41. package/dist/defaultConfigSchema.d.ts.map +0 -1
  42. package/dist/defaultConfigSchema.js.map +0 -1
  43. package/dist/deviceManager.d.ts +0 -46
  44. package/dist/deviceManager.d.ts.map +0 -1
  45. package/dist/deviceManager.js.map +0 -1
  46. package/dist/index.d.ts.map +0 -1
  47. package/dist/index.js.map +0 -1
  48. package/dist/logger/export.d.ts.map +0 -1
  49. package/dist/logger/export.js.map +0 -1
  50. package/dist/matter/export.d.ts.map +0 -1
  51. package/dist/matter/export.js.map +0 -1
  52. package/dist/matterbridge.d.ts +0 -466
  53. package/dist/matterbridge.d.ts.map +0 -1
  54. package/dist/matterbridge.js.map +0 -1
  55. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  56. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  57. package/dist/matterbridgeBehaviors.d.ts +0 -116
  58. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  59. package/dist/matterbridgeBehaviors.js.map +0 -1
  60. package/dist/matterbridgeDevice.d.ts +0 -1142
  61. package/dist/matterbridgeDevice.d.ts.map +0 -1
  62. package/dist/matterbridgeDevice.js.map +0 -1
  63. package/dist/matterbridgeDeviceTypes.d.ts +0 -109
  64. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  65. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  66. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  67. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  68. package/dist/matterbridgeEdge.d.ts +0 -90
  69. package/dist/matterbridgeEdge.d.ts.map +0 -1
  70. package/dist/matterbridgeEdge.js.map +0 -1
  71. package/dist/matterbridgeEndpoint.d.ts +0 -1134
  72. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  73. package/dist/matterbridgeEndpoint.js.map +0 -1
  74. package/dist/matterbridgePlatform.d.ts +0 -114
  75. package/dist/matterbridgePlatform.d.ts.map +0 -1
  76. package/dist/matterbridgePlatform.js.map +0 -1
  77. package/dist/matterbridgeTypes.d.ts.map +0 -1
  78. package/dist/matterbridgeTypes.js.map +0 -1
  79. package/dist/matterbridgeWebsocket.d.ts.map +0 -1
  80. package/dist/matterbridgeWebsocket.js.map +0 -1
  81. package/dist/pluginManager.d.ts +0 -238
  82. package/dist/pluginManager.d.ts.map +0 -1
  83. package/dist/pluginManager.js.map +0 -1
  84. package/dist/storage/export.d.ts.map +0 -1
  85. package/dist/storage/export.js.map +0 -1
  86. package/dist/utils/colorUtils.d.ts.map +0 -1
  87. package/dist/utils/colorUtils.js.map +0 -1
  88. package/dist/utils/export.d.ts.map +0 -1
  89. package/dist/utils/export.js.map +0 -1
  90. package/dist/utils/utils.d.ts +0 -221
  91. package/dist/utils/utils.d.ts.map +0 -1
  92. package/dist/utils/utils.js.map +0 -1
  93. package/frontend/build/static/css/main.823e08b6.css.map +0 -1
  94. package/frontend/build/static/js/main.4dd7e165.js.map +0 -1
  95. /package/frontend/build/static/js/{main.4dd7e165.js.LICENSE.txt → main.f1f06641.js.LICENSE.txt} +0 -0
@@ -1,91 +1,48 @@
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
1
  import { MatterbridgeDevice } from './matterbridgeDevice.js';
24
- // AnsiLogger module
25
- import { CYAN, nf } from 'node-ansi-logger';
26
2
  import { MatterbridgeEndpoint } from './matterbridgeEndpoint.js';
27
- import { isValidArray, isValidObject } from './utils/utils.js';
28
- /**
29
- * Represents the base Matterbridge platform.
30
- *
31
- */
3
+ import { isValidArray, isValidObject, isValidString } from './utils/utils.js';
4
+ import { CYAN, db, nf, wr } from 'node-ansi-logger';
5
+ import { NodeStorageManager } from 'node-persist-manager';
6
+ import path from 'path';
32
7
  export class MatterbridgePlatform {
33
8
  matterbridge;
34
9
  log;
35
10
  config = {};
36
- name = ''; // Will be set by the loadPlugin() method using the package.json value.
37
- type = ''; // Will be set by the extending classes.
38
- version = ''; // Will be set by the loadPlugin() method using the package.json value.
39
- /**
40
- * Creates an instance of the base MatterbridgePlatform.
41
- * @param {Matterbridge} matterbridge - The Matterbridge instance.
42
- * @param {AnsiLogger} log - The logger instance.
43
- * @param {PlatformConfig} config - The platform configuration.
44
- */
11
+ name = '';
12
+ type = '';
13
+ version = '';
14
+ storage;
15
+ context;
45
16
  constructor(matterbridge, log, config) {
46
17
  this.matterbridge = matterbridge;
47
18
  this.log = log;
48
19
  this.config = config;
20
+ if (!isValidString(this.config.name))
21
+ return;
22
+ this.log.debug(`Creating storage for plugin ${this.config.name} in ${path.join(this.matterbridge.matterbridgeDirectory, this.config.name)}`);
23
+ this.storage = new NodeStorageManager({
24
+ dir: path.join(this.matterbridge.matterbridgeDirectory, this.config.name),
25
+ writeQueue: false,
26
+ expiredInterval: undefined,
27
+ logging: false,
28
+ forgiveParseErrors: true,
29
+ });
49
30
  }
50
- /**
51
- * This method must be overridden in the extended class.
52
- * It is called when the platform is started.
53
- * Use this method to create the MatterbridgeDevice and call this.registerDevice().
54
- * @param {string} [reason] - The reason for starting.
55
- * @throws {Error} - Throws an error if the method is not overridden.
56
- */
57
31
  async onStart(reason) {
58
32
  this.log.error('Plugins must override onStart.', reason);
59
33
  throw new Error('Plugins must override onStart.');
60
34
  }
61
- /**
62
- * This method can be overridden in the extended class.
63
- * It is called after the platform has been commissioned.
64
- * Use this method to perform any configuration of your devices.
65
- */
66
35
  async onConfigure() {
67
- this.log.debug("The plugin doesn't override onConfigure.");
36
+ this.log.debug(`Configuring platform ${this.name}`);
37
+ await this.checkEndpointNumbers();
68
38
  }
69
- /**
70
- * This method can be overridden in the extended class.
71
- * It is called when the platform is shutting down.
72
- * Use this method to clean up any resources.
73
- * @param {string} [reason] - The reason for shutting down.
74
- */
75
39
  async onShutdown(reason) {
76
- this.log.debug("The plugin doesn't override onShutdown.", reason);
40
+ this.log.debug(`Shutting down platform ${this.name}`, reason);
41
+ await this.checkEndpointNumbers();
77
42
  }
78
- /**
79
- * Sets the logger level and logs a debug message indicating that the plugin doesn't override this method.
80
- * @param {LogLevel} logLevel The new logger level.
81
- */
82
43
  async onChangeLoggerLevel(logLevel) {
83
44
  this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
84
45
  }
85
- /**
86
- * Registers a device with the Matterbridge platform.
87
- * @param {MatterbridgeDevice} device - The device to register.
88
- */
89
46
  async registerDevice(device) {
90
47
  device.plugin = this.name;
91
48
  if (device instanceof MatterbridgeDevice)
@@ -93,30 +50,18 @@ export class MatterbridgePlatform {
93
50
  if (device instanceof MatterbridgeEndpoint)
94
51
  await this.matterbridge.addBridgedEndpoint(this.name, device);
95
52
  }
96
- /**
97
- * Unregisters a device registered with the Matterbridge platform.
98
- * @param {MatterbridgeDevice} device - The device to unregister.
99
- */
100
53
  async unregisterDevice(device) {
101
54
  if (device instanceof MatterbridgeDevice)
102
55
  await this.matterbridge.removeBridgedDevice(this.name, device);
103
56
  if (device instanceof MatterbridgeEndpoint)
104
57
  await this.matterbridge.removeBridgedEndpoint(this.name, device);
105
58
  }
106
- /**
107
- * Unregisters all devices registered with the Matterbridge platform.
108
- */
109
59
  async unregisterAllDevices() {
110
60
  if (this.matterbridge.edge)
111
61
  await this.matterbridge.removeAllBridgedEndpoints(this.name);
112
62
  else
113
63
  await this.matterbridge.removeAllBridgedDevices(this.name);
114
64
  }
115
- /**
116
- * Verifies if the Matterbridge version meets the required version.
117
- * @param {string} requiredVersion - The required version to compare against.
118
- * @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
119
- */
120
65
  verifyMatterbridgeVersion(requiredVersion) {
121
66
  const compareVersions = (matterbridgeVersion, requiredVersion) => {
122
67
  const stripTag = (v) => {
@@ -141,14 +86,6 @@ export class MatterbridgePlatform {
141
86
  return false;
142
87
  return true;
143
88
  }
144
- /**
145
- * Validates if a device is allowed based on the whitelist and blacklist configurations.
146
- * The blacklist has priority over the whitelist.
147
- *
148
- * @param {string | string[]} device - The device name(s) to validate.
149
- * @param {boolean} [log=true] - Whether to log the validation result.
150
- * @returns {boolean} - Returns true if the device is allowed, false otherwise.
151
- */
152
89
  validateDeviceWhiteBlackList(device, log = true) {
153
90
  if (!Array.isArray(device))
154
91
  device = [device];
@@ -178,20 +115,20 @@ export class MatterbridgePlatform {
178
115
  this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
179
116
  return false;
180
117
  }
181
- /**
182
- * Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
183
- *
184
- * @param {string} device - The device to which the entity belongs.
185
- * @param {string} entity - The entity to validate.
186
- * @param {boolean} [log=true] - Whether to log the validation result.
187
- * @returns {boolean} - Returns true if the entity is allowed, false otherwise.
188
- */
118
+ validateEntity(device, entity, log = true) {
119
+ return this.validateEntityBlackList(device, entity, log);
120
+ }
189
121
  validateEntityBlackList(device, entity, log = true) {
190
122
  if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
191
123
  if (log)
192
124
  this.log.info(`Skipping entity ${CYAN}${entity}${nf} because in entityBlackList`);
193
125
  return false;
194
126
  }
127
+ if (isValidArray(this.config.entityWhiteList, 1) && !this.config.entityWhiteList.find((e) => e === entity)) {
128
+ if (log)
129
+ this.log.info(`Skipping entity ${CYAN}${entity}${nf} because not in entityWhiteList`);
130
+ return false;
131
+ }
195
132
  if (isValidObject(this.config.deviceEntityBlackList, 1) && device in this.config.deviceEntityBlackList && this.config.deviceEntityBlackList[device].includes(entity)) {
196
133
  if (log)
197
134
  this.log.info(`Skipping entity ${CYAN}${entity}${nf} for device ${CYAN}${device}${nf} because in deviceEntityBlackList`);
@@ -199,5 +136,42 @@ export class MatterbridgePlatform {
199
136
  }
200
137
  return true;
201
138
  }
139
+ async checkEndpointNumbers() {
140
+ if (!this.storage)
141
+ return -1;
142
+ this.log.debug('Checking endpoint numbers...');
143
+ const context = await this.storage.createStorage('context');
144
+ const separator = '|.|';
145
+ const endpointMap = new Map(await context.get('endpointMap', []));
146
+ for (const device of this.matterbridge.getDevices().filter((d) => d.plugin === this.name)) {
147
+ if (device.uniqueId === undefined || device.maybeNumber === undefined) {
148
+ this.log.debug(`Not checking device ${device.deviceName} without uniqueId or maybeNumber`);
149
+ continue;
150
+ }
151
+ if (endpointMap.has(device.uniqueId) && endpointMap.get(device.uniqueId) !== device.maybeNumber) {
152
+ this.log.warn(`Endpoint number for device ${CYAN}${device.uniqueId}${wr} changed from ${CYAN}${endpointMap.get(device.uniqueId)}${wr} to ${CYAN}${device.maybeNumber}${wr}`);
153
+ endpointMap.set(device.uniqueId, device.maybeNumber);
154
+ }
155
+ if (!endpointMap.has(device.uniqueId)) {
156
+ this.log.debug(`Setting endpoint number for device ${CYAN}${device.uniqueId}${db} to ${CYAN}${device.maybeNumber}${db}`);
157
+ endpointMap.set(device.uniqueId, device.maybeNumber);
158
+ }
159
+ for (const child of device.getChildEndpoints()) {
160
+ const childId = child instanceof MatterbridgeEndpoint ? child.id : child.uniqueStorageKey;
161
+ if (!childId || !child.maybeNumber)
162
+ continue;
163
+ if (endpointMap.has(device.uniqueId + separator + childId) && endpointMap.get(device.uniqueId + separator + childId) !== child.maybeNumber) {
164
+ this.log.warn(`Child endpoint number for device ${CYAN}${device.uniqueId}${wr}.${CYAN}${childId}${wr} changed from ${CYAN}${endpointMap.get(device.uniqueId + separator + childId)}${wr} to ${CYAN}${child.maybeNumber}${wr}`);
165
+ endpointMap.set(device.uniqueId + separator + childId, child.maybeNumber);
166
+ }
167
+ if (!endpointMap.has(device.uniqueId + separator + childId)) {
168
+ this.log.debug(`Setting child endpoint number for device ${CYAN}${device.uniqueId}${db}.${CYAN}${childId}${db} to ${CYAN}${child.maybeNumber}${db}`);
169
+ endpointMap.set(device.uniqueId + separator + childId, child.maybeNumber);
170
+ }
171
+ }
172
+ }
173
+ await context.set('endpointMap', Array.from(endpointMap.entries()));
174
+ this.log.debug('Endpoint numbers check completed.');
175
+ return endpointMap.size;
176
+ }
202
177
  }
203
- //# sourceMappingURL=matterbridgePlatform.js.map
@@ -1,27 +1,3 @@
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
- // Default colors
24
1
  export const plg = '\u001B[38;5;33m';
25
2
  export const dev = '\u001B[38;5;79m';
26
3
  export const typ = '\u001B[38;5;207m';
27
- //# sourceMappingURL=matterbridgeTypes.js.map
@@ -1,54 +1,10 @@
1
- /**
2
- * This file contains the function matterbridgeMessageHandler.
3
- *
4
- * @file matterbridgeWebsocket.ts
5
- * @author Luca Liguori
6
- * @date 2024-10-16
7
- * @version 1.0.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
1
  import { isValidNumber, isValidObject, isValidString } from './utils/utils.js';
24
- // AnsiLogger module
25
2
  import { debugStringify } from 'node-ansi-logger';
26
- // @matter
27
3
  import { Logger } from '@matter/main';
28
4
  import { BasicInformationCluster, BridgedDeviceBasicInformationCluster } from '@matter/main/clusters';
29
- /**
30
- * Websocket message ID for logging.
31
- * @constant {number}
32
- */
33
5
  export const WS_ID_LOG = 0;
34
- /**
35
- * Websocket message ID indicating a refresh is needed.
36
- * @constant {number}
37
- */
38
6
  export const WS_ID_REFRESH_NEEDED = 1;
39
- /**
40
- * Websocket message ID indicating a restart is needed.
41
- * @constant {number}
42
- */
43
7
  export const WS_ID_RESTART_NEEDED = 2;
44
- /**
45
- * Handles incoming websocket messages for the Matterbridge.
46
- *
47
- * @param {Matterbridge} this - The Matterbridge instance.
48
- * @param {WebSocket} client - The websocket client that sent the message.
49
- * @param {WebSocket.RawData} message - The raw data of the message received from the client.
50
- * @returns {Promise<void>} A promise that resolves when the message has been handled.
51
- */
52
8
  export async function wsMessageHandler(client, message) {
53
9
  let data;
54
10
  try {
@@ -188,4 +144,3 @@ export async function wsMessageHandler(client, message) {
188
144
  return;
189
145
  }
190
146
  }
191
- //# sourceMappingURL=matterbridgeWebsocket.js.map