matterbridge 3.3.3 → 3.3.4-dev-20251020-4d2dd49
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 +21 -0
- package/dist/broadcastServer.js +1 -86
- package/dist/broadcastServerTypes.js +0 -24
- package/dist/cli.js +110 -444
- package/dist/cliEmitter.js +0 -37
- package/dist/cliHistory.js +15 -95
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -24
- package/dist/deviceManager.js +1 -124
- package/dist/devices/airConditioner.js +0 -57
- package/dist/devices/batteryStorage.js +1 -48
- package/dist/devices/cooktop.js +0 -55
- package/dist/devices/dishwasher.js +0 -57
- package/dist/devices/evse.js +10 -74
- package/dist/devices/export.js +0 -5
- package/dist/devices/extractorHood.js +0 -42
- package/dist/devices/heatPump.js +2 -50
- package/dist/devices/laundryDryer.js +3 -62
- package/dist/devices/laundryWasher.js +4 -70
- package/dist/devices/microwaveOven.js +5 -88
- package/dist/devices/oven.js +0 -85
- package/dist/devices/refrigerator.js +0 -102
- package/dist/devices/roboticVacuumCleaner.js +9 -100
- package/dist/devices/solarPower.js +0 -38
- package/dist/devices/speaker.js +0 -84
- package/dist/devices/temperatureControl.js +3 -25
- package/dist/devices/waterHeater.js +2 -82
- package/dist/dgram/coap.js +13 -126
- package/dist/dgram/dgram.js +2 -114
- package/dist/dgram/mb_coap.js +3 -41
- package/dist/dgram/mb_mdns.js +15 -80
- package/dist/dgram/mdns.js +137 -299
- package/dist/dgram/multicast.js +1 -62
- package/dist/dgram/unicast.js +0 -54
- package/dist/frontend.js +34 -413
- package/dist/frontendTypes.js +0 -45
- package/dist/helpers.js +0 -53
- package/dist/index.js +0 -25
- package/dist/logger/export.js +0 -1
- package/dist/matter/behaviors.js +0 -2
- package/dist/matter/clusters.js +0 -2
- package/dist/matter/devices.js +0 -2
- package/dist/matter/endpoints.js +0 -2
- package/dist/matter/export.js +0 -3
- package/dist/matter/types.js +0 -3
- package/dist/matterbridge.js +51 -873
- package/dist/matterbridgeAccessoryPlatform.js +0 -36
- package/dist/matterbridgeBehaviors.js +5 -71
- package/dist/matterbridgeDeviceTypes.js +17 -630
- package/dist/matterbridgeDynamicPlatform.js +0 -36
- package/dist/matterbridgeEndpoint.js +58 -1412
- package/dist/matterbridgeEndpointHelpers.js +10 -368
- package/dist/matterbridgePlatform.js +1 -341
- package/dist/matterbridgeTypes.js +0 -26
- package/dist/pluginManager.js +3 -325
- package/dist/shelly.js +7 -168
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -69
- package/dist/utils/colorUtils.js +2 -97
- package/dist/utils/commandLine.js +6 -55
- package/dist/utils/copyDirectory.js +1 -38
- package/dist/utils/createDirectory.js +0 -33
- package/dist/utils/createZip.js +2 -47
- package/dist/utils/deepCopy.js +0 -39
- package/dist/utils/deepEqual.js +1 -72
- package/dist/utils/error.js +0 -41
- package/dist/utils/export.js +0 -1
- package/dist/utils/hex.js +0 -124
- package/dist/utils/inspector.js +200 -0
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/jestHelpers.js +3 -153
- package/dist/utils/network.js +5 -108
- package/dist/utils/spawn.js +0 -71
- package/dist/utils/tracker.js +229 -0
- package/dist/utils/wait.js +8 -60
- package/frontend/build/assets/index.js +4 -4
- package/frontend/build/assets/vendor_mdi.js +1 -1
- package/frontend/package.json +1 -1
- package/npm-shrinkwrap.json +44 -44
- package/package.json +2 -3
- package/dist/broadcastServer.d.ts +0 -105
- package/dist/broadcastServer.d.ts.map +0 -1
- package/dist/broadcastServer.js.map +0 -1
- package/dist/broadcastServerTypes.d.ts +0 -719
- package/dist/broadcastServerTypes.d.ts.map +0 -1
- package/dist/broadcastServerTypes.js.map +0 -1
- package/dist/cli.d.ts +0 -26
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cliEmitter.d.ts +0 -50
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.js.map +0 -1
- package/dist/cliHistory.d.ts +0 -74
- package/dist/cliHistory.d.ts.map +0 -1
- package/dist/cliHistory.js.map +0 -1
- package/dist/clusters/export.d.ts +0 -2
- package/dist/clusters/export.d.ts.map +0 -1
- package/dist/clusters/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -28
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -117
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/devices/airConditioner.d.ts +0 -98
- package/dist/devices/airConditioner.d.ts.map +0 -1
- package/dist/devices/airConditioner.js.map +0 -1
- package/dist/devices/batteryStorage.d.ts +0 -48
- package/dist/devices/batteryStorage.d.ts.map +0 -1
- package/dist/devices/batteryStorage.js.map +0 -1
- package/dist/devices/cooktop.d.ts +0 -60
- package/dist/devices/cooktop.d.ts.map +0 -1
- package/dist/devices/cooktop.js.map +0 -1
- package/dist/devices/dishwasher.d.ts +0 -71
- package/dist/devices/dishwasher.d.ts.map +0 -1
- package/dist/devices/dishwasher.js.map +0 -1
- package/dist/devices/evse.d.ts +0 -75
- package/dist/devices/evse.d.ts.map +0 -1
- package/dist/devices/evse.js.map +0 -1
- package/dist/devices/export.d.ts +0 -17
- package/dist/devices/export.d.ts.map +0 -1
- package/dist/devices/export.js.map +0 -1
- package/dist/devices/extractorHood.d.ts +0 -46
- package/dist/devices/extractorHood.d.ts.map +0 -1
- package/dist/devices/extractorHood.js.map +0 -1
- package/dist/devices/heatPump.d.ts +0 -47
- package/dist/devices/heatPump.d.ts.map +0 -1
- package/dist/devices/heatPump.js.map +0 -1
- package/dist/devices/laundryDryer.d.ts +0 -67
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -81
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.js.map +0 -1
- package/dist/devices/microwaveOven.d.ts +0 -168
- package/dist/devices/microwaveOven.d.ts.map +0 -1
- package/dist/devices/microwaveOven.js.map +0 -1
- package/dist/devices/oven.d.ts +0 -105
- package/dist/devices/oven.d.ts.map +0 -1
- package/dist/devices/oven.js.map +0 -1
- package/dist/devices/refrigerator.d.ts +0 -118
- package/dist/devices/refrigerator.d.ts.map +0 -1
- package/dist/devices/refrigerator.js.map +0 -1
- package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
- package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/devices/roboticVacuumCleaner.js.map +0 -1
- package/dist/devices/solarPower.d.ts +0 -40
- package/dist/devices/solarPower.d.ts.map +0 -1
- package/dist/devices/solarPower.js.map +0 -1
- package/dist/devices/speaker.d.ts +0 -87
- package/dist/devices/speaker.d.ts.map +0 -1
- package/dist/devices/speaker.js.map +0 -1
- package/dist/devices/temperatureControl.d.ts +0 -166
- package/dist/devices/temperatureControl.d.ts.map +0 -1
- package/dist/devices/temperatureControl.js.map +0 -1
- package/dist/devices/waterHeater.d.ts +0 -111
- package/dist/devices/waterHeater.d.ts.map +0 -1
- package/dist/devices/waterHeater.js.map +0 -1
- package/dist/dgram/coap.d.ts +0 -205
- package/dist/dgram/coap.d.ts.map +0 -1
- package/dist/dgram/coap.js.map +0 -1
- package/dist/dgram/dgram.d.ts +0 -141
- package/dist/dgram/dgram.d.ts.map +0 -1
- package/dist/dgram/dgram.js.map +0 -1
- package/dist/dgram/mb_coap.d.ts +0 -24
- package/dist/dgram/mb_coap.d.ts.map +0 -1
- package/dist/dgram/mb_coap.js.map +0 -1
- package/dist/dgram/mb_mdns.d.ts +0 -24
- package/dist/dgram/mb_mdns.d.ts.map +0 -1
- package/dist/dgram/mb_mdns.js.map +0 -1
- package/dist/dgram/mdns.d.ts +0 -290
- package/dist/dgram/mdns.d.ts.map +0 -1
- package/dist/dgram/mdns.js.map +0 -1
- package/dist/dgram/multicast.d.ts +0 -67
- package/dist/dgram/multicast.d.ts.map +0 -1
- package/dist/dgram/multicast.js.map +0 -1
- package/dist/dgram/unicast.d.ts +0 -56
- package/dist/dgram/unicast.d.ts.map +0 -1
- package/dist/dgram/unicast.js.map +0 -1
- package/dist/frontend.d.ts +0 -235
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/frontendTypes.d.ts +0 -529
- package/dist/frontendTypes.d.ts.map +0 -1
- package/dist/frontendTypes.js.map +0 -1
- package/dist/helpers.d.ts +0 -48
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js.map +0 -1
- package/dist/index.d.ts +0 -33
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger/export.d.ts +0 -2
- package/dist/logger/export.d.ts.map +0 -1
- package/dist/logger/export.js.map +0 -1
- package/dist/matter/behaviors.d.ts +0 -2
- package/dist/matter/behaviors.d.ts.map +0 -1
- package/dist/matter/behaviors.js.map +0 -1
- package/dist/matter/clusters.d.ts +0 -2
- package/dist/matter/clusters.d.ts.map +0 -1
- package/dist/matter/clusters.js.map +0 -1
- package/dist/matter/devices.d.ts +0 -2
- package/dist/matter/devices.d.ts.map +0 -1
- package/dist/matter/devices.js.map +0 -1
- package/dist/matter/endpoints.d.ts +0 -2
- package/dist/matter/endpoints.d.ts.map +0 -1
- package/dist/matter/endpoints.js.map +0 -1
- package/dist/matter/export.d.ts +0 -5
- package/dist/matter/export.d.ts.map +0 -1
- package/dist/matter/export.js.map +0 -1
- package/dist/matter/types.d.ts +0 -3
- package/dist/matter/types.d.ts.map +0 -1
- package/dist/matter/types.js.map +0 -1
- package/dist/matterbridge.d.ts +0 -469
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -2399
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -761
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1545
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -560
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -402
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -209
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -353
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -174
- package/dist/shelly.d.ts.map +0 -1
- package/dist/shelly.js.map +0 -1
- package/dist/storage/export.d.ts +0 -2
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/update.d.ts +0 -75
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -99
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/commandLine.d.ts +0 -59
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -33
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createDirectory.d.ts +0 -34
- package/dist/utils/createDirectory.d.ts.map +0 -1
- package/dist/utils/createDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -39
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -32
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -54
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/error.d.ts +0 -44
- package/dist/utils/error.d.ts.map +0 -1
- package/dist/utils/error.js.map +0 -1
- package/dist/utils/export.d.ts +0 -13
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/hex.d.ts +0 -89
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -103
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/jestHelpers.d.ts +0 -137
- package/dist/utils/jestHelpers.d.ts.map +0 -1
- package/dist/utils/jestHelpers.js.map +0 -1
- package/dist/utils/network.d.ts +0 -115
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/spawn.d.ts +0 -35
- package/dist/utils/spawn.d.ts.map +0 -1
- package/dist/utils/spawn.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -54
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
|
@@ -1,34 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the helpers for the class MatterbridgeEndpoint.
|
|
3
|
-
*
|
|
4
|
-
* @file matterbridgeEndpointHelpers.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @created 2024-10-01
|
|
7
|
-
* @version 2.1.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
|
-
// Other modules
|
|
25
1
|
import { createHash } from 'node:crypto';
|
|
26
|
-
// AnsiLogger module
|
|
27
2
|
import { BLUE, CYAN, db, debugStringify, er, hk, or, YELLOW, zb } from 'node-ansi-logger';
|
|
28
|
-
// @matter
|
|
29
3
|
import { Lifecycle } from '@matter/main';
|
|
30
4
|
import { getClusterNameById, MeasurementType } from '@matter/main/types';
|
|
31
|
-
// @matter clusters
|
|
32
5
|
import { PowerSource } from '@matter/main/clusters/power-source';
|
|
33
6
|
import { UserLabel } from '@matter/main/clusters/user-label';
|
|
34
7
|
import { FixedLabel } from '@matter/main/clusters/fixed-label';
|
|
@@ -73,7 +46,6 @@ import { TotalVolatileOrganicCompoundsConcentrationMeasurement } from '@matter/m
|
|
|
73
46
|
import { OperationalState } from '@matter/main/clusters/operational-state';
|
|
74
47
|
import { DeviceEnergyManagement } from '@matter/main/clusters/device-energy-management';
|
|
75
48
|
import { DeviceEnergyManagementMode } from '@matter/main/clusters/device-energy-management-mode';
|
|
76
|
-
// @matter behaviors
|
|
77
49
|
import { PowerSourceServer } from '@matter/main/behaviors/power-source';
|
|
78
50
|
import { UserLabelServer } from '@matter/main/behaviors/user-label';
|
|
79
51
|
import { FixedLabelServer } from '@matter/main/behaviors/fixed-label';
|
|
@@ -104,126 +76,56 @@ import { Pm10ConcentrationMeasurementServer } from '@matter/main/behaviors/pm10-
|
|
|
104
76
|
import { RadonConcentrationMeasurementServer } from '@matter/main/behaviors/radon-concentration-measurement';
|
|
105
77
|
import { TotalVolatileOrganicCompoundsConcentrationMeasurementServer } from '@matter/main/behaviors/total-volatile-organic-compounds-concentration-measurement';
|
|
106
78
|
import { DeviceEnergyManagementServer } from '@matter/node/behaviors/device-energy-management';
|
|
107
|
-
// Matterbridge
|
|
108
79
|
import { deepCopy, deepEqual, isValidArray } from './utils/export.js';
|
|
109
80
|
import { MatterbridgeIdentifyServer, MatterbridgeOnOffServer, MatterbridgeLevelControlServer, MatterbridgeColorControlServer, MatterbridgeLiftWindowCoveringServer, MatterbridgeThermostatServer, MatterbridgeFanControlServer, MatterbridgeDoorLockServer, MatterbridgeModeSelectServer, MatterbridgeValveConfigurationAndControlServer, MatterbridgeSmokeCoAlarmServer, MatterbridgeBooleanStateConfigurationServer, MatterbridgeOperationalStateServer, MatterbridgeDeviceEnergyManagementModeServer, } from './matterbridgeBehaviors.js';
|
|
110
|
-
/**
|
|
111
|
-
* Capitalizes the first letter of a string.
|
|
112
|
-
*
|
|
113
|
-
* @param {string} name - The string to capitalize.
|
|
114
|
-
* @returns {string} The string with the first letter capitalized.
|
|
115
|
-
*/
|
|
116
81
|
export function capitalizeFirstLetter(name) {
|
|
117
82
|
if (!name)
|
|
118
83
|
return name;
|
|
119
84
|
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
120
85
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Lowercases the first letter of a string.
|
|
123
|
-
*
|
|
124
|
-
* @param {string} name - The string to lowercase the first letter of.
|
|
125
|
-
* @returns {string} The string with the first letter lowercased.
|
|
126
|
-
*/
|
|
127
86
|
export function lowercaseFirstLetter(name) {
|
|
128
87
|
if (!name)
|
|
129
88
|
return name;
|
|
130
89
|
return name.charAt(0).toLowerCase() + name.slice(1);
|
|
131
90
|
}
|
|
132
|
-
/**
|
|
133
|
-
* Checks if the device name contains non-Latin characters.
|
|
134
|
-
*
|
|
135
|
-
* @param {string} deviceName - The name of the device to check.
|
|
136
|
-
* @returns {boolean} Returns true if the device name contains non-Latin characters, false otherwise.
|
|
137
|
-
*/
|
|
138
91
|
export function checkNotLatinCharacters(deviceName) {
|
|
139
92
|
const nonLatinRegexList = [
|
|
140
|
-
/[\u0400-\u04FF\u0500-\u052F]/,
|
|
141
|
-
/[\u2E80-\u9FFF]/,
|
|
142
|
-
/[\uAC00-\uD7AF]/,
|
|
143
|
-
/[\u0600-\u06FF\u0750-\u077F]/,
|
|
144
|
-
/[\u0590-\u05FF]/,
|
|
145
|
-
/[\u0900-\u097F]/,
|
|
146
|
-
/[\u0E00-\u0E7F]/,
|
|
147
|
-
/[\u1200-\u137F]/,
|
|
93
|
+
/[\u0400-\u04FF\u0500-\u052F]/,
|
|
94
|
+
/[\u2E80-\u9FFF]/,
|
|
95
|
+
/[\uAC00-\uD7AF]/,
|
|
96
|
+
/[\u0600-\u06FF\u0750-\u077F]/,
|
|
97
|
+
/[\u0590-\u05FF]/,
|
|
98
|
+
/[\u0900-\u097F]/,
|
|
99
|
+
/[\u0E00-\u0E7F]/,
|
|
100
|
+
/[\u1200-\u137F]/,
|
|
148
101
|
];
|
|
149
102
|
return nonLatinRegexList.some((regex) => regex.test(deviceName));
|
|
150
103
|
}
|
|
151
|
-
/**
|
|
152
|
-
* Generates a unique ID based on the device name.
|
|
153
|
-
*
|
|
154
|
-
* @param {string} deviceName - The name of the device to generate a unique ID for.
|
|
155
|
-
* @returns {string} A unique ID generated from the device name using MD5 hashing.
|
|
156
|
-
*/
|
|
157
104
|
export function generateUniqueId(deviceName) {
|
|
158
|
-
return createHash('md5').update(deviceName).digest('hex');
|
|
105
|
+
return createHash('md5').update(deviceName).digest('hex');
|
|
159
106
|
}
|
|
160
|
-
/**
|
|
161
|
-
* Generates a unique ID based on four parameters.
|
|
162
|
-
*
|
|
163
|
-
* @param {string} param1 - The first parameter.
|
|
164
|
-
* @param {string} param2 - The second parameter.
|
|
165
|
-
* @param {string} param3 - The third parameter.
|
|
166
|
-
* @param {string} param4 - The fourth parameter.
|
|
167
|
-
* @returns {string} A unique ID generated from the concatenation of the parameters using MD5 hashing.
|
|
168
|
-
*/
|
|
169
107
|
export function createUniqueId(param1, param2, param3, param4) {
|
|
170
108
|
const hash = createHash('md5');
|
|
171
109
|
hash.update(param1 + param2 + param3 + param4);
|
|
172
110
|
return hash.digest('hex');
|
|
173
111
|
}
|
|
174
|
-
/**
|
|
175
|
-
* Retrieves the features for a specific behavior.
|
|
176
|
-
*
|
|
177
|
-
* @param {Endpoint} endpoint - The endpoint to retrieve the features from.
|
|
178
|
-
* @param {string} behavior - The behavior to retrieve the features for.
|
|
179
|
-
*
|
|
180
|
-
* @returns {Record<string, boolean | undefined>} The features for the specified behavior.
|
|
181
|
-
*
|
|
182
|
-
* @remarks Use with:
|
|
183
|
-
* ```typescript
|
|
184
|
-
* expect(featuresFor(device, 'powerSource').wired).toBe(true);
|
|
185
|
-
* ```
|
|
186
|
-
*/
|
|
187
112
|
export function featuresFor(endpoint, behavior) {
|
|
188
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
189
113
|
return endpoint.behaviors.supported[lowercaseFirstLetter(behavior)]['cluster']['supportedFeatures'];
|
|
190
114
|
}
|
|
191
|
-
/**
|
|
192
|
-
* Maps a list of ClusterId to Behavior.Type for server clusters.
|
|
193
|
-
*
|
|
194
|
-
* @param {ClusterId[]} clusterServerList - The list of ClusterId to map.
|
|
195
|
-
* @returns {Behavior.Type[]} An array of Behavior.Type corresponding to the ClusterId in the server list.
|
|
196
|
-
*/
|
|
197
115
|
export function getBehaviourTypesFromClusterServerIds(clusterServerList) {
|
|
198
|
-
// Map Server ClusterId to Behavior.Type
|
|
199
116
|
const behaviorTypes = [];
|
|
200
117
|
clusterServerList.forEach((clusterId) => {
|
|
201
118
|
behaviorTypes.push(getBehaviourTypeFromClusterServerId(clusterId));
|
|
202
119
|
});
|
|
203
120
|
return behaviorTypes;
|
|
204
121
|
}
|
|
205
|
-
/**
|
|
206
|
-
* Maps a list of ClusterId to Behavior.Type for client clusters.
|
|
207
|
-
*
|
|
208
|
-
* @param {ClusterId[]} clusterClientList - The list of ClusterId to map.
|
|
209
|
-
* @returns {Behavior.Type[]} An array of Behavior.Type corresponding to the ClusterId in the client list.
|
|
210
|
-
*/
|
|
211
122
|
export function getBehaviourTypesFromClusterClientIds(clusterClientList) {
|
|
212
|
-
// Map Client ClusterId to Behavior.Type
|
|
213
123
|
const behaviorTypes = [];
|
|
214
124
|
clusterClientList.forEach((_clusterId) => {
|
|
215
|
-
// behaviorTypes.push(getBehaviourTypeFromClusterClientId(clusterId));
|
|
216
125
|
});
|
|
217
126
|
return behaviorTypes;
|
|
218
127
|
}
|
|
219
|
-
/**
|
|
220
|
-
* Maps a ClusterId to a Behavior.Type for server clusters.
|
|
221
|
-
*
|
|
222
|
-
* @param {ClusterId} clusterId - The ClusterId to map.
|
|
223
|
-
* @returns {Behavior.Type} The corresponding Behavior.Type for the given ClusterId.
|
|
224
|
-
*/
|
|
225
128
|
export function getBehaviourTypeFromClusterServerId(clusterId) {
|
|
226
|
-
// Map ClusterId to Server Behavior.Type
|
|
227
129
|
if (clusterId === PowerSource.Cluster.id)
|
|
228
130
|
return PowerSourceServer.with(PowerSource.Feature.Wired);
|
|
229
131
|
if (clusterId === UserLabel.Cluster.id)
|
|
@@ -314,22 +216,8 @@ export function getBehaviourTypeFromClusterServerId(clusterId) {
|
|
|
314
216
|
return MatterbridgeDeviceEnergyManagementModeServer;
|
|
315
217
|
return MatterbridgeIdentifyServer;
|
|
316
218
|
}
|
|
317
|
-
/**
|
|
318
|
-
* Maps a ClusterId to a Behavior.Type for client clusters.
|
|
319
|
-
*
|
|
320
|
-
* @param {ClusterId} _clusterId - The ClusterId to map.
|
|
321
|
-
*/
|
|
322
219
|
export function getBehaviourTypeFromClusterClientId(_clusterId) {
|
|
323
|
-
// Map ClusterId to Client Behavior.Type
|
|
324
|
-
// return IdentifyClient;
|
|
325
220
|
}
|
|
326
|
-
/**
|
|
327
|
-
* Retrieves the Behavior.Type for a given cluster from the endpoint's supported behaviors.
|
|
328
|
-
*
|
|
329
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to retrieve the behavior from.
|
|
330
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to retrieve the behavior for.
|
|
331
|
-
* @returns {Behavior.Type | undefined} The Behavior.Type for the given cluster, or undefined if not found.
|
|
332
|
-
*/
|
|
333
221
|
export function getBehavior(endpoint, cluster) {
|
|
334
222
|
let behavior;
|
|
335
223
|
if (typeof cluster === 'string') {
|
|
@@ -346,18 +234,6 @@ export function getBehavior(endpoint, cluster) {
|
|
|
346
234
|
}
|
|
347
235
|
return behavior;
|
|
348
236
|
}
|
|
349
|
-
/**
|
|
350
|
-
* Invokes a command on the specified behavior of the endpoint. Used ONLY in Jest tests.
|
|
351
|
-
*
|
|
352
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to invoke the command on.
|
|
353
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to invoke the command on.
|
|
354
|
-
* @param {keyof MatterbridgeEndpointCommands} command - The command to invoke.
|
|
355
|
-
* @param {Record<string, boolean | number | bigint | string | object | null>} [params] - The parameters to pass to the command.
|
|
356
|
-
*
|
|
357
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the command was invoked successfully, false otherwise.
|
|
358
|
-
*
|
|
359
|
-
* @deprecated Used ONLY in Jest tests.
|
|
360
|
-
*/
|
|
361
237
|
export async function invokeBehaviorCommand(endpoint, cluster, command, params) {
|
|
362
238
|
const behaviorId = getBehavior(endpoint, cluster)?.id;
|
|
363
239
|
if (!behaviorId) {
|
|
@@ -365,7 +241,6 @@ export async function invokeBehaviorCommand(endpoint, cluster, command, params)
|
|
|
365
241
|
return false;
|
|
366
242
|
}
|
|
367
243
|
await endpoint.act((agent) => {
|
|
368
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
369
244
|
const behavior = agent[behaviorId];
|
|
370
245
|
if (!(command in behavior) || typeof behavior[command] !== 'function') {
|
|
371
246
|
endpoint.log?.error(`invokeBehaviorCommand error: command ${hk}${command}${er} not found on agent for endpoint ${or}${endpoint.maybeId}${er}:${or}${endpoint.maybeNumber}${er}`);
|
|
@@ -375,19 +250,6 @@ export async function invokeBehaviorCommand(endpoint, cluster, command, params)
|
|
|
375
250
|
});
|
|
376
251
|
return true;
|
|
377
252
|
}
|
|
378
|
-
/**
|
|
379
|
-
* Invokes the subscription handler on the specified cluster and attribute of the endpoint. Used ONLY in Jest tests.
|
|
380
|
-
*
|
|
381
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to invoke the subscription handler on.
|
|
382
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to invoke the subscription handler on.
|
|
383
|
-
* @param {string} attribute - The attribute to invoke the subscription handler on.
|
|
384
|
-
* @param {unknown} newValue - The new value of the attribute.
|
|
385
|
-
* @param {unknown} oldValue - The old value of the attribute.
|
|
386
|
-
*
|
|
387
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the subscription handler was invoked successfully, false otherwise.
|
|
388
|
-
*
|
|
389
|
-
* @deprecated Used ONLY in Jest tests.
|
|
390
|
-
*/
|
|
391
253
|
export async function invokeSubscribeHandler(endpoint, cluster, attribute, newValue, oldValue) {
|
|
392
254
|
const event = attribute + '$Changed';
|
|
393
255
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
@@ -404,17 +266,9 @@ export async function invokeSubscribeHandler(endpoint, cluster, attribute, newVa
|
|
|
404
266
|
endpoint.log.error(`invokeSubscribeHandler ${hk}${event}${er} error: cluster ${clusterName} not found on endpoint ${or}${endpoint.id}${er}:${or}${endpoint.number}${er}`);
|
|
405
267
|
return false;
|
|
406
268
|
}
|
|
407
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
408
|
-
// @ts-ignore
|
|
409
269
|
await endpoint.act((agent) => agent[clusterName].events[event].emit(newValue, oldValue, { ...agent.context, offline: false }));
|
|
410
270
|
return true;
|
|
411
271
|
}
|
|
412
|
-
/**
|
|
413
|
-
* Adds required cluster servers to the specified endpoint based on the device types.
|
|
414
|
-
*
|
|
415
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the required cluster servers to.
|
|
416
|
-
* @returns {void}
|
|
417
|
-
*/
|
|
418
272
|
export function addRequiredClusterServers(endpoint) {
|
|
419
273
|
const requiredServerList = [];
|
|
420
274
|
endpoint.log.debug(`addRequiredClusterServers for ${CYAN}${endpoint.maybeId}${db}`);
|
|
@@ -429,12 +283,6 @@ export function addRequiredClusterServers(endpoint) {
|
|
|
429
283
|
});
|
|
430
284
|
addClusterServers(endpoint, requiredServerList);
|
|
431
285
|
}
|
|
432
|
-
/**
|
|
433
|
-
* Adds optional cluster servers to the specified endpoint based on the device types.
|
|
434
|
-
*
|
|
435
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the optional cluster servers to.
|
|
436
|
-
* @returns {void}
|
|
437
|
-
*/
|
|
438
286
|
export function addOptionalClusterServers(endpoint) {
|
|
439
287
|
const optionalServerList = [];
|
|
440
288
|
endpoint.log.debug(`addOptionalClusterServers for ${CYAN}${endpoint.maybeId}${db}`);
|
|
@@ -449,12 +297,6 @@ export function addOptionalClusterServers(endpoint) {
|
|
|
449
297
|
});
|
|
450
298
|
addClusterServers(endpoint, optionalServerList);
|
|
451
299
|
}
|
|
452
|
-
/**
|
|
453
|
-
* Adds cluster servers to the specified endpoint based on the provided server list.
|
|
454
|
-
*
|
|
455
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
|
|
456
|
-
* @param {ClusterId[]} serverList - The list of cluster IDs to add.
|
|
457
|
-
*/
|
|
458
300
|
export function addClusterServers(endpoint, serverList) {
|
|
459
301
|
if (serverList.includes(PowerSource.Cluster.id))
|
|
460
302
|
endpoint.createDefaultPowerSourceWiredClusterServer();
|
|
@@ -535,13 +377,6 @@ export function addClusterServers(endpoint, serverList) {
|
|
|
535
377
|
if (serverList.includes(DeviceEnergyManagementMode.Cluster.id))
|
|
536
378
|
endpoint.createDefaultDeviceEnergyManagementModeClusterServer();
|
|
537
379
|
}
|
|
538
|
-
/**
|
|
539
|
-
* Adds a fixed label to the FixedLabel cluster. The FixedLabel cluster is created if it does not exist.
|
|
540
|
-
*
|
|
541
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
|
|
542
|
-
* @param {string} label - The label to add. Max 16 characters.
|
|
543
|
-
* @param {string} value - The value of the label. Max 16 characters.
|
|
544
|
-
*/
|
|
545
380
|
export async function addFixedLabel(endpoint, label, value) {
|
|
546
381
|
if (!endpoint.hasClusterServer(FixedLabel.Cluster.id)) {
|
|
547
382
|
endpoint.log.debug(`addFixedLabel: add cluster ${hk}FixedLabel${db}:${hk}fixedLabel${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
|
|
@@ -558,13 +393,6 @@ export async function addFixedLabel(endpoint, label, value) {
|
|
|
558
393
|
await endpoint.setAttribute(FixedLabel.Cluster.id, 'labelList', labelList, endpoint.log);
|
|
559
394
|
}
|
|
560
395
|
}
|
|
561
|
-
/**
|
|
562
|
-
* Adds a user label to the UserLabel cluster. The UserLabel cluster is created if it does not exist.
|
|
563
|
-
*
|
|
564
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
|
|
565
|
-
* @param {string} label - The label to add. Max 16 characters.
|
|
566
|
-
* @param {string} value - The value of the label. Max 16 characters.
|
|
567
|
-
*/
|
|
568
396
|
export async function addUserLabel(endpoint, label, value) {
|
|
569
397
|
if (!endpoint.hasClusterServer(UserLabel.Cluster.id)) {
|
|
570
398
|
endpoint.log.debug(`addUserLabel: add cluster ${hk}UserLabel${db}:${hk}userLabel${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
|
|
@@ -581,48 +409,16 @@ export async function addUserLabel(endpoint, label, value) {
|
|
|
581
409
|
await endpoint.setAttribute(UserLabel.Cluster.id, 'labelList', labelList, endpoint.log);
|
|
582
410
|
}
|
|
583
411
|
}
|
|
584
|
-
/**
|
|
585
|
-
* Returns the options for a given behavior type.
|
|
586
|
-
*
|
|
587
|
-
* @param {T} type - The behavior type.
|
|
588
|
-
* @param {Behavior.Options<T>} options - The options for the behavior type.
|
|
589
|
-
* @returns {Behavior.Options<T>} The options for the behavior type.
|
|
590
|
-
*/
|
|
591
412
|
export function optionsFor(type, options) {
|
|
592
413
|
return options;
|
|
593
414
|
}
|
|
594
|
-
/**
|
|
595
|
-
* Retrieves the cluster ID.
|
|
596
|
-
*
|
|
597
|
-
* @param {Endpoint} endpoint - The endpoint to retrieve the cluster ID from.
|
|
598
|
-
* @param {ClusterId} cluster - The ID of the cluster.
|
|
599
|
-
* @returns {number | undefined} The ID of the cluster.
|
|
600
|
-
*/
|
|
601
415
|
export function getClusterId(endpoint, cluster) {
|
|
602
416
|
return endpoint.behaviors.supported[lowercaseFirstLetter(cluster)]?.schema?.id;
|
|
603
417
|
}
|
|
604
|
-
/**
|
|
605
|
-
* Retrieves the ID of an attribute from a cluster behavior.
|
|
606
|
-
*
|
|
607
|
-
* @param {Endpoint} endpoint - The endpoint to retrieve the attribute ID from.
|
|
608
|
-
* @param {string} cluster - The name of the cluster.
|
|
609
|
-
* @param {string} attribute - The name of the attribute.
|
|
610
|
-
* @returns {number | undefined} The ID of the attribute, or undefined if not found.
|
|
611
|
-
*/
|
|
612
418
|
export function getAttributeId(endpoint, cluster, attribute) {
|
|
613
419
|
const clusterBehavior = endpoint.behaviors.supported[lowercaseFirstLetter(cluster)];
|
|
614
420
|
return clusterBehavior?.cluster?.attributes[lowercaseFirstLetter(attribute)]?.id;
|
|
615
421
|
}
|
|
616
|
-
/**
|
|
617
|
-
* Retrieves the value of the provided attribute from the given cluster.
|
|
618
|
-
*
|
|
619
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to retrieve the attribute from.
|
|
620
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to retrieve the attribute from.
|
|
621
|
-
* @param {string} attribute - The name of the attribute to retrieve.
|
|
622
|
-
* @param {AnsiLogger} [log] - (Optional) The logger to use for logging the retrieve. Errors are logged to the endpoint logger.
|
|
623
|
-
* @returns {any} The value of the attribute, or undefined if the attribute is not found.
|
|
624
|
-
*/
|
|
625
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
626
422
|
export function getAttribute(endpoint, cluster, attribute, log) {
|
|
627
423
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
628
424
|
if (!clusterName) {
|
|
@@ -645,16 +441,6 @@ export function getAttribute(endpoint, cluster, attribute, log) {
|
|
|
645
441
|
log?.info(`${db}Get endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} attribute ${hk}${capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db} value ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
|
|
646
442
|
return value;
|
|
647
443
|
}
|
|
648
|
-
/**
|
|
649
|
-
* Sets the value of an attribute on a cluster server.
|
|
650
|
-
*
|
|
651
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to set the attribute on.
|
|
652
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to set the attribute on.
|
|
653
|
-
* @param {string} attribute - The name of the attribute.
|
|
654
|
-
* @param {boolean | number | bigint | string | object | null} value - The value to set for the attribute.
|
|
655
|
-
* @param {AnsiLogger} [log] - (Optional) The logger to use for logging the set. Errors are logged to the endpoint logger.
|
|
656
|
-
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
|
|
657
|
-
*/
|
|
658
444
|
export async function setAttribute(endpoint, cluster, attribute, value, log) {
|
|
659
445
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
660
446
|
if (!clusterName) {
|
|
@@ -680,16 +466,6 @@ export async function setAttribute(endpoint, cluster, attribute, value, log) {
|
|
|
680
466
|
`to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
|
|
681
467
|
return true;
|
|
682
468
|
}
|
|
683
|
-
/**
|
|
684
|
-
* Sets the value of an attribute on a cluster server.
|
|
685
|
-
*
|
|
686
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to update the attribute on.
|
|
687
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to update the attribute on.
|
|
688
|
-
* @param {string} attribute - The name of the attribute.
|
|
689
|
-
* @param {boolean | number | bigint | string | object | null} value - The value to set for the attribute.
|
|
690
|
-
* @param {AnsiLogger} [log] - (Optional) The logger to use for logging the update. Errors are logged to the endpoint logger.
|
|
691
|
-
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
|
|
692
|
-
*/
|
|
693
469
|
export async function updateAttribute(endpoint, cluster, attribute, value, log) {
|
|
694
470
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
695
471
|
if (!clusterName) {
|
|
@@ -720,24 +496,7 @@ export async function updateAttribute(endpoint, cluster, attribute, value, log)
|
|
|
720
496
|
`to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
|
|
721
497
|
return true;
|
|
722
498
|
}
|
|
723
|
-
|
|
724
|
-
* Subscribes to the provided attribute on a cluster.
|
|
725
|
-
*
|
|
726
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to subscribe the attribute to.
|
|
727
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to subscribe the attribute to.
|
|
728
|
-
* @param {string} attribute - The name of the attribute to subscribe to.
|
|
729
|
-
* @param {(newValue: any, oldValue: any, context: ActionContext) => void} listener - A callback function that will be called when the attribute value changes. When context.offline === true then the change is locally generated and not from the controller.
|
|
730
|
-
* @param {AnsiLogger} [log] - Optional logger for logging errors and information.
|
|
731
|
-
* @returns {boolean} - A boolean indicating whether the subscription was successful.
|
|
732
|
-
*
|
|
733
|
-
* @remarks The listener function (cannot be async) will receive three parameters:
|
|
734
|
-
* - `newValue`: The new value of the attribute.
|
|
735
|
-
* - `oldValue`: The old value of the attribute.
|
|
736
|
-
* - `context`: The action context, which includes information about the action that triggered the change. When context.offline === true then the change is locally generated and not from the controller.
|
|
737
|
-
*/
|
|
738
|
-
export async function subscribeAttribute(endpoint, cluster, attribute,
|
|
739
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
740
|
-
listener, log) {
|
|
499
|
+
export async function subscribeAttribute(endpoint, cluster, attribute, listener, log) {
|
|
741
500
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
742
501
|
if (!clusterName) {
|
|
743
502
|
endpoint.log.error(`subscribeAttribute ${hk}${attribute}${er} error: cluster not found on endpoint ${or}${endpoint.maybeId}${er}:${or}${endpoint.maybeNumber}${er}`);
|
|
@@ -747,7 +506,6 @@ listener, log) {
|
|
|
747
506
|
endpoint.log.debug(`subscribeAttribute ${hk}${clusterName}.${attribute}${db}: Endpoint ${or}${endpoint.maybeId}${db}:${or}${endpoint.maybeNumber}${db} is in the ${BLUE}${endpoint.construction.status}${db} state`);
|
|
748
507
|
await endpoint.construction.ready;
|
|
749
508
|
}
|
|
750
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
751
509
|
const events = endpoint.events;
|
|
752
510
|
attribute = lowercaseFirstLetter(attribute) + '$Changed';
|
|
753
511
|
if (!(clusterName in events) || !(attribute in events[clusterName])) {
|
|
@@ -758,17 +516,6 @@ listener, log) {
|
|
|
758
516
|
log?.info(`${db}Subscribed endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} attribute ${hk}${capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db}`);
|
|
759
517
|
return true;
|
|
760
518
|
}
|
|
761
|
-
/**
|
|
762
|
-
* Triggers an event on the specified cluster.
|
|
763
|
-
*
|
|
764
|
-
* @param {MatterbridgeEndpoint} endpoint - The endpoint to trigger the event on.
|
|
765
|
-
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The ID of the cluster.
|
|
766
|
-
* @param {string} event - The name of the event to trigger.
|
|
767
|
-
* @param {Record<string, boolean | number | bigint | string | object | undefined | null>} payload - The payload to pass to the event.
|
|
768
|
-
* @param {AnsiLogger} [log] - Optional logger for logging information.
|
|
769
|
-
*
|
|
770
|
-
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the event was successfully triggered.
|
|
771
|
-
*/
|
|
772
519
|
export async function triggerEvent(endpoint, cluster, event, payload, log) {
|
|
773
520
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
774
521
|
if (!clusterName) {
|
|
@@ -779,32 +526,15 @@ export async function triggerEvent(endpoint, cluster, event, payload, log) {
|
|
|
779
526
|
endpoint.log.error(`triggerEvent ${hk}${clusterName}.${event}${er} error: Endpoint ${or}${endpoint.maybeId}${er}:${or}${endpoint.maybeNumber}${er} is in the ${BLUE}${endpoint.construction.status}${er} state`);
|
|
780
527
|
return false;
|
|
781
528
|
}
|
|
782
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
783
529
|
const events = endpoint.events;
|
|
784
530
|
if (!(clusterName in events) || !(event in events[clusterName])) {
|
|
785
531
|
endpoint.log.error(`triggerEvent ${hk}${event}${er} error: cluster ${clusterName} not found on endpoint ${or}${endpoint.id}${er}:${or}${endpoint.number}${er}`);
|
|
786
532
|
return false;
|
|
787
533
|
}
|
|
788
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
789
|
-
// @ts-ignore
|
|
790
534
|
await endpoint.act((agent) => agent[clusterName].events[event].emit(payload, agent.context));
|
|
791
535
|
log?.info(`${db}Trigger event ${hk}${capitalizeFirstLetter(clusterName)}${db}.${hk}${event}${db} with ${debugStringify(payload)}${db} on endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} `);
|
|
792
536
|
return true;
|
|
793
537
|
}
|
|
794
|
-
/**
|
|
795
|
-
* Get the default OperationalState Cluster Server.
|
|
796
|
-
*
|
|
797
|
-
* @param {OperationalState.OperationalStateEnum} operationalState - The initial operational state id.
|
|
798
|
-
*
|
|
799
|
-
* @returns {Behavior.Options<MatterbridgeOperationalStateServer>} - The default options for the OperationalState cluster server.
|
|
800
|
-
*
|
|
801
|
-
* @remarks
|
|
802
|
-
* This method adds a cluster server with a default operational state configuration:
|
|
803
|
-
* - { operationalStateId: OperationalState.OperationalStateEnum.Stopped, operationalStateLabel: 'Stopped' },
|
|
804
|
-
* - { operationalStateId: OperationalState.OperationalStateEnum.Running, operationalStateLabel: 'Running' },
|
|
805
|
-
* - { operationalStateId: OperationalState.OperationalStateEnum.Paused, operationalStateLabel: 'Paused' },
|
|
806
|
-
* - { operationalStateId: OperationalState.OperationalStateEnum.Error, operationalStateLabel: 'Error' },
|
|
807
|
-
*/
|
|
808
538
|
export function getDefaultOperationalStateClusterServer(operationalState = OperationalState.OperationalStateEnum.Stopped) {
|
|
809
539
|
return optionsFor(MatterbridgeOperationalStateServer, {
|
|
810
540
|
phaseList: [],
|
|
@@ -820,14 +550,6 @@ export function getDefaultOperationalStateClusterServer(operationalState = Opera
|
|
|
820
550
|
operationalError: { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' },
|
|
821
551
|
});
|
|
822
552
|
}
|
|
823
|
-
/**
|
|
824
|
-
* Get the default TemperatureMeasurement cluster server options.
|
|
825
|
-
*
|
|
826
|
-
* @param {number | null} measuredValue - The measured value of the temperature x 100.
|
|
827
|
-
* @param {number | null} minMeasuredValue - The minimum measured value of the temperature x 100.
|
|
828
|
-
* @param {number | null} maxMeasuredValue - The maximum measured value of the temperature x 100.
|
|
829
|
-
* @returns {Behavior.Options<MatterbridgeTemperatureMeasurementServer>} - The default options for the TemperatureMeasurement cluster server.
|
|
830
|
-
*/
|
|
831
553
|
export function getDefaultTemperatureMeasurementClusterServer(measuredValue = null, minMeasuredValue = null, maxMeasuredValue = null) {
|
|
832
554
|
return optionsFor(TemperatureMeasurementServer, {
|
|
833
555
|
measuredValue,
|
|
@@ -836,14 +558,6 @@ export function getDefaultTemperatureMeasurementClusterServer(measuredValue = nu
|
|
|
836
558
|
tolerance: 0,
|
|
837
559
|
});
|
|
838
560
|
}
|
|
839
|
-
/**
|
|
840
|
-
* Get the default RelativeHumidityMeasurement cluster server options.
|
|
841
|
-
*
|
|
842
|
-
* @param {number | null} measuredValue - The measured value of the relative humidity x 100.
|
|
843
|
-
* @param {number | null} minMeasuredValue - The minimum measured value of the relative humidity x 100.
|
|
844
|
-
* @param {number | null} maxMeasuredValue - The maximum measured value of the relative humidity x 100.
|
|
845
|
-
* @returns {Behavior.Options<MatterbridgeRelativeHumidityMeasurementServer>} - The default options for the RelativeHumidityMeasurement cluster server.
|
|
846
|
-
*/
|
|
847
561
|
export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue = null, minMeasuredValue = null, maxMeasuredValue = null) {
|
|
848
562
|
return optionsFor(RelativeHumidityMeasurementServer, {
|
|
849
563
|
measuredValue,
|
|
@@ -852,14 +566,6 @@ export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue
|
|
|
852
566
|
tolerance: 0,
|
|
853
567
|
});
|
|
854
568
|
}
|
|
855
|
-
/**
|
|
856
|
-
* Get the default PressureMeasurement cluster server options.
|
|
857
|
-
*
|
|
858
|
-
* @param {number | null} measuredValue - The measured value for the pressure in kPa x 10.
|
|
859
|
-
* @param {number | null} minMeasuredValue - The minimum measured value for the pressure in kPa x 10.
|
|
860
|
-
* @param {number | null} maxMeasuredValue - The maximum measured value for the pressure in kPa x 10.
|
|
861
|
-
* @returns {Behavior.Options<MatterbridgePressureMeasurementServer>} - The default options for the PressureMeasurement cluster server.
|
|
862
|
-
*/
|
|
863
569
|
export function getDefaultPressureMeasurementClusterServer(measuredValue = null, minMeasuredValue = null, maxMeasuredValue = null) {
|
|
864
570
|
return optionsFor(PressureMeasurementServer, {
|
|
865
571
|
measuredValue,
|
|
@@ -868,22 +574,6 @@ export function getDefaultPressureMeasurementClusterServer(measuredValue = null,
|
|
|
868
574
|
tolerance: 0,
|
|
869
575
|
});
|
|
870
576
|
}
|
|
871
|
-
/**
|
|
872
|
-
* Get the default IlluminanceMeasurement cluster server options.
|
|
873
|
-
*
|
|
874
|
-
* @param {number | null} measuredValue - The measured value of illuminance.
|
|
875
|
-
* @param {number | null} minMeasuredValue - The minimum measured value of illuminance.
|
|
876
|
-
* @param {number | null} maxMeasuredValue - The maximum measured value of illuminance.
|
|
877
|
-
*
|
|
878
|
-
* @returns {Behavior.Options<MatterbridgeIlluminanceMeasurementServer>} - The default options for the IlluminanceMeasurement cluster server.
|
|
879
|
-
*
|
|
880
|
-
* @remarks The default value for the illuminance measurement is null.
|
|
881
|
-
* This attribute SHALL indicate the illuminance in Lux (symbol lx) as follows:
|
|
882
|
-
* • MeasuredValue = 10,000 x log10(illuminance) + 1,
|
|
883
|
-
* where 1 lx <= illuminance <= 3.576 Mlx, corresponding to a MeasuredValue in the range 1 to 0xFFFE.
|
|
884
|
-
* • 0 indicates a value of illuminance that is too low to be measured
|
|
885
|
-
* • null indicates that the illuminance measurement is invalid.
|
|
886
|
-
*/
|
|
887
577
|
export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = null, minMeasuredValue = null, maxMeasuredValue = null) {
|
|
888
578
|
return optionsFor(IlluminanceMeasurementServer, {
|
|
889
579
|
measuredValue,
|
|
@@ -892,14 +582,6 @@ export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = nu
|
|
|
892
582
|
tolerance: 0,
|
|
893
583
|
});
|
|
894
584
|
}
|
|
895
|
-
/**
|
|
896
|
-
* Get the default FlowMeasurement cluster server options.
|
|
897
|
-
*
|
|
898
|
-
* @param {number | null} measuredValue - The measured value of the flow in 10 x m3/h.
|
|
899
|
-
* @param {number | null} minMeasuredValue - The minimum measured value of the flow in 10 x m3/h.
|
|
900
|
-
* @param {number | null} maxMeasuredValue - The maximum measured value of the flow in 10 x m3/h.
|
|
901
|
-
* @returns {Behavior.Options<MatterbridgeFlowMeasurementServer>} - The default options for the FlowMeasurement cluster server.
|
|
902
|
-
*/
|
|
903
585
|
export function getDefaultFlowMeasurementClusterServer(measuredValue = null, minMeasuredValue = null, maxMeasuredValue = null) {
|
|
904
586
|
return optionsFor(FlowMeasurementServer, {
|
|
905
587
|
measuredValue,
|
|
@@ -908,20 +590,6 @@ export function getDefaultFlowMeasurementClusterServer(measuredValue = null, min
|
|
|
908
590
|
tolerance: 0,
|
|
909
591
|
});
|
|
910
592
|
}
|
|
911
|
-
/**
|
|
912
|
-
* Get the default OccupancySensing cluster server options.
|
|
913
|
-
*
|
|
914
|
-
* @param {boolean} occupied - A boolean indicating whether the occupancy is occupied or not. Default is false.
|
|
915
|
-
* @param {number} holdTime - The hold time in seconds. Default is 30.
|
|
916
|
-
* @param {number} holdTimeMin - The minimum hold time in seconds. Default is 1.
|
|
917
|
-
* @param {number} holdTimeMax - The maximum hold time in seconds. Default is 300.
|
|
918
|
-
* @returns {Behavior.Options<MatterbridgeOccupancySensingServer>} - The default options for the OccupancySensing cluster server.
|
|
919
|
-
*
|
|
920
|
-
* @remarks The default value for the occupancy sensor type is PIR.
|
|
921
|
-
* Servers SHALL set these attributes for backward compatibility with clients implementing a cluster revision <= 4 as
|
|
922
|
-
* described in OccupancySensorType and OccupancySensorTypeBitmap Attributes.
|
|
923
|
-
* This replaces the 9 legacy attributes PIROccupiedToUnoccupiedDelay through PhysicalContactUnoccupiedToOccupiedThreshold.
|
|
924
|
-
*/
|
|
925
593
|
export function getDefaultOccupancySensingClusterServer(occupied = false, holdTime = 30, holdTimeMin = 1, holdTimeMax = 300) {
|
|
926
594
|
return optionsFor(OccupancySensingServer.with(OccupancySensing.Feature.PassiveInfrared), {
|
|
927
595
|
occupancy: { occupied },
|
|
@@ -933,13 +601,6 @@ export function getDefaultOccupancySensingClusterServer(occupied = false, holdTi
|
|
|
933
601
|
holdTimeLimits: { holdTimeMin, holdTimeMax, holdTimeDefault: holdTime },
|
|
934
602
|
});
|
|
935
603
|
}
|
|
936
|
-
/**
|
|
937
|
-
* Get the default Electrical Energy Measurement Cluster Server options with features ImportedEnergy, ExportedEnergy, and CumulativeEnergy.
|
|
938
|
-
*
|
|
939
|
-
* @param {number} energyImported - The total consumption value in mW/h.
|
|
940
|
-
* @param {number} energyExported - The total production value in mW/h.
|
|
941
|
-
* @returns {Behavior.Options<ElectricalEnergyMeasurementServer>} - The default options for the Electrical Energy Measurement Cluster Server.
|
|
942
|
-
*/
|
|
943
604
|
export function getDefaultElectricalEnergyMeasurementClusterServer(energyImported = null, energyExported = null) {
|
|
944
605
|
return optionsFor(ElectricalEnergyMeasurementServer.with(ElectricalEnergyMeasurement.Feature.ImportedEnergy, ElectricalEnergyMeasurement.Feature.ExportedEnergy, ElectricalEnergyMeasurement.Feature.CumulativeEnergy), {
|
|
945
606
|
accuracy: {
|
|
@@ -954,15 +615,6 @@ export function getDefaultElectricalEnergyMeasurementClusterServer(energyImporte
|
|
|
954
615
|
cumulativeEnergyExported: energyExported !== null && energyExported >= 0 ? { energy: energyExported } : null,
|
|
955
616
|
});
|
|
956
617
|
}
|
|
957
|
-
/**
|
|
958
|
-
* Get the default Electrical Power Measurement Cluster Server options with features AlternatingCurrent.
|
|
959
|
-
*
|
|
960
|
-
* @param {number} voltage - The voltage value in millivolts.
|
|
961
|
-
* @param {number} current - The current value in milliamperes.
|
|
962
|
-
* @param {number} power - The power value in milliwatts.
|
|
963
|
-
* @param {number} frequency - The frequency value in millihertz.
|
|
964
|
-
* @returns {Behavior.Options<ElectricalPowerMeasurementServer>} - The default options for the Electrical Power Measurement Cluster Server.
|
|
965
|
-
*/
|
|
966
618
|
export function getDefaultElectricalPowerMeasurementClusterServer(voltage = null, current = null, power = null, frequency = null) {
|
|
967
619
|
return optionsFor(ElectricalPowerMeasurementServer.with(ElectricalPowerMeasurement.Feature.AlternatingCurrent), {
|
|
968
620
|
powerMode: ElectricalPowerMeasurement.PowerMode.Ac,
|
|
@@ -1003,15 +655,6 @@ export function getDefaultElectricalPowerMeasurementClusterServer(voltage = null
|
|
|
1003
655
|
frequency: frequency,
|
|
1004
656
|
});
|
|
1005
657
|
}
|
|
1006
|
-
/**
|
|
1007
|
-
* Get the default Electrical Apparent Power Measurement Cluster Server with features AlternatingCurrent.
|
|
1008
|
-
*
|
|
1009
|
-
* @param {number} voltage - The voltage value in millivolts.
|
|
1010
|
-
* @param {number} apparentCurrent - The current value in milliamperes.
|
|
1011
|
-
* @param {number} apparentPower - The apparent power value in millivoltamperes.
|
|
1012
|
-
* @param {number} frequency - The frequency value in millihertz.
|
|
1013
|
-
* @returns {Behavior.Options<ElectricalPowerMeasurementServer>} - The default options for the Electrical Apparent Power Measurement Cluster Server.
|
|
1014
|
-
*/
|
|
1015
658
|
export function getApparentElectricalPowerMeasurementClusterServer(voltage = null, apparentCurrent = null, apparentPower = null, frequency = null) {
|
|
1016
659
|
return optionsFor(ElectricalPowerMeasurementServer.with(ElectricalPowerMeasurement.Feature.AlternatingCurrent), {
|
|
1017
660
|
powerMode: ElectricalPowerMeasurement.PowerMode.Ac,
|
|
@@ -1052,4 +695,3 @@ export function getApparentElectricalPowerMeasurementClusterServer(voltage = nul
|
|
|
1052
695
|
frequency: frequency,
|
|
1053
696
|
});
|
|
1054
697
|
}
|
|
1055
|
-
//# sourceMappingURL=matterbridgeEndpointHelpers.js.map
|