matterbridge 3.2.3 → 3.2.4-dev-20250830-5c48452
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 +16 -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/cooktop.js +0 -55
- package/dist/devices/dishwasher.js +0 -57
- package/dist/devices/evse.js +10 -74
- package/dist/devices/export.js +0 -4
- package/dist/devices/extractorHood.js +0 -42
- package/dist/devices/heatPump.js +2 -50
- package/dist/devices/laundryDryer.js +3 -62
- package/dist/devices/laundryWasher.js +4 -70
- package/dist/devices/microwaveOven.js +5 -88
- package/dist/devices/oven.js +0 -85
- package/dist/devices/refrigerator.js +0 -80
- package/dist/devices/roboticVacuumCleaner.js +7 -93
- package/dist/devices/solarPower.js +0 -38
- package/dist/devices/temperatureControl.js +3 -25
- package/dist/devices/waterHeater.js +2 -82
- package/dist/dgram/coap.js +13 -126
- package/dist/dgram/dgram.js +2 -113
- package/dist/dgram/mb_coap.js +3 -41
- package/dist/dgram/mb_mdns.js +13 -51
- package/dist/dgram/mdns.js +137 -298
- package/dist/dgram/multicast.js +1 -60
- package/dist/dgram/unicast.js +0 -54
- package/dist/frontend.js +24 -451
- 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 +50 -789
- package/dist/matterbridgeAccessoryPlatform.js +0 -36
- package/dist/matterbridgeBehaviors.js +5 -65
- package/dist/matterbridgeDeviceTypes.js +15 -579
- package/dist/matterbridgeDynamicPlatform.js +0 -36
- package/dist/matterbridgeEndpoint.js +54 -1220
- package/dist/matterbridgeEndpointHelpers.js +12 -345
- package/dist/matterbridgePlatform.js +4 -250
- 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 -69
- package/dist/utils/colorUtils.js +2 -97
- 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 -124
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/network.js +5 -91
- package/dist/utils/spawn.js +0 -40
- package/dist/utils/wait.js +8 -60
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -2
- 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/cooktop.d.ts +0 -60
- package/dist/devices/cooktop.d.ts.map +0 -1
- package/dist/devices/cooktop.js.map +0 -1
- package/dist/devices/dishwasher.d.ts +0 -71
- package/dist/devices/dishwasher.d.ts.map +0 -1
- package/dist/devices/dishwasher.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 -15
- package/dist/devices/export.d.ts.map +0 -1
- package/dist/devices/export.js.map +0 -1
- package/dist/devices/extractorHood.d.ts +0 -46
- package/dist/devices/extractorHood.d.ts.map +0 -1
- package/dist/devices/extractorHood.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 -67
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -81
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.js.map +0 -1
- package/dist/devices/microwaveOven.d.ts +0 -168
- package/dist/devices/microwaveOven.d.ts.map +0 -1
- package/dist/devices/microwaveOven.js.map +0 -1
- package/dist/devices/oven.d.ts +0 -105
- package/dist/devices/oven.d.ts.map +0 -1
- package/dist/devices/oven.js.map +0 -1
- package/dist/devices/refrigerator.d.ts +0 -93
- package/dist/devices/refrigerator.d.ts.map +0 -1
- package/dist/devices/refrigerator.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/temperatureControl.d.ts +0 -166
- package/dist/devices/temperatureControl.d.ts.map +0 -1
- package/dist/devices/temperatureControl.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/dgram/coap.d.ts +0 -205
- package/dist/dgram/coap.d.ts.map +0 -1
- package/dist/dgram/coap.js.map +0 -1
- package/dist/dgram/dgram.d.ts +0 -140
- package/dist/dgram/dgram.d.ts.map +0 -1
- package/dist/dgram/dgram.js.map +0 -1
- package/dist/dgram/mb_coap.d.ts +0 -24
- package/dist/dgram/mb_coap.d.ts.map +0 -1
- package/dist/dgram/mb_coap.js.map +0 -1
- package/dist/dgram/mb_mdns.d.ts +0 -24
- package/dist/dgram/mb_mdns.d.ts.map +0 -1
- package/dist/dgram/mb_mdns.js.map +0 -1
- package/dist/dgram/mdns.d.ts +0 -288
- package/dist/dgram/mdns.d.ts.map +0 -1
- package/dist/dgram/mdns.js.map +0 -1
- package/dist/dgram/multicast.d.ts +0 -65
- package/dist/dgram/multicast.d.ts.map +0 -1
- package/dist/dgram/multicast.js.map +0 -1
- package/dist/dgram/unicast.d.ts +0 -56
- package/dist/dgram/unicast.d.ts.map +0 -1
- package/dist/dgram/unicast.js.map +0 -1
- package/dist/frontend.d.ts +0 -313
- 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 -462
- 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 -1351
- 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 -1356
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -407
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -324
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -198
- 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 -75
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -99
- 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 -89
- 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 -84
- 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 -54
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
|
@@ -1,85 +1,32 @@
|
|
|
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 modules
|
|
25
1
|
import path from 'node:path';
|
|
26
2
|
import { Descriptor } from '@matter/main/clusters/descriptor';
|
|
27
3
|
import { BridgedDeviceBasicInformation } from '@matter/main/clusters/bridged-device-basic-information';
|
|
28
|
-
// Node AnsiLogger module
|
|
29
4
|
import { CYAN, db, er, nf, wr } from 'node-ansi-logger';
|
|
30
|
-
// Node Storage module
|
|
31
5
|
import { NodeStorageManager } from 'node-persist-manager';
|
|
32
6
|
import { checkNotLatinCharacters } from './matterbridgeEndpointHelpers.js';
|
|
33
7
|
import { bridgedNode } from './matterbridgeDeviceTypes.js';
|
|
34
8
|
import { isValidArray, isValidObject, isValidString } from './utils/export.js';
|
|
35
|
-
/**
|
|
36
|
-
* Represents the base Matterbridge platform. It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
9
|
export class MatterbridgePlatform {
|
|
40
|
-
/** The Matterbridge instance of this Platform. */
|
|
41
10
|
matterbridge;
|
|
42
|
-
/** The logger instance for this platform. */
|
|
43
11
|
log;
|
|
44
|
-
/** The configuration for this platform. */
|
|
45
12
|
config = {};
|
|
46
|
-
/** The name of the platform. Will be set by the loadPlugin() method using the package.json value. */
|
|
47
13
|
name = '';
|
|
48
|
-
/** The type of the platform. Will be set by the extending classes. */
|
|
49
14
|
type = '';
|
|
50
|
-
/** The version of the platform. Will be set by the loadPlugin() method using the package.json value */
|
|
51
15
|
version = '1.0.0';
|
|
52
|
-
/** Platform node storage manager. */
|
|
53
16
|
storage;
|
|
54
|
-
/** Platform context storage. */
|
|
55
17
|
context;
|
|
56
|
-
// Device and entity select in the plugin config UI
|
|
57
18
|
selectDevice = new Map();
|
|
58
19
|
selectEntity = new Map();
|
|
59
|
-
// Promises for storage
|
|
60
20
|
_contextReady;
|
|
61
21
|
_selectDeviceContextReady;
|
|
62
22
|
_selectEntityContextReady;
|
|
63
|
-
/** The ready promise for the platform, which resolves when the platform is fully initialized. */
|
|
64
23
|
ready;
|
|
65
|
-
/** Registered MatterbridgeEndpoint Map by uniqueId */
|
|
66
24
|
_registeredEndpoints = new Map();
|
|
67
|
-
/** Registered MatterbridgeEndpoint Map by deviceName */
|
|
68
25
|
_registeredEndpointsByName = new Map();
|
|
69
|
-
/**
|
|
70
|
-
* Creates an instance of the base MatterbridgePlatform.
|
|
71
|
-
* It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
|
|
72
|
-
* Each plugin must extend the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
|
|
73
|
-
*
|
|
74
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance.
|
|
75
|
-
* @param {AnsiLogger} log - The logger instance.
|
|
76
|
-
* @param {PlatformConfig} config - The platform configuration.
|
|
77
|
-
*/
|
|
78
26
|
constructor(matterbridge, log, config) {
|
|
79
27
|
this.matterbridge = matterbridge;
|
|
80
28
|
this.log = log;
|
|
81
29
|
this.config = config;
|
|
82
|
-
// create the NodeStorageManager for the plugin platform
|
|
83
30
|
if (!isValidString(this.config.name, 1))
|
|
84
31
|
throw new Error('Platform: the plugin name is missing or invalid.');
|
|
85
32
|
this.log.debug(`Creating storage for plugin ${this.config.name} in ${path.join(this.matterbridge.matterbridgeDirectory, this.config.name)}`);
|
|
@@ -90,14 +37,12 @@ export class MatterbridgePlatform {
|
|
|
90
37
|
logging: false,
|
|
91
38
|
forgiveParseErrors: true,
|
|
92
39
|
});
|
|
93
|
-
// create the context storage for the plugin platform
|
|
94
40
|
this.log.debug(`Creating context for plugin ${this.config.name}`);
|
|
95
41
|
this._contextReady = this.storage.createStorage('context').then((context) => {
|
|
96
42
|
this.context = context;
|
|
97
43
|
this.log.debug(`Created context for plugin ${this.config.name}`);
|
|
98
44
|
return;
|
|
99
45
|
});
|
|
100
|
-
// create the selectDevice storage for the plugin platform
|
|
101
46
|
this.log.debug(`Loading selectDevice for plugin ${this.config.name}`);
|
|
102
47
|
this._selectDeviceContextReady = this.storage.createStorage('selectDevice').then(async (context) => {
|
|
103
48
|
const selectDevice = await context.get('selectDevice', []);
|
|
@@ -106,7 +51,6 @@ export class MatterbridgePlatform {
|
|
|
106
51
|
this.log.debug(`Loaded ${this.selectDevice.size} selectDevice for plugin ${this.config.name}`);
|
|
107
52
|
return;
|
|
108
53
|
});
|
|
109
|
-
// create the selectEntity storage for the plugin platform
|
|
110
54
|
this.log.debug(`Loading selectEntity for plugin ${this.config.name}`);
|
|
111
55
|
this._selectEntityContextReady = this.storage.createStorage('selectEntity').then(async (context) => {
|
|
112
56
|
const selectEntity = await context.get('selectEntity', []);
|
|
@@ -115,140 +59,47 @@ export class MatterbridgePlatform {
|
|
|
115
59
|
this.log.debug(`Loaded ${this.selectEntity.size} selectEntity for plugin ${this.config.name}`);
|
|
116
60
|
return;
|
|
117
61
|
});
|
|
118
|
-
// Create the `ready` promise for the platform
|
|
119
62
|
this.ready = Promise.all([this._contextReady, this._selectDeviceContextReady, this._selectEntityContextReady]).then(() => {
|
|
120
63
|
this.log.debug(`MatterbridgePlatform for plugin ${this.config.name} is fully initialized`);
|
|
121
64
|
return;
|
|
122
65
|
});
|
|
123
66
|
}
|
|
124
|
-
/**
|
|
125
|
-
* This method must be overridden in the extended class.
|
|
126
|
-
* It is called when the platform is started.
|
|
127
|
-
* Use this method to create the MatterbridgeEndpoints and call this.registerDevice().
|
|
128
|
-
*
|
|
129
|
-
* @param {string} [reason] - The reason for starting.
|
|
130
|
-
* @throws {Error} - Throws an error if the method is not overridden.
|
|
131
|
-
*/
|
|
132
67
|
async onStart(reason) {
|
|
133
68
|
this.log.error('Plugins must override onStart.', reason);
|
|
134
69
|
throw new Error('Plugins must override onStart.');
|
|
135
70
|
}
|
|
136
|
-
/**
|
|
137
|
-
* This method can be overridden in the extended class. In this case always call super.onConfigure() to save the select and run checkEndpointNumbers().
|
|
138
|
-
* It is called after the platform has started.
|
|
139
|
-
* 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
|
|
140
|
-
* matter storage (i.e. the onOff attribute of the OnOff cluster).
|
|
141
|
-
*/
|
|
142
71
|
async onConfigure() {
|
|
143
72
|
this.log.debug(`Configuring platform ${this.name}`);
|
|
144
|
-
// Save the selectDevice and selectEntity
|
|
145
73
|
await this.saveSelects();
|
|
146
|
-
// Check and update the endpoint numbers
|
|
147
74
|
await this.checkEndpointNumbers();
|
|
148
75
|
}
|
|
149
|
-
/**
|
|
150
|
-
* 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.
|
|
151
|
-
* It is called when the platform is shutting down.
|
|
152
|
-
* Use this method to clean up any resources you used in the constructor or onStart.
|
|
153
|
-
*
|
|
154
|
-
* @param {string} [reason] - The reason for shutting down.
|
|
155
|
-
*/
|
|
156
76
|
async onShutdown(reason) {
|
|
157
77
|
this.log.debug(`Shutting down platform ${this.name}`, reason);
|
|
158
|
-
// Save the selectDevice and selectEntity
|
|
159
78
|
await this.saveSelects();
|
|
160
|
-
// Check and update the endpoint numbers
|
|
161
79
|
await this.checkEndpointNumbers();
|
|
162
|
-
// Cleanup memory
|
|
163
80
|
this.selectDevice.clear();
|
|
164
81
|
this.selectEntity.clear();
|
|
165
82
|
this._registeredEndpoints.clear();
|
|
166
83
|
this._registeredEndpointsByName.clear();
|
|
167
|
-
// Close the storage
|
|
168
84
|
await this.context?.close();
|
|
169
85
|
this.context = undefined;
|
|
170
86
|
await this.storage?.close();
|
|
171
87
|
}
|
|
172
|
-
/**
|
|
173
|
-
* Called when the logger level is changed.
|
|
174
|
-
*
|
|
175
|
-
* @param {LogLevel} logLevel The new logger level.
|
|
176
|
-
*/
|
|
177
88
|
async onChangeLoggerLevel(logLevel) {
|
|
178
89
|
this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
|
|
179
90
|
}
|
|
180
|
-
/**
|
|
181
|
-
* Called when a plugin config includes an action button or an action button with text field.
|
|
182
|
-
*
|
|
183
|
-
* @param {string} action The action triggered by the button in plugin config.
|
|
184
|
-
* @param {string} value The value of the field of the action button.
|
|
185
|
-
* @param {string} id The id of the schema associated with the action.
|
|
186
|
-
* @param {PlatformConfig} formData The changed form data of the plugin.
|
|
187
|
-
*
|
|
188
|
-
* @remarks
|
|
189
|
-
* This method can be overridden in the extended class.
|
|
190
|
-
*
|
|
191
|
-
* Use this method to handle the action defined in the plugin schema:
|
|
192
|
-
* ```json
|
|
193
|
-
* "addDevice": {
|
|
194
|
-
* "description": "Manually add a device that has not been discovered with mdns:",
|
|
195
|
-
* "type": "boolean",
|
|
196
|
-
* "buttonText": "ADD", // The text on the button. This is used when the action doesn't include a text field.
|
|
197
|
-
* "buttonField": "ADD", // The text on the button. This is used when the action includes a text field.
|
|
198
|
-
* "buttonClose": false, // optional, default is false. When true, the dialog will close after the action is sent.
|
|
199
|
-
* "buttonSave": false, // optional, default is false. When true, the dialog will close and trigger the restart required after the action is sent.
|
|
200
|
-
* "textPlaceholder": "Enter the device IP address", // optional: the placeholder text for the text field.
|
|
201
|
-
* "default": false
|
|
202
|
-
* },
|
|
203
|
-
* ```
|
|
204
|
-
*/
|
|
205
91
|
async onAction(action, value, id, formData) {
|
|
206
92
|
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);
|
|
207
93
|
}
|
|
208
|
-
/**
|
|
209
|
-
* Called when the plugin config has been updated.
|
|
210
|
-
*
|
|
211
|
-
* @param {PlatformConfig} config The new plugin config.
|
|
212
|
-
*/
|
|
213
94
|
async onConfigChanged(config) {
|
|
214
95
|
this.log.debug(`The plugin ${CYAN}${config.name}${db} doesn't override onConfigChanged. Received new config.`);
|
|
215
96
|
}
|
|
216
|
-
/**
|
|
217
|
-
* Retrieves the devices registered with the platform.
|
|
218
|
-
*
|
|
219
|
-
* @returns {MatterbridgeEndpoint[]} The registered devices.
|
|
220
|
-
*/
|
|
221
97
|
getDevices() {
|
|
222
98
|
return Array.from(this._registeredEndpoints.values());
|
|
223
99
|
}
|
|
224
|
-
/**
|
|
225
|
-
* Checks if a device with this name is already registered in the platform.
|
|
226
|
-
*
|
|
227
|
-
* @param {string} deviceName - The device name to check.
|
|
228
|
-
* @returns {boolean} True if the device is already registered, false otherwise.
|
|
229
|
-
*/
|
|
230
100
|
hasDeviceName(deviceName) {
|
|
231
101
|
return this._registeredEndpointsByName.has(deviceName);
|
|
232
102
|
}
|
|
233
|
-
/**
|
|
234
|
-
* Registers a device with the Matterbridge platform and performs validation checks.
|
|
235
|
-
*
|
|
236
|
-
* This method also checks if the implementation called createDefaultBasicInformationClusterServer() instead of createDefaultBridgedDeviceBasicInformationClusterServer().
|
|
237
|
-
*
|
|
238
|
-
* This is correct with Accessory platforms so we check if we are running in bridge mode and add the bridgedNode and the BridgedDeviceBasicInformation cluster.
|
|
239
|
-
*
|
|
240
|
-
* If we are in bridge mode, we add the bridgedNode and the BridgedDeviceBasicInformation cluster.
|
|
241
|
-
*
|
|
242
|
-
* If we are in childbridge mode and the plugin is a 'DynamicPlatform', we add the bridgedNode and the BridgedDeviceBasicInformation cluster.
|
|
243
|
-
*
|
|
244
|
-
* if we are in childbridge mode and the plugin is a 'AccessoryPlatform', the device is not bridged.
|
|
245
|
-
*
|
|
246
|
-
* If the device.mode = 'server', the device is not bridged.
|
|
247
|
-
*
|
|
248
|
-
* If the device.mode = 'matter', the device is not bridged.
|
|
249
|
-
*
|
|
250
|
-
* @param {MatterbridgeEndpoint} device - The device to register.
|
|
251
|
-
*/
|
|
252
103
|
async registerDevice(device) {
|
|
253
104
|
device.plugin = this.name;
|
|
254
105
|
if (!device.uniqueId) {
|
|
@@ -270,9 +121,7 @@ export class MatterbridgePlatform {
|
|
|
270
121
|
if (checkNotLatinCharacters(device.deviceName)) {
|
|
271
122
|
this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has non latin characters.`);
|
|
272
123
|
}
|
|
273
|
-
// Validate bridgedNode and BridgedDeviceBasicInformation cluster
|
|
274
124
|
if (device.mode === undefined && (this.matterbridge.bridgeMode === 'bridge' || (this.matterbridge.bridgeMode === 'childbridge' && this.type === 'DynamicPlatform'))) {
|
|
275
|
-
// If the device is a bridged device, we add the bridgedNode to the deviceTypes map and to the Descriptor Cluster options
|
|
276
125
|
if (!device.deviceTypes.has(bridgedNode.code)) {
|
|
277
126
|
this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has no bridgedNode device type. Adding it...`);
|
|
278
127
|
device.deviceTypes.set(bridgedNode.code, bridgedNode);
|
|
@@ -284,7 +133,6 @@ export class MatterbridgePlatform {
|
|
|
284
133
|
}
|
|
285
134
|
}
|
|
286
135
|
}
|
|
287
|
-
// If the device is a bridged device, we add the BridgedDeviceBasicInformation cluster
|
|
288
136
|
if (!device.hasClusterServer(BridgedDeviceBasicInformation.Cluster.id)) {
|
|
289
137
|
this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has no BridgedDeviceBasicInformation cluster. Adding it...`);
|
|
290
138
|
device.createDefaultBridgedDeviceBasicInformationClusterServer(device.deviceName, device.serialNumber, device.vendorId, device.vendorName, device.productName, device.softwareVersion, device.softwareVersionString, device.hardwareVersion, device.hardwareVersionString);
|
|
@@ -294,11 +142,6 @@ export class MatterbridgePlatform {
|
|
|
294
142
|
this._registeredEndpoints.set(device.uniqueId, device);
|
|
295
143
|
this._registeredEndpointsByName.set(device.deviceName, device);
|
|
296
144
|
}
|
|
297
|
-
/**
|
|
298
|
-
* Unregisters a device registered with the Matterbridge platform.
|
|
299
|
-
*
|
|
300
|
-
* @param {MatterbridgeEndpoint} device - The device to unregister.
|
|
301
|
-
*/
|
|
302
145
|
async unregisterDevice(device) {
|
|
303
146
|
await this.matterbridge.removeBridgedEndpoint(this.name, device);
|
|
304
147
|
if (device.uniqueId)
|
|
@@ -306,24 +149,11 @@ export class MatterbridgePlatform {
|
|
|
306
149
|
if (device.deviceName)
|
|
307
150
|
this._registeredEndpointsByName.delete(device.deviceName);
|
|
308
151
|
}
|
|
309
|
-
/**
|
|
310
|
-
* Unregisters all devices registered with the Matterbridge platform.
|
|
311
|
-
*
|
|
312
|
-
* @param {number} [delay] - The delay in milliseconds between removing each bridged endpoint (default: 0).
|
|
313
|
-
*/
|
|
314
152
|
async unregisterAllDevices(delay = 0) {
|
|
315
153
|
await this.matterbridge.removeAllBridgedEndpoints(this.name, delay);
|
|
316
154
|
this._registeredEndpoints.clear();
|
|
317
155
|
this._registeredEndpointsByName.clear();
|
|
318
156
|
}
|
|
319
|
-
/**
|
|
320
|
-
* Saves the select devices and entities to storage.
|
|
321
|
-
*
|
|
322
|
-
* This method saves the current state of `selectDevice` and `selectEntity` maps to their respective storage.
|
|
323
|
-
* It logs the number of items being saved and ensures that the storage is properly closed after saving.
|
|
324
|
-
*
|
|
325
|
-
* @returns {Promise<void>} A promise that resolves when the save operation is complete.
|
|
326
|
-
*/
|
|
327
157
|
async saveSelects() {
|
|
328
158
|
if (this.storage) {
|
|
329
159
|
this.log.debug(`Saving ${this.selectDevice.size} selectDevice...`);
|
|
@@ -336,36 +166,19 @@ export class MatterbridgePlatform {
|
|
|
336
166
|
await selectEntity.close();
|
|
337
167
|
}
|
|
338
168
|
}
|
|
339
|
-
/**
|
|
340
|
-
* Clears all the select device and entity maps.
|
|
341
|
-
*
|
|
342
|
-
* @returns {void}
|
|
343
|
-
*/
|
|
344
169
|
async clearSelect() {
|
|
345
170
|
this.selectDevice.clear();
|
|
346
171
|
this.selectEntity.clear();
|
|
347
172
|
await this.saveSelects();
|
|
348
173
|
}
|
|
349
|
-
/**
|
|
350
|
-
* Clears the select for a single device.
|
|
351
|
-
*
|
|
352
|
-
* @param {string} serial - The serial of the device to clear.
|
|
353
|
-
* @returns {void}
|
|
354
|
-
*/
|
|
355
174
|
async clearDeviceSelect(serial) {
|
|
356
175
|
this.selectDevice.delete(serial);
|
|
357
176
|
await this.saveSelects();
|
|
358
177
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
* @param {string} name - The name of the device.
|
|
364
|
-
* @param {string} [configUrl] - The configuration URL of the device.
|
|
365
|
-
* @param {string} [icon] - The icon of the device: 'wifi', 'ble', 'hub'
|
|
366
|
-
* @param {Array<{ name: string; description: string; icon?: string }>} [entities] - The entities associated with the device.
|
|
367
|
-
* @returns {void}
|
|
368
|
-
*/
|
|
178
|
+
async clearEntitySelect(name) {
|
|
179
|
+
this.selectEntity.delete(name);
|
|
180
|
+
await this.saveSelects();
|
|
181
|
+
}
|
|
369
182
|
setSelectDevice(serial, name, configUrl, icon, entities) {
|
|
370
183
|
const device = this.selectDevice.get(serial);
|
|
371
184
|
if (device) {
|
|
@@ -382,15 +195,6 @@ export class MatterbridgePlatform {
|
|
|
382
195
|
this.selectDevice.set(serial, { serial, name, configUrl, icon, entities });
|
|
383
196
|
}
|
|
384
197
|
}
|
|
385
|
-
/**
|
|
386
|
-
* Set the select device entity in the platform map.
|
|
387
|
-
*
|
|
388
|
-
* @param {string} serial - The serial number of the device.
|
|
389
|
-
* @param {string} entityName - The name of the entity.
|
|
390
|
-
* @param {string} entityDescription - The description of the entity.
|
|
391
|
-
* @param {string} [entityIcon] - The icon of the entity: 'wifi', 'ble', 'hub', 'component', 'matter'
|
|
392
|
-
* @returns {void}
|
|
393
|
-
*/
|
|
394
198
|
setSelectDeviceEntity(serial, entityName, entityDescription, entityIcon) {
|
|
395
199
|
const device = this.selectDevice.get(serial);
|
|
396
200
|
if (device) {
|
|
@@ -400,11 +204,6 @@ export class MatterbridgePlatform {
|
|
|
400
204
|
device.entities.push({ name: entityName, description: entityDescription, icon: entityIcon });
|
|
401
205
|
}
|
|
402
206
|
}
|
|
403
|
-
/**
|
|
404
|
-
* Retrieves the select devices from the platform map.
|
|
405
|
-
*
|
|
406
|
-
* @returns {{ pluginName: string; serial: string; name: string; configUrl?: string; icon?: string; entities?: { name: string; description: string; icon?: string }[] }[]} The selected devices array.
|
|
407
|
-
*/
|
|
408
207
|
getSelectDevices() {
|
|
409
208
|
const selectDevices = [];
|
|
410
209
|
for (const device of this.selectDevice.values()) {
|
|
@@ -412,22 +211,9 @@ export class MatterbridgePlatform {
|
|
|
412
211
|
}
|
|
413
212
|
return selectDevices;
|
|
414
213
|
}
|
|
415
|
-
/**
|
|
416
|
-
* Set the select entity in the platform map.
|
|
417
|
-
*
|
|
418
|
-
* @param {string} name - The entity name.
|
|
419
|
-
* @param {string} description - The entity description.
|
|
420
|
-
* @param {string} [icon] - The entity icon: 'wifi', 'ble', 'hub', 'component', 'matter'
|
|
421
|
-
* @returns {void}
|
|
422
|
-
*/
|
|
423
214
|
setSelectEntity(name, description, icon) {
|
|
424
215
|
this.selectEntity.set(name, { name, description, icon });
|
|
425
216
|
}
|
|
426
|
-
/**
|
|
427
|
-
* Retrieve the select entities.
|
|
428
|
-
*
|
|
429
|
-
* @returns {{ pluginName: string; name: string; description: string; icon?: string }[]} The select entities array.
|
|
430
|
-
*/
|
|
431
217
|
getSelectEntities() {
|
|
432
218
|
const selectEntities = [];
|
|
433
219
|
for (const entity of this.selectEntity.values()) {
|
|
@@ -435,12 +221,6 @@ export class MatterbridgePlatform {
|
|
|
435
221
|
}
|
|
436
222
|
return selectEntities;
|
|
437
223
|
}
|
|
438
|
-
/**
|
|
439
|
-
* Verifies if the Matterbridge version meets the required version.
|
|
440
|
-
*
|
|
441
|
-
* @param {string} requiredVersion - The required version to compare against.
|
|
442
|
-
* @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
|
|
443
|
-
*/
|
|
444
224
|
verifyMatterbridgeVersion(requiredVersion) {
|
|
445
225
|
const compareVersions = (matterbridgeVersion, requiredVersion) => {
|
|
446
226
|
const stripTag = (v) => {
|
|
@@ -465,14 +245,6 @@ export class MatterbridgePlatform {
|
|
|
465
245
|
return false;
|
|
466
246
|
return true;
|
|
467
247
|
}
|
|
468
|
-
/**
|
|
469
|
-
* Validates if a device is allowed based on the whitelist and blacklist configurations.
|
|
470
|
-
* The blacklist has priority over the whitelist.
|
|
471
|
-
*
|
|
472
|
-
* @param {string | string[]} device - The device name(s) to validate.
|
|
473
|
-
* @param {boolean} [log] - Whether to log the validation result.
|
|
474
|
-
* @returns {boolean} - Returns true if the device is allowed, false otherwise.
|
|
475
|
-
*/
|
|
476
248
|
validateDevice(device, log = true) {
|
|
477
249
|
if (!Array.isArray(device))
|
|
478
250
|
device = [device];
|
|
@@ -502,14 +274,6 @@ export class MatterbridgePlatform {
|
|
|
502
274
|
this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
|
|
503
275
|
return false;
|
|
504
276
|
}
|
|
505
|
-
/**
|
|
506
|
-
* Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
|
|
507
|
-
*
|
|
508
|
-
* @param {string} device - The device to which the entity belongs.
|
|
509
|
-
* @param {string} entity - The entity to validate.
|
|
510
|
-
* @param {boolean} [log] - Whether to log the validation result.
|
|
511
|
-
* @returns {boolean} - Returns true if the entity is allowed, false otherwise.
|
|
512
|
-
*/
|
|
513
277
|
validateEntity(device, entity, log = true) {
|
|
514
278
|
if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
|
|
515
279
|
if (log)
|
|
@@ -528,15 +292,6 @@ export class MatterbridgePlatform {
|
|
|
528
292
|
}
|
|
529
293
|
return true;
|
|
530
294
|
}
|
|
531
|
-
/**
|
|
532
|
-
* Checks and updates the endpoint numbers for Matterbridge devices.
|
|
533
|
-
*
|
|
534
|
-
* This method retrieves the list of Matterbridge devices and their child endpoints,
|
|
535
|
-
* compares their current endpoint numbers with the stored ones, and updates the storage
|
|
536
|
-
* if there are any changes. It logs the changes and updates the endpoint numbers accordingly.
|
|
537
|
-
*
|
|
538
|
-
* @returns {Promise<number>} The size of the updated endpoint map, or -1 if storage is not available.
|
|
539
|
-
*/
|
|
540
295
|
async checkEndpointNumbers() {
|
|
541
296
|
if (!this.storage)
|
|
542
297
|
return -1;
|
|
@@ -577,4 +332,3 @@ export class MatterbridgePlatform {
|
|
|
577
332
|
return endpointMap.size;
|
|
578
333
|
}
|
|
579
334
|
}
|
|
580
|
-
//# 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
|