matterbridge 2.2.9 → 3.0.0-edge.10
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.
- package/CHANGELOG.md +44 -0
- package/dist/cli.js +6 -38
- package/dist/cluster/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -23
- package/dist/deviceManager.js +1 -94
- package/dist/frontend.js +20 -328
- package/dist/index.js +1 -28
- package/dist/logger/export.js +0 -1
- package/dist/matter/behaviors.js +0 -2
- package/dist/matter/clusters.js +0 -2
- package/dist/matter/devices.js +0 -2
- package/dist/matter/endpoints.js +0 -2
- package/dist/matter/export.js +0 -2
- package/dist/matter/types.js +0 -2
- package/dist/matterbridge.js +104 -761
- package/dist/matterbridgeAccessoryPlatform.js +0 -33
- package/dist/matterbridgeBehaviors.js +46 -72
- package/dist/matterbridgeDeviceTypes.js +249 -233
- package/dist/matterbridgeDynamicPlatform.js +0 -33
- package/dist/matterbridgeEndpoint.js +85 -759
- package/dist/matterbridgeEndpointHelpers.js +30 -136
- package/dist/matterbridgePlatform.js +9 -218
- package/dist/matterbridgeTypes.js +0 -24
- package/dist/pluginManager.js +3 -262
- package/dist/shelly.js +6 -146
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -45
- package/dist/utils/colorUtils.js +2 -205
- package/dist/utils/copyDirectory.js +1 -37
- package/dist/utils/createZip.js +2 -42
- package/dist/utils/deepCopy.js +0 -40
- package/dist/utils/deepEqual.js +1 -65
- package/dist/utils/export.js +0 -1
- package/dist/utils/isvalid.js +0 -86
- package/dist/utils/network.js +5 -76
- package/dist/utils/parameter.js +0 -41
- package/dist/utils/wait.js +5 -48
- package/npm-shrinkwrap.json +289 -351
- package/package.json +3 -4
- package/dist/cli.d.ts +0 -29
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cluster/export.d.ts +0 -2
- package/dist/cluster/export.d.ts.map +0 -1
- package/dist/cluster/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -27
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -114
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/frontend.d.ts +0 -221
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/index.d.ts +0 -35
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger/export.d.ts +0 -2
- package/dist/logger/export.d.ts.map +0 -1
- package/dist/logger/export.js.map +0 -1
- package/dist/matter/behaviors.d.ts +0 -2
- package/dist/matter/behaviors.d.ts.map +0 -1
- package/dist/matter/behaviors.js.map +0 -1
- package/dist/matter/clusters.d.ts +0 -2
- package/dist/matter/clusters.d.ts.map +0 -1
- package/dist/matter/clusters.js.map +0 -1
- package/dist/matter/devices.d.ts +0 -2
- package/dist/matter/devices.d.ts.map +0 -1
- package/dist/matter/devices.js.map +0 -1
- package/dist/matter/endpoints.d.ts +0 -2
- package/dist/matter/endpoints.d.ts.map +0 -1
- package/dist/matter/endpoints.js.map +0 -1
- package/dist/matter/export.d.ts +0 -5
- package/dist/matter/export.d.ts.map +0 -1
- package/dist/matter/export.js.map +0 -1
- package/dist/matter/types.d.ts +0 -3
- package/dist/matter/types.d.ts.map +0 -1
- package/dist/matter/types.js.map +0 -1
- package/dist/matterbridge.d.ts +0 -425
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -39
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1056
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -178
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -39
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -867
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -2275
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -285
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -183
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -271
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -92
- package/dist/shelly.d.ts.map +0 -1
- package/dist/shelly.js.map +0 -1
- package/dist/storage/export.d.ts +0 -2
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/update.d.ts +0 -32
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -61
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -32
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -38
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -31
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -53
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/export.d.ts +0 -10
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -87
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/network.d.ts +0 -69
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/parameter.d.ts +0 -44
- package/dist/utils/parameter.d.ts.map +0 -1
- package/dist/utils/parameter.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -43
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
|
@@ -1,71 +1,30 @@
|
|
|
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 { checkNotLatinCharacters } from './matterbridgeEndpointHelpers.js';
|
|
24
2
|
import { isValidArray, isValidObject, isValidString } from './utils/export.js';
|
|
25
|
-
// AnsiLogger module
|
|
26
3
|
import { CYAN, db, er, nf, wr } from './logger/export.js';
|
|
27
|
-
// Storage module
|
|
28
4
|
import { NodeStorageManager } from './storage/export.js';
|
|
29
|
-
// Node.js module
|
|
30
5
|
import path from 'node:path';
|
|
31
|
-
/**
|
|
32
|
-
* Represents the base Matterbridge platform. It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
6
|
export class MatterbridgePlatform {
|
|
36
7
|
matterbridge;
|
|
37
8
|
log;
|
|
38
9
|
config = {};
|
|
39
|
-
name = '';
|
|
40
|
-
type = '';
|
|
41
|
-
version = '1.0.0';
|
|
42
|
-
// Platform storage
|
|
10
|
+
name = '';
|
|
11
|
+
type = '';
|
|
12
|
+
version = '1.0.0';
|
|
43
13
|
storage;
|
|
44
14
|
context;
|
|
45
|
-
// Device and entity selection
|
|
46
15
|
selectDevice = new Map();
|
|
47
16
|
selectEntity = new Map();
|
|
48
|
-
// Promises for storage
|
|
49
17
|
_contextReady;
|
|
50
18
|
_selectDeviceContextReady;
|
|
51
19
|
_selectEntityContextReady;
|
|
52
20
|
ready;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// Stored devices
|
|
57
|
-
_storedDevices = new Map(); // serial, { serial, name }
|
|
58
|
-
/**
|
|
59
|
-
* Creates an instance of the base MatterbridgePlatform. It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
|
|
60
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
61
|
-
* @param {AnsiLogger} log - The logger instance.
|
|
62
|
-
* @param {PlatformConfig} config - The platform configuration.
|
|
63
|
-
*/
|
|
21
|
+
_registeredEndpoints = new Map();
|
|
22
|
+
_registeredEndpointsByName = new Map();
|
|
23
|
+
_storedDevices = new Map();
|
|
64
24
|
constructor(matterbridge, log, config) {
|
|
65
25
|
this.matterbridge = matterbridge;
|
|
66
26
|
this.log = log;
|
|
67
27
|
this.config = config;
|
|
68
|
-
// create the NodeStorageManager for the plugin platform
|
|
69
28
|
if (!isValidString(this.config.name) || this.config.name === '')
|
|
70
29
|
throw new Error('Platform: the plugin name is missing or invalid.');
|
|
71
30
|
this.log.debug(`Creating storage for plugin ${this.config.name} in ${path.join(this.matterbridge.matterbridgeDirectory, this.config.name)}`);
|
|
@@ -76,14 +35,12 @@ export class MatterbridgePlatform {
|
|
|
76
35
|
logging: false,
|
|
77
36
|
forgiveParseErrors: true,
|
|
78
37
|
});
|
|
79
|
-
// create the context storage for the plugin platform
|
|
80
38
|
this.log.debug(`Creating context for plugin ${this.config.name}`);
|
|
81
39
|
this._contextReady = this.storage.createStorage('context').then((context) => {
|
|
82
40
|
this.context = context;
|
|
83
|
-
this.context.remove('endpointMap');
|
|
41
|
+
this.context.remove('endpointMap');
|
|
84
42
|
this.log.debug(`Created context for plugin ${this.config.name}`);
|
|
85
43
|
});
|
|
86
|
-
// create the selectDevice storage for the plugin platform
|
|
87
44
|
this.log.debug(`Loading selectDevice for plugin ${this.config.name}`);
|
|
88
45
|
this._selectDeviceContextReady = this.storage.createStorage('selectDevice').then(async (context) => {
|
|
89
46
|
const selectDevice = await context.get('selectDevice', []);
|
|
@@ -91,7 +48,6 @@ export class MatterbridgePlatform {
|
|
|
91
48
|
this.selectDevice.set(device.serial, device);
|
|
92
49
|
this.log.debug(`Loaded ${this.selectDevice.size} selectDevice for plugin ${this.config.name}`);
|
|
93
50
|
});
|
|
94
|
-
// create the selectEntity storage for the plugin platform
|
|
95
51
|
this.log.debug(`Loading selectEntity for plugin ${this.config.name}`);
|
|
96
52
|
this._selectEntityContextReady = this.storage.createStorage('selectEntity').then(async (context) => {
|
|
97
53
|
const selectEntity = await context.get('selectEntity', []);
|
|
@@ -99,107 +55,44 @@ export class MatterbridgePlatform {
|
|
|
99
55
|
this.selectEntity.set(entity.name, entity);
|
|
100
56
|
this.log.debug(`Loaded ${this.selectEntity.size} selectEntity for plugin ${this.config.name}`);
|
|
101
57
|
});
|
|
102
|
-
// Create the `ready` promise for the platform
|
|
103
58
|
this.ready = Promise.all([this._contextReady, this._selectDeviceContextReady, this._selectEntityContextReady]).then(() => {
|
|
104
59
|
this.log.debug(`MatterbridgePlatform for plugin ${this.config.name} is fully initialized`);
|
|
105
60
|
});
|
|
106
61
|
}
|
|
107
|
-
/**
|
|
108
|
-
* This method must be overridden in the extended class.
|
|
109
|
-
* It is called when the platform is started.
|
|
110
|
-
* Use this method to create the MatterbridgeDevice and call this.registerDevice().
|
|
111
|
-
* @param {string} [reason] - The reason for starting.
|
|
112
|
-
* @throws {Error} - Throws an error if the method is not overridden.
|
|
113
|
-
*/
|
|
114
62
|
async onStart(reason) {
|
|
115
63
|
this.log.error('Plugins must override onStart.', reason);
|
|
116
64
|
throw new Error('Plugins must override onStart.');
|
|
117
65
|
}
|
|
118
|
-
/**
|
|
119
|
-
* This method can be overridden in the extended class. Call super.onConfigure() to run checkEndpointNumbers().
|
|
120
|
-
* It is called after the platform has started.
|
|
121
|
-
* Use this method to perform any configuration of your devices.
|
|
122
|
-
*/
|
|
123
66
|
async onConfigure() {
|
|
124
67
|
this.log.debug(`Configuring platform ${this.name}`);
|
|
125
|
-
// Save the selectDevice and selectEntity
|
|
126
68
|
await this.saveSelects();
|
|
127
|
-
// Check and update the endpoint numbers
|
|
128
69
|
await this.checkEndpointNumbers();
|
|
129
70
|
}
|
|
130
|
-
/**
|
|
131
|
-
* 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.
|
|
132
|
-
* It is called when the platform is shutting down.
|
|
133
|
-
* Use this method to clean up any resources.
|
|
134
|
-
* @param {string} [reason] - The reason for shutting down.
|
|
135
|
-
*/
|
|
136
71
|
async onShutdown(reason) {
|
|
137
72
|
this.log.debug(`Shutting down platform ${this.name}`, reason);
|
|
138
|
-
// Save the selectDevice and selectEntity
|
|
139
73
|
await this.saveSelects();
|
|
140
|
-
// Check and update the endpoint numbers
|
|
141
74
|
await this.checkEndpointNumbers();
|
|
142
|
-
// Cleanup memory
|
|
143
75
|
this.selectDevice.clear();
|
|
144
76
|
this.selectEntity.clear();
|
|
145
77
|
this._registeredEndpoints.clear();
|
|
146
78
|
this._registeredEndpointsByName.clear();
|
|
147
79
|
this._storedDevices.clear();
|
|
148
|
-
// Close the storage
|
|
149
80
|
await this.context?.close();
|
|
150
81
|
this.context = undefined;
|
|
151
82
|
await this.storage?.close();
|
|
152
83
|
}
|
|
153
|
-
/**
|
|
154
|
-
* Sets the logger level and logs a debug message indicating that the plugin doesn't override this method.
|
|
155
|
-
* @param {LogLevel} logLevel The new logger level.
|
|
156
|
-
*/
|
|
157
84
|
async onChangeLoggerLevel(logLevel) {
|
|
158
85
|
this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
|
|
159
86
|
}
|
|
160
|
-
/**
|
|
161
|
-
* Called when a plugin config includes an action button or an action button with text field.
|
|
162
|
-
* @param {string} action The action triggered by the button in plugin config.
|
|
163
|
-
* @param {string} value The value of the field of the action button.
|
|
164
|
-
* @param {string} id The id of the schema associated with the action.
|
|
165
|
-
*
|
|
166
|
-
* @remarks
|
|
167
|
-
* This method can be overridden in the extended class.
|
|
168
|
-
*
|
|
169
|
-
* Use this method to handle the action defined in the plugin schema:
|
|
170
|
-
* "addDevice": {
|
|
171
|
-
* "description": "Manually add a device that has not been discovered with mdns:",
|
|
172
|
-
* "type": "boolean",
|
|
173
|
-
* "buttonText": "ADD", // The text on the button.
|
|
174
|
-
* "buttonField": "ADD", // The text on the button. This is used when the action includes a text field.
|
|
175
|
-
* "buttonClose": false, // optional, default is false. When true, the dialog will close after the action is sent.
|
|
176
|
-
* "buttonSave": false, // optional, default is false. When true, the dialog will close and trigger the restart required after the action is sent.
|
|
177
|
-
* "textPlaceholder": "Enter the device IP address", // optional: the placeholder text for the text field.
|
|
178
|
-
* "default": false
|
|
179
|
-
* },
|
|
180
|
-
*/
|
|
181
87
|
async onAction(action, value, id) {
|
|
182
88
|
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 : ''}`);
|
|
183
89
|
}
|
|
184
|
-
/**
|
|
185
|
-
* Called when the plugin config has been updated.
|
|
186
|
-
* @param {PlatformConfig} config The new plugin config.
|
|
187
|
-
*/
|
|
188
90
|
async onConfigChanged(config) {
|
|
189
91
|
this.log.debug(`The plugin ${CYAN}${config.name}${db} doesn't override onConfigChanged. Received new config.`);
|
|
190
92
|
}
|
|
191
|
-
/**
|
|
192
|
-
* Check if a device with this name is already registered in the platform.
|
|
193
|
-
* @param {string} deviceName - The device name to check.
|
|
194
|
-
* @returns {boolean} True if the device is already registered, false otherwise.
|
|
195
|
-
*/
|
|
196
93
|
hasDeviceName(deviceName) {
|
|
197
94
|
return this._registeredEndpointsByName.has(deviceName);
|
|
198
95
|
}
|
|
199
|
-
/**
|
|
200
|
-
* Registers a device with the Matterbridge platform.
|
|
201
|
-
* @param {MatterbridgeEndpoint} device - The device to register.
|
|
202
|
-
*/
|
|
203
96
|
async registerDevice(device) {
|
|
204
97
|
device.plugin = this.name;
|
|
205
98
|
if (device.deviceName && this._registeredEndpointsByName.has(device.deviceName)) {
|
|
@@ -215,10 +108,6 @@ export class MatterbridgePlatform {
|
|
|
215
108
|
if (device.deviceName)
|
|
216
109
|
this._registeredEndpointsByName.set(device.deviceName, device);
|
|
217
110
|
}
|
|
218
|
-
/**
|
|
219
|
-
* Unregisters a device registered with the Matterbridge platform.
|
|
220
|
-
* @param {MatterbridgeEndpoint} device - The device to unregister.
|
|
221
|
-
*/
|
|
222
111
|
async unregisterDevice(device) {
|
|
223
112
|
await this.matterbridge.removeBridgedEndpoint(this.name, device);
|
|
224
113
|
if (device.uniqueId)
|
|
@@ -226,22 +115,11 @@ export class MatterbridgePlatform {
|
|
|
226
115
|
if (device.deviceName)
|
|
227
116
|
this._registeredEndpointsByName.delete(device.deviceName);
|
|
228
117
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
*/
|
|
232
|
-
async unregisterAllDevices() {
|
|
233
|
-
await this.matterbridge.removeAllBridgedEndpoints(this.name);
|
|
118
|
+
async unregisterAllDevices(delay = 0) {
|
|
119
|
+
await this.matterbridge.removeAllBridgedEndpoints(this.name, delay);
|
|
234
120
|
this._registeredEndpoints.clear();
|
|
235
121
|
this._registeredEndpointsByName.clear();
|
|
236
122
|
}
|
|
237
|
-
/**
|
|
238
|
-
* Saves the select devices and entities to storage.
|
|
239
|
-
*
|
|
240
|
-
* This method saves the current state of `selectDevice` and `selectEntity` maps to their respective storage.
|
|
241
|
-
* It logs the number of items being saved and ensures that the storage is properly closed after saving.
|
|
242
|
-
*
|
|
243
|
-
* @returns {Promise<void>} A promise that resolves when the save operation is complete.
|
|
244
|
-
*/
|
|
245
123
|
async saveSelects() {
|
|
246
124
|
if (this.storage) {
|
|
247
125
|
this.log.debug(`Saving ${this.selectDevice.size} selectDevice...`);
|
|
@@ -254,36 +132,15 @@ export class MatterbridgePlatform {
|
|
|
254
132
|
await selectEntity.close();
|
|
255
133
|
}
|
|
256
134
|
}
|
|
257
|
-
/**
|
|
258
|
-
* Clears the select device and entity maps.
|
|
259
|
-
*
|
|
260
|
-
* @returns {void}
|
|
261
|
-
*/
|
|
262
135
|
async clearSelect() {
|
|
263
136
|
this.selectDevice.clear();
|
|
264
137
|
this.selectEntity.clear();
|
|
265
138
|
await this.saveSelects();
|
|
266
139
|
}
|
|
267
|
-
/**
|
|
268
|
-
* Clears the select for a single device.
|
|
269
|
-
*
|
|
270
|
-
* @param {string} device - The serial of the device to clear.
|
|
271
|
-
* @returns {void}
|
|
272
|
-
*/
|
|
273
140
|
async clearDeviceSelect(device) {
|
|
274
141
|
this.selectDevice.delete(device);
|
|
275
142
|
await this.saveSelects();
|
|
276
143
|
}
|
|
277
|
-
/**
|
|
278
|
-
* Set the select device in the platform map.
|
|
279
|
-
*
|
|
280
|
-
* @param {string} serial - The serial number of the device.
|
|
281
|
-
* @param {string} name - The name of the device.
|
|
282
|
-
* @param {string} [configUrl] - The configuration URL of the device.
|
|
283
|
-
* @param {string} [icon] - The icon of the device: 'wifi', 'ble', 'hub'
|
|
284
|
-
* @param {Array<{ name: string; description: string; icon?: string }>} [entities] - The entities associated with the device.
|
|
285
|
-
* @returns {void}
|
|
286
|
-
*/
|
|
287
144
|
setSelectDevice(serial, name, configUrl, icon, entities) {
|
|
288
145
|
const device = this.selectDevice.get(serial);
|
|
289
146
|
if (device) {
|
|
@@ -300,15 +157,6 @@ export class MatterbridgePlatform {
|
|
|
300
157
|
this.selectDevice.set(serial, { serial, name, configUrl, icon, entities });
|
|
301
158
|
}
|
|
302
159
|
}
|
|
303
|
-
/**
|
|
304
|
-
* Set the select device entity in the platform map.
|
|
305
|
-
*
|
|
306
|
-
* @param {string} serial - The serial number of the device.
|
|
307
|
-
* @param {string} entityName - The name of the entity.
|
|
308
|
-
* @param {string} entityDescription - The description of the entity.
|
|
309
|
-
* @param {string} [entityIcon] - The icon of the entity: 'wifi', 'ble', 'hub', 'component', 'matter'
|
|
310
|
-
* @returns {void}
|
|
311
|
-
*/
|
|
312
160
|
setSelectDeviceEntity(serial, entityName, entityDescription, entityIcon) {
|
|
313
161
|
const device = this.selectDevice.get(serial);
|
|
314
162
|
if (device) {
|
|
@@ -318,11 +166,6 @@ export class MatterbridgePlatform {
|
|
|
318
166
|
device.entities.push({ name: entityName, description: entityDescription, icon: entityIcon });
|
|
319
167
|
}
|
|
320
168
|
}
|
|
321
|
-
/**
|
|
322
|
-
* Retrieves the select devices from the platform map.
|
|
323
|
-
*
|
|
324
|
-
* @returns {{ pluginName: string; serial: string; name: string; configUrl?: string; icon?: string; entities?: { name: string; description: string; icon?: string }[] }[]} The selected devices array.
|
|
325
|
-
*/
|
|
326
169
|
getSelectDevices() {
|
|
327
170
|
const selectDevices = [];
|
|
328
171
|
for (const device of this.selectDevice.values()) {
|
|
@@ -330,22 +173,9 @@ export class MatterbridgePlatform {
|
|
|
330
173
|
}
|
|
331
174
|
return selectDevices;
|
|
332
175
|
}
|
|
333
|
-
/**
|
|
334
|
-
* Set the select entity in the platform map.
|
|
335
|
-
*
|
|
336
|
-
* @param {string} name - The entity name.
|
|
337
|
-
* @param {string} description - The entity description.
|
|
338
|
-
* @param {string} [icon] - The entity icon: 'wifi', 'ble', 'hub', 'component', 'matter'
|
|
339
|
-
* @returns {void}
|
|
340
|
-
*/
|
|
341
176
|
setSelectEntity(name, description, icon) {
|
|
342
177
|
this.selectEntity.set(name, { name, description, icon });
|
|
343
178
|
}
|
|
344
|
-
/**
|
|
345
|
-
* Retrieve the select entities.
|
|
346
|
-
*
|
|
347
|
-
* @returns {{ pluginName: string; name: string; description: string; icon?: string }[]} The select entities array.
|
|
348
|
-
*/
|
|
349
179
|
getSelectEntities() {
|
|
350
180
|
const selectEntities = [];
|
|
351
181
|
for (const entity of this.selectEntity.values()) {
|
|
@@ -353,11 +183,6 @@ export class MatterbridgePlatform {
|
|
|
353
183
|
}
|
|
354
184
|
return selectEntities;
|
|
355
185
|
}
|
|
356
|
-
/**
|
|
357
|
-
* Verifies if the Matterbridge version meets the required version.
|
|
358
|
-
* @param {string} requiredVersion - The required version to compare against.
|
|
359
|
-
* @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
|
|
360
|
-
*/
|
|
361
186
|
verifyMatterbridgeVersion(requiredVersion) {
|
|
362
187
|
const compareVersions = (matterbridgeVersion, requiredVersion) => {
|
|
363
188
|
const stripTag = (v) => {
|
|
@@ -382,21 +207,9 @@ export class MatterbridgePlatform {
|
|
|
382
207
|
return false;
|
|
383
208
|
return true;
|
|
384
209
|
}
|
|
385
|
-
/**
|
|
386
|
-
* @deprecated This method is deprecated and will be removed in future versions. Use validateDevice instead.
|
|
387
|
-
*/
|
|
388
210
|
validateDeviceWhiteBlackList(device, log = true) {
|
|
389
211
|
return this.validateDevice(device, log);
|
|
390
212
|
}
|
|
391
|
-
/**
|
|
392
|
-
* Validates if a device is allowed based on the whitelist and blacklist configurations.
|
|
393
|
-
* The blacklist has priority over the whitelist.
|
|
394
|
-
*
|
|
395
|
-
* @param {string | string[]} device - The device name(s) to validate.
|
|
396
|
-
* @param {boolean} [log=true] - Whether to log the validation result.
|
|
397
|
-
* @returns {boolean} - Returns true if the device is allowed, false otherwise.
|
|
398
|
-
*
|
|
399
|
-
*/
|
|
400
213
|
validateDevice(device, log = true) {
|
|
401
214
|
if (!Array.isArray(device))
|
|
402
215
|
device = [device];
|
|
@@ -426,21 +239,9 @@ export class MatterbridgePlatform {
|
|
|
426
239
|
this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
|
|
427
240
|
return false;
|
|
428
241
|
}
|
|
429
|
-
/**
|
|
430
|
-
* @deprecated This method is deprecated and will be removed in future versions. Use validateEntity instead.
|
|
431
|
-
*/
|
|
432
242
|
validateEntityBlackList(device, entity, log = true) {
|
|
433
243
|
return this.validateEntity(device, entity, log);
|
|
434
244
|
}
|
|
435
|
-
/**
|
|
436
|
-
* Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
|
|
437
|
-
*
|
|
438
|
-
* @param {string} device - The device to which the entity belongs.
|
|
439
|
-
* @param {string} entity - The entity to validate.
|
|
440
|
-
* @param {boolean} [log=true] - Whether to log the validation result.
|
|
441
|
-
* @returns {boolean} - Returns true if the entity is allowed, false otherwise.
|
|
442
|
-
*
|
|
443
|
-
*/
|
|
444
245
|
validateEntity(device, entity, log = true) {
|
|
445
246
|
if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
|
|
446
247
|
if (log)
|
|
@@ -459,15 +260,6 @@ export class MatterbridgePlatform {
|
|
|
459
260
|
}
|
|
460
261
|
return true;
|
|
461
262
|
}
|
|
462
|
-
/**
|
|
463
|
-
* Checks and updates the endpoint numbers for Matterbridge devices.
|
|
464
|
-
*
|
|
465
|
-
* This method retrieves the list of Matterbridge devices and their child endpoints,
|
|
466
|
-
* compares their current endpoint numbers with the stored ones, and updates the storage
|
|
467
|
-
* if there are any changes. It logs the changes and updates the endpoint numbers accordingly.
|
|
468
|
-
*
|
|
469
|
-
* @returns {Promise<number>} The size of the updated endpoint map, or -1 if storage is not available.
|
|
470
|
-
*/
|
|
471
263
|
async checkEndpointNumbers() {
|
|
472
264
|
if (!this.storage)
|
|
473
265
|
return -1;
|
|
@@ -508,4 +300,3 @@ export class MatterbridgePlatform {
|
|
|
508
300
|
return endpointMap.size;
|
|
509
301
|
}
|
|
510
302
|
}
|
|
511
|
-
//# 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
|