matterbridge 3.0.7 → 3.0.8-dev-20250622-f9e44a2
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 +24 -0
- package/bin/matterbridge +2 -0
- package/dist/cli.js +5 -66
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -23
- package/dist/deviceManager.js +2 -95
- package/dist/devices/export.js +0 -2
- package/dist/evse.js +9 -65
- package/dist/frontend.js +47 -383
- package/dist/globalMatterbridge.js +0 -20
- package/dist/helpers.js +4 -52
- package/dist/index.js +2 -29
- package/dist/laundryWasher.js +7 -92
- 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 +53 -755
- package/dist/matterbridgeAccessoryPlatform.js +0 -34
- package/dist/matterbridgeBehaviors.js +1 -54
- package/dist/matterbridgeDeviceTypes.js +15 -578
- package/dist/matterbridgeDynamicPlatform.js +0 -34
- package/dist/matterbridgeEndpoint.js +45 -1000
- package/dist/matterbridgeEndpointHelpers.js +12 -206
- package/dist/matterbridgePlatform.js +13 -224
- package/dist/matterbridgeTypes.js +0 -24
- package/dist/pluginManager.js +4 -270
- package/dist/roboticVacuumCleaner.js +9 -84
- package/dist/shelly.js +9 -156
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -53
- package/dist/utils/colorUtils.js +2 -205
- package/dist/utils/commandLine.js +0 -53
- package/dist/utils/copyDirectory.js +1 -37
- package/dist/utils/createDirectory.js +0 -31
- package/dist/utils/createZip.js +2 -42
- package/dist/utils/deepCopy.js +0 -38
- package/dist/utils/deepEqual.js +1 -71
- package/dist/utils/export.js +0 -1
- package/dist/utils/hex.js +0 -57
- package/dist/utils/isvalid.js +0 -100
- package/dist/utils/network.js +6 -77
- package/dist/utils/spawn.js +0 -16
- package/dist/utils/wait.js +10 -58
- package/dist/waterHeater.js +5 -65
- package/frontend/build/matterbridge 1250x1250.png +0 -0
- package/frontend/build/matterbridge 624x624.png +0 -0
- package/frontend/package-lock.json +19176 -0
- package/frontend/package.json +79 -0
- package/frontend/public/Shelly.svg +1 -0
- package/frontend/public/bmc-button.svg +22 -0
- package/frontend/public/discord.svg +5 -0
- package/frontend/public/favicon.ico +0 -0
- package/frontend/public/index.html +19 -0
- package/frontend/public/manifest.json +15 -0
- package/frontend/public/matter.png +0 -0
- package/frontend/public/matterbridge 1250x1250.png +0 -0
- package/frontend/public/matterbridge 32x32.png +0 -0
- package/frontend/public/matterbridge 624x624.png +0 -0
- package/frontend/public/matterbridge 64x64.png +0 -0
- package/frontend/public/matterbridge.svg +50 -0
- package/frontend/public/robots.txt +3 -0
- package/npm-shrinkwrap.json +27 -36
- package/package.json +2 -3
- package/dist/cli.d.ts +0 -29
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/clusters/export.d.ts +0 -2
- package/dist/clusters/export.d.ts.map +0 -1
- package/dist/clusters/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/devices/export.d.ts +0 -5
- package/dist/devices/export.d.ts.map +0 -1
- package/dist/devices/export.js.map +0 -1
- package/dist/evse.d.ts +0 -67
- package/dist/evse.d.ts.map +0 -1
- package/dist/evse.js.map +0 -1
- package/dist/frontend.d.ts +0 -256
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/globalMatterbridge.d.ts +0 -32
- package/dist/globalMatterbridge.d.ts.map +0 -1
- package/dist/globalMatterbridge.js.map +0 -1
- package/dist/helpers.d.ts +0 -47
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js.map +0 -1
- package/dist/index.d.ts +0 -37
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/laundryWasher.d.ts +0 -243
- package/dist/laundryWasher.d.ts.map +0 -1
- package/dist/laundryWasher.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 -445
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -40
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1333
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -644
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -40
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1145
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -3083
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -290
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -196
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -273
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/roboticVacuumCleaner.d.ts +0 -102
- package/dist/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/roboticVacuumCleaner.js.map +0 -1
- package/dist/shelly.d.ts +0 -161
- 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 -58
- 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/commandLine.d.ts +0 -58
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.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/createDirectory.d.ts +0 -32
- package/dist/utils/createDirectory.d.ts.map +0 -1
- package/dist/utils/createDirectory.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 -12
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/hex.d.ts +0 -48
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -102
- 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/spawn.d.ts +0 -12
- package/dist/utils/spawn.d.ts.map +0 -1
- package/dist/utils/spawn.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -52
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
- package/dist/waterHeater.d.ts +0 -90
- package/dist/waterHeater.d.ts.map +0 -1
- package/dist/waterHeater.js.map +0 -1
- package/tsconfig.jest.json +0 -8
- package/tsconfig.production.json +0 -13
|
@@ -1,72 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @file matterbridgePlatform.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2024-03-21
|
|
7
|
-
* @version 1.2.1
|
|
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
|
-
*/
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { CYAN, db, er, nf, wr } from 'node-ansi-logger';
|
|
3
|
+
import { NodeStorageManager } from 'node-persist-manager';
|
|
23
4
|
import { checkNotLatinCharacters } from './matterbridgeEndpointHelpers.js';
|
|
24
5
|
import { isValidArray, isValidObject, isValidString } from './utils/export.js';
|
|
25
|
-
// AnsiLogger module
|
|
26
|
-
import { CYAN, db, er, nf, wr } from './logger/export.js';
|
|
27
|
-
// Storage module
|
|
28
|
-
import { NodeStorageManager } from './storage/export.js';
|
|
29
|
-
// Node.js module
|
|
30
|
-
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 select in the plugin config UI
|
|
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
|
-
_registeredEndpointsByName = new Map(); // deviceName, MatterbridgeEndpoint
|
|
56
|
-
/**
|
|
57
|
-
* Creates an instance of the base MatterbridgePlatform.
|
|
58
|
-
* It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
|
|
59
|
-
* Each plugin must extend the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
|
|
60
|
-
*
|
|
61
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
62
|
-
* @param {AnsiLogger} log - The logger instance.
|
|
63
|
-
* @param {PlatformConfig} config - The platform configuration.
|
|
64
|
-
*/
|
|
21
|
+
_registeredEndpoints = new Map();
|
|
22
|
+
_registeredEndpointsByName = new Map();
|
|
65
23
|
constructor(matterbridge, log, config) {
|
|
66
24
|
this.matterbridge = matterbridge;
|
|
67
25
|
this.log = log;
|
|
68
26
|
this.config = config;
|
|
69
|
-
// create the NodeStorageManager for the plugin platform
|
|
70
27
|
if (!isValidString(this.config.name) || this.config.name === '')
|
|
71
28
|
throw new Error('Platform: the plugin name is missing or invalid.');
|
|
72
29
|
this.log.debug(`Creating storage for plugin ${this.config.name} in ${path.join(this.matterbridge.matterbridgeDirectory, this.config.name)}`);
|
|
@@ -77,140 +34,70 @@ export class MatterbridgePlatform {
|
|
|
77
34
|
logging: false,
|
|
78
35
|
forgiveParseErrors: true,
|
|
79
36
|
});
|
|
80
|
-
// create the context storage for the plugin platform
|
|
81
37
|
this.log.debug(`Creating context for plugin ${this.config.name}`);
|
|
82
38
|
this._contextReady = this.storage.createStorage('context').then((context) => {
|
|
83
39
|
this.context = context;
|
|
84
|
-
this.context.remove('endpointMap');
|
|
40
|
+
this.context.remove('endpointMap');
|
|
85
41
|
this.log.debug(`Created context for plugin ${this.config.name}`);
|
|
42
|
+
return;
|
|
86
43
|
});
|
|
87
|
-
// create the selectDevice storage for the plugin platform
|
|
88
44
|
this.log.debug(`Loading selectDevice for plugin ${this.config.name}`);
|
|
89
45
|
this._selectDeviceContextReady = this.storage.createStorage('selectDevice').then(async (context) => {
|
|
90
46
|
const selectDevice = await context.get('selectDevice', []);
|
|
91
47
|
for (const device of selectDevice)
|
|
92
48
|
this.selectDevice.set(device.serial, device);
|
|
93
49
|
this.log.debug(`Loaded ${this.selectDevice.size} selectDevice for plugin ${this.config.name}`);
|
|
50
|
+
return;
|
|
94
51
|
});
|
|
95
|
-
// create the selectEntity storage for the plugin platform
|
|
96
52
|
this.log.debug(`Loading selectEntity for plugin ${this.config.name}`);
|
|
97
53
|
this._selectEntityContextReady = this.storage.createStorage('selectEntity').then(async (context) => {
|
|
98
54
|
const selectEntity = await context.get('selectEntity', []);
|
|
99
55
|
for (const entity of selectEntity)
|
|
100
56
|
this.selectEntity.set(entity.name, entity);
|
|
101
57
|
this.log.debug(`Loaded ${this.selectEntity.size} selectEntity for plugin ${this.config.name}`);
|
|
58
|
+
return;
|
|
102
59
|
});
|
|
103
|
-
// Create the `ready` promise for the platform
|
|
104
60
|
this.ready = Promise.all([this._contextReady, this._selectDeviceContextReady, this._selectEntityContextReady]).then(() => {
|
|
105
61
|
this.log.debug(`MatterbridgePlatform for plugin ${this.config.name} is fully initialized`);
|
|
62
|
+
return;
|
|
106
63
|
});
|
|
107
64
|
}
|
|
108
|
-
/**
|
|
109
|
-
* This method must be overridden in the extended class.
|
|
110
|
-
* It is called when the platform is started.
|
|
111
|
-
* Use this method to create the MatterbridgeEndpoints and call this.registerDevice().
|
|
112
|
-
* @param {string} [reason] - The reason for starting.
|
|
113
|
-
* @throws {Error} - Throws an error if the method is not overridden.
|
|
114
|
-
*/
|
|
115
65
|
async onStart(reason) {
|
|
116
66
|
this.log.error('Plugins must override onStart.', reason);
|
|
117
67
|
throw new Error('Plugins must override onStart.');
|
|
118
68
|
}
|
|
119
|
-
/**
|
|
120
|
-
* This method can be overridden in the extended class. In this case always call super.onConfigure() to save the select and run checkEndpointNumbers().
|
|
121
|
-
* It is called after the platform has started.
|
|
122
|
-
* 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
|
|
123
|
-
* matter storage (i.e. the onOff attribute of the OnOff cluster).
|
|
124
|
-
*/
|
|
125
69
|
async onConfigure() {
|
|
126
70
|
this.log.debug(`Configuring platform ${this.name}`);
|
|
127
|
-
// Save the selectDevice and selectEntity
|
|
128
71
|
await this.saveSelects();
|
|
129
|
-
// Check and update the endpoint numbers
|
|
130
72
|
await this.checkEndpointNumbers();
|
|
131
73
|
}
|
|
132
|
-
/**
|
|
133
|
-
* 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.
|
|
134
|
-
* It is called when the platform is shutting down.
|
|
135
|
-
* Use this method to clean up any resources you used in the constructor or onStart.
|
|
136
|
-
* @param {string} [reason] - The reason for shutting down.
|
|
137
|
-
*/
|
|
138
74
|
async onShutdown(reason) {
|
|
139
75
|
this.log.debug(`Shutting down platform ${this.name}`, reason);
|
|
140
|
-
// Save the selectDevice and selectEntity
|
|
141
76
|
await this.saveSelects();
|
|
142
|
-
// Check and update the endpoint numbers
|
|
143
77
|
await this.checkEndpointNumbers();
|
|
144
|
-
// Cleanup memory
|
|
145
78
|
this.selectDevice.clear();
|
|
146
79
|
this.selectEntity.clear();
|
|
147
80
|
this._registeredEndpoints.clear();
|
|
148
81
|
this._registeredEndpointsByName.clear();
|
|
149
|
-
// Close the storage
|
|
150
82
|
await this.context?.close();
|
|
151
83
|
this.context = undefined;
|
|
152
84
|
await this.storage?.close();
|
|
153
85
|
}
|
|
154
|
-
/**
|
|
155
|
-
* Called when the logger level is changed.
|
|
156
|
-
* @param {LogLevel} logLevel The new logger level.
|
|
157
|
-
*/
|
|
158
86
|
async onChangeLoggerLevel(logLevel) {
|
|
159
87
|
this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
|
|
160
88
|
}
|
|
161
|
-
/**
|
|
162
|
-
* Called when a plugin config includes an action button or an action button with text field.
|
|
163
|
-
* @param {string} action The action triggered by the button in plugin config.
|
|
164
|
-
* @param {string} value The value of the field of the action button.
|
|
165
|
-
* @param {string} id The id of the schema associated with the action.
|
|
166
|
-
* @param {PlatformConfig} formData The changed form data of the plugin.
|
|
167
|
-
*
|
|
168
|
-
* @remarks
|
|
169
|
-
* This method can be overridden in the extended class.
|
|
170
|
-
*
|
|
171
|
-
* Use this method to handle the action defined in the plugin schema:
|
|
172
|
-
* ```json
|
|
173
|
-
* "addDevice": {
|
|
174
|
-
* "description": "Manually add a device that has not been discovered with mdns:",
|
|
175
|
-
* "type": "boolean",
|
|
176
|
-
* "buttonText": "ADD", // The text on the button. This is used when the action doesn't include a text field.
|
|
177
|
-
* "buttonField": "ADD", // The text on the button. This is used when the action includes a text field.
|
|
178
|
-
* "buttonClose": false, // optional, default is false. When true, the dialog will close after the action is sent.
|
|
179
|
-
* "buttonSave": false, // optional, default is false. When true, the dialog will close and trigger the restart required after the action is sent.
|
|
180
|
-
* "textPlaceholder": "Enter the device IP address", // optional: the placeholder text for the text field.
|
|
181
|
-
* "default": false
|
|
182
|
-
* },
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
89
|
async onAction(action, value, id, formData) {
|
|
186
90
|
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);
|
|
187
91
|
}
|
|
188
|
-
/**
|
|
189
|
-
* Called when the plugin config has been updated.
|
|
190
|
-
* @param {PlatformConfig} config The new plugin config.
|
|
191
|
-
*/
|
|
192
92
|
async onConfigChanged(config) {
|
|
193
93
|
this.log.debug(`The plugin ${CYAN}${config.name}${db} doesn't override onConfigChanged. Received new config.`);
|
|
194
94
|
}
|
|
195
|
-
/**
|
|
196
|
-
* Retrieves the devices registered with the platform.
|
|
197
|
-
* @returns {MatterbridgeEndpoint[]} The registered devices.
|
|
198
|
-
*/
|
|
199
95
|
getDevices() {
|
|
200
96
|
return Array.from(this._registeredEndpoints.values());
|
|
201
97
|
}
|
|
202
|
-
/**
|
|
203
|
-
* Checks if a device with this name is already registered in the platform.
|
|
204
|
-
* @param {string} deviceName - The device name to check.
|
|
205
|
-
* @returns {boolean} True if the device is already registered, false otherwise.
|
|
206
|
-
*/
|
|
207
98
|
hasDeviceName(deviceName) {
|
|
208
99
|
return this._registeredEndpointsByName.has(deviceName);
|
|
209
100
|
}
|
|
210
|
-
/**
|
|
211
|
-
* Registers a device with the Matterbridge platform.
|
|
212
|
-
* @param {MatterbridgeEndpoint} device - The device to register.
|
|
213
|
-
*/
|
|
214
101
|
async registerDevice(device) {
|
|
215
102
|
device.plugin = this.name;
|
|
216
103
|
if (device.deviceName && this._registeredEndpointsByName.has(device.deviceName)) {
|
|
@@ -226,10 +113,6 @@ export class MatterbridgePlatform {
|
|
|
226
113
|
if (device.deviceName)
|
|
227
114
|
this._registeredEndpointsByName.set(device.deviceName, device);
|
|
228
115
|
}
|
|
229
|
-
/**
|
|
230
|
-
* Unregisters a device registered with the Matterbridge platform.
|
|
231
|
-
* @param {MatterbridgeEndpoint} device - The device to unregister.
|
|
232
|
-
*/
|
|
233
116
|
async unregisterDevice(device) {
|
|
234
117
|
await this.matterbridge.removeBridgedEndpoint(this.name, device);
|
|
235
118
|
if (device.uniqueId)
|
|
@@ -237,24 +120,11 @@ export class MatterbridgePlatform {
|
|
|
237
120
|
if (device.deviceName)
|
|
238
121
|
this._registeredEndpointsByName.delete(device.deviceName);
|
|
239
122
|
}
|
|
240
|
-
/**
|
|
241
|
-
* Unregisters all devices registered with the Matterbridge platform.
|
|
242
|
-
*
|
|
243
|
-
* @param {number} [delay=0] - The delay in milliseconds between removing each bridged endpoint (default: 0).
|
|
244
|
-
*/
|
|
245
123
|
async unregisterAllDevices(delay = 0) {
|
|
246
124
|
await this.matterbridge.removeAllBridgedEndpoints(this.name, delay);
|
|
247
125
|
this._registeredEndpoints.clear();
|
|
248
126
|
this._registeredEndpointsByName.clear();
|
|
249
127
|
}
|
|
250
|
-
/**
|
|
251
|
-
* Saves the select devices and entities to storage.
|
|
252
|
-
*
|
|
253
|
-
* This method saves the current state of `selectDevice` and `selectEntity` maps to their respective storage.
|
|
254
|
-
* It logs the number of items being saved and ensures that the storage is properly closed after saving.
|
|
255
|
-
*
|
|
256
|
-
* @returns {Promise<void>} A promise that resolves when the save operation is complete.
|
|
257
|
-
*/
|
|
258
128
|
async saveSelects() {
|
|
259
129
|
if (this.storage) {
|
|
260
130
|
this.log.debug(`Saving ${this.selectDevice.size} selectDevice...`);
|
|
@@ -267,36 +137,15 @@ export class MatterbridgePlatform {
|
|
|
267
137
|
await selectEntity.close();
|
|
268
138
|
}
|
|
269
139
|
}
|
|
270
|
-
/**
|
|
271
|
-
* Clears all the select device and entity maps.
|
|
272
|
-
*
|
|
273
|
-
* @returns {void}
|
|
274
|
-
*/
|
|
275
140
|
async clearSelect() {
|
|
276
141
|
this.selectDevice.clear();
|
|
277
142
|
this.selectEntity.clear();
|
|
278
143
|
await this.saveSelects();
|
|
279
144
|
}
|
|
280
|
-
/**
|
|
281
|
-
* Clears the select for a single device.
|
|
282
|
-
*
|
|
283
|
-
* @param {string} serial - The serial of the device to clear.
|
|
284
|
-
* @returns {void}
|
|
285
|
-
*/
|
|
286
145
|
async clearDeviceSelect(serial) {
|
|
287
146
|
this.selectDevice.delete(serial);
|
|
288
147
|
await this.saveSelects();
|
|
289
148
|
}
|
|
290
|
-
/**
|
|
291
|
-
* Set the select device in the platform map.
|
|
292
|
-
*
|
|
293
|
-
* @param {string} serial - The serial number of the device.
|
|
294
|
-
* @param {string} name - The name of the device.
|
|
295
|
-
* @param {string} [configUrl] - The configuration URL of the device.
|
|
296
|
-
* @param {string} [icon] - The icon of the device: 'wifi', 'ble', 'hub'
|
|
297
|
-
* @param {Array<{ name: string; description: string; icon?: string }>} [entities] - The entities associated with the device.
|
|
298
|
-
* @returns {void}
|
|
299
|
-
*/
|
|
300
149
|
setSelectDevice(serial, name, configUrl, icon, entities) {
|
|
301
150
|
const device = this.selectDevice.get(serial);
|
|
302
151
|
if (device) {
|
|
@@ -313,15 +162,6 @@ export class MatterbridgePlatform {
|
|
|
313
162
|
this.selectDevice.set(serial, { serial, name, configUrl, icon, entities });
|
|
314
163
|
}
|
|
315
164
|
}
|
|
316
|
-
/**
|
|
317
|
-
* Set the select device entity in the platform map.
|
|
318
|
-
*
|
|
319
|
-
* @param {string} serial - The serial number of the device.
|
|
320
|
-
* @param {string} entityName - The name of the entity.
|
|
321
|
-
* @param {string} entityDescription - The description of the entity.
|
|
322
|
-
* @param {string} [entityIcon] - The icon of the entity: 'wifi', 'ble', 'hub', 'component', 'matter'
|
|
323
|
-
* @returns {void}
|
|
324
|
-
*/
|
|
325
165
|
setSelectDeviceEntity(serial, entityName, entityDescription, entityIcon) {
|
|
326
166
|
const device = this.selectDevice.get(serial);
|
|
327
167
|
if (device) {
|
|
@@ -331,11 +171,6 @@ export class MatterbridgePlatform {
|
|
|
331
171
|
device.entities.push({ name: entityName, description: entityDescription, icon: entityIcon });
|
|
332
172
|
}
|
|
333
173
|
}
|
|
334
|
-
/**
|
|
335
|
-
* Retrieves the select devices from the platform map.
|
|
336
|
-
*
|
|
337
|
-
* @returns {{ pluginName: string; serial: string; name: string; configUrl?: string; icon?: string; entities?: { name: string; description: string; icon?: string }[] }[]} The selected devices array.
|
|
338
|
-
*/
|
|
339
174
|
getSelectDevices() {
|
|
340
175
|
const selectDevices = [];
|
|
341
176
|
for (const device of this.selectDevice.values()) {
|
|
@@ -343,22 +178,9 @@ export class MatterbridgePlatform {
|
|
|
343
178
|
}
|
|
344
179
|
return selectDevices;
|
|
345
180
|
}
|
|
346
|
-
/**
|
|
347
|
-
* Set the select entity in the platform map.
|
|
348
|
-
*
|
|
349
|
-
* @param {string} name - The entity name.
|
|
350
|
-
* @param {string} description - The entity description.
|
|
351
|
-
* @param {string} [icon] - The entity icon: 'wifi', 'ble', 'hub', 'component', 'matter'
|
|
352
|
-
* @returns {void}
|
|
353
|
-
*/
|
|
354
181
|
setSelectEntity(name, description, icon) {
|
|
355
182
|
this.selectEntity.set(name, { name, description, icon });
|
|
356
183
|
}
|
|
357
|
-
/**
|
|
358
|
-
* Retrieve the select entities.
|
|
359
|
-
*
|
|
360
|
-
* @returns {{ pluginName: string; name: string; description: string; icon?: string }[]} The select entities array.
|
|
361
|
-
*/
|
|
362
184
|
getSelectEntities() {
|
|
363
185
|
const selectEntities = [];
|
|
364
186
|
for (const entity of this.selectEntity.values()) {
|
|
@@ -366,11 +188,6 @@ export class MatterbridgePlatform {
|
|
|
366
188
|
}
|
|
367
189
|
return selectEntities;
|
|
368
190
|
}
|
|
369
|
-
/**
|
|
370
|
-
* Verifies if the Matterbridge version meets the required version.
|
|
371
|
-
* @param {string} requiredVersion - The required version to compare against.
|
|
372
|
-
* @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
|
|
373
|
-
*/
|
|
374
191
|
verifyMatterbridgeVersion(requiredVersion) {
|
|
375
192
|
const compareVersions = (matterbridgeVersion, requiredVersion) => {
|
|
376
193
|
const stripTag = (v) => {
|
|
@@ -395,15 +212,6 @@ export class MatterbridgePlatform {
|
|
|
395
212
|
return false;
|
|
396
213
|
return true;
|
|
397
214
|
}
|
|
398
|
-
/**
|
|
399
|
-
* Validates if a device is allowed based on the whitelist and blacklist configurations.
|
|
400
|
-
* The blacklist has priority over the whitelist.
|
|
401
|
-
*
|
|
402
|
-
* @param {string | string[]} device - The device name(s) to validate.
|
|
403
|
-
* @param {boolean} [log=true] - Whether to log the validation result.
|
|
404
|
-
* @returns {boolean} - Returns true if the device is allowed, false otherwise.
|
|
405
|
-
*
|
|
406
|
-
*/
|
|
407
215
|
validateDevice(device, log = true) {
|
|
408
216
|
if (!Array.isArray(device))
|
|
409
217
|
device = [device];
|
|
@@ -433,15 +241,6 @@ export class MatterbridgePlatform {
|
|
|
433
241
|
this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
|
|
434
242
|
return false;
|
|
435
243
|
}
|
|
436
|
-
/**
|
|
437
|
-
* Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
|
|
438
|
-
*
|
|
439
|
-
* @param {string} device - The device to which the entity belongs.
|
|
440
|
-
* @param {string} entity - The entity to validate.
|
|
441
|
-
* @param {boolean} [log=true] - Whether to log the validation result.
|
|
442
|
-
* @returns {boolean} - Returns true if the entity is allowed, false otherwise.
|
|
443
|
-
*
|
|
444
|
-
*/
|
|
445
244
|
validateEntity(device, entity, log = true) {
|
|
446
245
|
if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
|
|
447
246
|
if (log)
|
|
@@ -460,15 +259,6 @@ export class MatterbridgePlatform {
|
|
|
460
259
|
}
|
|
461
260
|
return true;
|
|
462
261
|
}
|
|
463
|
-
/**
|
|
464
|
-
* Checks and updates the endpoint numbers for Matterbridge devices.
|
|
465
|
-
*
|
|
466
|
-
* This method retrieves the list of Matterbridge devices and their child endpoints,
|
|
467
|
-
* compares their current endpoint numbers with the stored ones, and updates the storage
|
|
468
|
-
* if there are any changes. It logs the changes and updates the endpoint numbers accordingly.
|
|
469
|
-
*
|
|
470
|
-
* @returns {Promise<number>} The size of the updated endpoint map, or -1 if storage is not available.
|
|
471
|
-
*/
|
|
472
262
|
async checkEndpointNumbers() {
|
|
473
263
|
if (!this.storage)
|
|
474
264
|
return -1;
|
|
@@ -509,4 +299,3 @@ export class MatterbridgePlatform {
|
|
|
509
299
|
return endpointMap.size;
|
|
510
300
|
}
|
|
511
301
|
}
|
|
512
|
-
//# 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
|