matterbridge 3.1.5 → 3.1.6-dev-20250721-75fab6b
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 +18 -0
- package/dist/cli.js +2 -91
- package/dist/cliEmitter.js +0 -30
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -24
- package/dist/deviceManager.js +1 -94
- package/dist/devices/batteryStorage.js +1 -48
- package/dist/devices/dishwasher.js +90 -0
- package/dist/devices/evse.js +10 -74
- package/dist/devices/export.js +2 -2
- package/dist/devices/extractorHood.js +35 -0
- package/dist/devices/heatPump.js +2 -50
- package/dist/devices/laundryDryer.js +6 -83
- package/dist/devices/laundryWasher.js +7 -91
- package/dist/devices/roboticVacuumCleaner.js +7 -93
- package/dist/devices/solarPower.js +0 -38
- package/dist/devices/waterHeater.js +2 -82
- package/dist/frontend.js +21 -429
- package/dist/globalMatterbridge.js +0 -47
- package/dist/helpers.js +0 -53
- package/dist/index.js +1 -30
- 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 -3
- package/dist/matter/types.js +0 -3
- package/dist/matterbridge.js +79 -802
- package/dist/matterbridgeAccessoryPlatform.js +0 -36
- package/dist/matterbridgeBehaviors.js +24 -61
- package/dist/matterbridgeDeviceTypes.js +15 -579
- package/dist/matterbridgeDynamicPlatform.js +0 -36
- package/dist/matterbridgeEndpoint.js +64 -1113
- package/dist/matterbridgeEndpointHelpers.js +12 -322
- package/dist/matterbridgePlatform.js +0 -233
- package/dist/matterbridgeTypes.js +0 -25
- package/dist/pluginManager.js +3 -249
- package/dist/shelly.js +7 -168
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -54
- package/dist/utils/colorUtils.js +2 -263
- package/dist/utils/commandLine.js +0 -54
- package/dist/utils/copyDirectory.js +1 -38
- package/dist/utils/createDirectory.js +0 -33
- package/dist/utils/createZip.js +2 -47
- package/dist/utils/deepCopy.js +0 -39
- package/dist/utils/deepEqual.js +1 -72
- package/dist/utils/error.js +0 -41
- package/dist/utils/export.js +0 -1
- package/dist/utils/hex.js +0 -58
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/network.js +5 -81
- package/dist/utils/spawn.js +0 -40
- package/dist/utils/wait.js +9 -62
- package/npm-shrinkwrap.json +9 -9
- package/package.json +2 -3
- package/dist/cli.d.ts +0 -26
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cliEmitter.d.ts +0 -34
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.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 -28
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -112
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/devices/batteryStorage.d.ts +0 -48
- package/dist/devices/batteryStorage.d.ts.map +0 -1
- package/dist/devices/batteryStorage.js.map +0 -1
- package/dist/devices/evse.d.ts +0 -75
- package/dist/devices/evse.d.ts.map +0 -1
- package/dist/devices/evse.js.map +0 -1
- package/dist/devices/export.d.ts +0 -9
- package/dist/devices/export.d.ts.map +0 -1
- package/dist/devices/export.js.map +0 -1
- package/dist/devices/heatPump.d.ts +0 -47
- package/dist/devices/heatPump.d.ts.map +0 -1
- package/dist/devices/heatPump.js.map +0 -1
- package/dist/devices/laundryDryer.d.ts +0 -87
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -242
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.js.map +0 -1
- package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
- package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/devices/roboticVacuumCleaner.js.map +0 -1
- package/dist/devices/solarPower.d.ts +0 -40
- package/dist/devices/solarPower.d.ts.map +0 -1
- package/dist/devices/solarPower.js.map +0 -1
- package/dist/devices/waterHeater.d.ts +0 -111
- package/dist/devices/waterHeater.d.ts.map +0 -1
- package/dist/devices/waterHeater.js.map +0 -1
- package/dist/frontend.d.ts +0 -304
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/globalMatterbridge.d.ts +0 -59
- package/dist/globalMatterbridge.d.ts.map +0 -1
- package/dist/globalMatterbridge.js.map +0 -1
- package/dist/helpers.d.ts +0 -48
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js.map +0 -1
- package/dist/index.d.ts +0 -33
- 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 -447
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1340
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -709
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1250
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -3198
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -310
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -195
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -270
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -174
- 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 -59
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -117
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/commandLine.d.ts +0 -59
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -33
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createDirectory.d.ts +0 -34
- package/dist/utils/createDirectory.d.ts.map +0 -1
- package/dist/utils/createDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -39
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -32
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -54
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/error.d.ts +0 -44
- package/dist/utils/error.d.ts.map +0 -1
- package/dist/utils/error.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 -49
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -103
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/network.d.ts +0 -74
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/spawn.d.ts +0 -33
- package/dist/utils/spawn.d.ts.map +0 -1
- package/dist/utils/spawn.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -56
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
|
@@ -1,82 +1,29 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the class MatterbridgePlatform.
|
|
3
|
-
*
|
|
4
|
-
* @file matterbridgePlatform.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @created 2024-03-21
|
|
7
|
-
* @version 1.2.1
|
|
8
|
-
* @license Apache-2.0
|
|
9
|
-
*
|
|
10
|
-
* Copyright 2024, 2025, 2026 Luca Liguori.
|
|
11
|
-
*
|
|
12
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License.
|
|
14
|
-
* You may obtain a copy of the License at
|
|
15
|
-
*
|
|
16
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
-
* See the License for the specific language governing permissions and
|
|
22
|
-
* limitations under the License.
|
|
23
|
-
*/
|
|
24
|
-
// Node.js module
|
|
25
1
|
import path from 'node:path';
|
|
26
|
-
// AnsiLogger module
|
|
27
2
|
import { CYAN, db, er, nf, wr } from 'node-ansi-logger';
|
|
28
|
-
// Storage module
|
|
29
3
|
import { NodeStorageManager } from 'node-persist-manager';
|
|
30
4
|
import { checkNotLatinCharacters } from './matterbridgeEndpointHelpers.js';
|
|
31
5
|
import { isValidArray, isValidObject, isValidString } from './utils/export.js';
|
|
32
|
-
/**
|
|
33
|
-
* Represents the base Matterbridge platform. It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
6
|
export class MatterbridgePlatform {
|
|
37
|
-
/** The Matterbridge instance of this Platform. */
|
|
38
7
|
matterbridge;
|
|
39
|
-
/** The logger instance for this platform. */
|
|
40
8
|
log;
|
|
41
|
-
/** The configuration for this platform. */
|
|
42
9
|
config = {};
|
|
43
|
-
/** The name of the platform. Will be set by the loadPlugin() method using the package.json value. */
|
|
44
10
|
name = '';
|
|
45
|
-
/** The type of the platform. Will be set by the extending classes. */
|
|
46
11
|
type = '';
|
|
47
|
-
/** The version of the platform. Will be set by the loadPlugin() method using the package.json value */
|
|
48
12
|
version = '1.0.0';
|
|
49
|
-
/** Platform node storage manager. */
|
|
50
13
|
storage;
|
|
51
|
-
/** Platform context storage. */
|
|
52
14
|
context;
|
|
53
|
-
// Device and entity select in the plugin config UI
|
|
54
15
|
selectDevice = new Map();
|
|
55
16
|
selectEntity = new Map();
|
|
56
|
-
// Promises for storage
|
|
57
17
|
_contextReady;
|
|
58
18
|
_selectDeviceContextReady;
|
|
59
19
|
_selectEntityContextReady;
|
|
60
|
-
/** The ready promise for the platform, which resolves when the platform is fully initialized. */
|
|
61
20
|
ready;
|
|
62
|
-
/** Registered MatterbridgeEndpoint Map by uniqueId */
|
|
63
21
|
_registeredEndpoints = new Map();
|
|
64
|
-
/** Registered MatterbridgeEndpoint Map by deviceName */
|
|
65
22
|
_registeredEndpointsByName = new Map();
|
|
66
|
-
/**
|
|
67
|
-
* Creates an instance of the base MatterbridgePlatform.
|
|
68
|
-
* It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
|
|
69
|
-
* Each plugin must extend the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
|
|
70
|
-
*
|
|
71
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
72
|
-
* @param {AnsiLogger} log - The logger instance.
|
|
73
|
-
* @param {PlatformConfig} config - The platform configuration.
|
|
74
|
-
*/
|
|
75
23
|
constructor(matterbridge, log, config) {
|
|
76
24
|
this.matterbridge = matterbridge;
|
|
77
25
|
this.log = log;
|
|
78
26
|
this.config = config;
|
|
79
|
-
// create the NodeStorageManager for the plugin platform
|
|
80
27
|
if (!isValidString(this.config.name, 1))
|
|
81
28
|
throw new Error('Platform: the plugin name is missing or invalid.');
|
|
82
29
|
this.log.debug(`Creating storage for plugin ${this.config.name} in ${path.join(this.matterbridge.matterbridgeDirectory, this.config.name)}`);
|
|
@@ -87,14 +34,12 @@ export class MatterbridgePlatform {
|
|
|
87
34
|
logging: false,
|
|
88
35
|
forgiveParseErrors: true,
|
|
89
36
|
});
|
|
90
|
-
// create the context storage for the plugin platform
|
|
91
37
|
this.log.debug(`Creating context for plugin ${this.config.name}`);
|
|
92
38
|
this._contextReady = this.storage.createStorage('context').then((context) => {
|
|
93
39
|
this.context = context;
|
|
94
40
|
this.log.debug(`Created context for plugin ${this.config.name}`);
|
|
95
41
|
return;
|
|
96
42
|
});
|
|
97
|
-
// create the selectDevice storage for the plugin platform
|
|
98
43
|
this.log.debug(`Loading selectDevice for plugin ${this.config.name}`);
|
|
99
44
|
this._selectDeviceContextReady = this.storage.createStorage('selectDevice').then(async (context) => {
|
|
100
45
|
const selectDevice = await context.get('selectDevice', []);
|
|
@@ -103,7 +48,6 @@ export class MatterbridgePlatform {
|
|
|
103
48
|
this.log.debug(`Loaded ${this.selectDevice.size} selectDevice for plugin ${this.config.name}`);
|
|
104
49
|
return;
|
|
105
50
|
});
|
|
106
|
-
// create the selectEntity storage for the plugin platform
|
|
107
51
|
this.log.debug(`Loading selectEntity for plugin ${this.config.name}`);
|
|
108
52
|
this._selectEntityContextReady = this.storage.createStorage('selectEntity').then(async (context) => {
|
|
109
53
|
const selectEntity = await context.get('selectEntity', []);
|
|
@@ -112,126 +56,47 @@ export class MatterbridgePlatform {
|
|
|
112
56
|
this.log.debug(`Loaded ${this.selectEntity.size} selectEntity for plugin ${this.config.name}`);
|
|
113
57
|
return;
|
|
114
58
|
});
|
|
115
|
-
// Create the `ready` promise for the platform
|
|
116
59
|
this.ready = Promise.all([this._contextReady, this._selectDeviceContextReady, this._selectEntityContextReady]).then(() => {
|
|
117
60
|
this.log.debug(`MatterbridgePlatform for plugin ${this.config.name} is fully initialized`);
|
|
118
61
|
return;
|
|
119
62
|
});
|
|
120
63
|
}
|
|
121
|
-
/**
|
|
122
|
-
* This method must be overridden in the extended class.
|
|
123
|
-
* It is called when the platform is started.
|
|
124
|
-
* Use this method to create the MatterbridgeEndpoints and call this.registerDevice().
|
|
125
|
-
*
|
|
126
|
-
* @param {string} [reason] - The reason for starting.
|
|
127
|
-
* @throws {Error} - Throws an error if the method is not overridden.
|
|
128
|
-
*/
|
|
129
64
|
async onStart(reason) {
|
|
130
65
|
this.log.error('Plugins must override onStart.', reason);
|
|
131
66
|
throw new Error('Plugins must override onStart.');
|
|
132
67
|
}
|
|
133
|
-
/**
|
|
134
|
-
* This method can be overridden in the extended class. In this case always call super.onConfigure() to save the select and run checkEndpointNumbers().
|
|
135
|
-
* It is called after the platform has started.
|
|
136
|
-
* Use this method to perform any configuration of your devices and to override the value of the attributes that are persistent and stored in the
|
|
137
|
-
* matter storage (i.e. the onOff attribute of the OnOff cluster).
|
|
138
|
-
*/
|
|
139
68
|
async onConfigure() {
|
|
140
69
|
this.log.debug(`Configuring platform ${this.name}`);
|
|
141
|
-
// Save the selectDevice and selectEntity
|
|
142
70
|
await this.saveSelects();
|
|
143
|
-
// Check and update the endpoint numbers
|
|
144
71
|
await this.checkEndpointNumbers();
|
|
145
72
|
}
|
|
146
|
-
/**
|
|
147
|
-
* This method can be overridden in the extended class. In this case always call super.onShutdown() to save the selects, run checkEndpointNumbers() and cleanup memory.
|
|
148
|
-
* It is called when the platform is shutting down.
|
|
149
|
-
* Use this method to clean up any resources you used in the constructor or onStart.
|
|
150
|
-
*
|
|
151
|
-
* @param {string} [reason] - The reason for shutting down.
|
|
152
|
-
*/
|
|
153
73
|
async onShutdown(reason) {
|
|
154
74
|
this.log.debug(`Shutting down platform ${this.name}`, reason);
|
|
155
|
-
// Save the selectDevice and selectEntity
|
|
156
75
|
await this.saveSelects();
|
|
157
|
-
// Check and update the endpoint numbers
|
|
158
76
|
await this.checkEndpointNumbers();
|
|
159
|
-
// Cleanup memory
|
|
160
77
|
this.selectDevice.clear();
|
|
161
78
|
this.selectEntity.clear();
|
|
162
79
|
this._registeredEndpoints.clear();
|
|
163
80
|
this._registeredEndpointsByName.clear();
|
|
164
|
-
// Close the storage
|
|
165
81
|
await this.context?.close();
|
|
166
82
|
this.context = undefined;
|
|
167
83
|
await this.storage?.close();
|
|
168
84
|
}
|
|
169
|
-
/**
|
|
170
|
-
* Called when the logger level is changed.
|
|
171
|
-
*
|
|
172
|
-
* @param {LogLevel} logLevel The new logger level.
|
|
173
|
-
*/
|
|
174
85
|
async onChangeLoggerLevel(logLevel) {
|
|
175
86
|
this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
|
|
176
87
|
}
|
|
177
|
-
/**
|
|
178
|
-
* Called when a plugin config includes an action button or an action button with text field.
|
|
179
|
-
*
|
|
180
|
-
* @param {string} action The action triggered by the button in plugin config.
|
|
181
|
-
* @param {string} value The value of the field of the action button.
|
|
182
|
-
* @param {string} id The id of the schema associated with the action.
|
|
183
|
-
* @param {PlatformConfig} formData The changed form data of the plugin.
|
|
184
|
-
*
|
|
185
|
-
* @remarks
|
|
186
|
-
* This method can be overridden in the extended class.
|
|
187
|
-
*
|
|
188
|
-
* Use this method to handle the action defined in the plugin schema:
|
|
189
|
-
* ```json
|
|
190
|
-
* "addDevice": {
|
|
191
|
-
* "description": "Manually add a device that has not been discovered with mdns:",
|
|
192
|
-
* "type": "boolean",
|
|
193
|
-
* "buttonText": "ADD", // The text on the button. This is used when the action doesn't include a text field.
|
|
194
|
-
* "buttonField": "ADD", // The text on the button. This is used when the action includes a text field.
|
|
195
|
-
* "buttonClose": false, // optional, default is false. When true, the dialog will close after the action is sent.
|
|
196
|
-
* "buttonSave": false, // optional, default is false. When true, the dialog will close and trigger the restart required after the action is sent.
|
|
197
|
-
* "textPlaceholder": "Enter the device IP address", // optional: the placeholder text for the text field.
|
|
198
|
-
* "default": false
|
|
199
|
-
* },
|
|
200
|
-
* ```
|
|
201
|
-
*/
|
|
202
88
|
async onAction(action, value, id, formData) {
|
|
203
89
|
this.log.debug(`The plugin ${CYAN}${this.name}${db} doesn't override onAction. Received action ${CYAN}${action}${db}${value ? ' with ' + CYAN + value + db : ''} ${id ? ' for schema ' + CYAN + id + db : ''}`, formData);
|
|
204
90
|
}
|
|
205
|
-
/**
|
|
206
|
-
* Called when the plugin config has been updated.
|
|
207
|
-
*
|
|
208
|
-
* @param {PlatformConfig} config The new plugin config.
|
|
209
|
-
*/
|
|
210
91
|
async onConfigChanged(config) {
|
|
211
92
|
this.log.debug(`The plugin ${CYAN}${config.name}${db} doesn't override onConfigChanged. Received new config.`);
|
|
212
93
|
}
|
|
213
|
-
/**
|
|
214
|
-
* Retrieves the devices registered with the platform.
|
|
215
|
-
*
|
|
216
|
-
* @returns {MatterbridgeEndpoint[]} The registered devices.
|
|
217
|
-
*/
|
|
218
94
|
getDevices() {
|
|
219
95
|
return Array.from(this._registeredEndpoints.values());
|
|
220
96
|
}
|
|
221
|
-
/**
|
|
222
|
-
* Checks if a device with this name is already registered in the platform.
|
|
223
|
-
*
|
|
224
|
-
* @param {string} deviceName - The device name to check.
|
|
225
|
-
* @returns {boolean} True if the device is already registered, false otherwise.
|
|
226
|
-
*/
|
|
227
97
|
hasDeviceName(deviceName) {
|
|
228
98
|
return this._registeredEndpointsByName.has(deviceName);
|
|
229
99
|
}
|
|
230
|
-
/**
|
|
231
|
-
* Registers a device with the Matterbridge platform.
|
|
232
|
-
*
|
|
233
|
-
* @param {MatterbridgeEndpoint} device - The device to register.
|
|
234
|
-
*/
|
|
235
100
|
async registerDevice(device) {
|
|
236
101
|
device.plugin = this.name;
|
|
237
102
|
if (device.deviceName && this._registeredEndpointsByName.has(device.deviceName)) {
|
|
@@ -247,11 +112,6 @@ export class MatterbridgePlatform {
|
|
|
247
112
|
if (device.deviceName)
|
|
248
113
|
this._registeredEndpointsByName.set(device.deviceName, device);
|
|
249
114
|
}
|
|
250
|
-
/**
|
|
251
|
-
* Unregisters a device registered with the Matterbridge platform.
|
|
252
|
-
*
|
|
253
|
-
* @param {MatterbridgeEndpoint} device - The device to unregister.
|
|
254
|
-
*/
|
|
255
115
|
async unregisterDevice(device) {
|
|
256
116
|
await this.matterbridge.removeBridgedEndpoint(this.name, device);
|
|
257
117
|
if (device.uniqueId)
|
|
@@ -259,24 +119,11 @@ export class MatterbridgePlatform {
|
|
|
259
119
|
if (device.deviceName)
|
|
260
120
|
this._registeredEndpointsByName.delete(device.deviceName);
|
|
261
121
|
}
|
|
262
|
-
/**
|
|
263
|
-
* Unregisters all devices registered with the Matterbridge platform.
|
|
264
|
-
*
|
|
265
|
-
* @param {number} [delay] - The delay in milliseconds between removing each bridged endpoint (default: 0).
|
|
266
|
-
*/
|
|
267
122
|
async unregisterAllDevices(delay = 0) {
|
|
268
123
|
await this.matterbridge.removeAllBridgedEndpoints(this.name, delay);
|
|
269
124
|
this._registeredEndpoints.clear();
|
|
270
125
|
this._registeredEndpointsByName.clear();
|
|
271
126
|
}
|
|
272
|
-
/**
|
|
273
|
-
* Saves the select devices and entities to storage.
|
|
274
|
-
*
|
|
275
|
-
* This method saves the current state of `selectDevice` and `selectEntity` maps to their respective storage.
|
|
276
|
-
* It logs the number of items being saved and ensures that the storage is properly closed after saving.
|
|
277
|
-
*
|
|
278
|
-
* @returns {Promise<void>} A promise that resolves when the save operation is complete.
|
|
279
|
-
*/
|
|
280
127
|
async saveSelects() {
|
|
281
128
|
if (this.storage) {
|
|
282
129
|
this.log.debug(`Saving ${this.selectDevice.size} selectDevice...`);
|
|
@@ -289,36 +136,15 @@ export class MatterbridgePlatform {
|
|
|
289
136
|
await selectEntity.close();
|
|
290
137
|
}
|
|
291
138
|
}
|
|
292
|
-
/**
|
|
293
|
-
* Clears all the select device and entity maps.
|
|
294
|
-
*
|
|
295
|
-
* @returns {void}
|
|
296
|
-
*/
|
|
297
139
|
async clearSelect() {
|
|
298
140
|
this.selectDevice.clear();
|
|
299
141
|
this.selectEntity.clear();
|
|
300
142
|
await this.saveSelects();
|
|
301
143
|
}
|
|
302
|
-
/**
|
|
303
|
-
* Clears the select for a single device.
|
|
304
|
-
*
|
|
305
|
-
* @param {string} serial - The serial of the device to clear.
|
|
306
|
-
* @returns {void}
|
|
307
|
-
*/
|
|
308
144
|
async clearDeviceSelect(serial) {
|
|
309
145
|
this.selectDevice.delete(serial);
|
|
310
146
|
await this.saveSelects();
|
|
311
147
|
}
|
|
312
|
-
/**
|
|
313
|
-
* Set the select device in the platform map.
|
|
314
|
-
*
|
|
315
|
-
* @param {string} serial - The serial number of the device.
|
|
316
|
-
* @param {string} name - The name of the device.
|
|
317
|
-
* @param {string} [configUrl] - The configuration URL of the device.
|
|
318
|
-
* @param {string} [icon] - The icon of the device: 'wifi', 'ble', 'hub'
|
|
319
|
-
* @param {Array<{ name: string; description: string; icon?: string }>} [entities] - The entities associated with the device.
|
|
320
|
-
* @returns {void}
|
|
321
|
-
*/
|
|
322
148
|
setSelectDevice(serial, name, configUrl, icon, entities) {
|
|
323
149
|
const device = this.selectDevice.get(serial);
|
|
324
150
|
if (device) {
|
|
@@ -335,15 +161,6 @@ export class MatterbridgePlatform {
|
|
|
335
161
|
this.selectDevice.set(serial, { serial, name, configUrl, icon, entities });
|
|
336
162
|
}
|
|
337
163
|
}
|
|
338
|
-
/**
|
|
339
|
-
* Set the select device entity in the platform map.
|
|
340
|
-
*
|
|
341
|
-
* @param {string} serial - The serial number of the device.
|
|
342
|
-
* @param {string} entityName - The name of the entity.
|
|
343
|
-
* @param {string} entityDescription - The description of the entity.
|
|
344
|
-
* @param {string} [entityIcon] - The icon of the entity: 'wifi', 'ble', 'hub', 'component', 'matter'
|
|
345
|
-
* @returns {void}
|
|
346
|
-
*/
|
|
347
164
|
setSelectDeviceEntity(serial, entityName, entityDescription, entityIcon) {
|
|
348
165
|
const device = this.selectDevice.get(serial);
|
|
349
166
|
if (device) {
|
|
@@ -353,11 +170,6 @@ export class MatterbridgePlatform {
|
|
|
353
170
|
device.entities.push({ name: entityName, description: entityDescription, icon: entityIcon });
|
|
354
171
|
}
|
|
355
172
|
}
|
|
356
|
-
/**
|
|
357
|
-
* Retrieves the select devices from the platform map.
|
|
358
|
-
*
|
|
359
|
-
* @returns {{ pluginName: string; serial: string; name: string; configUrl?: string; icon?: string; entities?: { name: string; description: string; icon?: string }[] }[]} The selected devices array.
|
|
360
|
-
*/
|
|
361
173
|
getSelectDevices() {
|
|
362
174
|
const selectDevices = [];
|
|
363
175
|
for (const device of this.selectDevice.values()) {
|
|
@@ -365,22 +177,9 @@ export class MatterbridgePlatform {
|
|
|
365
177
|
}
|
|
366
178
|
return selectDevices;
|
|
367
179
|
}
|
|
368
|
-
/**
|
|
369
|
-
* Set the select entity in the platform map.
|
|
370
|
-
*
|
|
371
|
-
* @param {string} name - The entity name.
|
|
372
|
-
* @param {string} description - The entity description.
|
|
373
|
-
* @param {string} [icon] - The entity icon: 'wifi', 'ble', 'hub', 'component', 'matter'
|
|
374
|
-
* @returns {void}
|
|
375
|
-
*/
|
|
376
180
|
setSelectEntity(name, description, icon) {
|
|
377
181
|
this.selectEntity.set(name, { name, description, icon });
|
|
378
182
|
}
|
|
379
|
-
/**
|
|
380
|
-
* Retrieve the select entities.
|
|
381
|
-
*
|
|
382
|
-
* @returns {{ pluginName: string; name: string; description: string; icon?: string }[]} The select entities array.
|
|
383
|
-
*/
|
|
384
183
|
getSelectEntities() {
|
|
385
184
|
const selectEntities = [];
|
|
386
185
|
for (const entity of this.selectEntity.values()) {
|
|
@@ -388,12 +187,6 @@ export class MatterbridgePlatform {
|
|
|
388
187
|
}
|
|
389
188
|
return selectEntities;
|
|
390
189
|
}
|
|
391
|
-
/**
|
|
392
|
-
* Verifies if the Matterbridge version meets the required version.
|
|
393
|
-
*
|
|
394
|
-
* @param {string} requiredVersion - The required version to compare against.
|
|
395
|
-
* @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
|
|
396
|
-
*/
|
|
397
190
|
verifyMatterbridgeVersion(requiredVersion) {
|
|
398
191
|
const compareVersions = (matterbridgeVersion, requiredVersion) => {
|
|
399
192
|
const stripTag = (v) => {
|
|
@@ -418,14 +211,6 @@ export class MatterbridgePlatform {
|
|
|
418
211
|
return false;
|
|
419
212
|
return true;
|
|
420
213
|
}
|
|
421
|
-
/**
|
|
422
|
-
* Validates if a device is allowed based on the whitelist and blacklist configurations.
|
|
423
|
-
* The blacklist has priority over the whitelist.
|
|
424
|
-
*
|
|
425
|
-
* @param {string | string[]} device - The device name(s) to validate.
|
|
426
|
-
* @param {boolean} [log] - Whether to log the validation result.
|
|
427
|
-
* @returns {boolean} - Returns true if the device is allowed, false otherwise.
|
|
428
|
-
*/
|
|
429
214
|
validateDevice(device, log = true) {
|
|
430
215
|
if (!Array.isArray(device))
|
|
431
216
|
device = [device];
|
|
@@ -455,14 +240,6 @@ export class MatterbridgePlatform {
|
|
|
455
240
|
this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
|
|
456
241
|
return false;
|
|
457
242
|
}
|
|
458
|
-
/**
|
|
459
|
-
* Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
|
|
460
|
-
*
|
|
461
|
-
* @param {string} device - The device to which the entity belongs.
|
|
462
|
-
* @param {string} entity - The entity to validate.
|
|
463
|
-
* @param {boolean} [log] - Whether to log the validation result.
|
|
464
|
-
* @returns {boolean} - Returns true if the entity is allowed, false otherwise.
|
|
465
|
-
*/
|
|
466
243
|
validateEntity(device, entity, log = true) {
|
|
467
244
|
if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
|
|
468
245
|
if (log)
|
|
@@ -481,15 +258,6 @@ export class MatterbridgePlatform {
|
|
|
481
258
|
}
|
|
482
259
|
return true;
|
|
483
260
|
}
|
|
484
|
-
/**
|
|
485
|
-
* Checks and updates the endpoint numbers for Matterbridge devices.
|
|
486
|
-
*
|
|
487
|
-
* This method retrieves the list of Matterbridge devices and their child endpoints,
|
|
488
|
-
* compares their current endpoint numbers with the stored ones, and updates the storage
|
|
489
|
-
* if there are any changes. It logs the changes and updates the endpoint numbers accordingly.
|
|
490
|
-
*
|
|
491
|
-
* @returns {Promise<number>} The size of the updated endpoint map, or -1 if storage is not available.
|
|
492
|
-
*/
|
|
493
261
|
async checkEndpointNumbers() {
|
|
494
262
|
if (!this.storage)
|
|
495
263
|
return -1;
|
|
@@ -530,4 +298,3 @@ export class MatterbridgePlatform {
|
|
|
530
298
|
return endpointMap.size;
|
|
531
299
|
}
|
|
532
300
|
}
|
|
533
|
-
//# sourceMappingURL=matterbridgePlatform.js.map
|
|
@@ -1,28 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the types for Matterbridge.
|
|
3
|
-
*
|
|
4
|
-
* @file matterbridgeTypes.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @created 2024-07-12
|
|
7
|
-
* @version 1.0.2
|
|
8
|
-
* @license Apache-2.0
|
|
9
|
-
*
|
|
10
|
-
* Copyright 2023, 2024, 2025 Luca Liguori.
|
|
11
|
-
*
|
|
12
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License.
|
|
14
|
-
* You may obtain a copy of the License at
|
|
15
|
-
*
|
|
16
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
-
* See the License for the specific language governing permissions and
|
|
22
|
-
* limitations under the License.
|
|
23
|
-
*/
|
|
24
|
-
// Default colors
|
|
25
1
|
export const plg = '\u001B[38;5;33m';
|
|
26
2
|
export const dev = '\u001B[38;5;79m';
|
|
27
3
|
export const typ = '\u001B[38;5;207m';
|
|
28
|
-
//# sourceMappingURL=matterbridgeTypes.js.map
|