matterbridge 3.4.1-dev-20251130-422c2fc → 3.4.1
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 +10 -9
- package/README-SERVICE-OPT.md +1 -0
- package/dist/broadcastServer.d.ts +136 -0
- package/dist/broadcastServer.d.ts.map +1 -0
- package/dist/broadcastServer.js +112 -0
- package/dist/broadcastServer.js.map +1 -0
- package/dist/broadcastServerTypes.d.ts +841 -0
- package/dist/broadcastServerTypes.d.ts.map +1 -0
- package/dist/broadcastServerTypes.js +24 -0
- package/dist/broadcastServerTypes.js.map +1 -0
- package/dist/cli.d.ts +30 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +97 -1
- package/dist/cli.js.map +1 -0
- package/dist/cliEmitter.d.ts +50 -0
- package/dist/cliEmitter.d.ts.map +1 -0
- package/dist/cliEmitter.js +37 -0
- package/dist/cliEmitter.js.map +1 -0
- package/dist/cliHistory.d.ts +48 -0
- package/dist/cliHistory.d.ts.map +1 -0
- package/dist/cliHistory.js +38 -0
- package/dist/cliHistory.js.map +1 -0
- package/dist/clusters/export.d.ts +2 -0
- package/dist/clusters/export.d.ts.map +1 -0
- package/dist/clusters/export.js +2 -0
- package/dist/clusters/export.js.map +1 -0
- package/dist/deviceManager.d.ts +135 -0
- package/dist/deviceManager.d.ts.map +1 -0
- package/dist/deviceManager.js +113 -1
- package/dist/deviceManager.js.map +1 -0
- package/dist/devices/airConditioner.d.ts +98 -0
- package/dist/devices/airConditioner.d.ts.map +1 -0
- package/dist/devices/airConditioner.js +57 -0
- package/dist/devices/airConditioner.js.map +1 -0
- package/dist/devices/batteryStorage.d.ts +48 -0
- package/dist/devices/batteryStorage.d.ts.map +1 -0
- package/dist/devices/batteryStorage.js +48 -1
- package/dist/devices/batteryStorage.js.map +1 -0
- package/dist/devices/cooktop.d.ts +61 -0
- package/dist/devices/cooktop.d.ts.map +1 -0
- package/dist/devices/cooktop.js +56 -0
- package/dist/devices/cooktop.js.map +1 -0
- package/dist/devices/dishwasher.d.ts +71 -0
- package/dist/devices/dishwasher.d.ts.map +1 -0
- package/dist/devices/dishwasher.js +57 -0
- package/dist/devices/dishwasher.js.map +1 -0
- package/dist/devices/evse.d.ts +76 -0
- package/dist/devices/evse.d.ts.map +1 -0
- package/dist/devices/evse.js +74 -10
- package/dist/devices/evse.js.map +1 -0
- package/dist/devices/export.d.ts +17 -0
- package/dist/devices/export.d.ts.map +1 -0
- package/dist/devices/export.js +5 -0
- package/dist/devices/export.js.map +1 -0
- package/dist/devices/extractorHood.d.ts +46 -0
- package/dist/devices/extractorHood.d.ts.map +1 -0
- package/dist/devices/extractorHood.js +43 -0
- package/dist/devices/extractorHood.js.map +1 -0
- package/dist/devices/heatPump.d.ts +47 -0
- package/dist/devices/heatPump.d.ts.map +1 -0
- package/dist/devices/heatPump.js +50 -2
- package/dist/devices/heatPump.js.map +1 -0
- package/dist/devices/laundryDryer.d.ts +67 -0
- package/dist/devices/laundryDryer.d.ts.map +1 -0
- package/dist/devices/laundryDryer.js +62 -3
- package/dist/devices/laundryDryer.js.map +1 -0
- package/dist/devices/laundryWasher.d.ts +81 -0
- package/dist/devices/laundryWasher.d.ts.map +1 -0
- package/dist/devices/laundryWasher.js +70 -4
- package/dist/devices/laundryWasher.js.map +1 -0
- package/dist/devices/microwaveOven.d.ts +168 -0
- package/dist/devices/microwaveOven.d.ts.map +1 -0
- package/dist/devices/microwaveOven.js +88 -5
- package/dist/devices/microwaveOven.js.map +1 -0
- package/dist/devices/oven.d.ts +105 -0
- package/dist/devices/oven.d.ts.map +1 -0
- package/dist/devices/oven.js +85 -0
- package/dist/devices/oven.js.map +1 -0
- package/dist/devices/refrigerator.d.ts +118 -0
- package/dist/devices/refrigerator.d.ts.map +1 -0
- package/dist/devices/refrigerator.js +102 -0
- package/dist/devices/refrigerator.js.map +1 -0
- package/dist/devices/roboticVacuumCleaner.d.ts +112 -0
- package/dist/devices/roboticVacuumCleaner.d.ts.map +1 -0
- package/dist/devices/roboticVacuumCleaner.js +100 -9
- package/dist/devices/roboticVacuumCleaner.js.map +1 -0
- package/dist/devices/solarPower.d.ts +40 -0
- package/dist/devices/solarPower.d.ts.map +1 -0
- package/dist/devices/solarPower.js +38 -0
- package/dist/devices/solarPower.js.map +1 -0
- package/dist/devices/speaker.d.ts +87 -0
- package/dist/devices/speaker.d.ts.map +1 -0
- package/dist/devices/speaker.js +84 -0
- package/dist/devices/speaker.js.map +1 -0
- package/dist/devices/temperatureControl.d.ts +166 -0
- package/dist/devices/temperatureControl.d.ts.map +1 -0
- package/dist/devices/temperatureControl.js +24 -3
- package/dist/devices/temperatureControl.js.map +1 -0
- package/dist/devices/waterHeater.d.ts +111 -0
- package/dist/devices/waterHeater.d.ts.map +1 -0
- package/dist/devices/waterHeater.js +82 -2
- package/dist/devices/waterHeater.js.map +1 -0
- package/dist/dgram/coap.d.ts +205 -0
- package/dist/dgram/coap.d.ts.map +1 -0
- package/dist/dgram/coap.js +126 -13
- package/dist/dgram/coap.js.map +1 -0
- package/dist/dgram/dgram.d.ts +141 -0
- package/dist/dgram/dgram.d.ts.map +1 -0
- package/dist/dgram/dgram.js +114 -2
- package/dist/dgram/dgram.js.map +1 -0
- package/dist/dgram/mb_coap.d.ts +24 -0
- package/dist/dgram/mb_coap.d.ts.map +1 -0
- package/dist/dgram/mb_coap.js +41 -3
- package/dist/dgram/mb_coap.js.map +1 -0
- package/dist/dgram/mb_mdns.d.ts +24 -0
- package/dist/dgram/mb_mdns.d.ts.map +1 -0
- package/dist/dgram/mb_mdns.js +80 -15
- package/dist/dgram/mb_mdns.js.map +1 -0
- package/dist/dgram/mdns.d.ts +290 -0
- package/dist/dgram/mdns.d.ts.map +1 -0
- package/dist/dgram/mdns.js +299 -137
- package/dist/dgram/mdns.js.map +1 -0
- package/dist/dgram/multicast.d.ts +67 -0
- package/dist/dgram/multicast.d.ts.map +1 -0
- package/dist/dgram/multicast.js +62 -1
- package/dist/dgram/multicast.js.map +1 -0
- package/dist/dgram/unicast.d.ts +56 -0
- package/dist/dgram/unicast.d.ts.map +1 -0
- package/dist/dgram/unicast.js +54 -0
- package/dist/dgram/unicast.js.map +1 -0
- package/dist/frontend.d.ts +238 -0
- package/dist/frontend.d.ts.map +1 -0
- package/dist/frontend.js +455 -35
- package/dist/frontend.js.map +1 -0
- package/dist/frontendTypes.d.ts +529 -0
- package/dist/frontendTypes.d.ts.map +1 -0
- package/dist/frontendTypes.js +45 -0
- package/dist/frontendTypes.js.map +1 -0
- package/dist/helpers.d.ts +48 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +53 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/jestutils/export.d.ts +2 -0
- package/dist/jestutils/export.d.ts.map +1 -0
- package/dist/jestutils/export.js +1 -0
- package/dist/jestutils/export.js.map +1 -0
- package/dist/jestutils/jestHelpers.d.ts +340 -0
- package/dist/jestutils/jestHelpers.d.ts.map +1 -0
- package/dist/jestutils/jestHelpers.js +375 -14
- package/dist/jestutils/jestHelpers.js.map +1 -0
- package/dist/logger/export.d.ts +2 -0
- package/dist/logger/export.d.ts.map +1 -0
- package/dist/logger/export.js +1 -0
- package/dist/logger/export.js.map +1 -0
- package/dist/matter/behaviors.d.ts +2 -0
- package/dist/matter/behaviors.d.ts.map +1 -0
- package/dist/matter/behaviors.js +2 -0
- package/dist/matter/behaviors.js.map +1 -0
- package/dist/matter/clusters.d.ts +2 -0
- package/dist/matter/clusters.d.ts.map +1 -0
- package/dist/matter/clusters.js +2 -0
- package/dist/matter/clusters.js.map +1 -0
- package/dist/matter/devices.d.ts +2 -0
- package/dist/matter/devices.d.ts.map +1 -0
- package/dist/matter/devices.js +2 -0
- package/dist/matter/devices.js.map +1 -0
- package/dist/matter/endpoints.d.ts +2 -0
- package/dist/matter/endpoints.d.ts.map +1 -0
- package/dist/matter/endpoints.js +2 -0
- package/dist/matter/endpoints.js.map +1 -0
- package/dist/matter/export.d.ts +5 -0
- package/dist/matter/export.d.ts.map +1 -0
- package/dist/matter/export.js +3 -0
- package/dist/matter/export.js.map +1 -0
- package/dist/matter/types.d.ts +3 -0
- package/dist/matter/types.d.ts.map +1 -0
- package/dist/matter/types.js +3 -0
- package/dist/matter/types.js.map +1 -0
- package/dist/matterNode.d.ts +342 -0
- package/dist/matterNode.d.ts.map +1 -0
- package/dist/matterNode.js +369 -8
- package/dist/matterNode.js.map +1 -0
- package/dist/matterbridge.d.ts +493 -0
- package/dist/matterbridge.d.ts.map +1 -0
- package/dist/matterbridge.js +808 -46
- package/dist/matterbridge.js.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts +41 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.js +38 -0
- package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
- package/dist/matterbridgeBehaviors.d.ts +2404 -0
- package/dist/matterbridgeBehaviors.d.ts.map +1 -0
- package/dist/matterbridgeBehaviors.js +68 -5
- package/dist/matterbridgeBehaviors.js.map +1 -0
- package/dist/matterbridgeDeviceTypes.d.ts +698 -0
- package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
- package/dist/matterbridgeDeviceTypes.js +635 -14
- package/dist/matterbridgeDeviceTypes.js.map +1 -0
- package/dist/matterbridgeDynamicPlatform.d.ts +41 -0
- package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
- package/dist/matterbridgeDynamicPlatform.js +38 -0
- package/dist/matterbridgeDynamicPlatform.js.map +1 -0
- package/dist/matterbridgeEndpoint.d.ts +1507 -0
- package/dist/matterbridgeEndpoint.d.ts.map +1 -0
- package/dist/matterbridgeEndpoint.js +1444 -53
- package/dist/matterbridgeEndpoint.js.map +1 -0
- package/dist/matterbridgeEndpointHelpers.d.ts +787 -0
- package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
- package/dist/matterbridgeEndpointHelpers.js +483 -20
- package/dist/matterbridgeEndpointHelpers.js.map +1 -0
- package/dist/matterbridgeEndpointTypes.d.ts +166 -0
- package/dist/matterbridgeEndpointTypes.d.ts.map +1 -0
- package/dist/matterbridgeEndpointTypes.js +25 -0
- package/dist/matterbridgeEndpointTypes.js.map +1 -0
- package/dist/matterbridgePlatform.d.ts +537 -0
- package/dist/matterbridgePlatform.d.ts.map +1 -0
- package/dist/matterbridgePlatform.js +471 -8
- package/dist/matterbridgePlatform.js.map +1 -0
- package/dist/matterbridgeTypes.d.ts +251 -0
- package/dist/matterbridgeTypes.d.ts.map +1 -0
- package/dist/matterbridgeTypes.js +26 -0
- package/dist/matterbridgeTypes.js.map +1 -0
- package/dist/pluginManager.d.ts +372 -0
- package/dist/pluginManager.d.ts.map +1 -0
- package/dist/pluginManager.js +342 -5
- package/dist/pluginManager.js.map +1 -0
- package/dist/shelly.d.ts +181 -0
- package/dist/shelly.d.ts.map +1 -0
- package/dist/shelly.js +178 -7
- package/dist/shelly.js.map +1 -0
- package/dist/storage/export.d.ts +2 -0
- package/dist/storage/export.d.ts.map +1 -0
- package/dist/storage/export.js +1 -0
- package/dist/storage/export.js.map +1 -0
- package/dist/update.d.ts +84 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +93 -1
- package/dist/update.js.map +1 -0
- package/dist/utils/colorUtils.d.ts +101 -0
- package/dist/utils/colorUtils.d.ts.map +1 -0
- package/dist/utils/colorUtils.js +97 -2
- package/dist/utils/colorUtils.js.map +1 -0
- package/dist/utils/commandLine.d.ts +66 -0
- package/dist/utils/commandLine.d.ts.map +1 -0
- package/dist/utils/commandLine.js +60 -0
- package/dist/utils/commandLine.js.map +1 -0
- package/dist/utils/copyDirectory.d.ts +35 -0
- package/dist/utils/copyDirectory.d.ts.map +1 -0
- package/dist/utils/copyDirectory.js +37 -0
- package/dist/utils/copyDirectory.js.map +1 -0
- package/dist/utils/createDirectory.d.ts +34 -0
- package/dist/utils/createDirectory.d.ts.map +1 -0
- package/dist/utils/createDirectory.js +33 -0
- package/dist/utils/createDirectory.js.map +1 -0
- package/dist/utils/createZip.d.ts +39 -0
- package/dist/utils/createZip.d.ts.map +1 -0
- package/dist/utils/createZip.js +47 -2
- package/dist/utils/createZip.js.map +1 -0
- package/dist/utils/deepCopy.d.ts +32 -0
- package/dist/utils/deepCopy.d.ts.map +1 -0
- package/dist/utils/deepCopy.js +39 -0
- package/dist/utils/deepCopy.js.map +1 -0
- package/dist/utils/deepEqual.d.ts +54 -0
- package/dist/utils/deepEqual.d.ts.map +1 -0
- package/dist/utils/deepEqual.js +72 -1
- package/dist/utils/deepEqual.js.map +1 -0
- package/dist/utils/error.d.ts +45 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +42 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/export.d.ts +13 -0
- package/dist/utils/export.d.ts.map +1 -0
- package/dist/utils/export.js +1 -0
- package/dist/utils/export.js.map +1 -0
- package/dist/utils/format.d.ts +53 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +49 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/hex.d.ts +89 -0
- package/dist/utils/hex.d.ts.map +1 -0
- package/dist/utils/hex.js +124 -0
- package/dist/utils/hex.js.map +1 -0
- package/dist/utils/inspector.d.ts +87 -0
- package/dist/utils/inspector.d.ts.map +1 -0
- package/dist/utils/inspector.js +69 -1
- package/dist/utils/inspector.js.map +1 -0
- package/dist/utils/isvalid.d.ts +103 -0
- package/dist/utils/isvalid.d.ts.map +1 -0
- package/dist/utils/isvalid.js +101 -0
- package/dist/utils/isvalid.js.map +1 -0
- package/dist/utils/network.d.ts +111 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/network.js +96 -5
- package/dist/utils/network.js.map +1 -0
- package/dist/utils/spawn.d.ts +33 -0
- package/dist/utils/spawn.d.ts.map +1 -0
- package/dist/utils/spawn.js +71 -1
- package/dist/utils/spawn.js.map +1 -0
- package/dist/utils/tracker.d.ts +108 -0
- package/dist/utils/tracker.d.ts.map +1 -0
- package/dist/utils/tracker.js +64 -1
- package/dist/utils/tracker.js.map +1 -0
- package/dist/utils/wait.d.ts +54 -0
- package/dist/utils/wait.d.ts.map +1 -0
- package/dist/utils/wait.js +60 -8
- package/dist/utils/wait.js.map +1 -0
- package/dist/workerGlobalPrefix.d.ts +25 -0
- package/dist/workerGlobalPrefix.d.ts.map +1 -0
- package/dist/workerGlobalPrefix.js +37 -5
- package/dist/workerGlobalPrefix.js.map +1 -0
- package/dist/workerTypes.d.ts +52 -0
- package/dist/workerTypes.d.ts.map +1 -0
- package/dist/workerTypes.js +24 -0
- package/dist/workerTypes.js.map +1 -0
- package/dist/workers.d.ts +69 -0
- package/dist/workers.d.ts.map +1 -0
- package/dist/workers.js +68 -4
- package/dist/workers.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
|
@@ -1,7 +1,34 @@
|
|
|
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.6.0
|
|
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
|
+
// eslint-disable-next-line no-console
|
|
1
25
|
if (process.argv.includes('--loader') || process.argv.includes('-loader'))
|
|
2
26
|
console.log('\u001B[32mMatterbridgePlatform loaded.\u001B[40;0m');
|
|
27
|
+
// Node.js modules
|
|
3
28
|
import path from 'node:path';
|
|
29
|
+
// Node AnsiLogger module
|
|
4
30
|
import { CYAN, db, er, nf, wr } from 'node-ansi-logger';
|
|
31
|
+
// Node Storage module
|
|
5
32
|
import { NodeStorageManager } from 'node-persist-manager';
|
|
6
33
|
import { Descriptor } from '@matter/types/clusters/descriptor';
|
|
7
34
|
import { BridgedDeviceBasicInformation } from '@matter/types/clusters/bridged-device-basic-information';
|
|
@@ -10,29 +37,82 @@ import { bridgedNode } from './matterbridgeDeviceTypes.js';
|
|
|
10
37
|
import { isValidArray, isValidObject, isValidString } from './utils/isvalid.js';
|
|
11
38
|
import { hasParameter } from './utils/commandLine.js';
|
|
12
39
|
import { BroadcastServer } from './broadcastServer.js';
|
|
40
|
+
/**
|
|
41
|
+
* Represents the base Matterbridge platform. It is extended by the MatterbridgeAccessoryPlatform and MatterbridgeServicePlatform classes.
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
13
44
|
export class MatterbridgePlatform {
|
|
45
|
+
/** The PlatformMatterbridge instance of this Platform. */
|
|
14
46
|
matterbridge;
|
|
47
|
+
/** The logger instance for this platform. Created by the PluginManager.load() method. */
|
|
15
48
|
log;
|
|
49
|
+
/** The configuration for this platform. Set by the PluginManager.load() method using the stored config file. */
|
|
16
50
|
config;
|
|
51
|
+
/** The name of the platform. Set by the PluginManager.load() method using the package.json name value. */
|
|
17
52
|
name = '';
|
|
53
|
+
/** The type of the platform. Set by the extending classes: MatterbridgeDynamicPlatform and MatterbridgeAccessoryPlatform */
|
|
18
54
|
type = 'AnyPlatform';
|
|
55
|
+
/** The version of the platform. Set by the PluginManager.load() method using the package.json version value. */
|
|
19
56
|
version = '1.0.0';
|
|
57
|
+
/** Platform node storage manager created in the matterbridgeDirectory with the plugin name. */
|
|
20
58
|
#storage;
|
|
59
|
+
/** Platform context in the storage of matterbridgeDirectory. Use await platform.ready to access it early. */
|
|
21
60
|
context;
|
|
61
|
+
/** Indicates whether the platform is is fully initialized (including context and selects). */
|
|
22
62
|
isReady = false;
|
|
63
|
+
/** Indicates whether the platform has been loaded. */
|
|
23
64
|
isLoaded = false;
|
|
65
|
+
/** Indicates whether the platform has been started. */
|
|
24
66
|
isStarted = false;
|
|
67
|
+
/** Indicates whether the platform has been configured. */
|
|
25
68
|
isConfigured = false;
|
|
69
|
+
// Device and entity select in the plugin config UI
|
|
26
70
|
#selectDevices = new Map();
|
|
27
71
|
#selectEntities = new Map();
|
|
72
|
+
// Promises for platform initialization. They are grouped in MatterbridgePlatform.ready with Promise.all.
|
|
28
73
|
#contextReady;
|
|
29
74
|
#selectDeviceContextReady;
|
|
30
75
|
#selectEntityContextReady;
|
|
76
|
+
/** The ready promise for the platform, which resolves when the platform is fully initialized (including context and selects). Await platform.ready if you access the platform context or select early. */
|
|
31
77
|
ready;
|
|
78
|
+
/** Registered MatterbridgeEndpoint map keyed by uniqueId */
|
|
32
79
|
#registeredEndpoints = new Map();
|
|
80
|
+
/** Broadcast server */
|
|
33
81
|
#server;
|
|
34
82
|
#debug = hasParameter('debug') || hasParameter('verbose');
|
|
35
83
|
#verbose = hasParameter('verbose');
|
|
84
|
+
/** MatterNode helper injected by the PluginManager.load() method */
|
|
85
|
+
#addBridgedEndpoint;
|
|
86
|
+
/** MatterNode helper injected by the PluginManager.load() method */
|
|
87
|
+
#removeBridgedEndpoint;
|
|
88
|
+
/** MatterNode helper injected by the PluginManager.load() method */
|
|
89
|
+
#removeAllBridgedEndpoints;
|
|
90
|
+
/** MatterNode helper injected by the PluginManager.load() method */
|
|
91
|
+
#addVirtualEndpoint;
|
|
92
|
+
/**
|
|
93
|
+
* MatterNode helpers injected by the PluginManager.load() method
|
|
94
|
+
*
|
|
95
|
+
* @param {(pluginName: string, device: MatterbridgeEndpoint) => Promise<void>} addBridgedEndpoint - Function to add a bridged endpoint.
|
|
96
|
+
* @param {(pluginName: string, device: MatterbridgeEndpoint) => Promise<void>} removeBridgedEndpoint - Function to remove a bridged endpoint.
|
|
97
|
+
* @param {(pluginName: string, delay?: number) => Promise<void>} removeAllBridgedEndpoints - Function to remove all bridged endpoints.
|
|
98
|
+
* @param {(pluginName: string, name: string, type: 'light' | 'outlet' | 'switch' | 'mounted_switch', callback: () => Promise<void>) => Promise<boolean>} addVirtualEndpoint - Function to add a virtual endpoint.
|
|
99
|
+
*/
|
|
100
|
+
setMatterNode = (addBridgedEndpoint, removeBridgedEndpoint, removeAllBridgedEndpoints, addVirtualEndpoint) => {
|
|
101
|
+
this.#addBridgedEndpoint = addBridgedEndpoint;
|
|
102
|
+
this.#removeBridgedEndpoint = removeBridgedEndpoint;
|
|
103
|
+
this.#removeAllBridgedEndpoints = removeAllBridgedEndpoints;
|
|
104
|
+
this.#addVirtualEndpoint = addVirtualEndpoint;
|
|
105
|
+
this.setMatterNode = undefined;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Creates an instance of the base MatterbridgePlatform.
|
|
109
|
+
* Each plugin must extend the MatterbridgeDynamicPlatform or MatterbridgeAccessoryPlatform class.
|
|
110
|
+
* MatterbridgePlatform cannot be instantiated directly, it can only be extended by the MatterbridgeDynamicPlatform or MatterbridgeAccessoryPlatform class.
|
|
111
|
+
*
|
|
112
|
+
* @param {PlatformMatterbridge} matterbridge - The PlatformMatterbridge instance.
|
|
113
|
+
* @param {AnsiLogger} log - The logger instance.
|
|
114
|
+
* @param {PlatformConfig} config - The platform configuration.
|
|
115
|
+
*/
|
|
36
116
|
constructor(matterbridge, log, config) {
|
|
37
117
|
this.matterbridge = matterbridge;
|
|
38
118
|
this.log = log;
|
|
@@ -42,6 +122,7 @@ export class MatterbridgePlatform {
|
|
|
42
122
|
this.log.debug(`Creating MatterbridgePlatform for plugin ${this.config.name}`);
|
|
43
123
|
if (this.#verbose)
|
|
44
124
|
this.log.debug(`Creating MatterbridgePlatform for plugin ${this.config.name} with config:\n${JSON.stringify(this.config, null, 2)}\n`);
|
|
125
|
+
// create the NodeStorageManager for the plugin platform
|
|
45
126
|
if (!isValidString(this.config.name, 1)) {
|
|
46
127
|
this.#server.close();
|
|
47
128
|
throw new Error('Platform: the plugin name is missing or invalid.');
|
|
@@ -54,12 +135,14 @@ export class MatterbridgePlatform {
|
|
|
54
135
|
logging: false,
|
|
55
136
|
forgiveParseErrors: true,
|
|
56
137
|
});
|
|
138
|
+
// create the context storage for the plugin platform
|
|
57
139
|
this.log.debug(`Creating context for plugin ${this.config.name}`);
|
|
58
140
|
this.#contextReady = this.#storage.createStorage('context').then((context) => {
|
|
59
141
|
this.context = context;
|
|
60
142
|
this.log.debug(`Created context for plugin ${this.config.name}`);
|
|
61
143
|
return;
|
|
62
144
|
});
|
|
145
|
+
// create the selectDevice storage for the plugin platform
|
|
63
146
|
this.log.debug(`Loading selectDevice for plugin ${this.config.name}`);
|
|
64
147
|
this.#selectDeviceContextReady = this.#storage.createStorage('selectDevice').then(async (context) => {
|
|
65
148
|
const selectDevice = await context.get('selectDevice', []);
|
|
@@ -68,6 +151,7 @@ export class MatterbridgePlatform {
|
|
|
68
151
|
this.log.debug(`Loaded ${this.#selectDevices.size} selectDevice for plugin ${this.config.name}`);
|
|
69
152
|
return;
|
|
70
153
|
});
|
|
154
|
+
// create the selectEntity storage for the plugin platform
|
|
71
155
|
this.log.debug(`Loading selectEntity for plugin ${this.config.name}`);
|
|
72
156
|
this.#selectEntityContextReady = this.#storage.createStorage('selectEntity').then(async (context) => {
|
|
73
157
|
const selectEntity = await context.get('selectEntity', []);
|
|
@@ -76,98 +160,300 @@ export class MatterbridgePlatform {
|
|
|
76
160
|
this.log.debug(`Loaded ${this.#selectEntities.size} selectEntity for plugin ${this.config.name}`);
|
|
77
161
|
return;
|
|
78
162
|
});
|
|
163
|
+
// Create the `ready` promise for the platform
|
|
79
164
|
this.ready = Promise.all([this.#contextReady, this.#selectDeviceContextReady, this.#selectEntityContextReady]).then(() => {
|
|
80
165
|
this.log.debug(`MatterbridgePlatform for plugin ${this.config.name} is fully initialized`);
|
|
81
166
|
this.isReady = true;
|
|
82
167
|
return;
|
|
83
168
|
});
|
|
84
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Destroys the platform, cleaning up memory, closing storage and broadcast server.
|
|
172
|
+
*/
|
|
85
173
|
async destroy() {
|
|
86
174
|
if (this.#verbose)
|
|
87
175
|
this.log.debug(`Destroying MatterbridgePlatform for plugin ${this.config.name}`);
|
|
176
|
+
// Cleanup memory
|
|
88
177
|
this.#selectDevices.clear();
|
|
89
178
|
this.#selectEntities.clear();
|
|
90
179
|
this.#registeredEndpoints.clear();
|
|
180
|
+
// Close the storage
|
|
91
181
|
await this.context?.close();
|
|
92
182
|
this.context = undefined;
|
|
93
183
|
await this.#storage?.close();
|
|
184
|
+
// Close the broadcast server
|
|
94
185
|
this.#server.close();
|
|
95
186
|
if (this.#verbose)
|
|
96
187
|
this.log.debug(`Destroyed MatterbridgePlatform for plugin ${this.config.name}`);
|
|
97
188
|
this.isReady = false;
|
|
98
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* This method shall be overridden in the extended class.
|
|
192
|
+
* It is called when the platform is started.
|
|
193
|
+
* Use this method to create the MatterbridgeEndpoints and call this.registerDevice().
|
|
194
|
+
*
|
|
195
|
+
* @param {string} [reason] - The reason for starting.
|
|
196
|
+
* @throws {Error} - Throws an error if the method is not overridden.
|
|
197
|
+
*/
|
|
99
198
|
async onStart(reason) {
|
|
100
199
|
this.log.error('Plugins must override onStart.', reason);
|
|
101
200
|
throw new Error('Plugins must override onStart.');
|
|
102
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* This method can be overridden in the extended class. In this case always call super.onConfigure() to save the select and run checkEndpointNumbers().
|
|
204
|
+
* It is called after the platform has started.
|
|
205
|
+
* 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
|
|
206
|
+
* matter storage (i.e. the onOff attribute of the OnOff cluster).
|
|
207
|
+
*/
|
|
103
208
|
async onConfigure() {
|
|
104
209
|
this.log.debug(`Configuring platform ${this.name}`);
|
|
210
|
+
// Save the selectDevice and selectEntity
|
|
105
211
|
await this.saveSelects();
|
|
212
|
+
// Check and update the endpoint numbers
|
|
106
213
|
await this.checkEndpointNumbers();
|
|
107
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* 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.
|
|
217
|
+
* It is called when the platform is shutting down.
|
|
218
|
+
* Use this method to clean up any resources you used in the constructor or onStart.
|
|
219
|
+
*
|
|
220
|
+
* @param {string} [reason] - The reason for shutting down.
|
|
221
|
+
*/
|
|
108
222
|
async onShutdown(reason) {
|
|
109
223
|
this.log.debug(`Shutting down platform ${this.name}`, reason);
|
|
224
|
+
// Save the selectDevice and selectEntity
|
|
110
225
|
await this.saveSelects();
|
|
226
|
+
// Check and update the endpoint numbers
|
|
111
227
|
await this.checkEndpointNumbers();
|
|
228
|
+
// Cleanup memory and close storage and broadcast server
|
|
112
229
|
await this.destroy();
|
|
113
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Called when the logger level is changed.
|
|
233
|
+
*
|
|
234
|
+
* @param {LogLevel} logLevel The new logger level.
|
|
235
|
+
*/
|
|
114
236
|
async onChangeLoggerLevel(logLevel) {
|
|
115
237
|
this.log.debug(`The plugin doesn't override onChangeLoggerLevel. Logger level set to: ${logLevel}`);
|
|
116
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Called when a plugin config includes an action button or an action button with text field.
|
|
241
|
+
*
|
|
242
|
+
* @param {string} action The action triggered by the button in plugin config.
|
|
243
|
+
* @param {string} value The value of the field of the action button.
|
|
244
|
+
* @param {string} id The id of the schema associated with the action.
|
|
245
|
+
* @param {PlatformConfig} formData The changed form data of the plugin.
|
|
246
|
+
*
|
|
247
|
+
* @remarks
|
|
248
|
+
* This method can be overridden in the extended class.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* Use this method to handle the action defined in the plugin schema:
|
|
252
|
+
* ```json
|
|
253
|
+
* "addDevice": {
|
|
254
|
+
* "description": "Manually add a device that has not been discovered with mdns:",
|
|
255
|
+
* "type": "boolean",
|
|
256
|
+
* "buttonText": "ADD", // The text on the button. This is used when the action doesn't include a text field.
|
|
257
|
+
* "buttonField": "ADD", // The text on the button. This is used when the action includes a text field.
|
|
258
|
+
* "buttonClose": false, // optional, default is false. When true, the dialog will close after the action is sent.
|
|
259
|
+
* "buttonSave": false, // optional, default is false. When true, the dialog will close and trigger the restart required after the action is sent.
|
|
260
|
+
* "textPlaceholder": "Enter the device IP address", // optional: the placeholder text for the text field.
|
|
261
|
+
* "default": false
|
|
262
|
+
* },
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
117
265
|
async onAction(action, value, id, formData) {
|
|
118
266
|
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);
|
|
119
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Called when the plugin config has been updated.
|
|
270
|
+
*
|
|
271
|
+
* @param {PlatformConfig} config The new plugin config.
|
|
272
|
+
*/
|
|
120
273
|
async onConfigChanged(config) {
|
|
121
274
|
this.log.debug(`The plugin ${CYAN}${config.name}${db} doesn't override onConfigChanged. Received new config.`);
|
|
122
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* Save the platform configuration to the platform config JSON.
|
|
278
|
+
*
|
|
279
|
+
* @param {PlatformConfig} [config] - The platform configuration to save.
|
|
280
|
+
* @returns {void}
|
|
281
|
+
*/
|
|
123
282
|
saveConfig(config) {
|
|
124
283
|
this.#server.request({ type: 'plugins_saveconfigfromjson', src: 'platform', dst: 'plugins', params: { name: this.name, config } });
|
|
125
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* Get the platform schema for the config editor. This will retrieve the schema from the Matterbridge plugin manager.
|
|
287
|
+
*
|
|
288
|
+
* @returns {Promise<PlatformSchema | undefined>} The platform schema.
|
|
289
|
+
*/
|
|
126
290
|
async getSchema() {
|
|
127
291
|
return (await this.#server.fetch({ type: 'plugins_getschema', src: 'platform', dst: 'plugins', params: { name: this.name } })).result.schema;
|
|
128
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Set the platform schema for the config editor. This will update the schema in the Matterbridge plugin manager but will not change the schema file.
|
|
295
|
+
* It must be called from onStart() to update the schema in the plugin.
|
|
296
|
+
* Calling this method from the platform constructor will have no effect.
|
|
297
|
+
*
|
|
298
|
+
* @param {PlatformSchema} [schema] - The platform schema to set.
|
|
299
|
+
* @returns {void}
|
|
300
|
+
*/
|
|
129
301
|
setSchema(schema) {
|
|
130
302
|
this.#server.request({ type: 'plugins_setschema', src: 'platform', dst: 'plugins', params: { name: this.name, schema } });
|
|
131
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* Sends a restart required message to the frontend.
|
|
306
|
+
*
|
|
307
|
+
* @param {boolean} [snackbar] - If true, shows a snackbar notification. Default is true.
|
|
308
|
+
* @param {boolean} [fixed] - If true, shows a fixed notification. Default is false.
|
|
309
|
+
* @returns {void}
|
|
310
|
+
*/
|
|
132
311
|
wssSendRestartRequired(snackbar = true, fixed = false) {
|
|
133
312
|
this.#server.request({ type: 'frontend_restartrequired', src: 'platform', dst: 'frontend', params: { snackbar, fixed } });
|
|
134
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Sends an open snackbar message to all connected clients.
|
|
316
|
+
*
|
|
317
|
+
* @param {string} message - The message to send.
|
|
318
|
+
* @param {number} timeout - The timeout in seconds for the snackbar message. Default is 5 seconds.
|
|
319
|
+
* @param {'info' | 'warning' | 'error' | 'success'} severity - The severity of the message.
|
|
320
|
+
* possible values are: 'info', 'warning', 'error', 'success'. Default is 'info'.
|
|
321
|
+
*
|
|
322
|
+
* @remarks
|
|
323
|
+
* If timeout is 0, the snackbar message will be displayed until closed by the user.
|
|
324
|
+
*/
|
|
135
325
|
wssSendSnackbarMessage(message, timeout, severity) {
|
|
136
326
|
this.#server.request({ type: 'frontend_snackbarmessage', src: 'platform', dst: 'frontend', params: { message, timeout, severity } });
|
|
137
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* Retrieves the number of devices registered with the platform.
|
|
330
|
+
*
|
|
331
|
+
* @returns {number} The number of registered devices.
|
|
332
|
+
*/
|
|
138
333
|
size() {
|
|
139
334
|
return this.#registeredEndpoints.size;
|
|
140
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* Retrieves the devices registered with the platform.
|
|
338
|
+
*
|
|
339
|
+
* @returns {MatterbridgeEndpoint[]} The registered devices.
|
|
340
|
+
*/
|
|
141
341
|
getDevices() {
|
|
142
342
|
return Array.from(this.#registeredEndpoints.values());
|
|
143
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Retrieves a registered device by its name.
|
|
346
|
+
*
|
|
347
|
+
* @param {string} deviceName - The device name to search for.
|
|
348
|
+
* @returns {MatterbridgeEndpoint | undefined} The registered device or undefined if not found.
|
|
349
|
+
*/
|
|
144
350
|
getDeviceByName(deviceName) {
|
|
145
351
|
return Array.from(this.#registeredEndpoints.values()).find((device) => device.deviceName === deviceName);
|
|
146
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* Retrieves a registered device by its uniqueId.
|
|
355
|
+
*
|
|
356
|
+
* @param {string} uniqueId - The device unique ID to search for.
|
|
357
|
+
* @returns {MatterbridgeEndpoint | undefined} The registered device or undefined if not found.
|
|
358
|
+
*/
|
|
147
359
|
getDeviceByUniqueId(uniqueId) {
|
|
148
360
|
return Array.from(this.#registeredEndpoints.values()).find((device) => device.uniqueId === uniqueId);
|
|
149
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* Retrieves a registered device by its serialNumber.
|
|
364
|
+
*
|
|
365
|
+
* @param {string} serialNumber - The device serial number to search for.
|
|
366
|
+
* @returns {MatterbridgeEndpoint | undefined} The registered device or undefined if not found.
|
|
367
|
+
*/
|
|
150
368
|
getDeviceBySerialNumber(serialNumber) {
|
|
151
369
|
return Array.from(this.#registeredEndpoints.values()).find((device) => device.serialNumber === serialNumber);
|
|
152
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Retrieves a registered device by its id.
|
|
373
|
+
*
|
|
374
|
+
* @param {string} id - The device id to search for.
|
|
375
|
+
* @returns {MatterbridgeEndpoint | undefined} The registered device or undefined if not found.
|
|
376
|
+
*/
|
|
153
377
|
getDeviceById(id) {
|
|
154
378
|
return Array.from(this.#registeredEndpoints.values()).find((device) => device.maybeId === id);
|
|
155
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* Retrieves a registered device by its originalId.
|
|
382
|
+
*
|
|
383
|
+
* @param {string} originalId - The device originalId to search for.
|
|
384
|
+
* @returns {MatterbridgeEndpoint | undefined} The registered device or undefined if not found.
|
|
385
|
+
*/
|
|
156
386
|
getDeviceByOriginalId(originalId) {
|
|
157
387
|
return Array.from(this.#registeredEndpoints.values()).find((device) => device.originalId === originalId);
|
|
158
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* Retrieves a registered device by its number.
|
|
391
|
+
*
|
|
392
|
+
* @param {EndpointNumber | number} number - The device number to search for.
|
|
393
|
+
* @returns {MatterbridgeEndpoint | undefined} The registered device or undefined if not found.
|
|
394
|
+
*/
|
|
159
395
|
getDeviceByNumber(number) {
|
|
160
396
|
return Array.from(this.#registeredEndpoints.values()).find((device) => device.maybeNumber === number);
|
|
161
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Checks if a device with this name is already registered in the platform.
|
|
400
|
+
*
|
|
401
|
+
* @param {string} deviceName - The device name to check.
|
|
402
|
+
* @returns {boolean} True if the device is already registered, false otherwise.
|
|
403
|
+
*/
|
|
162
404
|
hasDeviceName(deviceName) {
|
|
163
405
|
return Array.from(this.#registeredEndpoints.values()).find((device) => device.deviceName === deviceName) !== undefined;
|
|
164
|
-
|
|
406
|
+
// return this.registeredEndpointsByName.has(deviceName);
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Checks if a device with this uniqueId is already registered in the platform.
|
|
410
|
+
*
|
|
411
|
+
* @param {string} deviceUniqueId - The device unique ID to check.
|
|
412
|
+
* @returns {boolean} True if the device is already registered, false otherwise.
|
|
413
|
+
*/
|
|
165
414
|
hasDeviceUniqueId(deviceUniqueId) {
|
|
166
415
|
return this.#registeredEndpoints.has(deviceUniqueId);
|
|
167
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* Registers a virtual device with the Matterbridge platform.
|
|
419
|
+
* Virtual devices are only supported in bridge mode and childbridge mode with a DynamicPlatform.
|
|
420
|
+
*
|
|
421
|
+
* The virtual device is created as an instance of `Endpoint` with the provided device type.
|
|
422
|
+
* When the virtual device is turned on, the provided callback function is executed.
|
|
423
|
+
* The onOff state of the virtual device always reverts to false when the device is turned on.
|
|
424
|
+
*
|
|
425
|
+
* @param { string } name - The name of the virtual device.
|
|
426
|
+
* @param { 'light' | 'outlet' | 'switch' | 'mounted_switch' } type - The type of the virtual device.
|
|
427
|
+
* @param { () => Promise<void> } callback - The callback to call when the virtual device is turned on.
|
|
428
|
+
*
|
|
429
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the virtual device was successfully registered, false otherwise.
|
|
430
|
+
*
|
|
431
|
+
* @remarks
|
|
432
|
+
* The virtual devices don't show up in the device list of the frontend.
|
|
433
|
+
* Type 'switch' is not supported by Alexa and 'mounted_switch' is not supported by Apple Home.
|
|
434
|
+
*/
|
|
168
435
|
async registerVirtualDevice(name, type, callback) {
|
|
169
|
-
return await this
|
|
170
|
-
}
|
|
436
|
+
return (await this.#addVirtualEndpoint?.(this.name, name, type, callback)) ?? false;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Registers a device with the Matterbridge platform and performs validation checks.
|
|
440
|
+
*
|
|
441
|
+
* This method also checks if the implementation called createDefaultBasicInformationClusterServer() instead of createDefaultBridgedDeviceBasicInformationClusterServer().
|
|
442
|
+
*
|
|
443
|
+
* This is correct with Accessory platforms so we check if we are running in bridge mode and add the bridgedNode and the BridgedDeviceBasicInformation cluster.
|
|
444
|
+
*
|
|
445
|
+
* If we are in bridge mode, we add the bridgedNode device type and the BridgedDeviceBasicInformation cluster.
|
|
446
|
+
*
|
|
447
|
+
* If we are in childbridge mode and the plugin is a 'DynamicPlatform', we add the bridgedNode device type and the BridgedDeviceBasicInformation cluster.
|
|
448
|
+
*
|
|
449
|
+
* if we are in childbridge mode and the plugin is a 'AccessoryPlatform', the device is not bridged so no action is taken.
|
|
450
|
+
*
|
|
451
|
+
* If the device.mode = 'server', the device is not bridged so no action is taken.
|
|
452
|
+
*
|
|
453
|
+
* If the device.mode = 'matter', the device is not bridged so no action is taken.
|
|
454
|
+
*
|
|
455
|
+
* @param {MatterbridgeEndpoint} device - The device to register.
|
|
456
|
+
*/
|
|
171
457
|
async registerDevice(device) {
|
|
172
458
|
device.plugin = this.name;
|
|
173
459
|
if (!device.uniqueId) {
|
|
@@ -189,7 +475,9 @@ export class MatterbridgePlatform {
|
|
|
189
475
|
if (checkNotLatinCharacters(device.deviceName)) {
|
|
190
476
|
this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has non latin characters.`);
|
|
191
477
|
}
|
|
478
|
+
// Validate bridgedNode and BridgedDeviceBasicInformation cluster
|
|
192
479
|
if (device.mode === undefined && (this.matterbridge.bridgeMode === 'bridge' || (this.matterbridge.bridgeMode === 'childbridge' && this.type === 'DynamicPlatform'))) {
|
|
480
|
+
// If the device is a bridged device, we add the bridgedNode to the deviceTypes map and to the Descriptor Cluster options
|
|
193
481
|
if (!device.deviceTypes.has(bridgedNode.code)) {
|
|
194
482
|
this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has no bridgedNode device type. Adding it...`);
|
|
195
483
|
device.deviceTypes.set(bridgedNode.code, bridgedNode);
|
|
@@ -201,23 +489,42 @@ export class MatterbridgePlatform {
|
|
|
201
489
|
}
|
|
202
490
|
}
|
|
203
491
|
}
|
|
492
|
+
// If the device is a bridged device, we add the BridgedDeviceBasicInformation cluster
|
|
204
493
|
if (!device.hasClusterServer(BridgedDeviceBasicInformation.Cluster.id)) {
|
|
205
494
|
this.log.debug(`Device with name ${CYAN}${device.deviceName}${db} has no BridgedDeviceBasicInformation cluster. Adding it...`);
|
|
206
495
|
device.createDefaultBridgedDeviceBasicInformationClusterServer(device.deviceName, device.serialNumber, device.vendorId, device.vendorName, device.productName, device.softwareVersion, device.softwareVersionString, device.hardwareVersion, device.hardwareVersionString);
|
|
207
496
|
}
|
|
208
497
|
}
|
|
209
|
-
await this
|
|
498
|
+
await this.#addBridgedEndpoint?.(this.name, device);
|
|
210
499
|
this.#registeredEndpoints.set(device.uniqueId, device);
|
|
211
500
|
}
|
|
501
|
+
/**
|
|
502
|
+
* Unregisters a device registered with the Matterbridge platform.
|
|
503
|
+
*
|
|
504
|
+
* @param {MatterbridgeEndpoint} device - The device to unregister.
|
|
505
|
+
*/
|
|
212
506
|
async unregisterDevice(device) {
|
|
213
|
-
await this
|
|
507
|
+
await this.#removeBridgedEndpoint?.(this.name, device);
|
|
214
508
|
if (device.uniqueId)
|
|
215
509
|
this.#registeredEndpoints.delete(device.uniqueId);
|
|
216
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* Unregisters all devices registered with the Matterbridge platform.
|
|
513
|
+
*
|
|
514
|
+
* @param {number} [delay] - The delay in milliseconds between removing each bridged endpoint (default: 0).
|
|
515
|
+
*/
|
|
217
516
|
async unregisterAllDevices(delay = 0) {
|
|
218
|
-
await this
|
|
517
|
+
await this.#removeAllBridgedEndpoints?.(this.name, delay);
|
|
219
518
|
this.#registeredEndpoints.clear();
|
|
220
519
|
}
|
|
520
|
+
/**
|
|
521
|
+
* Saves the select devices and entities to storage.
|
|
522
|
+
*
|
|
523
|
+
* This method saves the current state of `selectDevice` and `selectEntity` maps to their respective storage.
|
|
524
|
+
* It logs the number of items being saved and ensures that the storage is properly closed after saving.
|
|
525
|
+
*
|
|
526
|
+
* @returns {Promise<void>} A promise that resolves when the save operation is complete.
|
|
527
|
+
*/
|
|
221
528
|
async saveSelects() {
|
|
222
529
|
if (this.#storage) {
|
|
223
530
|
this.log.debug(`Saving ${this.#selectDevices.size} selectDevice...`);
|
|
@@ -230,19 +537,60 @@ export class MatterbridgePlatform {
|
|
|
230
537
|
await selectEntity.close();
|
|
231
538
|
}
|
|
232
539
|
}
|
|
540
|
+
/**
|
|
541
|
+
* Clears all the select device and entity maps and saves the changes to the storage.
|
|
542
|
+
*
|
|
543
|
+
* @returns {void}
|
|
544
|
+
*/
|
|
233
545
|
async clearSelect() {
|
|
234
546
|
this.#selectDevices.clear();
|
|
235
547
|
this.#selectEntities.clear();
|
|
236
548
|
await this.saveSelects();
|
|
237
549
|
}
|
|
550
|
+
/**
|
|
551
|
+
* Clears the select for a single device and saves the changes to the storage.
|
|
552
|
+
*
|
|
553
|
+
* @param {string} serial - The serial of the device to clear.
|
|
554
|
+
* @returns {void}
|
|
555
|
+
*/
|
|
238
556
|
async clearDeviceSelect(serial) {
|
|
239
557
|
this.#selectDevices.delete(serial);
|
|
240
558
|
await this.saveSelects();
|
|
241
559
|
}
|
|
560
|
+
/**
|
|
561
|
+
* Clears the select for a single entity and saves the changes to the storage.
|
|
562
|
+
*
|
|
563
|
+
* @param {string} name - The name of the entity to clear.
|
|
564
|
+
* @returns {void}
|
|
565
|
+
*/
|
|
242
566
|
async clearEntitySelect(name) {
|
|
243
567
|
this.#selectEntities.delete(name);
|
|
244
568
|
await this.saveSelects();
|
|
245
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
* Set the select device in the platform map.
|
|
572
|
+
*
|
|
573
|
+
* @param {string} serial - The serial number of the device.
|
|
574
|
+
* @param {string} name - The name of the device.
|
|
575
|
+
* @param {string} [configUrl] - The configuration URL of the device.
|
|
576
|
+
* @param {string} [icon] - The icon of the device: 'wifi', 'ble', 'hub'
|
|
577
|
+
* @param {Array<{ name: string; description: string; icon?: string }>} [entities] - The entities associated with the device.
|
|
578
|
+
* @returns {void}
|
|
579
|
+
*
|
|
580
|
+
* @remarks
|
|
581
|
+
* In the schema use selectFrom: 'serial' or 'name'
|
|
582
|
+
* ```json
|
|
583
|
+
* "whiteList": {
|
|
584
|
+
* "description": "Only the devices in the list will be exposed.",
|
|
585
|
+
* "type": "array",
|
|
586
|
+
* "items": {
|
|
587
|
+
* "type": "string"
|
|
588
|
+
* },
|
|
589
|
+
* "uniqueItems": true,
|
|
590
|
+
* "selectFrom": "name"
|
|
591
|
+
* },
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
246
594
|
setSelectDevice(serial, name, configUrl, icon, entities) {
|
|
247
595
|
const device = this.#selectDevices.get(serial);
|
|
248
596
|
if (device) {
|
|
@@ -259,9 +607,44 @@ export class MatterbridgePlatform {
|
|
|
259
607
|
this.#selectDevices.set(serial, { serial, name, configUrl, icon, entities });
|
|
260
608
|
}
|
|
261
609
|
}
|
|
610
|
+
/**
|
|
611
|
+
* Retrieve a select device by serial.
|
|
612
|
+
*
|
|
613
|
+
* @param {string} serial - The serial number of the device.
|
|
614
|
+
* @returns {{ serial: string; name: string; configUrl?: string; icon?: string; entities?: { name: string; description: string; icon?: string }[] } | undefined} The select device or undefined if not found.
|
|
615
|
+
*/
|
|
262
616
|
getSelectDevice(serial) {
|
|
263
617
|
return this.#selectDevices.get(serial);
|
|
264
618
|
}
|
|
619
|
+
/**
|
|
620
|
+
* Set the select device entity in the platform map.
|
|
621
|
+
*
|
|
622
|
+
* @param {string} serial - The serial number of the device.
|
|
623
|
+
* @param {string} entityName - The name of the entity.
|
|
624
|
+
* @param {string} entityDescription - The description of the entity.
|
|
625
|
+
* @param {string} [entityIcon] - The icon of the entity: 'wifi', 'ble', 'hub', 'component', 'matter'
|
|
626
|
+
* @returns {void}
|
|
627
|
+
*
|
|
628
|
+
* @remarks
|
|
629
|
+
* In the schema use selectDeviceEntityFrom: 'name' or 'description'
|
|
630
|
+
* ```json
|
|
631
|
+
* "deviceEntityBlackList": {
|
|
632
|
+
* "description": "List of entities not to be exposed for a single device.",
|
|
633
|
+
* "type": "object",
|
|
634
|
+
* "uniqueItems": true,
|
|
635
|
+
* "selectFrom": "name",
|
|
636
|
+
* "additionalProperties": {
|
|
637
|
+
* "description": "List of entities not to be exposed for this device.",
|
|
638
|
+
* "type": "array",
|
|
639
|
+
* "items": {
|
|
640
|
+
* "type": "string"
|
|
641
|
+
* },
|
|
642
|
+
* "uniqueItems": true,
|
|
643
|
+
* "selectDeviceEntityFrom": "name"
|
|
644
|
+
* }
|
|
645
|
+
* },
|
|
646
|
+
* ```
|
|
647
|
+
*/
|
|
265
648
|
setSelectDeviceEntity(serial, entityName, entityDescription, entityIcon) {
|
|
266
649
|
const device = this.#selectDevices.get(serial);
|
|
267
650
|
if (device) {
|
|
@@ -271,6 +654,11 @@ export class MatterbridgePlatform {
|
|
|
271
654
|
device.entities.push({ name: entityName, description: entityDescription, icon: entityIcon });
|
|
272
655
|
}
|
|
273
656
|
}
|
|
657
|
+
/**
|
|
658
|
+
* Retrieves the select devices from the platform map.
|
|
659
|
+
*
|
|
660
|
+
* @returns {ApiSelectDevice[]} The selected devices array.
|
|
661
|
+
*/
|
|
274
662
|
getSelectDevices() {
|
|
275
663
|
const selectDevices = [];
|
|
276
664
|
for (const device of this.#selectDevices.values()) {
|
|
@@ -278,12 +666,45 @@ export class MatterbridgePlatform {
|
|
|
278
666
|
}
|
|
279
667
|
return selectDevices;
|
|
280
668
|
}
|
|
669
|
+
/**
|
|
670
|
+
* Set the select entity in the platform map.
|
|
671
|
+
*
|
|
672
|
+
* @param {string} name - The entity name.
|
|
673
|
+
* @param {string} description - The entity description.
|
|
674
|
+
* @param {string} [icon] - The entity icon: 'wifi', 'ble', 'hub', 'component', 'matter'
|
|
675
|
+
* @returns {void}
|
|
676
|
+
*
|
|
677
|
+
* @remarks
|
|
678
|
+
* In the schema use selectEntityFrom: 'name' or 'description'
|
|
679
|
+
* ```json
|
|
680
|
+
* "entityBlackList": {
|
|
681
|
+
* "description": "The entities in the list will not be exposed.",
|
|
682
|
+
* "type": "array",
|
|
683
|
+
* "items": {
|
|
684
|
+
* "type": "string"
|
|
685
|
+
* },
|
|
686
|
+
* "uniqueItems": true,
|
|
687
|
+
* "selectEntityFrom": "name"
|
|
688
|
+
* },
|
|
689
|
+
* ```
|
|
690
|
+
*/
|
|
281
691
|
setSelectEntity(name, description, icon) {
|
|
282
692
|
this.#selectEntities.set(name, { name, description, icon });
|
|
283
693
|
}
|
|
694
|
+
/**
|
|
695
|
+
* Retrieve a select entity by name.
|
|
696
|
+
*
|
|
697
|
+
* @param {string} name - The name of the entity.
|
|
698
|
+
* @returns {{ name: string; description: string; icon?: string } | undefined} The select entity or undefined if not found.
|
|
699
|
+
*/
|
|
284
700
|
getSelectEntity(name) {
|
|
285
701
|
return this.#selectEntities.get(name);
|
|
286
702
|
}
|
|
703
|
+
/**
|
|
704
|
+
* Retrieve the select entities.
|
|
705
|
+
*
|
|
706
|
+
* @returns {ApiSelectEntity[]} The select entities array.
|
|
707
|
+
*/
|
|
287
708
|
getSelectEntities() {
|
|
288
709
|
const selectEntities = [];
|
|
289
710
|
for (const entity of this.#selectEntities.values()) {
|
|
@@ -291,7 +712,15 @@ export class MatterbridgePlatform {
|
|
|
291
712
|
}
|
|
292
713
|
return selectEntities;
|
|
293
714
|
}
|
|
294
|
-
|
|
715
|
+
/**
|
|
716
|
+
* Verifies if the Matterbridge version meets the required version.
|
|
717
|
+
* If not, it destroys the platform cause the implementation may not call destroy().
|
|
718
|
+
*
|
|
719
|
+
* @param {string} requiredVersion - The required version to compare against.
|
|
720
|
+
* @param {boolean} [destroy] - Whether to destroy the platform if the version check fails. Default is true.
|
|
721
|
+
* @returns {boolean} True if the Matterbridge version meets or exceeds the required version, false otherwise.
|
|
722
|
+
*/
|
|
723
|
+
verifyMatterbridgeVersion(requiredVersion, destroy = true) {
|
|
295
724
|
const compareVersions = (matterbridgeVersion, requiredVersion) => {
|
|
296
725
|
const stripTag = (v) => {
|
|
297
726
|
const parts = v.split('-');
|
|
@@ -311,10 +740,21 @@ export class MatterbridgePlatform {
|
|
|
311
740
|
}
|
|
312
741
|
return true;
|
|
313
742
|
};
|
|
314
|
-
if (!compareVersions(this.matterbridge.matterbridgeVersion, requiredVersion))
|
|
743
|
+
if (!compareVersions(this.matterbridge.matterbridgeVersion, requiredVersion)) {
|
|
744
|
+
if (destroy)
|
|
745
|
+
this.destroy();
|
|
315
746
|
return false;
|
|
747
|
+
}
|
|
316
748
|
return true;
|
|
317
749
|
}
|
|
750
|
+
/**
|
|
751
|
+
* Validates if a device is allowed based on the whitelist and blacklist configurations.
|
|
752
|
+
* The blacklist has priority over the whitelist.
|
|
753
|
+
*
|
|
754
|
+
* @param {string | string[]} device - The device name(s) to validate.
|
|
755
|
+
* @param {boolean} [log] - Whether to log the validation result.
|
|
756
|
+
* @returns {boolean} - Returns true if the device is allowed, false otherwise.
|
|
757
|
+
*/
|
|
318
758
|
validateDevice(device, log = true) {
|
|
319
759
|
if (!Array.isArray(device))
|
|
320
760
|
device = [device];
|
|
@@ -344,6 +784,14 @@ export class MatterbridgePlatform {
|
|
|
344
784
|
this.log.info(`Skipping device ${CYAN}${device.join(', ')}${nf} because not in whitelist`);
|
|
345
785
|
return false;
|
|
346
786
|
}
|
|
787
|
+
/**
|
|
788
|
+
* Validates if an entity is allowed based on the entity blacklist and device-entity blacklist configurations.
|
|
789
|
+
*
|
|
790
|
+
* @param {string} device - The device to which the entity belongs.
|
|
791
|
+
* @param {string} entity - The entity to validate.
|
|
792
|
+
* @param {boolean} [log] - Whether to log the validation result.
|
|
793
|
+
* @returns {boolean} - Returns true if the entity is allowed, false otherwise.
|
|
794
|
+
*/
|
|
347
795
|
validateEntity(device, entity, log = true) {
|
|
348
796
|
if (isValidArray(this.config.entityBlackList, 1) && this.config.entityBlackList.find((e) => e === entity)) {
|
|
349
797
|
if (log)
|
|
@@ -362,10 +810,24 @@ export class MatterbridgePlatform {
|
|
|
362
810
|
}
|
|
363
811
|
return true;
|
|
364
812
|
}
|
|
813
|
+
/**
|
|
814
|
+
* Clears all stored endpoint numbers for checkEndpointNumbers().
|
|
815
|
+
*
|
|
816
|
+
* @returns {Promise<void>} A promise that resolves when the endpoint numbers have been cleared.
|
|
817
|
+
*/
|
|
365
818
|
async clearEndpointNumbers() {
|
|
366
819
|
const context = await this.#storage.createStorage('endpointNumbers');
|
|
367
820
|
await context.set('endpointMap', []);
|
|
368
821
|
}
|
|
822
|
+
/**
|
|
823
|
+
* Checks and updates the endpoint numbers for Matterbridge devices.
|
|
824
|
+
*
|
|
825
|
+
* This method retrieves the list of Matterbridge devices and their child endpoints,
|
|
826
|
+
* compares their current endpoint numbers with the stored ones, and updates the storage
|
|
827
|
+
* if there are any changes. It logs the changes and updates the endpoint numbers accordingly.
|
|
828
|
+
*
|
|
829
|
+
* @returns {Promise<number>} The size of the updated endpoint map, or -1 if storage is not available.
|
|
830
|
+
*/
|
|
369
831
|
async checkEndpointNumbers() {
|
|
370
832
|
this.log.debug('Checking endpoint numbers...');
|
|
371
833
|
const context = await this.#storage.createStorage('endpointNumbers');
|
|
@@ -404,3 +866,4 @@ export class MatterbridgePlatform {
|
|
|
404
866
|
return endpointMap.size;
|
|
405
867
|
}
|
|
406
868
|
}
|
|
869
|
+
//# sourceMappingURL=matterbridgePlatform.js.map
|