matterbridge 3.5.0-dev-20260117-88ddbe4 → 3.5.0
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 +130 -122
- package/README.md +14 -14
- package/dist/broadcastServer.d.ts +115 -0
- package/dist/broadcastServer.d.ts.map +1 -0
- package/dist/broadcastServer.js +117 -0
- package/dist/broadcastServer.js.map +1 -0
- package/dist/broadcastServerTypes.d.ts +43 -0
- package/dist/broadcastServerTypes.d.ts.map +1 -0
- package/dist/broadcastServerTypes.js +24 -0
- package/dist/broadcastServerTypes.js.map +1 -0
- package/dist/cli.d.ts +24 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +98 -1
- package/dist/cli.js.map +1 -0
- package/dist/cliEmitter.d.ts +36 -0
- package/dist/cliEmitter.d.ts.map +1 -0
- package/dist/cliEmitter.js +37 -0
- package/dist/cliEmitter.js.map +1 -0
- package/dist/cliHistory.d.ts +42 -0
- package/dist/cliHistory.d.ts.map +1 -0
- package/dist/cliHistory.js +38 -0
- package/dist/cliHistory.js.map +1 -0
- package/dist/clusters/export.d.ts +1 -0
- package/dist/clusters/export.d.ts.map +1 -0
- package/dist/clusters/export.js +2 -0
- package/dist/clusters/export.js.map +1 -0
- package/dist/deviceManager.d.ts +108 -0
- package/dist/deviceManager.d.ts.map +1 -0
- package/dist/deviceManager.js +113 -1
- package/dist/deviceManager.js.map +1 -0
- package/dist/devices/airConditioner.d.ts +75 -0
- package/dist/devices/airConditioner.d.ts.map +1 -0
- package/dist/devices/airConditioner.js +57 -0
- package/dist/devices/airConditioner.js.map +1 -0
- package/dist/devices/batteryStorage.d.ts +43 -0
- package/dist/devices/batteryStorage.d.ts.map +1 -0
- package/dist/devices/batteryStorage.js +48 -1
- package/dist/devices/batteryStorage.js.map +1 -0
- package/dist/devices/cooktop.d.ts +55 -0
- package/dist/devices/cooktop.d.ts.map +1 -0
- package/dist/devices/cooktop.js +56 -0
- package/dist/devices/cooktop.js.map +1 -0
- package/dist/devices/dishwasher.d.ts +55 -0
- package/dist/devices/dishwasher.d.ts.map +1 -0
- package/dist/devices/dishwasher.js +57 -0
- package/dist/devices/dishwasher.js.map +1 -0
- package/dist/devices/evse.d.ts +57 -0
- package/dist/devices/evse.d.ts.map +1 -0
- package/dist/devices/evse.js +74 -10
- package/dist/devices/evse.js.map +1 -0
- package/dist/devices/export.d.ts +1 -0
- package/dist/devices/export.d.ts.map +1 -0
- package/dist/devices/export.js +5 -0
- package/dist/devices/export.js.map +1 -0
- package/dist/devices/extractorHood.d.ts +41 -0
- package/dist/devices/extractorHood.d.ts.map +1 -0
- package/dist/devices/extractorHood.js +43 -0
- package/dist/devices/extractorHood.js.map +1 -0
- package/dist/devices/heatPump.d.ts +43 -0
- package/dist/devices/heatPump.d.ts.map +1 -0
- package/dist/devices/heatPump.js +50 -2
- package/dist/devices/heatPump.js.map +1 -0
- package/dist/devices/laundryDryer.d.ts +58 -0
- package/dist/devices/laundryDryer.d.ts.map +1 -0
- package/dist/devices/laundryDryer.js +62 -3
- package/dist/devices/laundryDryer.js.map +1 -0
- package/dist/devices/laundryWasher.d.ts +64 -0
- package/dist/devices/laundryWasher.d.ts.map +1 -0
- package/dist/devices/laundryWasher.js +70 -4
- package/dist/devices/laundryWasher.js.map +1 -0
- package/dist/devices/microwaveOven.d.ts +77 -1
- package/dist/devices/microwaveOven.d.ts.map +1 -0
- package/dist/devices/microwaveOven.js +88 -5
- package/dist/devices/microwaveOven.js.map +1 -0
- package/dist/devices/oven.d.ts +82 -0
- package/dist/devices/oven.d.ts.map +1 -0
- package/dist/devices/oven.js +85 -0
- package/dist/devices/oven.js.map +1 -0
- package/dist/devices/refrigerator.d.ts +100 -0
- package/dist/devices/refrigerator.d.ts.map +1 -0
- package/dist/devices/refrigerator.js +102 -0
- package/dist/devices/refrigerator.js.map +1 -0
- package/dist/devices/roboticVacuumCleaner.d.ts +83 -0
- package/dist/devices/roboticVacuumCleaner.d.ts.map +1 -0
- package/dist/devices/roboticVacuumCleaner.js +100 -9
- package/dist/devices/roboticVacuumCleaner.js.map +1 -0
- package/dist/devices/solarPower.d.ts +36 -0
- package/dist/devices/solarPower.d.ts.map +1 -0
- package/dist/devices/solarPower.js +38 -0
- package/dist/devices/solarPower.js.map +1 -0
- package/dist/devices/speaker.d.ts +79 -0
- package/dist/devices/speaker.d.ts.map +1 -0
- package/dist/devices/speaker.js +84 -0
- package/dist/devices/speaker.js.map +1 -0
- package/dist/devices/temperatureControl.d.ts +21 -0
- package/dist/devices/temperatureControl.d.ts.map +1 -0
- package/dist/devices/temperatureControl.js +24 -3
- package/dist/devices/temperatureControl.js.map +1 -0
- package/dist/devices/waterHeater.d.ts +74 -0
- package/dist/devices/waterHeater.d.ts.map +1 -0
- package/dist/devices/waterHeater.js +82 -2
- package/dist/devices/waterHeater.js.map +1 -0
- package/dist/dgram/coap.d.ts +171 -0
- package/dist/dgram/coap.d.ts.map +1 -0
- package/dist/dgram/coap.js +126 -13
- package/dist/dgram/coap.js.map +1 -0
- package/dist/dgram/dgram.d.ts +99 -0
- package/dist/dgram/dgram.d.ts.map +1 -0
- package/dist/dgram/dgram.js +114 -2
- package/dist/dgram/dgram.js.map +1 -0
- package/dist/dgram/mb_coap.d.ts +23 -0
- package/dist/dgram/mb_coap.d.ts.map +1 -0
- package/dist/dgram/mb_coap.js +41 -3
- package/dist/dgram/mb_coap.js.map +1 -0
- package/dist/dgram/mb_mdns.d.ts +23 -0
- package/dist/dgram/mb_mdns.d.ts.map +1 -0
- package/dist/dgram/mb_mdns.js +80 -24
- package/dist/dgram/mb_mdns.js.map +1 -0
- package/dist/dgram/mdns.d.ts +187 -4
- package/dist/dgram/mdns.d.ts.map +1 -0
- package/dist/dgram/mdns.js +371 -139
- package/dist/dgram/mdns.js.map +1 -0
- package/dist/dgram/multicast.d.ts +49 -0
- package/dist/dgram/multicast.d.ts.map +1 -0
- package/dist/dgram/multicast.js +62 -1
- package/dist/dgram/multicast.js.map +1 -0
- package/dist/dgram/unicast.d.ts +53 -0
- package/dist/dgram/unicast.d.ts.map +1 -0
- package/dist/dgram/unicast.js +60 -0
- package/dist/dgram/unicast.js.map +1 -0
- package/dist/frontend.d.ts +187 -0
- package/dist/frontend.d.ts.map +1 -0
- package/dist/frontend.js +543 -73
- package/dist/frontend.js.map +1 -0
- package/dist/frontendTypes.d.ts +57 -0
- package/dist/frontendTypes.d.ts.map +1 -0
- package/dist/frontendTypes.js +45 -0
- package/dist/frontendTypes.js.map +1 -0
- package/dist/helpers.d.ts +43 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +53 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/jestutils/export.d.ts +1 -0
- package/dist/jestutils/export.d.ts.map +1 -0
- package/dist/jestutils/export.js +1 -0
- package/dist/jestutils/export.js.map +1 -0
- package/dist/jestutils/jestHelpers.d.ts +255 -0
- package/dist/jestutils/jestHelpers.d.ts.map +1 -0
- package/dist/jestutils/jestHelpers.js +372 -14
- package/dist/jestutils/jestHelpers.js.map +1 -0
- package/dist/logger/export.d.ts +1 -0
- package/dist/logger/export.d.ts.map +1 -0
- package/dist/logger/export.js +1 -0
- package/dist/logger/export.js.map +1 -0
- package/dist/matter/behaviors.d.ts +1 -0
- package/dist/matter/behaviors.d.ts.map +1 -0
- package/dist/matter/behaviors.js +2 -0
- package/dist/matter/behaviors.js.map +1 -0
- package/dist/matter/clusters.d.ts +1 -0
- package/dist/matter/clusters.d.ts.map +1 -0
- package/dist/matter/clusters.js +2 -0
- package/dist/matter/clusters.js.map +1 -0
- package/dist/matter/devices.d.ts +1 -0
- package/dist/matter/devices.d.ts.map +1 -0
- package/dist/matter/devices.js +2 -0
- package/dist/matter/devices.js.map +1 -0
- package/dist/matter/endpoints.d.ts +1 -0
- package/dist/matter/endpoints.d.ts.map +1 -0
- package/dist/matter/endpoints.js +2 -0
- package/dist/matter/endpoints.js.map +1 -0
- package/dist/matter/export.d.ts +1 -0
- package/dist/matter/export.d.ts.map +1 -0
- package/dist/matter/export.js +2 -0
- package/dist/matter/export.js.map +1 -0
- package/dist/matter/types.d.ts +1 -0
- package/dist/matter/types.d.ts.map +1 -0
- package/dist/matter/types.js +2 -0
- package/dist/matter/types.js.map +1 -0
- package/dist/matterNode.d.ts +258 -0
- package/dist/matterNode.d.ts.map +1 -0
- package/dist/matterNode.js +362 -9
- package/dist/matterNode.js.map +1 -0
- package/dist/matterbridge.d.ts +362 -0
- package/dist/matterbridge.d.ts.map +1 -0
- package/dist/matterbridge.js +879 -56
- package/dist/matterbridge.js.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts +36 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.js +38 -0
- package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
- package/dist/matterbridgeBehaviors.d.ts +24 -0
- package/dist/matterbridgeBehaviors.d.ts.map +1 -0
- package/dist/matterbridgeBehaviors.js +68 -5
- package/dist/matterbridgeBehaviors.js.map +1 -0
- package/dist/matterbridgeDeviceTypes.d.ts +649 -0
- package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
- package/dist/matterbridgeDeviceTypes.js +673 -6
- package/dist/matterbridgeDeviceTypes.js.map +1 -0
- package/dist/matterbridgeDynamicPlatform.d.ts +36 -0
- package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
- package/dist/matterbridgeDynamicPlatform.js +38 -0
- package/dist/matterbridgeDynamicPlatform.js.map +1 -0
- package/dist/matterbridgeEndpoint.d.ts +1332 -0
- package/dist/matterbridgeEndpoint.d.ts.map +1 -0
- package/dist/matterbridgeEndpoint.js +1457 -53
- package/dist/matterbridgeEndpoint.js.map +1 -0
- package/dist/matterbridgeEndpointHelpers.d.ts +425 -0
- package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
- package/dist/matterbridgeEndpointHelpers.js +483 -20
- package/dist/matterbridgeEndpointHelpers.js.map +1 -0
- package/dist/matterbridgeEndpointTypes.d.ts +70 -0
- package/dist/matterbridgeEndpointTypes.d.ts.map +1 -0
- package/dist/matterbridgeEndpointTypes.js +25 -0
- package/dist/matterbridgeEndpointTypes.js.map +1 -0
- package/dist/matterbridgePlatform.d.ts +425 -0
- package/dist/matterbridgePlatform.d.ts.map +1 -0
- package/dist/matterbridgePlatform.js +451 -1
- package/dist/matterbridgePlatform.js.map +1 -0
- package/dist/matterbridgeTypes.d.ts +46 -0
- package/dist/matterbridgeTypes.d.ts.map +1 -0
- package/dist/matterbridgeTypes.js +26 -0
- package/dist/matterbridgeTypes.js.map +1 -0
- package/dist/pluginManager.d.ts +305 -0
- package/dist/pluginManager.d.ts.map +1 -0
- package/dist/pluginManager.js +341 -5
- package/dist/pluginManager.js.map +1 -0
- package/dist/shelly.d.ts +157 -0
- package/dist/shelly.d.ts.map +1 -0
- package/dist/shelly.js +178 -7
- package/dist/shelly.js.map +1 -0
- package/dist/storage/export.d.ts +1 -0
- package/dist/storage/export.d.ts.map +1 -0
- package/dist/storage/export.js +1 -0
- package/dist/storage/export.js.map +1 -0
- package/dist/update.d.ts +75 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +93 -1
- package/dist/update.js.map +1 -0
- package/dist/utils/colorUtils.d.ts +77 -0
- package/dist/utils/colorUtils.d.ts.map +1 -0
- package/dist/utils/colorUtils.js +97 -2
- package/dist/utils/colorUtils.js.map +1 -0
- package/dist/utils/commandLine.d.ts +60 -0
- package/dist/utils/commandLine.d.ts.map +1 -0
- package/dist/utils/commandLine.js +60 -0
- package/dist/utils/commandLine.js.map +1 -0
- package/dist/utils/copyDirectory.d.ts +33 -0
- package/dist/utils/copyDirectory.d.ts.map +1 -0
- package/dist/utils/copyDirectory.js +37 -0
- package/dist/utils/copyDirectory.js.map +1 -0
- package/dist/utils/createDirectory.d.ts +32 -0
- package/dist/utils/createDirectory.d.ts.map +1 -0
- package/dist/utils/createDirectory.js +33 -0
- package/dist/utils/createDirectory.js.map +1 -0
- package/dist/utils/createZip.d.ts +38 -0
- package/dist/utils/createZip.d.ts.map +1 -0
- package/dist/utils/createZip.js +47 -2
- package/dist/utils/createZip.js.map +1 -0
- package/dist/utils/deepCopy.d.ts +31 -0
- package/dist/utils/deepCopy.d.ts.map +1 -0
- package/dist/utils/deepCopy.js +39 -0
- package/dist/utils/deepCopy.js.map +1 -0
- package/dist/utils/deepEqual.d.ts +53 -0
- package/dist/utils/deepEqual.d.ts.map +1 -0
- package/dist/utils/deepEqual.js +72 -1
- package/dist/utils/deepEqual.js.map +1 -0
- package/dist/utils/error.d.ts +42 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +42 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/export.d.ts +1 -0
- package/dist/utils/export.d.ts.map +1 -0
- package/dist/utils/export.js +1 -0
- package/dist/utils/export.js.map +1 -0
- package/dist/utils/format.d.ts +49 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +49 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/hex.d.ts +85 -0
- package/dist/utils/hex.d.ts.map +1 -0
- package/dist/utils/hex.js +124 -0
- package/dist/utils/hex.js.map +1 -0
- package/dist/utils/inspector.d.ts +63 -0
- package/dist/utils/inspector.d.ts.map +1 -0
- package/dist/utils/inspector.js +69 -1
- package/dist/utils/inspector.js.map +1 -0
- package/dist/utils/isValid.d.ts +93 -0
- package/dist/utils/isValid.d.ts.map +1 -0
- package/dist/utils/isValid.js +93 -0
- package/dist/utils/isValid.js.map +1 -0
- package/dist/utils/network.d.ts +116 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/network.js +126 -5
- package/dist/utils/network.js.map +1 -0
- package/dist/utils/spawn.d.ts +32 -0
- package/dist/utils/spawn.d.ts.map +1 -0
- package/dist/utils/spawn.js +71 -1
- package/dist/utils/spawn.js.map +1 -0
- package/dist/utils/tracker.d.ts +56 -0
- package/dist/utils/tracker.d.ts.map +1 -0
- package/dist/utils/tracker.js +64 -1
- package/dist/utils/tracker.js.map +1 -0
- package/dist/utils/wait.d.ts +51 -0
- package/dist/utils/wait.d.ts.map +1 -0
- package/dist/utils/wait.js +60 -8
- package/dist/utils/wait.js.map +1 -0
- package/dist/workerGlobalPrefix.d.ts +24 -0
- package/dist/workerGlobalPrefix.d.ts.map +1 -0
- package/dist/workerGlobalPrefix.js +37 -5
- package/dist/workerGlobalPrefix.js.map +1 -0
- package/dist/workerTypes.d.ts +25 -0
- package/dist/workerTypes.d.ts.map +1 -0
- package/dist/workerTypes.js +24 -0
- package/dist/workerTypes.js.map +1 -0
- package/dist/workers.d.ts +61 -0
- package/dist/workers.d.ts.map +1 -0
- package/dist/workers.js +68 -4
- package/dist/workers.js.map +1 -0
- package/frontend/build/assets/index.js +4 -4
- package/frontend/package.json +1 -1
- package/npm-shrinkwrap.json +5 -35
- package/package.json +7 -7
|
@@ -1,10 +1,38 @@
|
|
|
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
|
+
// eslint-disable-next-line no-console
|
|
1
25
|
if (process.argv.includes('--loader') || process.argv.includes('-loader'))
|
|
2
26
|
console.log('\u001B[32mMatterbridgeEndpointHelpers loaded.\u001B[40;0m');
|
|
27
|
+
// Other modules
|
|
3
28
|
import { createHash } from 'node:crypto';
|
|
29
|
+
// AnsiLogger module
|
|
4
30
|
import { BLUE, CYAN, db, debugStringify, er, hk, or, YELLOW, zb } from 'node-ansi-logger';
|
|
31
|
+
// @matter
|
|
5
32
|
import { Lifecycle } from '@matter/general';
|
|
6
33
|
import { MeasurementType } from '@matter/types/globals';
|
|
7
34
|
import { getClusterNameById } from '@matter/types/cluster';
|
|
35
|
+
// @matter clusters
|
|
8
36
|
import { PowerSource } from '@matter/types/clusters/power-source';
|
|
9
37
|
import { UserLabel } from '@matter/types/clusters/user-label';
|
|
10
38
|
import { FixedLabel } from '@matter/types/clusters/fixed-label';
|
|
@@ -50,6 +78,7 @@ import { TotalVolatileOrganicCompoundsConcentrationMeasurement } from '@matter/t
|
|
|
50
78
|
import { OperationalState } from '@matter/types/clusters/operational-state';
|
|
51
79
|
import { DeviceEnergyManagement } from '@matter/types/clusters/device-energy-management';
|
|
52
80
|
import { DeviceEnergyManagementMode } from '@matter/types/clusters/device-energy-management-mode';
|
|
81
|
+
// @matter behaviors
|
|
53
82
|
import { PowerSourceServer } from '@matter/node/behaviors/power-source';
|
|
54
83
|
import { UserLabelServer } from '@matter/node/behaviors/user-label';
|
|
55
84
|
import { FixedLabelServer } from '@matter/node/behaviors/fixed-label';
|
|
@@ -80,63 +109,133 @@ import { Pm25ConcentrationMeasurementServer } from '@matter/node/behaviors/pm25-
|
|
|
80
109
|
import { Pm10ConcentrationMeasurementServer } from '@matter/node/behaviors/pm10-concentration-measurement';
|
|
81
110
|
import { RadonConcentrationMeasurementServer } from '@matter/node/behaviors/radon-concentration-measurement';
|
|
82
111
|
import { TotalVolatileOrganicCompoundsConcentrationMeasurementServer } from '@matter/node/behaviors/total-volatile-organic-compounds-concentration-measurement';
|
|
112
|
+
// Matterbridge
|
|
83
113
|
import { deepCopy } from './utils/deepCopy.js';
|
|
84
114
|
import { deepEqual } from './utils/deepEqual.js';
|
|
85
115
|
import { isValidArray } from './utils/isValid.js';
|
|
86
116
|
import { MatterbridgeIdentifyServer, MatterbridgeOnOffServer, MatterbridgeLevelControlServer, MatterbridgeColorControlServer, MatterbridgeLiftWindowCoveringServer, MatterbridgeThermostatServer, MatterbridgeFanControlServer, MatterbridgeDoorLockServer, MatterbridgeModeSelectServer, MatterbridgeValveConfigurationAndControlServer, MatterbridgeSmokeCoAlarmServer, MatterbridgeBooleanStateConfigurationServer, MatterbridgeOperationalStateServer, MatterbridgePowerSourceServer, MatterbridgeDeviceEnergyManagementServer, MatterbridgeDeviceEnergyManagementModeServer, } from './matterbridgeBehaviors.js';
|
|
117
|
+
/**
|
|
118
|
+
* Capitalizes the first letter of a string.
|
|
119
|
+
*
|
|
120
|
+
* @param {string} name - The string to capitalize.
|
|
121
|
+
* @returns {string} The string with the first letter capitalized.
|
|
122
|
+
*/
|
|
87
123
|
export function capitalizeFirstLetter(name) {
|
|
88
124
|
if (!name)
|
|
89
125
|
return name;
|
|
90
126
|
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
91
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Lowercases the first letter of a string.
|
|
130
|
+
*
|
|
131
|
+
* @param {string} name - The string to lowercase the first letter of.
|
|
132
|
+
* @returns {string} The string with the first letter lowercased.
|
|
133
|
+
*/
|
|
92
134
|
export function lowercaseFirstLetter(name) {
|
|
93
135
|
if (!name)
|
|
94
136
|
return name;
|
|
95
137
|
return name.charAt(0).toLowerCase() + name.slice(1);
|
|
96
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Checks if the device name contains non-Latin characters.
|
|
141
|
+
*
|
|
142
|
+
* @param {string} deviceName - The name of the device to check.
|
|
143
|
+
* @returns {boolean} Returns true if the device name contains non-Latin characters, false otherwise.
|
|
144
|
+
*/
|
|
97
145
|
export function checkNotLatinCharacters(deviceName) {
|
|
98
146
|
const nonLatinRegexList = [
|
|
99
|
-
/[\u0400-\u04FF\u0500-\u052F]/,
|
|
100
|
-
/[\u2E80-\u9FFF]/,
|
|
101
|
-
/[\uAC00-\uD7AF]/,
|
|
102
|
-
/[\u0600-\u06FF\u0750-\u077F]/,
|
|
103
|
-
/[\u0590-\u05FF]/,
|
|
104
|
-
/[\u0900-\u097F]/,
|
|
105
|
-
/[\u0E00-\u0E7F]/,
|
|
106
|
-
/[\u1200-\u137F]/,
|
|
147
|
+
/[\u0400-\u04FF\u0500-\u052F]/, // Cyrillic
|
|
148
|
+
/[\u2E80-\u9FFF]/, // CJK (Chinese, Japanese, Korean)
|
|
149
|
+
/[\uAC00-\uD7AF]/, // Korean Hangul
|
|
150
|
+
/[\u0600-\u06FF\u0750-\u077F]/, // Arabic, Persian
|
|
151
|
+
/[\u0590-\u05FF]/, // Hebrew
|
|
152
|
+
/[\u0900-\u097F]/, // Devanagari (Hindi, Sanskrit)
|
|
153
|
+
/[\u0E00-\u0E7F]/, // Thai
|
|
154
|
+
/[\u1200-\u137F]/, // Ethiopic (Amharic, Tigrinya)
|
|
107
155
|
];
|
|
108
156
|
return nonLatinRegexList.some((regex) => regex.test(deviceName));
|
|
109
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Generates a unique ID based on the device name.
|
|
160
|
+
*
|
|
161
|
+
* @param {string} deviceName - The name of the device to generate a unique ID for.
|
|
162
|
+
* @returns {string} A unique ID generated from the device name using MD5 hashing.
|
|
163
|
+
*/
|
|
110
164
|
export function generateUniqueId(deviceName) {
|
|
111
|
-
return createHash('md5').update(deviceName).digest('hex');
|
|
165
|
+
return createHash('md5').update(deviceName).digest('hex'); // MD5 hash of the device name
|
|
112
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Generates a unique ID based on four parameters.
|
|
169
|
+
*
|
|
170
|
+
* @param {string} param1 - The first parameter.
|
|
171
|
+
* @param {string} param2 - The second parameter.
|
|
172
|
+
* @param {string} param3 - The third parameter.
|
|
173
|
+
* @param {string} param4 - The fourth parameter.
|
|
174
|
+
* @returns {string} A unique ID generated from the concatenation of the parameters using MD5 hashing.
|
|
175
|
+
*/
|
|
113
176
|
export function createUniqueId(param1, param2, param3, param4) {
|
|
114
177
|
const hash = createHash('md5');
|
|
115
178
|
hash.update(param1 + param2 + param3 + param4);
|
|
116
179
|
return hash.digest('hex');
|
|
117
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Retrieves the features for a specific behavior.
|
|
183
|
+
*
|
|
184
|
+
* @param {Endpoint} endpoint - The endpoint to retrieve the features from.
|
|
185
|
+
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to retrieve the features for.
|
|
186
|
+
*
|
|
187
|
+
* @returns {Record<string, boolean | undefined>} The features for the specified behavior.
|
|
188
|
+
*
|
|
189
|
+
* @remarks Use with:
|
|
190
|
+
* ```typescript
|
|
191
|
+
* expect(featuresFor(device, 'powerSource').wired).toBe(true);
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
118
194
|
export function featuresFor(endpoint, cluster) {
|
|
119
195
|
const behaviorId = getBehavior(endpoint, cluster)?.id;
|
|
120
196
|
if (!behaviorId) {
|
|
121
197
|
endpoint.log?.error(`featuresFor error: cluster not found on endpoint ${or}${endpoint.maybeId}${er}:${or}${endpoint.maybeNumber}${er}`);
|
|
122
198
|
return {};
|
|
123
199
|
}
|
|
200
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
201
|
return endpoint.behaviors.supported[lowercaseFirstLetter(behaviorId)]['cluster']['supportedFeatures'];
|
|
125
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Maps a list of ClusterId to Behavior.Type for server clusters.
|
|
205
|
+
*
|
|
206
|
+
* @param {ClusterId[]} clusterServerList - The list of ClusterId to map.
|
|
207
|
+
* @returns {Behavior.Type[]} An array of Behavior.Type corresponding to the ClusterId in the server list.
|
|
208
|
+
*/
|
|
126
209
|
export function getBehaviourTypesFromClusterServerIds(clusterServerList) {
|
|
210
|
+
// Map Server ClusterId to Behavior.Type
|
|
127
211
|
const behaviorTypes = [];
|
|
128
212
|
clusterServerList.forEach((clusterId) => {
|
|
129
213
|
behaviorTypes.push(getBehaviourTypeFromClusterServerId(clusterId));
|
|
130
214
|
});
|
|
131
215
|
return behaviorTypes;
|
|
132
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Maps a list of ClusterId to Behavior.Type for client clusters.
|
|
219
|
+
*
|
|
220
|
+
* @param {ClusterId[]} clusterClientList - The list of ClusterId to map.
|
|
221
|
+
* @returns {Behavior.Type[]} An array of Behavior.Type corresponding to the ClusterId in the client list.
|
|
222
|
+
*/
|
|
133
223
|
export function getBehaviourTypesFromClusterClientIds(clusterClientList) {
|
|
224
|
+
// Map Client ClusterId to Behavior.Type
|
|
134
225
|
const behaviorTypes = [];
|
|
135
226
|
clusterClientList.forEach((_clusterId) => {
|
|
227
|
+
// behaviorTypes.push(getBehaviourTypeFromClusterClientId(clusterId));
|
|
136
228
|
});
|
|
137
229
|
return behaviorTypes;
|
|
138
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Maps a ClusterId to a Behavior.Type for server clusters.
|
|
233
|
+
*
|
|
234
|
+
* @param {ClusterId} clusterId - The ClusterId to map.
|
|
235
|
+
* @returns {Behavior.Type} The corresponding Behavior.Type for the given ClusterId.
|
|
236
|
+
*/
|
|
139
237
|
export function getBehaviourTypeFromClusterServerId(clusterId) {
|
|
238
|
+
// Map ClusterId to Server Behavior.Type
|
|
140
239
|
if (clusterId === PowerSource.Cluster.id)
|
|
141
240
|
return PowerSourceServer.with(PowerSource.Feature.Wired);
|
|
142
241
|
if (clusterId === UserLabel.Cluster.id)
|
|
@@ -229,8 +328,22 @@ export function getBehaviourTypeFromClusterServerId(clusterId) {
|
|
|
229
328
|
return MatterbridgeDeviceEnergyManagementModeServer;
|
|
230
329
|
return MatterbridgeIdentifyServer;
|
|
231
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* Maps a ClusterId to a Behavior.Type for client clusters.
|
|
333
|
+
*
|
|
334
|
+
* @param {ClusterId} _clusterId - The ClusterId to map.
|
|
335
|
+
*/
|
|
232
336
|
export function getBehaviourTypeFromClusterClientId(_clusterId) {
|
|
337
|
+
// Map ClusterId to Client Behavior.Type
|
|
338
|
+
// return IdentifyClient;
|
|
233
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* Retrieves the Behavior.Type for a given cluster from the endpoint's supported behaviors.
|
|
342
|
+
*
|
|
343
|
+
* @param {MatterbridgeEndpoint} endpoint - The endpoint to retrieve the behavior from.
|
|
344
|
+
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to retrieve the behavior for.
|
|
345
|
+
* @returns {Behavior.Type | undefined} The Behavior.Type for the given cluster, or undefined if not found.
|
|
346
|
+
*/
|
|
234
347
|
export function getBehavior(endpoint, cluster) {
|
|
235
348
|
let behavior;
|
|
236
349
|
if (typeof cluster === 'string') {
|
|
@@ -247,6 +360,18 @@ export function getBehavior(endpoint, cluster) {
|
|
|
247
360
|
}
|
|
248
361
|
return behavior;
|
|
249
362
|
}
|
|
363
|
+
/**
|
|
364
|
+
* Invokes a command on the specified behavior of the endpoint. Used ONLY in Jest tests.
|
|
365
|
+
*
|
|
366
|
+
* @param {MatterbridgeEndpoint} endpoint - The endpoint to invoke the command on.
|
|
367
|
+
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to invoke the command on.
|
|
368
|
+
* @param {keyof MatterbridgeEndpointCommands} command - The command to invoke.
|
|
369
|
+
* @param {Record<string, boolean | number | bigint | string | object | null>} [params] - The parameters to pass to the command.
|
|
370
|
+
*
|
|
371
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the command was invoked successfully, false otherwise.
|
|
372
|
+
*
|
|
373
|
+
* @deprecated Used ONLY in Jest tests.
|
|
374
|
+
*/
|
|
250
375
|
export async function invokeBehaviorCommand(endpoint, cluster, command, params) {
|
|
251
376
|
const behaviorId = getBehavior(endpoint, cluster)?.id;
|
|
252
377
|
if (!behaviorId) {
|
|
@@ -254,6 +379,7 @@ export async function invokeBehaviorCommand(endpoint, cluster, command, params)
|
|
|
254
379
|
return false;
|
|
255
380
|
}
|
|
256
381
|
await endpoint.act((agent) => {
|
|
382
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
257
383
|
const behavior = agent[behaviorId];
|
|
258
384
|
if (!(command in behavior) || typeof behavior[command] !== 'function') {
|
|
259
385
|
endpoint.log?.error(`invokeBehaviorCommand error: command ${hk}${command}${er} not found on agent for endpoint ${or}${endpoint.maybeId}${er}:${or}${endpoint.maybeNumber}${er}`);
|
|
@@ -263,6 +389,19 @@ export async function invokeBehaviorCommand(endpoint, cluster, command, params)
|
|
|
263
389
|
});
|
|
264
390
|
return true;
|
|
265
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* Invokes the subscription handler on the specified cluster and attribute of the endpoint. Used ONLY in Jest tests.
|
|
394
|
+
*
|
|
395
|
+
* @param {MatterbridgeEndpoint} endpoint - The endpoint to invoke the subscription handler on.
|
|
396
|
+
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to invoke the subscription handler on.
|
|
397
|
+
* @param {string} attribute - The attribute to invoke the subscription handler on.
|
|
398
|
+
* @param {unknown} newValue - The new value of the attribute.
|
|
399
|
+
* @param {unknown} oldValue - The old value of the attribute.
|
|
400
|
+
*
|
|
401
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the subscription handler was invoked successfully, false otherwise.
|
|
402
|
+
*
|
|
403
|
+
* @deprecated Used ONLY in Jest tests.
|
|
404
|
+
*/
|
|
266
405
|
export async function invokeSubscribeHandler(endpoint, cluster, attribute, newValue, oldValue) {
|
|
267
406
|
const event = attribute + '$Changed';
|
|
268
407
|
const behaviorId = getBehavior(endpoint, cluster)?.id;
|
|
@@ -279,9 +418,17 @@ export async function invokeSubscribeHandler(endpoint, cluster, attribute, newVa
|
|
|
279
418
|
endpoint.log.error(`invokeSubscribeHandler ${hk}${event}${er} error: cluster ${behaviorId} not found on endpoint ${or}${endpoint.id}${er}:${or}${endpoint.number}${er}`);
|
|
280
419
|
return false;
|
|
281
420
|
}
|
|
421
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
422
|
+
// @ts-ignore
|
|
282
423
|
await endpoint.act((agent) => agent[behaviorId].events[event].emit(newValue, oldValue, { ...agent.context, offline: false }));
|
|
283
424
|
return true;
|
|
284
425
|
}
|
|
426
|
+
/**
|
|
427
|
+
* Adds required cluster servers to the specified endpoint based on the device types.
|
|
428
|
+
*
|
|
429
|
+
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the required cluster servers to.
|
|
430
|
+
* @returns {void}
|
|
431
|
+
*/
|
|
285
432
|
export function addRequiredClusterServers(endpoint) {
|
|
286
433
|
const requiredServerList = [];
|
|
287
434
|
endpoint.log.debug(`addRequiredClusterServers for ${CYAN}${endpoint.maybeId}${db}`);
|
|
@@ -296,6 +443,12 @@ export function addRequiredClusterServers(endpoint) {
|
|
|
296
443
|
});
|
|
297
444
|
addClusterServers(endpoint, requiredServerList);
|
|
298
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
* Adds optional cluster servers to the specified endpoint based on the device types.
|
|
448
|
+
*
|
|
449
|
+
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the optional cluster servers to.
|
|
450
|
+
* @returns {void}
|
|
451
|
+
*/
|
|
299
452
|
export function addOptionalClusterServers(endpoint) {
|
|
300
453
|
const optionalServerList = [];
|
|
301
454
|
endpoint.log.debug(`addOptionalClusterServers for ${CYAN}${endpoint.maybeId}${db}`);
|
|
@@ -310,6 +463,12 @@ export function addOptionalClusterServers(endpoint) {
|
|
|
310
463
|
});
|
|
311
464
|
addClusterServers(endpoint, optionalServerList);
|
|
312
465
|
}
|
|
466
|
+
/**
|
|
467
|
+
* Adds cluster servers to the specified endpoint based on the provided server list.
|
|
468
|
+
*
|
|
469
|
+
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
|
|
470
|
+
* @param {ClusterId[]} serverList - The list of cluster IDs to add.
|
|
471
|
+
*/
|
|
313
472
|
export function addClusterServers(endpoint, serverList) {
|
|
314
473
|
if (serverList.includes(PowerSource.Cluster.id))
|
|
315
474
|
endpoint.createDefaultPowerSourceWiredClusterServer();
|
|
@@ -392,6 +551,13 @@ export function addClusterServers(endpoint, serverList) {
|
|
|
392
551
|
if (serverList.includes(DeviceEnergyManagementMode.Cluster.id))
|
|
393
552
|
endpoint.createDefaultDeviceEnergyManagementModeClusterServer();
|
|
394
553
|
}
|
|
554
|
+
/**
|
|
555
|
+
* Adds a fixed label to the FixedLabel cluster. The FixedLabel cluster is created if it does not exist.
|
|
556
|
+
*
|
|
557
|
+
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
|
|
558
|
+
* @param {string} label - The label to add. Max 16 characters.
|
|
559
|
+
* @param {string} value - The value of the label. Max 16 characters.
|
|
560
|
+
*/
|
|
395
561
|
export async function addFixedLabel(endpoint, label, value) {
|
|
396
562
|
if (!endpoint.hasClusterServer(FixedLabel.Cluster.id)) {
|
|
397
563
|
endpoint.log.debug(`addFixedLabel: add cluster ${hk}FixedLabel${db}:${hk}fixedLabel${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
|
|
@@ -408,6 +574,13 @@ export async function addFixedLabel(endpoint, label, value) {
|
|
|
408
574
|
await endpoint.setAttribute(FixedLabel.Cluster.id, 'labelList', labelList, endpoint.log);
|
|
409
575
|
}
|
|
410
576
|
}
|
|
577
|
+
/**
|
|
578
|
+
* Adds a user label to the UserLabel cluster. The UserLabel cluster is created if it does not exist.
|
|
579
|
+
*
|
|
580
|
+
* @param {MatterbridgeEndpoint} endpoint - The endpoint to add the cluster servers to.
|
|
581
|
+
* @param {string} label - The label to add. Max 16 characters.
|
|
582
|
+
* @param {string} value - The value of the label. Max 16 characters.
|
|
583
|
+
*/
|
|
411
584
|
export async function addUserLabel(endpoint, label, value) {
|
|
412
585
|
if (!endpoint.hasClusterServer(UserLabel.Cluster.id)) {
|
|
413
586
|
endpoint.log.debug(`addUserLabel: add cluster ${hk}UserLabel${db}:${hk}userLabel${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
|
|
@@ -424,16 +597,48 @@ export async function addUserLabel(endpoint, label, value) {
|
|
|
424
597
|
await endpoint.setAttribute(UserLabel.Cluster.id, 'labelList', labelList, endpoint.log);
|
|
425
598
|
}
|
|
426
599
|
}
|
|
600
|
+
/**
|
|
601
|
+
* Returns the options for a given behavior type.
|
|
602
|
+
*
|
|
603
|
+
* @param {T} type - The behavior type.
|
|
604
|
+
* @param {Behavior.Options<T>} options - The options for the behavior type.
|
|
605
|
+
* @returns {Behavior.Options<T>} The options for the behavior type.
|
|
606
|
+
*/
|
|
427
607
|
export function optionsFor(type, options) {
|
|
428
608
|
return options;
|
|
429
609
|
}
|
|
610
|
+
/**
|
|
611
|
+
* Retrieves the cluster ID.
|
|
612
|
+
*
|
|
613
|
+
* @param {Endpoint} endpoint - The endpoint to retrieve the cluster ID from.
|
|
614
|
+
* @param {ClusterId} cluster - The ID of the cluster.
|
|
615
|
+
* @returns {number | undefined} The ID of the cluster.
|
|
616
|
+
*/
|
|
430
617
|
export function getClusterId(endpoint, cluster) {
|
|
431
618
|
return endpoint.behaviors.supported[lowercaseFirstLetter(cluster)]?.schema?.id;
|
|
432
619
|
}
|
|
620
|
+
/**
|
|
621
|
+
* Retrieves the ID of an attribute from a cluster behavior.
|
|
622
|
+
*
|
|
623
|
+
* @param {Endpoint} endpoint - The endpoint to retrieve the attribute ID from.
|
|
624
|
+
* @param {string} cluster - The name of the cluster.
|
|
625
|
+
* @param {string} attribute - The name of the attribute.
|
|
626
|
+
* @returns {number | undefined} The ID of the attribute, or undefined if not found.
|
|
627
|
+
*/
|
|
433
628
|
export function getAttributeId(endpoint, cluster, attribute) {
|
|
434
629
|
const clusterBehavior = endpoint.behaviors.supported[lowercaseFirstLetter(cluster)];
|
|
435
630
|
return clusterBehavior?.cluster?.attributes[lowercaseFirstLetter(attribute)]?.id;
|
|
436
631
|
}
|
|
632
|
+
/**
|
|
633
|
+
* Retrieves the value of the provided attribute from the given cluster.
|
|
634
|
+
*
|
|
635
|
+
* @param {MatterbridgeEndpoint} endpoint - The endpoint to retrieve the attribute from.
|
|
636
|
+
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to retrieve the attribute from.
|
|
637
|
+
* @param {string} attribute - The name of the attribute to retrieve.
|
|
638
|
+
* @param {AnsiLogger} [log] - (Optional) The logger to use for logging the retrieve. Errors are logged to the endpoint logger.
|
|
639
|
+
* @returns {any} The value of the attribute, or undefined if the attribute is not found.
|
|
640
|
+
*/
|
|
641
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
437
642
|
export function getAttribute(endpoint, cluster, attribute, log) {
|
|
438
643
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
439
644
|
if (!clusterName) {
|
|
@@ -456,6 +661,16 @@ export function getAttribute(endpoint, cluster, attribute, log) {
|
|
|
456
661
|
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}`);
|
|
457
662
|
return value;
|
|
458
663
|
}
|
|
664
|
+
/**
|
|
665
|
+
* Sets the value of an attribute on a cluster server.
|
|
666
|
+
*
|
|
667
|
+
* @param {MatterbridgeEndpoint} endpoint - The endpoint to set the attribute on.
|
|
668
|
+
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to set the attribute on.
|
|
669
|
+
* @param {string} attribute - The name of the attribute.
|
|
670
|
+
* @param {boolean | number | bigint | string | object | null} value - The value to set for the attribute.
|
|
671
|
+
* @param {AnsiLogger} [log] - (Optional) The logger to use for logging the set. Errors are logged to the endpoint logger.
|
|
672
|
+
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
|
|
673
|
+
*/
|
|
459
674
|
export async function setAttribute(endpoint, cluster, attribute, value, log) {
|
|
460
675
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
461
676
|
if (!clusterName) {
|
|
@@ -481,6 +696,16 @@ export async function setAttribute(endpoint, cluster, attribute, value, log) {
|
|
|
481
696
|
`to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
|
|
482
697
|
return true;
|
|
483
698
|
}
|
|
699
|
+
/**
|
|
700
|
+
* Sets the value of an attribute on a cluster server.
|
|
701
|
+
*
|
|
702
|
+
* @param {MatterbridgeEndpoint} endpoint - The endpoint to update the attribute on.
|
|
703
|
+
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to update the attribute on.
|
|
704
|
+
* @param {string} attribute - The name of the attribute.
|
|
705
|
+
* @param {boolean | number | bigint | string | object | null} value - The value to set for the attribute.
|
|
706
|
+
* @param {AnsiLogger} [log] - (Optional) The logger to use for logging the update. Errors are logged to the endpoint logger.
|
|
707
|
+
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
|
|
708
|
+
*/
|
|
484
709
|
export async function updateAttribute(endpoint, cluster, attribute, value, log) {
|
|
485
710
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
486
711
|
if (!clusterName) {
|
|
@@ -511,7 +736,24 @@ export async function updateAttribute(endpoint, cluster, attribute, value, log)
|
|
|
511
736
|
`to ${YELLOW}${value !== null && typeof value === 'object' ? debugStringify(value) : value}${db}`);
|
|
512
737
|
return true;
|
|
513
738
|
}
|
|
514
|
-
|
|
739
|
+
/**
|
|
740
|
+
* Subscribes to the provided attribute on a cluster.
|
|
741
|
+
*
|
|
742
|
+
* @param {MatterbridgeEndpoint} endpoint - The endpoint to subscribe the attribute to.
|
|
743
|
+
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The cluster to subscribe the attribute to.
|
|
744
|
+
* @param {string} attribute - The name of the attribute to subscribe to.
|
|
745
|
+
* @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.
|
|
746
|
+
* @param {AnsiLogger} [log] - Optional logger for logging errors and information.
|
|
747
|
+
* @returns {boolean} - A boolean indicating whether the subscription was successful.
|
|
748
|
+
*
|
|
749
|
+
* @remarks The listener function (cannot be async) will receive three parameters:
|
|
750
|
+
* - `newValue`: The new value of the attribute.
|
|
751
|
+
* - `oldValue`: The old value of the attribute.
|
|
752
|
+
* - `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.
|
|
753
|
+
*/
|
|
754
|
+
export async function subscribeAttribute(endpoint, cluster, attribute,
|
|
755
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
756
|
+
listener, log) {
|
|
515
757
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
516
758
|
if (!clusterName) {
|
|
517
759
|
endpoint.log.error(`subscribeAttribute ${hk}${attribute}${er} error: cluster not found on endpoint ${or}${endpoint.maybeId}${er}:${or}${endpoint.maybeNumber}${er}`);
|
|
@@ -521,6 +763,7 @@ export async function subscribeAttribute(endpoint, cluster, attribute, listener,
|
|
|
521
763
|
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`);
|
|
522
764
|
await endpoint.construction.ready;
|
|
523
765
|
}
|
|
766
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
524
767
|
const events = endpoint.events;
|
|
525
768
|
attribute = lowercaseFirstLetter(attribute) + '$Changed';
|
|
526
769
|
if (!(clusterName in events) || !(attribute in events[clusterName])) {
|
|
@@ -531,6 +774,17 @@ export async function subscribeAttribute(endpoint, cluster, attribute, listener,
|
|
|
531
774
|
log?.info(`${db}Subscribed endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} attribute ${hk}${capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db}`);
|
|
532
775
|
return true;
|
|
533
776
|
}
|
|
777
|
+
/**
|
|
778
|
+
* Triggers an event on the specified cluster.
|
|
779
|
+
*
|
|
780
|
+
* @param {MatterbridgeEndpoint} endpoint - The endpoint to trigger the event on.
|
|
781
|
+
* @param {Behavior.Type | ClusterType | ClusterId | string} cluster - The ID of the cluster.
|
|
782
|
+
* @param {string} event - The name of the event to trigger.
|
|
783
|
+
* @param {Record<string, boolean | number | bigint | string | object | undefined | null>} payload - The payload to pass to the event.
|
|
784
|
+
* @param {AnsiLogger} [log] - Optional logger for logging information.
|
|
785
|
+
*
|
|
786
|
+
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the event was successfully triggered.
|
|
787
|
+
*/
|
|
534
788
|
export async function triggerEvent(endpoint, cluster, event, payload, log) {
|
|
535
789
|
const clusterName = getBehavior(endpoint, cluster)?.id;
|
|
536
790
|
if (!clusterName) {
|
|
@@ -541,30 +795,63 @@ export async function triggerEvent(endpoint, cluster, event, payload, log) {
|
|
|
541
795
|
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`);
|
|
542
796
|
return false;
|
|
543
797
|
}
|
|
798
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
544
799
|
const events = endpoint.events;
|
|
545
800
|
if (!(clusterName in events) || !(event in events[clusterName])) {
|
|
546
801
|
endpoint.log.error(`triggerEvent ${hk}${event}${er} error: cluster ${clusterName} not found on endpoint ${or}${endpoint.id}${er}:${or}${endpoint.number}${er}`);
|
|
547
802
|
return false;
|
|
548
803
|
}
|
|
804
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
805
|
+
// @ts-ignore
|
|
549
806
|
await endpoint.act((agent) => agent[clusterName].events[event].emit(payload, agent.context));
|
|
550
807
|
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} `);
|
|
551
808
|
return true;
|
|
552
809
|
}
|
|
810
|
+
/** Utility Cluster Helpers */
|
|
811
|
+
/**
|
|
812
|
+
* Get the default power source wired cluster server options.
|
|
813
|
+
*
|
|
814
|
+
* @param {PowerSource.WiredCurrentType} wiredCurrentType - The type of wired current (default: PowerSource.WiredCurrentType.Ac)
|
|
815
|
+
* @returns {Behavior.Options<PowerSourceClusterServer>} The options for the power source wired cluster server.
|
|
816
|
+
*
|
|
817
|
+
* @remarks
|
|
818
|
+
* - order: The order of the power source is a persisted attribute that indicates the order in which the power sources are used.
|
|
819
|
+
* - description: The description of the power source is a fixed attribute that describes the power source type.
|
|
820
|
+
* - wiredCurrentType: The type of wired current is a fixed attribute that indicates the type of wired current used by the power source (AC or DC).
|
|
821
|
+
*/
|
|
553
822
|
export function getDefaultPowerSourceWiredClusterServer(wiredCurrentType = PowerSource.WiredCurrentType.Ac) {
|
|
554
823
|
return optionsFor(MatterbridgePowerSourceServer.with(PowerSource.Feature.Wired), {
|
|
824
|
+
// Base attributes
|
|
555
825
|
status: PowerSource.PowerSourceStatus.Active,
|
|
556
826
|
order: 0,
|
|
557
827
|
description: wiredCurrentType === PowerSource.WiredCurrentType.Ac ? 'AC Power' : 'DC Power',
|
|
558
|
-
endpointList: [],
|
|
828
|
+
endpointList: [], // Will be filled by the MatterbridgePowerSourceServer
|
|
829
|
+
// Wired feature attributes
|
|
559
830
|
wiredCurrentType,
|
|
560
831
|
});
|
|
561
832
|
}
|
|
833
|
+
/**
|
|
834
|
+
* Get the default power source battery cluster server options.
|
|
835
|
+
*
|
|
836
|
+
* @param {null | number} batPercentRemaining - The remaining battery percentage (default: null). The attribute is in the range 0-200.
|
|
837
|
+
* @param {PowerSource.BatChargeLevel} batChargeLevel - The battery charge level (default: PowerSource.BatChargeLevel.Ok).
|
|
838
|
+
* @param {null | number} batVoltage - The battery voltage (default: null).
|
|
839
|
+
* @param {PowerSource.BatReplaceability} batReplaceability - The replaceability of the battery (default: PowerSource.BatReplaceability.Unspecified).
|
|
840
|
+
* @returns {Behavior.Options<PowerSourceClusterServer>} The options for the power source replaceable battery cluster server.
|
|
841
|
+
*
|
|
842
|
+
* @remarks
|
|
843
|
+
* - order: The order of the power source is a persisted attribute that indicates the order in which the power sources are used.
|
|
844
|
+
* - description: The description of the power source is a fixed attribute that describes the power source type.
|
|
845
|
+
* - batReplaceability: The replaceability of the battery is a fixed attribute that indicates whether the battery is user-replaceable or not.
|
|
846
|
+
*/
|
|
562
847
|
export function getDefaultPowerSourceBatteryClusterServer(batPercentRemaining = null, batChargeLevel = PowerSource.BatChargeLevel.Ok, batVoltage = null, batReplaceability = PowerSource.BatReplaceability.Unspecified) {
|
|
563
848
|
return optionsFor(MatterbridgePowerSourceServer.with(PowerSource.Feature.Battery), {
|
|
849
|
+
// Base attributes
|
|
564
850
|
status: PowerSource.PowerSourceStatus.Active,
|
|
565
851
|
order: 0,
|
|
566
852
|
description: 'Primary battery',
|
|
567
|
-
endpointList: [],
|
|
853
|
+
endpointList: [], // Will be filled by the MatterbridgePowerSourceServer
|
|
854
|
+
// Battery feature attributes
|
|
568
855
|
batVoltage,
|
|
569
856
|
batPercentRemaining: batPercentRemaining !== null ? Math.min(Math.max(batPercentRemaining * 2, 0), 200) : null,
|
|
570
857
|
batChargeLevel,
|
|
@@ -572,40 +859,85 @@ export function getDefaultPowerSourceBatteryClusterServer(batPercentRemaining =
|
|
|
572
859
|
batReplaceability,
|
|
573
860
|
});
|
|
574
861
|
}
|
|
862
|
+
/**
|
|
863
|
+
* Get the default power source replaceable battery cluster server options.
|
|
864
|
+
*
|
|
865
|
+
* @param {number} batPercentRemaining - The remaining battery percentage (default: 100). The attribute is in the range 0-200.
|
|
866
|
+
* @param {PowerSource.BatChargeLevel} batChargeLevel - The battery charge level (default: PowerSource.BatChargeLevel.Ok).
|
|
867
|
+
* @param {number} batVoltage - The battery voltage (default: 1500).
|
|
868
|
+
* @param {string} batReplacementDescription - The description of the battery replacement (default: 'Battery type').
|
|
869
|
+
* @param {number} batQuantity - The quantity of the battery (default: 1).
|
|
870
|
+
* @param {PowerSource.BatReplaceability} batReplaceability - The replaceability of the battery (default: PowerSource.BatReplaceability.UserReplaceable).
|
|
871
|
+
* @returns {Behavior.Options<PowerSourceClusterServer>} The options for the power source replaceable battery cluster server.
|
|
872
|
+
*
|
|
873
|
+
* @remarks
|
|
874
|
+
* - order: The order of the power source is a persisted attribute that indicates the order in which the power sources are used.
|
|
875
|
+
* - description: The description of the power source is a fixed attribute that describes the power source type.
|
|
876
|
+
* - batReplaceability: The replaceability of the battery is a fixed attribute that indicates whether the battery is user-replaceable or not.
|
|
877
|
+
* - batReplacementDescription: The description of the battery replacement is a fixed attribute that describes the battery type.
|
|
878
|
+
* - batQuantity: The quantity of the battery is a fixed attribute that indicates how many batteries are present in the device.
|
|
879
|
+
*/
|
|
575
880
|
export function getDefaultPowerSourceReplaceableBatteryClusterServer(batPercentRemaining = 100, batChargeLevel = PowerSource.BatChargeLevel.Ok, batVoltage = 1500, batReplacementDescription = 'Battery type', batQuantity = 1, batReplaceability = PowerSource.BatReplaceability.UserReplaceable) {
|
|
576
881
|
return optionsFor(MatterbridgePowerSourceServer.with(PowerSource.Feature.Battery, PowerSource.Feature.Replaceable), {
|
|
882
|
+
// Base attributes
|
|
577
883
|
status: PowerSource.PowerSourceStatus.Active,
|
|
578
884
|
order: 0,
|
|
579
885
|
description: 'Primary battery',
|
|
580
|
-
endpointList: [],
|
|
886
|
+
endpointList: [], // Will be filled by the MatterbridgePowerSourceServer
|
|
887
|
+
// Battery feature attributes
|
|
581
888
|
batVoltage,
|
|
582
889
|
batPercentRemaining: Math.min(Math.max(batPercentRemaining * 2, 0), 200),
|
|
583
890
|
batChargeLevel,
|
|
584
891
|
batReplacementNeeded: false,
|
|
585
892
|
batReplaceability,
|
|
586
893
|
activeBatFaults: undefined,
|
|
894
|
+
// Replaceable feature attributes
|
|
587
895
|
batReplacementDescription,
|
|
588
896
|
batQuantity,
|
|
589
897
|
});
|
|
590
898
|
}
|
|
899
|
+
/**
|
|
900
|
+
* Creates a default power source rechargeable battery cluster server.
|
|
901
|
+
*
|
|
902
|
+
* @param {number} [batPercentRemaining] - The remaining battery percentage (default: 100). The attribute is in the range 0-200.
|
|
903
|
+
* @param {PowerSource.BatChargeLevel} [batChargeLevel] - The battery charge level (default: PowerSource.BatChargeLevel.Ok).
|
|
904
|
+
* @param {number} [batVoltage] - The battery voltage in mV (default: 1500).
|
|
905
|
+
* @param {PowerSource.BatReplaceability} [batReplaceability] - The replaceability of the battery (default: PowerSource.BatReplaceability.Unspecified).
|
|
906
|
+
* @returns {Behavior.Options<PowerSourceClusterServer>} The options for the power source rechargeable battery cluster server.
|
|
907
|
+
*
|
|
908
|
+
* @remarks
|
|
909
|
+
* - order: The order of the power source is a persisted attribute that indicates the order in which the power sources are used.
|
|
910
|
+
* - description: The description of the power source is a fixed attribute that describes the power source type.
|
|
911
|
+
* - batReplaceability: The replaceability of the battery is a fixed attribute that indicates whether the battery is user-replaceable or not.
|
|
912
|
+
*/
|
|
591
913
|
export function getDefaultPowerSourceRechargeableBatteryClusterServer(batPercentRemaining = 100, batChargeLevel = PowerSource.BatChargeLevel.Ok, batVoltage = 1500, batReplaceability = PowerSource.BatReplaceability.Unspecified) {
|
|
592
914
|
return optionsFor(MatterbridgePowerSourceServer.with(PowerSource.Feature.Battery, PowerSource.Feature.Rechargeable), {
|
|
915
|
+
// Base attributes
|
|
593
916
|
status: PowerSource.PowerSourceStatus.Active,
|
|
594
917
|
order: 0,
|
|
595
918
|
description: 'Primary battery',
|
|
596
|
-
endpointList: [],
|
|
919
|
+
endpointList: [], // Will be filled by the MatterbridgePowerSourceServer
|
|
920
|
+
// Battery feature attributes
|
|
597
921
|
batVoltage,
|
|
598
922
|
batPercentRemaining: Math.min(Math.max(batPercentRemaining * 2, 0), 200),
|
|
599
|
-
batTimeRemaining: null,
|
|
923
|
+
batTimeRemaining: null, // Indicates the estimated time in seconds before the battery will no longer be able to provide power to the Node
|
|
600
924
|
batChargeLevel,
|
|
601
925
|
batReplacementNeeded: false,
|
|
602
926
|
batReplaceability,
|
|
603
927
|
batPresent: true,
|
|
604
928
|
activeBatFaults: [],
|
|
929
|
+
// Rechargeable feature attributes
|
|
605
930
|
batChargeState: PowerSource.BatChargeState.IsNotCharging,
|
|
606
931
|
batFunctionalWhileCharging: true,
|
|
607
932
|
});
|
|
608
933
|
}
|
|
934
|
+
/**
|
|
935
|
+
* Get the default Electrical Energy Measurement Cluster Server options with features ImportedEnergy, ExportedEnergy, and CumulativeEnergy.
|
|
936
|
+
*
|
|
937
|
+
* @param {number} energyImported - The total consumption value in mW/h.
|
|
938
|
+
* @param {number} energyExported - The total production value in mW/h.
|
|
939
|
+
* @returns {Behavior.Options<ElectricalEnergyMeasurementServer>} - The default options for the Electrical Energy Measurement Cluster Server.
|
|
940
|
+
*/
|
|
609
941
|
export function getDefaultElectricalEnergyMeasurementClusterServer(energyImported = null, energyExported = null) {
|
|
610
942
|
return optionsFor(ElectricalEnergyMeasurementServer.with(ElectricalEnergyMeasurement.Feature.ImportedEnergy, ElectricalEnergyMeasurement.Feature.ExportedEnergy, ElectricalEnergyMeasurement.Feature.CumulativeEnergy), {
|
|
611
943
|
accuracy: {
|
|
@@ -620,6 +952,15 @@ export function getDefaultElectricalEnergyMeasurementClusterServer(energyImporte
|
|
|
620
952
|
cumulativeEnergyExported: energyExported !== null && energyExported >= 0 ? { energy: energyExported } : null,
|
|
621
953
|
});
|
|
622
954
|
}
|
|
955
|
+
/**
|
|
956
|
+
* Get the default Electrical Power Measurement Cluster Server options with features AlternatingCurrent.
|
|
957
|
+
*
|
|
958
|
+
* @param {number} voltage - The voltage value in millivolts.
|
|
959
|
+
* @param {number} current - The current value in milliamperes.
|
|
960
|
+
* @param {number} power - The power value in milliwatts.
|
|
961
|
+
* @param {number} frequency - The frequency value in millihertz.
|
|
962
|
+
* @returns {Behavior.Options<ElectricalPowerMeasurementServer>} - The default options for the Electrical Power Measurement Cluster Server.
|
|
963
|
+
*/
|
|
623
964
|
export function getDefaultElectricalPowerMeasurementClusterServer(voltage = null, current = null, power = null, frequency = null) {
|
|
624
965
|
return optionsFor(ElectricalPowerMeasurementServer.with(ElectricalPowerMeasurement.Feature.AlternatingCurrent), {
|
|
625
966
|
powerMode: ElectricalPowerMeasurement.PowerMode.Ac,
|
|
@@ -660,6 +1001,15 @@ export function getDefaultElectricalPowerMeasurementClusterServer(voltage = null
|
|
|
660
1001
|
frequency: frequency,
|
|
661
1002
|
});
|
|
662
1003
|
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Get the default Electrical Apparent Power Measurement Cluster Server with features AlternatingCurrent.
|
|
1006
|
+
*
|
|
1007
|
+
* @param {number} voltage - The voltage value in millivolts.
|
|
1008
|
+
* @param {number} apparentCurrent - The current value in milliamperes.
|
|
1009
|
+
* @param {number} apparentPower - The apparent power value in millivoltamperes.
|
|
1010
|
+
* @param {number} frequency - The frequency value in millihertz.
|
|
1011
|
+
* @returns {Behavior.Options<ElectricalPowerMeasurementServer>} - The default options for the Electrical Apparent Power Measurement Cluster Server.
|
|
1012
|
+
*/
|
|
663
1013
|
export function getApparentElectricalPowerMeasurementClusterServer(voltage = null, apparentCurrent = null, apparentPower = null, frequency = null) {
|
|
664
1014
|
return optionsFor(ElectricalPowerMeasurementServer.with(ElectricalPowerMeasurement.Feature.AlternatingCurrent), {
|
|
665
1015
|
powerMode: ElectricalPowerMeasurement.PowerMode.Ac,
|
|
@@ -700,19 +1050,55 @@ export function getApparentElectricalPowerMeasurementClusterServer(voltage = nul
|
|
|
700
1050
|
frequency: frequency,
|
|
701
1051
|
});
|
|
702
1052
|
}
|
|
1053
|
+
/**
|
|
1054
|
+
* Get the default Device Energy Management Cluster Server with feature PowerForecastReporting and with the specified ESA type, ESA canGenerate, ESA state, and power limits.
|
|
1055
|
+
*
|
|
1056
|
+
* @param {DeviceEnergyManagement.EsaType} [esaType] - The ESA type. Defaults to `DeviceEnergyManagement.EsaType.Other`.
|
|
1057
|
+
* @param {boolean} [esaCanGenerate] - Indicates if the ESA can generate energy. Defaults to `false`.
|
|
1058
|
+
* @param {DeviceEnergyManagement.EsaState} [esaState] - The ESA state. Defaults to `DeviceEnergyManagement.EsaState.Online`.
|
|
1059
|
+
* @param {number} [absMinPower] - Indicate the minimum electrical power in mw that the ESA can consume when switched on. Defaults to `0` if not provided.
|
|
1060
|
+
* @param {number} [absMaxPower] - Indicate the maximum electrical power in mw that the ESA can consume when switched on. Defaults to `0` if not provided.
|
|
1061
|
+
* @returns {Behavior.Options<DeviceEnergyManagementClusterServer>} - The default options for the Device Energy Management Cluster Server.
|
|
1062
|
+
*
|
|
1063
|
+
* @remarks
|
|
1064
|
+
* - The forecast attribute is set to null, indicating that there is no forecast currently available.
|
|
1065
|
+
* - The ESA type and canGenerate attributes are fixed and cannot be changed after creation.
|
|
1066
|
+
* - The ESA state is set to Online by default.
|
|
1067
|
+
* - The absolute minimum and maximum power attributes are set to 0 by default.
|
|
1068
|
+
* - For example, a battery storage inverter that can charge its battery at a maximum power of 2000W and can
|
|
1069
|
+
* discharge the battery at a maximum power of 3000W, would have a absMinPower: -3000W, absMaxPower: 2000W.
|
|
1070
|
+
*/
|
|
703
1071
|
export function getDefaultDeviceEnergyManagementClusterServer(esaType = DeviceEnergyManagement.EsaType.Other, esaCanGenerate = false, esaState = DeviceEnergyManagement.EsaState.Online, absMinPower = 0, absMaxPower = 0) {
|
|
704
1072
|
return optionsFor(MatterbridgeDeviceEnergyManagementServer.with(DeviceEnergyManagement.Feature.PowerForecastReporting, DeviceEnergyManagement.Feature.PowerAdjustment), {
|
|
705
|
-
esaType,
|
|
706
|
-
esaCanGenerate,
|
|
1073
|
+
esaType, // Fixed attribute
|
|
1074
|
+
esaCanGenerate, // Fixed attribute
|
|
707
1075
|
esaState,
|
|
708
1076
|
absMinPower,
|
|
709
1077
|
absMaxPower,
|
|
710
|
-
|
|
1078
|
+
// PowerAdjustment feature (commands: powerAdjustRequest and cancelPowerAdjustRequest events: powerAdjustStart and powerAdjustEnd)
|
|
1079
|
+
powerAdjustmentCapability: null, // A null value indicates that no power adjustment is currently possible, and nor is any adjustment currently active
|
|
711
1080
|
optOutState: DeviceEnergyManagement.OptOutState.NoOptOut,
|
|
712
|
-
|
|
1081
|
+
// PowerForecastReporting
|
|
1082
|
+
forecast: null, // A null value indicates that there is no forecast currently available
|
|
713
1083
|
});
|
|
714
1084
|
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Get the default EnergyManagementMode Cluster Server.
|
|
1087
|
+
*
|
|
1088
|
+
* @param {number} [currentMode] - The current mode of the EnergyManagementMode cluster. Defaults to mode 1 (DeviceEnergyManagementMode.ModeTag.NoOptimization).
|
|
1089
|
+
* @param {EnergyManagementMode.ModeOption[]} [supportedModes] - The supported modes for the DeviceEnergyManagementMode cluster. The attribute is fixed and defaults to a predefined set of cluster modes.
|
|
1090
|
+
* @returns {Behavior.Options<DeviceEnergyManagementModeClusterServer>} - The default options for the Device Energy Management Mode cluster server.
|
|
1091
|
+
*
|
|
1092
|
+
* @remarks
|
|
1093
|
+
* A few examples of Device Energy Management modes and their mode tags are provided below.
|
|
1094
|
+
* - For the "No Energy Management (Forecast reporting only)" mode, tags: 0x4000 (NoOptimization).
|
|
1095
|
+
* - For the "Device Energy Management" mode, tags: 0x4001 (DeviceOptimization).
|
|
1096
|
+
* - For the "Home Energy Management" mode, tags: 0x4001 (DeviceOptimization), 0x4002 (LocalOptimization).
|
|
1097
|
+
* - For the "Grid Energy Management" mode, tags: 0x4003 (GridOptimization).
|
|
1098
|
+
* - For the "Full Energy Management" mode, tags: 0x4001 (DeviceOptimization), 0x4002 (LocalOptimization), 0x4003 (GridOptimization).
|
|
1099
|
+
*/
|
|
715
1100
|
export function getDefaultDeviceEnergyManagementModeClusterServer(currentMode, supportedModes) {
|
|
1101
|
+
// TODO: matter.js 0.16.0 needs a with() method
|
|
716
1102
|
return optionsFor(MatterbridgeDeviceEnergyManagementModeServer.with(), {
|
|
717
1103
|
supportedModes: supportedModes ?? [
|
|
718
1104
|
{ label: 'No Energy Management (Forecast reporting only)', mode: 1, modeTags: [{ value: DeviceEnergyManagementMode.ModeTag.NoOptimization }] },
|
|
@@ -732,11 +1118,26 @@ export function getDefaultDeviceEnergyManagementModeClusterServer(currentMode, s
|
|
|
732
1118
|
mode: 5,
|
|
733
1119
|
modeTags: [{ value: DeviceEnergyManagementMode.ModeTag.DeviceOptimization }, { value: DeviceEnergyManagementMode.ModeTag.LocalOptimization }, { value: DeviceEnergyManagementMode.ModeTag.GridOptimization }],
|
|
734
1120
|
},
|
|
735
|
-
],
|
|
1121
|
+
], // Fixed attribute
|
|
736
1122
|
currentMode: currentMode ?? 1,
|
|
737
1123
|
});
|
|
738
1124
|
}
|
|
1125
|
+
/** Application Cluster Helpers */
|
|
1126
|
+
/**
|
|
1127
|
+
* Get the default OperationalState Cluster Server.
|
|
1128
|
+
*
|
|
1129
|
+
* @param {OperationalState.OperationalStateEnum} operationalState - The initial operational state id.
|
|
1130
|
+
* @returns {Behavior.Options<MatterbridgeOperationalStateServer>} - The default options for the OperationalState cluster server.
|
|
1131
|
+
*
|
|
1132
|
+
* @remarks
|
|
1133
|
+
* This method adds a cluster server with a default operational state configuration:
|
|
1134
|
+
* - { operationalStateId: OperationalState.OperationalStateEnum.Stopped, operationalStateLabel: 'Stopped' },
|
|
1135
|
+
* - { operationalStateId: OperationalState.OperationalStateEnum.Running, operationalStateLabel: 'Running' },
|
|
1136
|
+
* - { operationalStateId: OperationalState.OperationalStateEnum.Paused, operationalStateLabel: 'Paused' },
|
|
1137
|
+
* - { operationalStateId: OperationalState.OperationalStateEnum.Error, operationalStateLabel: 'Error' },
|
|
1138
|
+
*/
|
|
739
1139
|
export function getDefaultOperationalStateClusterServer(operationalState = OperationalState.OperationalStateEnum.Stopped) {
|
|
1140
|
+
// TODO: matter.js 0.16.0 needs a with() method
|
|
740
1141
|
return optionsFor(MatterbridgeOperationalStateServer.with(), {
|
|
741
1142
|
phaseList: [],
|
|
742
1143
|
currentPhase: null,
|
|
@@ -751,6 +1152,14 @@ export function getDefaultOperationalStateClusterServer(operationalState = Opera
|
|
|
751
1152
|
operationalError: { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' },
|
|
752
1153
|
});
|
|
753
1154
|
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Get the default TemperatureMeasurement cluster server options.
|
|
1157
|
+
*
|
|
1158
|
+
* @param {number | null} measuredValue - The measured value of the temperature x 100.
|
|
1159
|
+
* @param {number | null} minMeasuredValue - The minimum measured value of the temperature x 100.
|
|
1160
|
+
* @param {number | null} maxMeasuredValue - The maximum measured value of the temperature x 100.
|
|
1161
|
+
* @returns {Behavior.Options<MatterbridgeTemperatureMeasurementServer>} - The default options for the TemperatureMeasurement cluster server.
|
|
1162
|
+
*/
|
|
754
1163
|
export function getDefaultTemperatureMeasurementClusterServer(measuredValue = null, minMeasuredValue = null, maxMeasuredValue = null) {
|
|
755
1164
|
return optionsFor(TemperatureMeasurementServer, {
|
|
756
1165
|
measuredValue,
|
|
@@ -759,6 +1168,14 @@ export function getDefaultTemperatureMeasurementClusterServer(measuredValue = nu
|
|
|
759
1168
|
tolerance: 0,
|
|
760
1169
|
});
|
|
761
1170
|
}
|
|
1171
|
+
/**
|
|
1172
|
+
* Get the default RelativeHumidityMeasurement cluster server options.
|
|
1173
|
+
*
|
|
1174
|
+
* @param {number | null} measuredValue - The measured value of the relative humidity x 100.
|
|
1175
|
+
* @param {number | null} minMeasuredValue - The minimum measured value of the relative humidity x 100.
|
|
1176
|
+
* @param {number | null} maxMeasuredValue - The maximum measured value of the relative humidity x 100.
|
|
1177
|
+
* @returns {Behavior.Options<MatterbridgeRelativeHumidityMeasurementServer>} - The default options for the RelativeHumidityMeasurement cluster server.
|
|
1178
|
+
*/
|
|
762
1179
|
export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue = null, minMeasuredValue = null, maxMeasuredValue = null) {
|
|
763
1180
|
return optionsFor(RelativeHumidityMeasurementServer, {
|
|
764
1181
|
measuredValue,
|
|
@@ -767,6 +1184,14 @@ export function getDefaultRelativeHumidityMeasurementClusterServer(measuredValue
|
|
|
767
1184
|
tolerance: 0,
|
|
768
1185
|
});
|
|
769
1186
|
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Get the default PressureMeasurement cluster server options.
|
|
1189
|
+
*
|
|
1190
|
+
* @param {number | null} measuredValue - The measured value for the pressure in kPa x 10.
|
|
1191
|
+
* @param {number | null} minMeasuredValue - The minimum measured value for the pressure in kPa x 10.
|
|
1192
|
+
* @param {number | null} maxMeasuredValue - The maximum measured value for the pressure in kPa x 10.
|
|
1193
|
+
* @returns {Behavior.Options<MatterbridgePressureMeasurementServer>} - The default options for the PressureMeasurement cluster server.
|
|
1194
|
+
*/
|
|
770
1195
|
export function getDefaultPressureMeasurementClusterServer(measuredValue = null, minMeasuredValue = null, maxMeasuredValue = null) {
|
|
771
1196
|
return optionsFor(PressureMeasurementServer, {
|
|
772
1197
|
measuredValue,
|
|
@@ -775,6 +1200,21 @@ export function getDefaultPressureMeasurementClusterServer(measuredValue = null,
|
|
|
775
1200
|
tolerance: 0,
|
|
776
1201
|
});
|
|
777
1202
|
}
|
|
1203
|
+
/**
|
|
1204
|
+
* Get the default IlluminanceMeasurement cluster server options.
|
|
1205
|
+
*
|
|
1206
|
+
* @param {number | null} measuredValue - The measured value of illuminance.
|
|
1207
|
+
* @param {number | null} minMeasuredValue - The minimum measured value of illuminance.
|
|
1208
|
+
* @param {number | null} maxMeasuredValue - The maximum measured value of illuminance.
|
|
1209
|
+
* @returns {Behavior.Options<MatterbridgeIlluminanceMeasurementServer>} - The default options for the IlluminanceMeasurement cluster server.
|
|
1210
|
+
*
|
|
1211
|
+
* @remarks The default value for the illuminance measurement is null.
|
|
1212
|
+
* This attribute SHALL indicate the illuminance in Lux (symbol lx) as follows:
|
|
1213
|
+
* • MeasuredValue = 10,000 x log10(illuminance) + 1,
|
|
1214
|
+
* where 1 lx <= illuminance <= 3.576 Mlx, corresponding to a MeasuredValue in the range 1 to 0xFFFE.
|
|
1215
|
+
* • 0 indicates a value of illuminance that is too low to be measured
|
|
1216
|
+
* • null indicates that the illuminance measurement is invalid.
|
|
1217
|
+
*/
|
|
778
1218
|
export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = null, minMeasuredValue = null, maxMeasuredValue = null) {
|
|
779
1219
|
return optionsFor(IlluminanceMeasurementServer, {
|
|
780
1220
|
measuredValue,
|
|
@@ -783,6 +1223,14 @@ export function getDefaultIlluminanceMeasurementClusterServer(measuredValue = nu
|
|
|
783
1223
|
tolerance: 0,
|
|
784
1224
|
});
|
|
785
1225
|
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Get the default FlowMeasurement cluster server options.
|
|
1228
|
+
*
|
|
1229
|
+
* @param {number | null} measuredValue - The measured value of the flow in 10 x m3/h.
|
|
1230
|
+
* @param {number | null} minMeasuredValue - The minimum measured value of the flow in 10 x m3/h.
|
|
1231
|
+
* @param {number | null} maxMeasuredValue - The maximum measured value of the flow in 10 x m3/h.
|
|
1232
|
+
* @returns {Behavior.Options<MatterbridgeFlowMeasurementServer>} - The default options for the FlowMeasurement cluster server.
|
|
1233
|
+
*/
|
|
786
1234
|
export function getDefaultFlowMeasurementClusterServer(measuredValue = null, minMeasuredValue = null, maxMeasuredValue = null) {
|
|
787
1235
|
return optionsFor(FlowMeasurementServer, {
|
|
788
1236
|
measuredValue,
|
|
@@ -791,6 +1239,20 @@ export function getDefaultFlowMeasurementClusterServer(measuredValue = null, min
|
|
|
791
1239
|
tolerance: 0,
|
|
792
1240
|
});
|
|
793
1241
|
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Get the default OccupancySensing cluster server options.
|
|
1244
|
+
*
|
|
1245
|
+
* @param {boolean} occupied - A boolean indicating whether the occupancy is occupied or not. Default is false.
|
|
1246
|
+
* @param {number} holdTime - The hold time in seconds. Default is 30.
|
|
1247
|
+
* @param {number} holdTimeMin - The minimum hold time in seconds. Default is 1.
|
|
1248
|
+
* @param {number} holdTimeMax - The maximum hold time in seconds. Default is 300.
|
|
1249
|
+
* @returns {Behavior.Options<MatterbridgeOccupancySensingServer>} - The default options for the OccupancySensing cluster server.
|
|
1250
|
+
*
|
|
1251
|
+
* @remarks The default value for the occupancy sensor type is PIR.
|
|
1252
|
+
* Servers SHALL set these attributes for backward compatibility with clients implementing a cluster revision <= 4 as
|
|
1253
|
+
* described in OccupancySensorType and OccupancySensorTypeBitmap Attributes.
|
|
1254
|
+
* This replaces the 9 legacy attributes PIROccupiedToUnoccupiedDelay through PhysicalContactUnoccupiedToOccupiedThreshold.
|
|
1255
|
+
*/
|
|
794
1256
|
export function getDefaultOccupancySensingClusterServer(occupied = false, holdTime = 30, holdTimeMin = 1, holdTimeMax = 300) {
|
|
795
1257
|
return optionsFor(OccupancySensingServer.with(OccupancySensing.Feature.PassiveInfrared), {
|
|
796
1258
|
occupancy: { occupied },
|
|
@@ -803,3 +1265,4 @@ export function getDefaultOccupancySensingClusterServer(occupied = false, holdTi
|
|
|
803
1265
|
holdTimeLimits: { holdTimeMin, holdTimeMax, holdTimeDefault: holdTime },
|
|
804
1266
|
});
|
|
805
1267
|
}
|
|
1268
|
+
//# sourceMappingURL=matterbridgeEndpointHelpers.js.map
|