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