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