matterbridge 1.5.9 → 1.6.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 +36 -3
- package/README-DEV.md +10 -6
- package/README-PODMAN.md +2 -0
- package/README-SERVICE.md +44 -6
- package/README.md +53 -7
- package/dist/cluster/export.js +1 -1
- package/dist/cluster/export.js.map +1 -1
- package/dist/defaultConfigSchema.d.ts.map +1 -1
- package/dist/defaultConfigSchema.js +9 -1
- package/dist/defaultConfigSchema.js.map +1 -1
- package/dist/matterbridge.d.ts +72 -48
- package/dist/matterbridge.d.ts.map +1 -1
- package/dist/matterbridge.js +174 -173
- package/dist/matterbridge.js.map +1 -1
- package/dist/matterbridgeDevice.d.ts +140 -1042
- package/dist/matterbridgeDevice.d.ts.map +1 -1
- package/dist/matterbridgeDevice.js +57 -363
- package/dist/matterbridgeDevice.js.map +1 -1
- package/dist/matterbridgeEdge.d.ts +90 -0
- package/dist/matterbridgeEdge.d.ts.map +1 -0
- package/dist/matterbridgeEdge.js +555 -0
- package/dist/matterbridgeEdge.js.map +1 -0
- package/dist/matterbridgeEndpoint.d.ts +5195 -0
- package/dist/matterbridgeEndpoint.d.ts.map +1 -0
- package/dist/matterbridgeEndpoint.js +2196 -0
- package/dist/matterbridgeEndpoint.js.map +1 -0
- package/dist/matterbridgeTypes.d.ts +6 -5
- package/dist/matterbridgeTypes.d.ts.map +1 -1
- package/dist/matterbridgeTypes.js +1 -1
- package/dist/matterbridgeTypes.js.map +1 -1
- package/dist/matterbridgeWebsocket.d.ts +49 -0
- package/dist/matterbridgeWebsocket.d.ts.map +1 -0
- package/dist/matterbridgeWebsocket.js +145 -0
- package/dist/matterbridgeWebsocket.js.map +1 -0
- package/dist/pluginManager.d.ts +134 -1
- package/dist/pluginManager.d.ts.map +1 -1
- package/dist/pluginManager.js +167 -14
- package/dist/pluginManager.js.map +1 -1
- package/frontend/build/asset-manifest.json +3 -3
- package/frontend/build/index.html +1 -1
- package/frontend/build/static/js/{main.96d6324b.js → main.045d08f7.js} +3 -3
- package/frontend/build/static/js/main.045d08f7.js.map +1 -0
- package/npm-shrinkwrap.json +838 -6222
- package/package.json +3 -78
- package/CODEOWNERS +0 -1
- package/dist/history/export.d.ts +0 -2
- package/dist/history/export.d.ts.map +0 -1
- package/dist/history/export.js +0 -2
- package/dist/history/export.js.map +0 -1
- package/frontend/build/static/js/main.96d6324b.js.map +0 -1
- /package/frontend/build/static/js/{main.96d6324b.js.LICENSE.txt → main.045d08f7.js.LICENSE.txt} +0 -0
|
@@ -0,0 +1,2196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains the class MatterbridgeEndpoint that extends the Endpoint class from the Matter.js library.
|
|
3
|
+
*
|
|
4
|
+
* @file matterbridgeEndpoint.ts
|
|
5
|
+
* @author Luca Liguori
|
|
6
|
+
* @date 2024-10-01
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2024 Luca Liguori.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License. *
|
|
22
|
+
*/
|
|
23
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
24
|
+
// New API imports
|
|
25
|
+
import { Endpoint } from '@project-chip/matter.js/endpoint';
|
|
26
|
+
import { MutableEndpoint } from '@project-chip/matter.js/endpoint/type';
|
|
27
|
+
import { SupportedBehaviors } from '@project-chip/matter.js/endpoint/properties';
|
|
28
|
+
import { DescriptorServer } from '@project-chip/matter.js/behavior/definitions/descriptor';
|
|
29
|
+
import { IdentifyServer } from '@project-chip/matter.js/behavior/definitions/identify';
|
|
30
|
+
import { GroupsServer } from '@project-chip/matter.js/behavior/definitions/groups';
|
|
31
|
+
// import { ScenesServer, ScenesBehavior } from '@project-chip/matter.js/behavior/definitions/scenes';
|
|
32
|
+
import { OnOffServer } from '@project-chip/matter.js/behavior/definitions/on-off';
|
|
33
|
+
import { TemperatureMeasurementServer } from '@project-chip/matter.js/behavior/definitions/temperature-measurement';
|
|
34
|
+
import { RelativeHumidityMeasurementServer } from '@project-chip/matter.js/behavior/definitions/relative-humidity-measurement';
|
|
35
|
+
import { PressureMeasurementServer } from '@project-chip/matter.js/behavior/definitions/pressure-measurement';
|
|
36
|
+
import { BridgedDeviceBasicInformationServer } from '@project-chip/matter.js/behavior/definitions/bridged-device-basic-information';
|
|
37
|
+
import { AirQuality, AirQualityCluster, BasicInformationCluster, BooleanState, BooleanStateCluster, BooleanStateConfiguration, BooleanStateConfigurationCluster, BridgedDeviceBasicInformation, BridgedDeviceBasicInformationCluster, CarbonDioxideConcentrationMeasurement, CarbonDioxideConcentrationMeasurementCluster, CarbonMonoxideConcentrationMeasurement, CarbonMonoxideConcentrationMeasurementCluster, ClusterServer, ColorControl, ColorControlCluster, ConcentrationMeasurement, DoorLock, DoorLockCluster, ElectricalEnergyMeasurement, ElectricalEnergyMeasurementCluster, ElectricalPowerMeasurement, ElectricalPowerMeasurementCluster, FanControl, FanControlCluster, FlowMeasurement, FlowMeasurementCluster, FormaldehydeConcentrationMeasurement, FormaldehydeConcentrationMeasurementCluster, Groups, GroupsCluster, GroupsClusterHandler, Identify, IdentifyCluster, IlluminanceMeasurement, IlluminanceMeasurementCluster, LevelControl, LevelControlCluster, MeasurementType, ModeSelectCluster, NitrogenDioxideConcentrationMeasurement, NitrogenDioxideConcentrationMeasurementCluster, OccupancySensing, OccupancySensingCluster, OnOff, OnOffCluster, OzoneConcentrationMeasurement, OzoneConcentrationMeasurementCluster, Pm10ConcentrationMeasurement, Pm10ConcentrationMeasurementCluster, Pm1ConcentrationMeasurement, Pm1ConcentrationMeasurementCluster, Pm25ConcentrationMeasurement, Pm25ConcentrationMeasurementCluster, PowerSource, PowerSourceCluster, PowerSourceConfigurationCluster, PowerTopology, PowerTopologyCluster, PressureMeasurement, PressureMeasurementCluster, RadonConcentrationMeasurement, RadonConcentrationMeasurementCluster, RelativeHumidityMeasurement, RelativeHumidityMeasurementCluster, SmokeCoAlarm, SmokeCoAlarmCluster, Switch, SwitchCluster, TemperatureMeasurement, TemperatureMeasurementCluster, Thermostat, ThermostatCluster, ThreadNetworkDiagnostics, ThreadNetworkDiagnosticsCluster, TimeSynchronization, TimeSynchronizationCluster, TotalVolatileOrganicCompoundsConcentrationMeasurement, TotalVolatileOrganicCompoundsConcentrationMeasurementCluster, WindowCovering, WindowCoveringCluster, getClusterNameById, } from '@project-chip/matter-node.js/cluster';
|
|
38
|
+
import { NamedHandler } from '@project-chip/matter-node.js/util';
|
|
39
|
+
import { EndpointNumber, VendorId } from '@project-chip/matter-node.js/datatype';
|
|
40
|
+
// Matterbridge imports
|
|
41
|
+
import { AnsiLogger, YELLOW, db, debugStringify, er, hk, or, rs, zb } from 'node-ansi-logger';
|
|
42
|
+
import { createHash } from 'crypto';
|
|
43
|
+
import { Specification } from '@project-chip/matter-node.js/model';
|
|
44
|
+
import { LevelControlServer } from '@project-chip/matter.js/behaviors/level-control';
|
|
45
|
+
import { ColorControlServer } from '@project-chip/matter.js/behaviors/color-control';
|
|
46
|
+
import { FlowMeasurementServer } from '@project-chip/matter.js/behaviors/flow-measurement';
|
|
47
|
+
import { DoorLockServer } from '@project-chip/matter.js/behaviors/door-lock';
|
|
48
|
+
import { ThermostatServer } from '@project-chip/matter.js/behaviors/thermostat';
|
|
49
|
+
import { WindowCoveringServer } from '@project-chip/matter.js/behaviors/window-covering';
|
|
50
|
+
import { FanControlServer } from '@project-chip/matter.js/behaviors/fan-control';
|
|
51
|
+
import { TimeSynchronizationServer } from '@project-chip/matter.js/behaviors/time-synchronization';
|
|
52
|
+
import { IlluminanceMeasurementServer } from '@project-chip/matter.js/behaviors/illuminance-measurement';
|
|
53
|
+
import { BooleanStateServer } from '@project-chip/matter.js/behaviors/boolean-state';
|
|
54
|
+
import { BooleanStateConfigurationServer } from '@project-chip/matter.js/behaviors/boolean-state-configuration';
|
|
55
|
+
import { OccupancySensingServer } from '@project-chip/matter.js/behaviors/occupancy-sensing';
|
|
56
|
+
export class MatterbridgeEndpoint extends Endpoint {
|
|
57
|
+
static bridgeMode = '';
|
|
58
|
+
log;
|
|
59
|
+
serialNumber = undefined;
|
|
60
|
+
deviceName = undefined;
|
|
61
|
+
uniqueId = undefined;
|
|
62
|
+
// Maps matter deviceTypes and endpoints
|
|
63
|
+
deviceTypes = new Map();
|
|
64
|
+
clusterServers = new Map();
|
|
65
|
+
clusterClients = new Map();
|
|
66
|
+
commandHandler = new NamedHandler();
|
|
67
|
+
/**
|
|
68
|
+
* Represents a MatterbridgeEndpoint device.
|
|
69
|
+
* @constructor
|
|
70
|
+
* @param {DeviceTypeDefinition} definition - The definition of the device.
|
|
71
|
+
* @param {EndpointOptions} [options={}] - The options for the device.
|
|
72
|
+
*/
|
|
73
|
+
constructor(definition, options = {}) {
|
|
74
|
+
// Convert the DeviceTypeDefinition to a EndpointType.Options
|
|
75
|
+
const deviceTypeDefinitionV8 = {
|
|
76
|
+
name: definition.name.replace('-', '_'),
|
|
77
|
+
deviceType: definition.code,
|
|
78
|
+
deviceRevision: definition.revision,
|
|
79
|
+
deviceClass: definition.deviceClass,
|
|
80
|
+
requirements: {
|
|
81
|
+
server: {
|
|
82
|
+
mandatory: SupportedBehaviors(...MatterbridgeEndpoint.getBehaviourTypesFromClusterServerIds(definition.requiredServerClusters)),
|
|
83
|
+
optional: SupportedBehaviors(...MatterbridgeEndpoint.getBehaviourTypesFromClusterServerIds(definition.optionalServerClusters)),
|
|
84
|
+
},
|
|
85
|
+
client: {
|
|
86
|
+
mandatory: SupportedBehaviors(...MatterbridgeEndpoint.getBehaviourTypesFromClusterClientIds(definition.requiredClientClusters)),
|
|
87
|
+
optional: SupportedBehaviors(...MatterbridgeEndpoint.getBehaviourTypesFromClusterClientIds(definition.optionalClientClusters)),
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
behaviors: SupportedBehaviors(...MatterbridgeEndpoint.getBehaviourTypesFromClusterServerIds(definition.requiredServerClusters)),
|
|
91
|
+
};
|
|
92
|
+
const endpointV8 = MutableEndpoint(deviceTypeDefinitionV8);
|
|
93
|
+
const optionsV8 = {
|
|
94
|
+
id: options.uniqueStorageKey,
|
|
95
|
+
};
|
|
96
|
+
super(endpointV8, optionsV8);
|
|
97
|
+
this.log = new AnsiLogger({ logName: 'MatterbridgeDevice', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logDebug: true });
|
|
98
|
+
this.deviceTypes.set(definition.code, definition);
|
|
99
|
+
}
|
|
100
|
+
static getBehaviourTypesFromClusterServerIds(clusterServerList) {
|
|
101
|
+
// Map Server ClusterId to Behavior.Type
|
|
102
|
+
const behaviorTypes = [];
|
|
103
|
+
clusterServerList.forEach((clusterId) => {
|
|
104
|
+
behaviorTypes.push(MatterbridgeEndpoint.getBehaviourTypeFromClusterServerId(clusterId));
|
|
105
|
+
});
|
|
106
|
+
return behaviorTypes;
|
|
107
|
+
}
|
|
108
|
+
static getBehaviourTypesFromClusterClientIds(clusterClientList) {
|
|
109
|
+
// Map Client ClusterId to Behavior.Type
|
|
110
|
+
const behaviorTypes = [];
|
|
111
|
+
clusterClientList.forEach((clusterId) => {
|
|
112
|
+
// behaviorTypes.push(MatterbridgeEndpoint.getBehaviourTypeFromClusterClientId(clusterId));
|
|
113
|
+
});
|
|
114
|
+
return behaviorTypes;
|
|
115
|
+
}
|
|
116
|
+
static getBehaviourTypeFromClusterServerId(clusterId) {
|
|
117
|
+
// Map ClusterId to Behavior.Type
|
|
118
|
+
if (clusterId === Identify.Cluster.id)
|
|
119
|
+
return IdentifyServer;
|
|
120
|
+
if (clusterId === Groups.Cluster.id)
|
|
121
|
+
return GroupsServer;
|
|
122
|
+
// if (clusterId === Scenes.Cluster.id) return ScenesServer;
|
|
123
|
+
if (clusterId === OnOff.Cluster.id)
|
|
124
|
+
return OnOffServer;
|
|
125
|
+
if (clusterId === LevelControl.Cluster.id)
|
|
126
|
+
return LevelControlServer;
|
|
127
|
+
if (clusterId === ColorControl.Cluster.id)
|
|
128
|
+
return ColorControlServer.with(ColorControl.Feature.HueSaturation, ColorControl.Feature.Xy, ColorControl.Feature.ColorTemperature);
|
|
129
|
+
if (clusterId === DoorLock.Cluster.id)
|
|
130
|
+
return DoorLockServer;
|
|
131
|
+
if (clusterId === Thermostat.Cluster.id)
|
|
132
|
+
return ThermostatServer.with(Thermostat.Feature.Heating, Thermostat.Feature.Cooling, Thermostat.Feature.AutoMode);
|
|
133
|
+
if (clusterId === TimeSynchronization.Cluster.id)
|
|
134
|
+
return TimeSynchronizationServer.with(TimeSynchronization.Feature.TimeZone);
|
|
135
|
+
if (clusterId === WindowCovering.Cluster.id)
|
|
136
|
+
return WindowCoveringServer.with(WindowCovering.Feature.Lift, WindowCovering.Feature.PositionAwareLift);
|
|
137
|
+
if (clusterId === FanControl.Cluster.id)
|
|
138
|
+
return FanControlServer.with(FanControl.Feature.MultiSpeed, FanControl.Feature.Auto, FanControl.Feature.Step);
|
|
139
|
+
if (clusterId === TemperatureMeasurement.Cluster.id)
|
|
140
|
+
return TemperatureMeasurementServer;
|
|
141
|
+
if (clusterId === RelativeHumidityMeasurement.Cluster.id)
|
|
142
|
+
return RelativeHumidityMeasurementServer;
|
|
143
|
+
if (clusterId === PressureMeasurement.Cluster.id)
|
|
144
|
+
return PressureMeasurementServer.with(PressureMeasurement.Feature.Extended);
|
|
145
|
+
if (clusterId === FlowMeasurement.Cluster.id)
|
|
146
|
+
return FlowMeasurementServer;
|
|
147
|
+
if (clusterId === BooleanState.Cluster.id)
|
|
148
|
+
return BooleanStateServer;
|
|
149
|
+
if (clusterId === BooleanStateConfiguration.Cluster.id)
|
|
150
|
+
return BooleanStateConfigurationServer;
|
|
151
|
+
if (clusterId === OccupancySensing.Cluster.id)
|
|
152
|
+
return OccupancySensingServer;
|
|
153
|
+
if (clusterId === IlluminanceMeasurement.Cluster.id)
|
|
154
|
+
return IlluminanceMeasurementServer;
|
|
155
|
+
if (clusterId === BridgedDeviceBasicInformation.Cluster.id)
|
|
156
|
+
return BridgedDeviceBasicInformationServer;
|
|
157
|
+
return IdentifyServer;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Loads an instance of the MatterbridgeDevice class.
|
|
161
|
+
*
|
|
162
|
+
* @param {DeviceTypeDefinition} definition - The DeviceTypeDefinition of the device.
|
|
163
|
+
* @returns MatterbridgeDevice instance.
|
|
164
|
+
*/
|
|
165
|
+
static async loadInstance(definition, options = {}) {
|
|
166
|
+
return new MatterbridgeEndpoint(definition, options);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Adds a device type to the list of device types.
|
|
170
|
+
* If the device type is not already present in the list, it will be added.
|
|
171
|
+
*
|
|
172
|
+
* @param {DeviceTypeDefinition} deviceType - The device type to add.
|
|
173
|
+
*/
|
|
174
|
+
addDeviceType(deviceType) {
|
|
175
|
+
if (!this.deviceTypes.has(deviceType.code)) {
|
|
176
|
+
// Keep the Matterbridge internal map
|
|
177
|
+
this.log.debug(`addDeviceType: ${zb}${deviceType.code}${db}-${zb}${deviceType.name}${db}`);
|
|
178
|
+
this.deviceTypes.set(deviceType.code, deviceType);
|
|
179
|
+
// Add the device types to the descriptor server
|
|
180
|
+
const deviceTypeList = Array.from(this.deviceTypes.values()).map((dt) => ({
|
|
181
|
+
deviceType: dt.code,
|
|
182
|
+
revision: dt.revision,
|
|
183
|
+
}));
|
|
184
|
+
this.behaviors.require(DescriptorServer, {
|
|
185
|
+
deviceTypeList,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Adds one or more device types with the required cluster servers and the specified cluster servers.
|
|
191
|
+
*
|
|
192
|
+
* @param {AtLeastOne<DeviceTypeDefinition>} deviceTypes - The device types to add.
|
|
193
|
+
* @param {ClusterId[]} includeServerList - The list of cluster IDs to include.
|
|
194
|
+
*/
|
|
195
|
+
addDeviceTypeWithClusterServer(deviceTypes, includeServerList) {
|
|
196
|
+
this.log.debug('addDeviceTypeWithClusterServer:');
|
|
197
|
+
deviceTypes.forEach((deviceType) => {
|
|
198
|
+
this.log.debug(`- with deviceType: ${zb}${deviceType.code}${db}-${zb}${deviceType.name}${db}`);
|
|
199
|
+
deviceType.requiredServerClusters.forEach((clusterId) => {
|
|
200
|
+
if (!includeServerList.includes(clusterId))
|
|
201
|
+
includeServerList.push(clusterId);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
includeServerList.forEach((clusterId) => {
|
|
205
|
+
this.log.debug(`- with cluster: ${hk}${clusterId}${db}-${hk}${getClusterNameById(clusterId)}${db}`);
|
|
206
|
+
});
|
|
207
|
+
deviceTypes.forEach((deviceType) => {
|
|
208
|
+
this.addDeviceType(deviceType);
|
|
209
|
+
});
|
|
210
|
+
this.addClusterServerFromList(this, includeServerList);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Adds a child endpoint with one or more device types with the required cluster servers and the specified cluster servers.
|
|
214
|
+
* If the child endpoint is not already present in the childEndpoints, it will be added.
|
|
215
|
+
* If the child endpoint is already present in the childEndpoints, the device types and cluster servers will be added to the existing child endpoint.
|
|
216
|
+
*
|
|
217
|
+
* @param {string} endpointName - The name of the new enpoint to add.
|
|
218
|
+
* @param {AtLeastOne<DeviceTypeDefinition>} deviceTypes - The device types to add.
|
|
219
|
+
* @param {ClusterId[]} includeServerList - The list of cluster IDs to include.
|
|
220
|
+
* @returns {Endpoint} - The child endpoint that was found or added.
|
|
221
|
+
*/
|
|
222
|
+
addChildDeviceTypeWithClusterServer(endpointName, deviceTypes, includeServerList) {
|
|
223
|
+
/*
|
|
224
|
+
this.log.debug(`addChildDeviceTypeWithClusterServer: ${CYAN}${endpointName}${db}`);
|
|
225
|
+
let child = this.getChildEndpoints().find((endpoint) => endpoint.uniqueStorageKey === endpointName);
|
|
226
|
+
if (!child) {
|
|
227
|
+
child = new Endpoint(deviceTypes, { uniqueStorageKey: endpointName });
|
|
228
|
+
child.addFixedLabel('endpointName', endpointName);
|
|
229
|
+
}
|
|
230
|
+
deviceTypes.forEach((deviceType) => {
|
|
231
|
+
this.log.debug(`- with deviceType: ${zb}${deviceType.code}${db}-${zb}${deviceType.name}${db}`);
|
|
232
|
+
deviceType.requiredServerClusters.forEach((clusterId) => {
|
|
233
|
+
if (!includeServerList.includes(clusterId)) includeServerList.push(clusterId);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
includeServerList.forEach((clusterId) => {
|
|
237
|
+
this.log.debug(`- with cluster: ${hk}${clusterId}${db}-${hk}${getClusterNameById(clusterId)}${db}`);
|
|
238
|
+
});
|
|
239
|
+
this.addClusterServerFromList(child, includeServerList);
|
|
240
|
+
this.addChildEndpoint(child);
|
|
241
|
+
return child;
|
|
242
|
+
*/
|
|
243
|
+
}
|
|
244
|
+
getClusterServer(cluster) {
|
|
245
|
+
const clusterServer = this.clusterServers.get(cluster.id);
|
|
246
|
+
if (clusterServer !== undefined) {
|
|
247
|
+
return clusterServer;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
getClusterServerById(clusterId) {
|
|
251
|
+
return this.clusterServers.get(clusterId);
|
|
252
|
+
}
|
|
253
|
+
addClusterServer(cluster) {
|
|
254
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
255
|
+
const options = {};
|
|
256
|
+
for (const attribute of Object.values(cluster.attributes)) {
|
|
257
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
258
|
+
if (attribute.id < 0xfff0) {
|
|
259
|
+
// No issue here for value, as cluster here is just a definition without getter setter
|
|
260
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
261
|
+
options[attribute.name] = attribute.value;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
this.log.debug(`addClusterServer: ${hk}${cluster.id}${db}-${hk}${getClusterNameById(cluster.id)}${db} with options: ${debugStringify(options)}${rs}`);
|
|
265
|
+
const behavior = MatterbridgeEndpoint.getBehaviourTypeFromClusterServerId(cluster.id);
|
|
266
|
+
this.behaviors.require(behavior, options);
|
|
267
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
268
|
+
this.clusterServers.set(cluster.id, cluster);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Adds cluster servers to the specified endpoint based on the provided server list.
|
|
272
|
+
*
|
|
273
|
+
* @param {Endpoint} endpoint - The endpoint to add cluster servers to.
|
|
274
|
+
* @param {ClusterId[]} includeServerList - The list of cluster IDs to include.
|
|
275
|
+
* @returns void
|
|
276
|
+
*/
|
|
277
|
+
addClusterServerFromList(endpoint, includeServerList) {
|
|
278
|
+
if (includeServerList.includes(Identify.Cluster.id))
|
|
279
|
+
endpoint.addClusterServer(this.getDefaultIdentifyClusterServer());
|
|
280
|
+
if (includeServerList.includes(Groups.Cluster.id))
|
|
281
|
+
endpoint.addClusterServer(this.getDefaultGroupsClusterServer());
|
|
282
|
+
// if (includeServerList.includes(Scenes.Cluster.id)) endpoint.addClusterServer(this.getDefaultScenesClusterServer());
|
|
283
|
+
if (includeServerList.includes(OnOff.Cluster.id))
|
|
284
|
+
endpoint.addClusterServer(this.getDefaultOnOffClusterServer());
|
|
285
|
+
if (includeServerList.includes(LevelControl.Cluster.id))
|
|
286
|
+
endpoint.addClusterServer(this.getDefaultLevelControlClusterServer());
|
|
287
|
+
if (includeServerList.includes(ColorControl.Cluster.id))
|
|
288
|
+
endpoint.addClusterServer(this.getDefaultCompleteColorControlClusterServer());
|
|
289
|
+
if (includeServerList.includes(Switch.Cluster.id))
|
|
290
|
+
endpoint.addClusterServer(this.getDefaultSwitchClusterServer());
|
|
291
|
+
if (includeServerList.includes(DoorLock.Cluster.id))
|
|
292
|
+
endpoint.addClusterServer(this.getDefaultDoorLockClusterServer());
|
|
293
|
+
if (includeServerList.includes(Thermostat.Cluster.id))
|
|
294
|
+
endpoint.addClusterServer(this.getDefaultThermostatClusterServer());
|
|
295
|
+
if (includeServerList.includes(TimeSynchronization.Cluster.id))
|
|
296
|
+
endpoint.addClusterServer(this.getDefaultTimeSyncClusterServer());
|
|
297
|
+
if (includeServerList.includes(WindowCovering.Cluster.id))
|
|
298
|
+
endpoint.addClusterServer(this.getDefaultWindowCoveringClusterServer());
|
|
299
|
+
if (includeServerList.includes(FanControl.Cluster.id))
|
|
300
|
+
endpoint.addClusterServer(this.getDefaultFanControlClusterServer());
|
|
301
|
+
if (includeServerList.includes(TemperatureMeasurement.Cluster.id))
|
|
302
|
+
endpoint.addClusterServer(this.getDefaultTemperatureMeasurementClusterServer());
|
|
303
|
+
if (includeServerList.includes(RelativeHumidityMeasurement.Cluster.id))
|
|
304
|
+
endpoint.addClusterServer(this.getDefaultRelativeHumidityMeasurementClusterServer());
|
|
305
|
+
if (includeServerList.includes(PressureMeasurement.Cluster.id))
|
|
306
|
+
endpoint.addClusterServer(this.getDefaultPressureMeasurementClusterServer());
|
|
307
|
+
if (includeServerList.includes(FlowMeasurement.Cluster.id))
|
|
308
|
+
endpoint.addClusterServer(this.getDefaultFlowMeasurementClusterServer());
|
|
309
|
+
if (includeServerList.includes(BooleanState.Cluster.id))
|
|
310
|
+
endpoint.addClusterServer(this.getDefaultBooleanStateClusterServer());
|
|
311
|
+
if (includeServerList.includes(BooleanStateConfiguration.Cluster.id))
|
|
312
|
+
endpoint.addClusterServer(this.getDefaultBooleanStateConfigurationClusterServer());
|
|
313
|
+
if (includeServerList.includes(OccupancySensing.Cluster.id))
|
|
314
|
+
endpoint.addClusterServer(this.getDefaultOccupancySensingClusterServer());
|
|
315
|
+
if (includeServerList.includes(IlluminanceMeasurement.Cluster.id))
|
|
316
|
+
endpoint.addClusterServer(this.getDefaultIlluminanceMeasurementClusterServer());
|
|
317
|
+
if (includeServerList.includes(PowerSource.Cluster.id))
|
|
318
|
+
endpoint.addClusterServer(this.getDefaultPowerSourceWiredClusterServer());
|
|
319
|
+
if (includeServerList.includes(PowerTopology.Cluster.id))
|
|
320
|
+
endpoint.addClusterServer(this.getDefaultPowerTopologyClusterServer());
|
|
321
|
+
if (includeServerList.includes(ElectricalPowerMeasurement.Cluster.id))
|
|
322
|
+
endpoint.addClusterServer(this.getDefaultElectricalPowerMeasurementClusterServer());
|
|
323
|
+
if (includeServerList.includes(ElectricalEnergyMeasurement.Cluster.id))
|
|
324
|
+
endpoint.addClusterServer(this.getDefaultElectricalEnergyMeasurementClusterServer());
|
|
325
|
+
if (includeServerList.includes(SmokeCoAlarm.Cluster.id))
|
|
326
|
+
endpoint.addClusterServer(this.getDefaultSmokeCOAlarmClusterServer());
|
|
327
|
+
if (includeServerList.includes(AirQuality.Cluster.id))
|
|
328
|
+
endpoint.addClusterServer(this.getDefaultAirQualityClusterServer());
|
|
329
|
+
if (includeServerList.includes(CarbonMonoxideConcentrationMeasurement.Cluster.id))
|
|
330
|
+
endpoint.addClusterServer(this.getDefaultCarbonMonoxideConcentrationMeasurementClusterServer());
|
|
331
|
+
if (includeServerList.includes(CarbonDioxideConcentrationMeasurement.Cluster.id))
|
|
332
|
+
endpoint.addClusterServer(this.getDefaultCarbonDioxideConcentrationMeasurementClusterServer());
|
|
333
|
+
if (includeServerList.includes(NitrogenDioxideConcentrationMeasurement.Cluster.id))
|
|
334
|
+
endpoint.addClusterServer(this.getDefaultNitrogenDioxideConcentrationMeasurementClusterServer());
|
|
335
|
+
if (includeServerList.includes(OzoneConcentrationMeasurement.Cluster.id))
|
|
336
|
+
endpoint.addClusterServer(this.getDefaultOzoneConcentrationMeasurementClusterServer());
|
|
337
|
+
if (includeServerList.includes(FormaldehydeConcentrationMeasurement.Cluster.id))
|
|
338
|
+
endpoint.addClusterServer(this.getDefaultFormaldehydeConcentrationMeasurementClusterServer());
|
|
339
|
+
if (includeServerList.includes(Pm1ConcentrationMeasurement.Cluster.id))
|
|
340
|
+
endpoint.addClusterServer(this.getDefaultPm1ConcentrationMeasurementClusterServer());
|
|
341
|
+
if (includeServerList.includes(Pm25ConcentrationMeasurement.Cluster.id))
|
|
342
|
+
endpoint.addClusterServer(this.getDefaultPm25ConcentrationMeasurementClusterServer());
|
|
343
|
+
if (includeServerList.includes(Pm10ConcentrationMeasurement.Cluster.id))
|
|
344
|
+
endpoint.addClusterServer(this.getDefaultPm10ConcentrationMeasurementClusterServer());
|
|
345
|
+
if (includeServerList.includes(RadonConcentrationMeasurement.Cluster.id))
|
|
346
|
+
endpoint.addClusterServer(this.getDefaultRadonConcentrationMeasurementClusterServer());
|
|
347
|
+
if (includeServerList.includes(TotalVolatileOrganicCompoundsConcentrationMeasurement.Cluster.id))
|
|
348
|
+
endpoint.addClusterServer(this.getDefaultTvocMeasurementClusterServer());
|
|
349
|
+
// if (includeServerList.includes(DeviceEnergyManagement.Cluster.id)) endpoint.addClusterServer(this.getDefaultDeviceEnergyManagementClusterServer());
|
|
350
|
+
// if (includeServerList.includes(DeviceEnergyManagementMode.Cluster.id)) endpoint.addClusterServer(this.getDefaultDeviceEnergyManagementModeClusterServer());
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* From here copy paste from MatterbridgeDevice
|
|
354
|
+
*/
|
|
355
|
+
/**
|
|
356
|
+
* Retrieves a child endpoint by its name.
|
|
357
|
+
*
|
|
358
|
+
* @param {string} endpointName - The name of the endpoint to retrieve.
|
|
359
|
+
* @returns {Endpoint | undefined} The child endpoint with the specified name, or undefined if not found.
|
|
360
|
+
*/
|
|
361
|
+
/*
|
|
362
|
+
getChildEndpointByName(endpointName: string): Endpoint | undefined {
|
|
363
|
+
return this.getChildEndpoints().find((endpoint) => endpoint.uniqueStorageKey === endpointName);
|
|
364
|
+
}
|
|
365
|
+
*/
|
|
366
|
+
/**
|
|
367
|
+
* Retrieves the value of the specified attribute from the given endpoint and cluster.
|
|
368
|
+
*
|
|
369
|
+
* @param {ClusterId} clusterId - The ID of the cluster to retrieve the attribute from.
|
|
370
|
+
* @param {string} attribute - The name of the attribute to retrieve.
|
|
371
|
+
* @param {AnsiLogger} [log] - Optional logger for error and info messages.
|
|
372
|
+
* @param {Endpoint} [endpoint] - Optional the child endpoint to retrieve the attribute from.
|
|
373
|
+
* @returns {any} The value of the attribute, or undefined if the attribute is not found.
|
|
374
|
+
*/
|
|
375
|
+
/*
|
|
376
|
+
getAttribute(clusterId: ClusterId, attribute: string, log?: AnsiLogger, endpoint?: Endpoint): any {
|
|
377
|
+
if (!endpoint) endpoint = this as Endpoint;
|
|
378
|
+
|
|
379
|
+
const clusterServer = endpoint.getClusterServerById(clusterId);
|
|
380
|
+
if (!clusterServer) {
|
|
381
|
+
log?.error(`getAttribute error: Cluster ${clusterId} not found on endpoint ${endpoint.name}:${endpoint.number}`);
|
|
382
|
+
return undefined;
|
|
383
|
+
}
|
|
384
|
+
const capitalizedAttributeName = attribute.charAt(0).toUpperCase() + attribute.slice(1);
|
|
385
|
+
if (!clusterServer.isAttributeSupportedByName(attribute) && !clusterServer.isAttributeSupportedByName(capitalizedAttributeName)) {
|
|
386
|
+
if (log) log.error(`getAttribute error: Attribute ${attribute} not found on Cluster ${clusterServer.name} on endpoint ${endpoint.name}:${endpoint.number}`);
|
|
387
|
+
return undefined;
|
|
388
|
+
}
|
|
389
|
+
// Find the getter method
|
|
390
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
391
|
+
if (!(clusterServer as any)[`get${capitalizedAttributeName}Attribute`]) {
|
|
392
|
+
log?.error(`getAttribute error: Getter get${capitalizedAttributeName}Attribute not found on Cluster ${clusterServer.name} on endpoint ${endpoint.name}:${endpoint.number}`);
|
|
393
|
+
return undefined;
|
|
394
|
+
}
|
|
395
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-object-type
|
|
396
|
+
const getter = (clusterServer as any)[`get${capitalizedAttributeName}Attribute`] as () => {};
|
|
397
|
+
const value = getter();
|
|
398
|
+
log?.info(`${db}Get endpoint ${or}${endpoint.name}:${endpoint.number}${db} attribute ${hk}${clusterServer.name}.${capitalizedAttributeName}${db} value ${YELLOW}${typeof value === 'object' ? debugStringify(value) : value}${db}`);
|
|
399
|
+
return value;
|
|
400
|
+
}
|
|
401
|
+
*/
|
|
402
|
+
/**
|
|
403
|
+
* Sets the value of an attribute on a cluster server endpoint.
|
|
404
|
+
*
|
|
405
|
+
* @param {ClusterId} clusterId - The ID of the cluster.
|
|
406
|
+
* @param {string} attribute - The name of the attribute.
|
|
407
|
+
* @param {any} value - The value to set for the attribute.
|
|
408
|
+
* @param {AnsiLogger} [log] - (Optional) The logger to use for logging errors and information.
|
|
409
|
+
* @param {Endpoint} [endpoint] - (Optional) The endpoint to set the attribute on. If not provided, the attribute will be set on the current endpoint.
|
|
410
|
+
*/
|
|
411
|
+
/*
|
|
412
|
+
setAttribute(clusterId: ClusterId, attribute: string, value: any, log?: AnsiLogger, endpoint?: Endpoint): boolean {
|
|
413
|
+
if (!endpoint) endpoint = this as Endpoint;
|
|
414
|
+
|
|
415
|
+
const clusterServer = endpoint.getClusterServerById(clusterId);
|
|
416
|
+
if (!clusterServer) {
|
|
417
|
+
log?.error(`setAttribute error: Cluster ${clusterId} not found on endpoint ${endpoint.name}:${endpoint.number}`);
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
const capitalizedAttributeName = attribute.charAt(0).toUpperCase() + attribute.slice(1);
|
|
421
|
+
if (!clusterServer.isAttributeSupportedByName(attribute) && !clusterServer.isAttributeSupportedByName(capitalizedAttributeName)) {
|
|
422
|
+
if (log) log.error(`setAttribute error: Attribute ${attribute} not found on Cluster ${clusterId} on endpoint ${endpoint.name}:${endpoint.number}`);
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
// Find the getter method
|
|
426
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
427
|
+
if (!(clusterServer as any)[`get${capitalizedAttributeName}Attribute`]) {
|
|
428
|
+
log?.error(`setAttribute error: Getter get${capitalizedAttributeName}Attribute not found on Cluster ${clusterServer.name} on endpoint ${endpoint.name}:${endpoint.number}`);
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-object-type
|
|
432
|
+
const getter = (clusterServer as any)[`get${capitalizedAttributeName}Attribute`] as () => {};
|
|
433
|
+
// Find the setter method
|
|
434
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
435
|
+
if (!(clusterServer as any)[`set${capitalizedAttributeName}Attribute`]) {
|
|
436
|
+
log?.error(`setAttribute error: Setter set${capitalizedAttributeName}Attribute not found on Cluster ${clusterServer.name} on endpoint ${endpoint.name}:${endpoint.number}`);
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-object-type
|
|
440
|
+
const setter = (clusterServer as any)[`set${capitalizedAttributeName}Attribute`] as (value: any) => {};
|
|
441
|
+
const oldValue = getter();
|
|
442
|
+
setter(value);
|
|
443
|
+
log?.info(
|
|
444
|
+
`${db}Set endpoint ${or}${endpoint.name}:${endpoint.number}${db} attribute ${hk}${clusterServer.name}.${capitalizedAttributeName}${db} ` +
|
|
445
|
+
`from ${YELLOW}${typeof oldValue === 'object' ? debugStringify(oldValue) : oldValue}${db} ` +
|
|
446
|
+
`to ${YELLOW}${typeof value === 'object' ? debugStringify(value) : value}${db}`,
|
|
447
|
+
);
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
*/
|
|
451
|
+
/**
|
|
452
|
+
* Subscribes to an attribute on a cluster.
|
|
453
|
+
*
|
|
454
|
+
* @param {ClusterId} clusterId - The ID of the cluster.
|
|
455
|
+
* @param {string} attribute - The name of the attribute to subscribe to.
|
|
456
|
+
* @param {(newValue: any, oldValue: any) => void} listener - A callback function that will be called when the attribute value changes.
|
|
457
|
+
* @param {AnsiLogger} log - (Optional) An AnsiLogger instance for logging errors and information.
|
|
458
|
+
* @param {Endpoint} endpoint - (Optional) The endpoint to subscribe the attribute on. If not provided, the current endpoint will be used.
|
|
459
|
+
* @returns A boolean indicating whether the subscription was successful.
|
|
460
|
+
*/
|
|
461
|
+
/*
|
|
462
|
+
subscribeAttribute(clusterId: ClusterId, attribute: string, listener: (newValue: any, oldValue: any) => void, log?: AnsiLogger, endpoint?: Endpoint): boolean {
|
|
463
|
+
if (!endpoint) endpoint = this as Endpoint;
|
|
464
|
+
|
|
465
|
+
const clusterServer = endpoint.getClusterServerById(clusterId);
|
|
466
|
+
if (!clusterServer) {
|
|
467
|
+
log?.error(`subscribeAttribute error: Cluster ${clusterId} not found on endpoint ${endpoint.name}:${endpoint.number}`);
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
const capitalizedAttributeName = attribute.charAt(0).toUpperCase() + attribute.slice(1);
|
|
471
|
+
if (!clusterServer.isAttributeSupportedByName(attribute) && !clusterServer.isAttributeSupportedByName(capitalizedAttributeName)) {
|
|
472
|
+
if (log) log.error(`subscribeAttribute error: Attribute ${attribute} not found on Cluster ${clusterServer.name} on endpoint ${endpoint.name}:${endpoint.number}`);
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
// Find the subscribe method
|
|
476
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
477
|
+
if (!(clusterServer as any)[`subscribe${capitalizedAttributeName}Attribute`]) {
|
|
478
|
+
log?.error(`subscribeAttribute error: subscribe${capitalizedAttributeName}Attribute not found on Cluster ${clusterServer.name} on endpoint ${endpoint.name}:${endpoint.number}`);
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
// Subscribe to the attribute
|
|
482
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-object-type
|
|
483
|
+
const subscribe = (clusterServer as any)[`subscribe${capitalizedAttributeName}Attribute`] as (listener: (newValue: any, oldValue: any) => void) => {};
|
|
484
|
+
subscribe(listener);
|
|
485
|
+
log?.info(`${db}Subscribe endpoint ${or}${endpoint.name}:${endpoint.number}${db} attribute ${hk}${clusterServer.name}.${capitalizedAttributeName}${db}`);
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
488
|
+
*/
|
|
489
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
490
|
+
addCommandHandler(clusterId, command, handler) {
|
|
491
|
+
const clusterServer = this.getClusterServerById(clusterId);
|
|
492
|
+
if (!clusterServer) {
|
|
493
|
+
this.log.error(`addCommandHandler error: Cluster ${clusterId} not found on endpoint ${this.id}:${this.number}`);
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
if (!clusterServer.isCommandSupportedByName(command)) {
|
|
497
|
+
this.log.error(`addCommandHandler error: Command ${command} not found on Cluster ${clusterServer.name} on endpoint ${this.id}:${this.number}`);
|
|
498
|
+
return false;
|
|
499
|
+
}
|
|
500
|
+
// Find the command
|
|
501
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
502
|
+
const commands = clusterServer.commands;
|
|
503
|
+
for (const [key, value] of Object.entries(commands)) {
|
|
504
|
+
// console.log(`Key "${key}": ${debugStringify(value)}`);
|
|
505
|
+
if (key === command) {
|
|
506
|
+
value.handler = handler;
|
|
507
|
+
this.log.info(`${db}Command handler added for endpoint ${or}${this.id}:${this.number}${db} ${hk}${clusterServer.name}.${command}${db}`);
|
|
508
|
+
return true;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
this.log.error(`Command handler not found for endpoint ${or}${this.id}:${this.number}${er} ${hk}${clusterServer.name}.${command}${er}`);
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Serializes the Matterbridge device into a serialized object.
|
|
516
|
+
*
|
|
517
|
+
* @param pluginName - The name of the plugin.
|
|
518
|
+
* @returns The serialized Matterbridge device object.
|
|
519
|
+
*/
|
|
520
|
+
/*
|
|
521
|
+
serialize(): SerializedMatterbridgeDevice | undefined {
|
|
522
|
+
if (!this.serialNumber || !this.deviceName || !this.uniqueId) return;
|
|
523
|
+
const cluster = this.getClusterServer(BasicInformationCluster) ?? this.getClusterServer(BridgedDeviceBasicInformationCluster);
|
|
524
|
+
if (!cluster) return;
|
|
525
|
+
const serialized: SerializedMatterbridgeDevice = {
|
|
526
|
+
pluginName: this.plugin ?? 'Unknown',
|
|
527
|
+
serialNumber: this.serialNumber,
|
|
528
|
+
deviceName: this.deviceName,
|
|
529
|
+
uniqueId: this.uniqueId,
|
|
530
|
+
productName: cluster.attributes.productName?.getLocal(),
|
|
531
|
+
vendorId: cluster.attributes.vendorId?.getLocal(),
|
|
532
|
+
vendorName: cluster.attributes.vendorName?.getLocal(),
|
|
533
|
+
deviceTypes: this.getDeviceTypes(),
|
|
534
|
+
endpoint: this.number,
|
|
535
|
+
endpointName: this.name,
|
|
536
|
+
clusterServersId: [],
|
|
537
|
+
};
|
|
538
|
+
this.getAllClusterServers().forEach((clusterServer) => {
|
|
539
|
+
serialized.clusterServersId.push(clusterServer.id);
|
|
540
|
+
});
|
|
541
|
+
return serialized;
|
|
542
|
+
}
|
|
543
|
+
*/
|
|
544
|
+
/**
|
|
545
|
+
* Deserializes the device into a serialized object.
|
|
546
|
+
*
|
|
547
|
+
* @returns The deserialized MatterbridgeDevice.
|
|
548
|
+
*/
|
|
549
|
+
/*
|
|
550
|
+
static deserialize(serializedDevice: SerializedMatterbridgeDevice): MatterbridgeDevice {
|
|
551
|
+
const device = new MatterbridgeDevice(serializedDevice.deviceTypes);
|
|
552
|
+
device.serialNumber = serializedDevice.serialNumber;
|
|
553
|
+
device.deviceName = serializedDevice.deviceName;
|
|
554
|
+
device.uniqueId = serializedDevice.uniqueId;
|
|
555
|
+
for (const clusterId of serializedDevice.clusterServersId) {
|
|
556
|
+
if (clusterId === BasicInformationCluster.id)
|
|
557
|
+
device.createDefaultBasicInformationClusterServer(
|
|
558
|
+
serializedDevice.deviceName,
|
|
559
|
+
serializedDevice.serialNumber,
|
|
560
|
+
serializedDevice.vendorId ?? 0xfff1,
|
|
561
|
+
serializedDevice.vendorName ?? 'Matterbridge',
|
|
562
|
+
serializedDevice.productId ?? 0x8000,
|
|
563
|
+
serializedDevice.productName ?? 'Matterbridge device',
|
|
564
|
+
);
|
|
565
|
+
else if (clusterId === BridgedDeviceBasicInformationCluster.id)
|
|
566
|
+
device.createDefaultBridgedDeviceBasicInformationClusterServer(
|
|
567
|
+
serializedDevice.deviceName,
|
|
568
|
+
serializedDevice.serialNumber,
|
|
569
|
+
serializedDevice.vendorId ?? 0xfff1,
|
|
570
|
+
serializedDevice.vendorName ?? 'Matterbridge',
|
|
571
|
+
serializedDevice.productName ?? 'Matterbridge device',
|
|
572
|
+
);
|
|
573
|
+
else device.addClusterServerFromList(device, [clusterId]);
|
|
574
|
+
}
|
|
575
|
+
return device;
|
|
576
|
+
}
|
|
577
|
+
*/
|
|
578
|
+
/**
|
|
579
|
+
* Get a default IdentifyCluster server.
|
|
580
|
+
*/
|
|
581
|
+
getDefaultIdentifyClusterServer(identifyTime = 0, identifyType = Identify.IdentifyType.None) {
|
|
582
|
+
return ClusterServer(IdentifyCluster, {
|
|
583
|
+
identifyTime,
|
|
584
|
+
identifyType,
|
|
585
|
+
}, {
|
|
586
|
+
identify: async (data) => {
|
|
587
|
+
this.log.debug('Matter command: Identify');
|
|
588
|
+
await this.commandHandler.executeHandler('identify', data);
|
|
589
|
+
},
|
|
590
|
+
triggerEffect: async (data) => {
|
|
591
|
+
this.log.debug('Matter command: TriggerEffect');
|
|
592
|
+
await this.commandHandler.executeHandler('triggerEffect', data);
|
|
593
|
+
},
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Creates a default IdentifyCluster server.
|
|
598
|
+
*/
|
|
599
|
+
createDefaultIdentifyClusterServer(identifyTime = 0, identifyType = Identify.IdentifyType.None) {
|
|
600
|
+
this.addClusterServer(this.getDefaultIdentifyClusterServer(identifyTime, identifyType));
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Get a default IdentifyCluster server.
|
|
604
|
+
*/
|
|
605
|
+
getDefaultGroupsClusterServer() {
|
|
606
|
+
return ClusterServer(GroupsCluster, {
|
|
607
|
+
nameSupport: {
|
|
608
|
+
nameSupport: true,
|
|
609
|
+
},
|
|
610
|
+
}, GroupsClusterHandler());
|
|
611
|
+
// return createDefaultGroupsClusterServer();
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Creates a default groups cluster server and adds it to the device.
|
|
615
|
+
*/
|
|
616
|
+
createDefaultGroupsClusterServer() {
|
|
617
|
+
this.addClusterServer(this.getDefaultGroupsClusterServer());
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Get a default scenes cluster server and adds it to the current instance.
|
|
621
|
+
* @deprecated This method is deprecated.
|
|
622
|
+
*
|
|
623
|
+
*/
|
|
624
|
+
getDefaultScenesClusterServer() {
|
|
625
|
+
/*
|
|
626
|
+
return ClusterServer(
|
|
627
|
+
ScenesCluster,
|
|
628
|
+
{
|
|
629
|
+
sceneCount: 0,
|
|
630
|
+
currentScene: 0,
|
|
631
|
+
currentGroup: GroupId(0),
|
|
632
|
+
sceneValid: false,
|
|
633
|
+
nameSupport: {
|
|
634
|
+
nameSupport: true,
|
|
635
|
+
},
|
|
636
|
+
lastConfiguredBy: null,
|
|
637
|
+
},
|
|
638
|
+
{},
|
|
639
|
+
);
|
|
640
|
+
*/
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Creates a default scenes cluster server and adds it to the current instance.
|
|
644
|
+
* @deprecated This method is deprecated.
|
|
645
|
+
*/
|
|
646
|
+
createDefaultScenesClusterServer() {
|
|
647
|
+
/*
|
|
648
|
+
this.addClusterServer(this.getDefaultScenesClusterServer());
|
|
649
|
+
*/
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Creates a unique identifier based on the provided parameters.
|
|
653
|
+
* @param param1 - The first parameter.
|
|
654
|
+
* @param param2 - The second parameter.
|
|
655
|
+
* @param param3 - The third parameter.
|
|
656
|
+
* @param param4 - The fourth parameter.
|
|
657
|
+
* @returns A unique identifier generated using the MD5 hash algorithm.
|
|
658
|
+
*/
|
|
659
|
+
createUniqueId(param1, param2, param3, param4) {
|
|
660
|
+
const hash = createHash('md5');
|
|
661
|
+
hash.update(param1 + param2 + param3 + param4);
|
|
662
|
+
return hash.digest('hex');
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Get a default Basic Information Cluster Server.
|
|
666
|
+
*
|
|
667
|
+
* @param deviceName - The name of the device.
|
|
668
|
+
* @param serialNumber - The serial number of the device.
|
|
669
|
+
* @param vendorId - The vendor ID of the device.
|
|
670
|
+
* @param vendorName - The vendor name of the device.
|
|
671
|
+
* @param productId - The product ID of the device.
|
|
672
|
+
* @param productName - The product name of the device.
|
|
673
|
+
* @param softwareVersion - The software version of the device. Default is 1.
|
|
674
|
+
* @param softwareVersionString - The software version string of the device. Default is 'v.1.0.0'.
|
|
675
|
+
* @param hardwareVersion - The hardware version of the device. Default is 1.
|
|
676
|
+
* @param hardwareVersionString - The hardware version string of the device. Default is 'v.1.0.0'.
|
|
677
|
+
*/
|
|
678
|
+
getDefaultBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productId, productName, softwareVersion = 1, softwareVersionString = '1.0.0', hardwareVersion = 1, hardwareVersionString = '1.0.0') {
|
|
679
|
+
return ClusterServer(BasicInformationCluster, {
|
|
680
|
+
dataModelRevision: 1,
|
|
681
|
+
location: 'XX',
|
|
682
|
+
vendorId: VendorId(vendorId),
|
|
683
|
+
vendorName: vendorName.slice(0, 32),
|
|
684
|
+
productId: productId,
|
|
685
|
+
productName: productName.slice(0, 32),
|
|
686
|
+
productLabel: deviceName.slice(0, 64),
|
|
687
|
+
nodeLabel: deviceName.slice(0, 32),
|
|
688
|
+
serialNumber: serialNumber.slice(0, 32),
|
|
689
|
+
uniqueId: this.createUniqueId(deviceName, serialNumber, vendorName, productName),
|
|
690
|
+
softwareVersion,
|
|
691
|
+
softwareVersionString: softwareVersionString.slice(0, 64),
|
|
692
|
+
hardwareVersion,
|
|
693
|
+
hardwareVersionString: hardwareVersionString.slice(0, 64),
|
|
694
|
+
reachable: true,
|
|
695
|
+
capabilityMinima: { caseSessionsPerFabric: 3, subscriptionsPerFabric: 3 },
|
|
696
|
+
specificationVersion: Specification.SPECIFICATION_VERSION,
|
|
697
|
+
maxPathsPerInvoke: 1,
|
|
698
|
+
}, {}, {
|
|
699
|
+
startUp: true,
|
|
700
|
+
shutDown: true,
|
|
701
|
+
leave: true,
|
|
702
|
+
reachableChanged: true,
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Creates a default Basic Information Cluster Server.
|
|
707
|
+
*
|
|
708
|
+
* @param deviceName - The name of the device.
|
|
709
|
+
* @param serialNumber - The serial number of the device.
|
|
710
|
+
* @param vendorId - The vendor ID of the device.
|
|
711
|
+
* @param vendorName - The vendor name of the device.
|
|
712
|
+
* @param productId - The product ID of the device.
|
|
713
|
+
* @param productName - The product name of the device.
|
|
714
|
+
* @param softwareVersion - The software version of the device. Default is 1.
|
|
715
|
+
* @param softwareVersionString - The software version string of the device. Default is 'v.1.0.0'.
|
|
716
|
+
* @param hardwareVersion - The hardware version of the device. Default is 1.
|
|
717
|
+
* @param hardwareVersionString - The hardware version string of the device. Default is 'v.1.0.0'.
|
|
718
|
+
*/
|
|
719
|
+
createDefaultBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productId, productName, softwareVersion = 1, softwareVersionString = '1.0.0', hardwareVersion = 1, hardwareVersionString = '1.0.0') {
|
|
720
|
+
this.deviceName = deviceName;
|
|
721
|
+
this.serialNumber = serialNumber;
|
|
722
|
+
this.uniqueId = this.createUniqueId(deviceName, serialNumber, vendorName, productName);
|
|
723
|
+
if (MatterbridgeEndpoint.bridgeMode === 'bridge') {
|
|
724
|
+
this.createDefaultBridgedDeviceBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productName, softwareVersion, softwareVersionString, hardwareVersion, hardwareVersionString);
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
this.addClusterServer(this.getDefaultBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productId, productName, softwareVersion, softwareVersionString, hardwareVersion, hardwareVersionString));
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* Get a default BridgedDeviceBasicInformationClusterServer.
|
|
731
|
+
*
|
|
732
|
+
* @param deviceName - The name of the device.
|
|
733
|
+
* @param serialNumber - The serial number of the device.
|
|
734
|
+
* @param vendorId - The vendor ID of the device.
|
|
735
|
+
* @param vendorName - The name of the vendor.
|
|
736
|
+
* @param productName - The name of the product.
|
|
737
|
+
* @param softwareVersion - The software version of the device. Default is 1.
|
|
738
|
+
* @param softwareVersionString - The software version string of the device. Default is 'v.1.0.0'.
|
|
739
|
+
* @param hardwareVersion - The hardware version of the device. Default is 1.
|
|
740
|
+
* @param hardwareVersionString - The hardware version string of the device. Default is 'v.1.0.0'.
|
|
741
|
+
*/
|
|
742
|
+
getDefaultBridgedDeviceBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productName, softwareVersion = 1, softwareVersionString = '1.0.0', hardwareVersion = 1, hardwareVersionString = '1.0.0') {
|
|
743
|
+
return ClusterServer(BridgedDeviceBasicInformationCluster, {
|
|
744
|
+
vendorId: vendorId !== undefined ? VendorId(vendorId) : undefined, // 4874
|
|
745
|
+
vendorName: vendorName.slice(0, 32),
|
|
746
|
+
productName: productName.slice(0, 32),
|
|
747
|
+
productLabel: deviceName.slice(0, 64),
|
|
748
|
+
nodeLabel: deviceName.slice(0, 32),
|
|
749
|
+
serialNumber: serialNumber.slice(0, 32),
|
|
750
|
+
uniqueId: this.createUniqueId(deviceName, serialNumber, vendorName, productName),
|
|
751
|
+
softwareVersion,
|
|
752
|
+
softwareVersionString: softwareVersionString.slice(0, 64),
|
|
753
|
+
hardwareVersion,
|
|
754
|
+
hardwareVersionString: hardwareVersionString.slice(0, 64),
|
|
755
|
+
reachable: true,
|
|
756
|
+
}, {}, {
|
|
757
|
+
startUp: true,
|
|
758
|
+
shutDown: true,
|
|
759
|
+
leave: true,
|
|
760
|
+
reachableChanged: true,
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Creates a default BridgedDeviceBasicInformationClusterServer.
|
|
765
|
+
*
|
|
766
|
+
* @param deviceName - The name of the device.
|
|
767
|
+
* @param serialNumber - The serial number of the device.
|
|
768
|
+
* @param vendorId - The vendor ID of the device.
|
|
769
|
+
* @param vendorName - The name of the vendor.
|
|
770
|
+
* @param productName - The name of the product.
|
|
771
|
+
* @param softwareVersion - The software version of the device. Default is 1.
|
|
772
|
+
* @param softwareVersionString - The software version string of the device. Default is 'v.1.0.0'.
|
|
773
|
+
* @param hardwareVersion - The hardware version of the device. Default is 1.
|
|
774
|
+
* @param hardwareVersionString - The hardware version string of the device. Default is 'v.1.0.0'.
|
|
775
|
+
*/
|
|
776
|
+
createDefaultBridgedDeviceBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productName, softwareVersion = 1, softwareVersionString = '1.0.0', hardwareVersion = 1, hardwareVersionString = '1.0.0') {
|
|
777
|
+
this.deviceName = deviceName;
|
|
778
|
+
this.serialNumber = serialNumber;
|
|
779
|
+
this.uniqueId = this.createUniqueId(deviceName, serialNumber, vendorName, productName);
|
|
780
|
+
this.addClusterServer(this.getDefaultBridgedDeviceBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productName, softwareVersion, softwareVersionString, hardwareVersion, hardwareVersionString));
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Get a default Power Topology Cluster Server. Only needed for an electricalSensor device type.
|
|
784
|
+
*
|
|
785
|
+
* @returns {ClusterServer} - The configured Power Topology Cluster Server.
|
|
786
|
+
*/
|
|
787
|
+
getDefaultPowerTopologyClusterServer() {
|
|
788
|
+
return ClusterServer(PowerTopologyCluster.with(PowerTopology.Feature.TreeTopology), {}, {}, {});
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Get a default Electrical Energy Measurement Cluster Server.
|
|
792
|
+
*
|
|
793
|
+
* @param {number} energy - The total consumption value in mW/h.
|
|
794
|
+
* @returns {ClusterServer} - The configured Electrical Energy Measurement Cluster Server.
|
|
795
|
+
*/
|
|
796
|
+
getDefaultElectricalEnergyMeasurementClusterServer(energy = null) {
|
|
797
|
+
return ClusterServer(ElectricalEnergyMeasurementCluster.with(ElectricalEnergyMeasurement.Feature.ImportedEnergy, ElectricalEnergyMeasurement.Feature.ExportedEnergy, ElectricalEnergyMeasurement.Feature.CumulativeEnergy), {
|
|
798
|
+
accuracy: {
|
|
799
|
+
measurementType: MeasurementType.ElectricalEnergy,
|
|
800
|
+
measured: true,
|
|
801
|
+
minMeasuredValue: Number.MIN_SAFE_INTEGER,
|
|
802
|
+
maxMeasuredValue: Number.MAX_SAFE_INTEGER,
|
|
803
|
+
accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
|
|
804
|
+
},
|
|
805
|
+
cumulativeEnergyReset: null,
|
|
806
|
+
cumulativeEnergyImported: energy ? { energy } : null,
|
|
807
|
+
cumulativeEnergyExported: null,
|
|
808
|
+
}, {}, {
|
|
809
|
+
cumulativeEnergyMeasured: true,
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Get a default Electrical Power Measurement Cluster Server.
|
|
814
|
+
*
|
|
815
|
+
* @param {number} voltage - The voltage value in millivolts.
|
|
816
|
+
* @param {number} current - The current value in milliamperes.
|
|
817
|
+
* @param {number} power - The power value in milliwatts.
|
|
818
|
+
* @param {number} frequency - The frequency value in millihertz.
|
|
819
|
+
* @returns {ClusterServer} - The configured Electrical Power Measurement Cluster Server.
|
|
820
|
+
*/
|
|
821
|
+
getDefaultElectricalPowerMeasurementClusterServer(voltage = null, current = null, power = null, frequency = null) {
|
|
822
|
+
return ClusterServer(ElectricalPowerMeasurementCluster.with(ElectricalPowerMeasurement.Feature.AlternatingCurrent), {
|
|
823
|
+
powerMode: ElectricalPowerMeasurement.PowerMode.Ac,
|
|
824
|
+
numberOfMeasurementTypes: 3,
|
|
825
|
+
accuracy: [
|
|
826
|
+
{
|
|
827
|
+
measurementType: MeasurementType.Voltage,
|
|
828
|
+
measured: true,
|
|
829
|
+
minMeasuredValue: Number.MIN_SAFE_INTEGER,
|
|
830
|
+
maxMeasuredValue: Number.MAX_SAFE_INTEGER,
|
|
831
|
+
accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
measurementType: MeasurementType.ActiveCurrent,
|
|
835
|
+
measured: true,
|
|
836
|
+
minMeasuredValue: Number.MIN_SAFE_INTEGER,
|
|
837
|
+
maxMeasuredValue: Number.MAX_SAFE_INTEGER,
|
|
838
|
+
accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
measurementType: MeasurementType.ActivePower,
|
|
842
|
+
measured: true,
|
|
843
|
+
minMeasuredValue: Number.MIN_SAFE_INTEGER,
|
|
844
|
+
maxMeasuredValue: Number.MAX_SAFE_INTEGER,
|
|
845
|
+
accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
|
|
846
|
+
},
|
|
847
|
+
{
|
|
848
|
+
measurementType: MeasurementType.Frequency,
|
|
849
|
+
measured: true,
|
|
850
|
+
minMeasuredValue: Number.MIN_SAFE_INTEGER,
|
|
851
|
+
maxMeasuredValue: Number.MAX_SAFE_INTEGER,
|
|
852
|
+
accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
|
|
853
|
+
},
|
|
854
|
+
],
|
|
855
|
+
voltage: voltage,
|
|
856
|
+
activeCurrent: current,
|
|
857
|
+
activePower: power,
|
|
858
|
+
frequency: frequency,
|
|
859
|
+
}, {}, {});
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Creates a default Dummy Thread Network Diagnostics Cluster server.
|
|
863
|
+
* @deprecated This method is deprecated and is only used for testing.
|
|
864
|
+
*
|
|
865
|
+
* @remarks
|
|
866
|
+
* This method adds a cluster server used only to give the networkName to Eve app.
|
|
867
|
+
*
|
|
868
|
+
* @returns void
|
|
869
|
+
*/
|
|
870
|
+
createDefaultDummyThreadNetworkDiagnosticsClusterServer() {
|
|
871
|
+
this.addClusterServer(ClusterServer(ThreadNetworkDiagnosticsCluster.with(ThreadNetworkDiagnostics.Feature.PacketCounts, ThreadNetworkDiagnostics.Feature.ErrorCounts), {
|
|
872
|
+
channel: 1,
|
|
873
|
+
routingRole: ThreadNetworkDiagnostics.RoutingRole.Router,
|
|
874
|
+
networkName: 'MyMatterThread',
|
|
875
|
+
panId: 0,
|
|
876
|
+
extendedPanId: 0,
|
|
877
|
+
meshLocalPrefix: null,
|
|
878
|
+
neighborTable: [],
|
|
879
|
+
routeTable: [],
|
|
880
|
+
partitionId: null,
|
|
881
|
+
weighting: null,
|
|
882
|
+
dataVersion: null,
|
|
883
|
+
stableDataVersion: null,
|
|
884
|
+
leaderRouterId: null,
|
|
885
|
+
securityPolicy: null,
|
|
886
|
+
channelPage0Mask: null,
|
|
887
|
+
operationalDatasetComponents: null,
|
|
888
|
+
overrunCount: 0,
|
|
889
|
+
activeNetworkFaultsList: [],
|
|
890
|
+
}, {
|
|
891
|
+
resetCounts: async (data) => {
|
|
892
|
+
this.log.debug('Matter command: resetCounts');
|
|
893
|
+
await this.commandHandler.executeHandler('resetCounts', data);
|
|
894
|
+
},
|
|
895
|
+
}, {}));
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Get a default OnOff cluster server.
|
|
899
|
+
*
|
|
900
|
+
* @param onOff - The initial state of the OnOff cluster (default: false).
|
|
901
|
+
*/
|
|
902
|
+
getDefaultOnOffClusterServer(onOff = false) {
|
|
903
|
+
return ClusterServer(OnOffCluster, {
|
|
904
|
+
onOff,
|
|
905
|
+
}, {
|
|
906
|
+
on: async (data) => {
|
|
907
|
+
this.log.debug('Matter command: on onOff:', data.attributes.onOff.getLocal());
|
|
908
|
+
await this.commandHandler.executeHandler('on', data);
|
|
909
|
+
},
|
|
910
|
+
off: async (data) => {
|
|
911
|
+
this.log.debug('Matter command: off onOff:', data.attributes.onOff.getLocal());
|
|
912
|
+
await this.commandHandler.executeHandler('off', data);
|
|
913
|
+
},
|
|
914
|
+
toggle: async (data) => {
|
|
915
|
+
this.log.debug('Matter command: toggle onOff:', data.attributes.onOff.getLocal());
|
|
916
|
+
await this.commandHandler.executeHandler('toggle', data);
|
|
917
|
+
},
|
|
918
|
+
}, {});
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Creates a default OnOff cluster server.
|
|
922
|
+
*
|
|
923
|
+
* @param onOff - The initial state of the OnOff cluster (default: false).
|
|
924
|
+
*/
|
|
925
|
+
createDefaultOnOffClusterServer(onOff = false) {
|
|
926
|
+
this.addClusterServer(this.getDefaultOnOffClusterServer(onOff));
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* Get a default level control cluster server.
|
|
930
|
+
*
|
|
931
|
+
* @param currentLevel - The current level (default: 0).
|
|
932
|
+
*/
|
|
933
|
+
getDefaultLevelControlClusterServer(currentLevel = 0) {
|
|
934
|
+
return ClusterServer(LevelControlCluster.with(LevelControl.Feature.OnOff), {
|
|
935
|
+
currentLevel,
|
|
936
|
+
onLevel: 0,
|
|
937
|
+
options: {
|
|
938
|
+
executeIfOff: false,
|
|
939
|
+
coupleColorTempToLevel: false,
|
|
940
|
+
},
|
|
941
|
+
}, {
|
|
942
|
+
moveToLevel: async (data) => {
|
|
943
|
+
this.log.debug('Matter command: moveToLevel request:', data.request, 'attributes.currentLevel:', data.attributes.currentLevel.getLocal());
|
|
944
|
+
await this.commandHandler.executeHandler('moveToLevel', data);
|
|
945
|
+
},
|
|
946
|
+
move: async () => {
|
|
947
|
+
this.log.error('Matter command: move not implemented');
|
|
948
|
+
},
|
|
949
|
+
step: async () => {
|
|
950
|
+
this.log.error('Matter command: step not implemented');
|
|
951
|
+
},
|
|
952
|
+
stop: async () => {
|
|
953
|
+
this.log.error('Matter command: stop not implemented');
|
|
954
|
+
},
|
|
955
|
+
moveToLevelWithOnOff: async (data) => {
|
|
956
|
+
this.log.debug('Matter command: moveToLevelWithOnOff request:', data.request, 'attributes.currentLevel:', data.attributes.currentLevel.getLocal());
|
|
957
|
+
await this.commandHandler.executeHandler('moveToLevelWithOnOff', data);
|
|
958
|
+
},
|
|
959
|
+
moveWithOnOff: async () => {
|
|
960
|
+
this.log.error('Matter command: moveWithOnOff not implemented');
|
|
961
|
+
},
|
|
962
|
+
stepWithOnOff: async () => {
|
|
963
|
+
this.log.error('Matter command: stepWithOnOff not implemented');
|
|
964
|
+
},
|
|
965
|
+
stopWithOnOff: async () => {
|
|
966
|
+
this.log.error('Matter command: stopWithOnOff not implemented');
|
|
967
|
+
},
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Creates a default level control cluster server.
|
|
972
|
+
*
|
|
973
|
+
* @param currentLevel - The current level (default: 0).
|
|
974
|
+
*/
|
|
975
|
+
createDefaultLevelControlClusterServer(currentLevel = 0) {
|
|
976
|
+
this.addClusterServer(this.getDefaultLevelControlClusterServer(currentLevel));
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Get a default color control cluster server.
|
|
980
|
+
*
|
|
981
|
+
* @param currentX - The current X value.
|
|
982
|
+
* @param currentY - The current Y value.
|
|
983
|
+
* @param currentHue - The current hue value.
|
|
984
|
+
* @param currentSaturation - The current saturation value.
|
|
985
|
+
* @param colorTemperatureMireds - The color temperature in mireds.
|
|
986
|
+
* @param colorTempPhysicalMinMireds - The physical minimum color temperature in mireds.
|
|
987
|
+
* @param colorTempPhysicalMaxMireds - The physical maximum color temperature in mireds.
|
|
988
|
+
*/
|
|
989
|
+
getDefaultCompleteColorControlClusterServer(currentX = 0, currentY = 0, currentHue = 0, currentSaturation = 0, colorTemperatureMireds = 500, colorTempPhysicalMinMireds = 147, colorTempPhysicalMaxMireds = 500) {
|
|
990
|
+
return ClusterServer(ColorControlCluster.with(ColorControl.Feature.Xy, ColorControl.Feature.HueSaturation, ColorControl.Feature.ColorTemperature), {
|
|
991
|
+
colorMode: ColorControl.ColorMode.CurrentHueAndCurrentSaturation,
|
|
992
|
+
enhancedColorMode: ColorControl.EnhancedColorMode.CurrentHueAndCurrentSaturation,
|
|
993
|
+
colorCapabilities: { xy: true, hueSaturation: true, colorLoop: false, enhancedHue: false, colorTemperature: true },
|
|
994
|
+
options: {
|
|
995
|
+
executeIfOff: false,
|
|
996
|
+
},
|
|
997
|
+
numberOfPrimaries: null,
|
|
998
|
+
currentX,
|
|
999
|
+
currentY,
|
|
1000
|
+
currentHue,
|
|
1001
|
+
currentSaturation,
|
|
1002
|
+
colorTemperatureMireds,
|
|
1003
|
+
colorTempPhysicalMinMireds,
|
|
1004
|
+
colorTempPhysicalMaxMireds,
|
|
1005
|
+
}, {
|
|
1006
|
+
moveToColor: async (data) => {
|
|
1007
|
+
this.log.debug('Matter command: moveToColor request:', data.request, 'attributes.currentX:', data.attributes.currentX.getLocal(), 'attributes.currentY:', data.attributes.currentY.getLocal());
|
|
1008
|
+
this.commandHandler.executeHandler('moveToColor', data);
|
|
1009
|
+
},
|
|
1010
|
+
moveColor: async () => {
|
|
1011
|
+
this.log.error('Matter command: moveColor not implemented');
|
|
1012
|
+
},
|
|
1013
|
+
stepColor: async () => {
|
|
1014
|
+
this.log.error('Matter command: stepColor not implemented');
|
|
1015
|
+
},
|
|
1016
|
+
moveToHue: async (data) => {
|
|
1017
|
+
this.log.debug('Matter command: moveToHue request:', data.request, 'attributes.currentHue:', data.attributes.currentHue.getLocal());
|
|
1018
|
+
this.commandHandler.executeHandler('moveToHue', data);
|
|
1019
|
+
},
|
|
1020
|
+
moveHue: async () => {
|
|
1021
|
+
this.log.error('Matter command: moveHue not implemented');
|
|
1022
|
+
},
|
|
1023
|
+
stepHue: async () => {
|
|
1024
|
+
this.log.error('Matter command: stepHue not implemented');
|
|
1025
|
+
},
|
|
1026
|
+
moveToSaturation: async (data) => {
|
|
1027
|
+
this.log.debug('Matter command: moveToSaturation request:', data.request, 'attributes.currentSaturation:', data.attributes.currentSaturation.getLocal());
|
|
1028
|
+
this.commandHandler.executeHandler('moveToSaturation', data);
|
|
1029
|
+
},
|
|
1030
|
+
moveSaturation: async () => {
|
|
1031
|
+
this.log.error('Matter command: moveSaturation not implemented');
|
|
1032
|
+
},
|
|
1033
|
+
stepSaturation: async () => {
|
|
1034
|
+
this.log.error('Matter command: stepSaturation not implemented');
|
|
1035
|
+
},
|
|
1036
|
+
moveToHueAndSaturation: async (data) => {
|
|
1037
|
+
this.log.debug('Matter command: moveToHueAndSaturation request:', data.request, 'attributes.currentHue:', data.attributes.currentHue.getLocal(), 'attributes.currentSaturation:', data.attributes.currentSaturation.getLocal());
|
|
1038
|
+
this.commandHandler.executeHandler('moveToHueAndSaturation', data);
|
|
1039
|
+
},
|
|
1040
|
+
stopMoveStep: async () => {
|
|
1041
|
+
this.log.error('Matter command: stopMoveStep not implemented');
|
|
1042
|
+
},
|
|
1043
|
+
moveToColorTemperature: async (data) => {
|
|
1044
|
+
this.log.debug('Matter command: moveToColorTemperature request:', data.request, 'attributes.colorTemperatureMireds:', data.attributes.colorTemperatureMireds.getLocal());
|
|
1045
|
+
this.commandHandler.executeHandler('moveToColorTemperature', data);
|
|
1046
|
+
},
|
|
1047
|
+
moveColorTemperature: async () => {
|
|
1048
|
+
this.log.error('Matter command: moveColorTemperature not implemented');
|
|
1049
|
+
},
|
|
1050
|
+
stepColorTemperature: async () => {
|
|
1051
|
+
this.log.error('Matter command: stepColorTemperature not implemented');
|
|
1052
|
+
},
|
|
1053
|
+
}, {});
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* Creates a default color control cluster server.
|
|
1057
|
+
*
|
|
1058
|
+
* @param currentX - The current X value.
|
|
1059
|
+
* @param currentY - The current Y value.
|
|
1060
|
+
* @param currentHue - The current hue value.
|
|
1061
|
+
* @param currentSaturation - The current saturation value.
|
|
1062
|
+
* @param colorTemperatureMireds - The color temperature in mireds.
|
|
1063
|
+
* @param colorTempPhysicalMinMireds - The physical minimum color temperature in mireds.
|
|
1064
|
+
* @param colorTempPhysicalMaxMireds - The physical maximum color temperature in mireds.
|
|
1065
|
+
*/
|
|
1066
|
+
createDefaultCompleteColorControlClusterServer(currentX = 0, currentY = 0, currentHue = 0, currentSaturation = 0, colorTemperatureMireds = 500, colorTempPhysicalMinMireds = 147, colorTempPhysicalMaxMireds = 500) {
|
|
1067
|
+
this.addClusterServer(this.getDefaultCompleteColorControlClusterServer(currentX, currentY, currentHue, currentSaturation, colorTemperatureMireds, colorTempPhysicalMinMireds, colorTempPhysicalMaxMireds));
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* Configures the color control cluster for a device.
|
|
1071
|
+
*
|
|
1072
|
+
* @remark This method must be called only after creating the cluster with getDefaultCompleteColorControlClusterServer or createDefaultCompleteColorControlClusterServer
|
|
1073
|
+
* and before starting the matter server.
|
|
1074
|
+
*
|
|
1075
|
+
* @param {boolean} hueSaturation - A boolean indicating whether the device supports hue and saturation control.
|
|
1076
|
+
* @param {boolean} xy - A boolean indicating whether the device supports XY control.
|
|
1077
|
+
* @param {boolean} colorTemperature - A boolean indicating whether the device supports color temperature control.
|
|
1078
|
+
* @param {ColorControl.ColorMode} colorMode - An optional parameter specifying the color mode of the device.
|
|
1079
|
+
* @param {Endpoint} endpoint - An optional parameter specifying the endpoint to configure. If not provided, the device endpoint will be used.
|
|
1080
|
+
*/
|
|
1081
|
+
configureColorControlCluster(hueSaturation, xy, colorTemperature, colorMode, endpoint) {
|
|
1082
|
+
if (!endpoint)
|
|
1083
|
+
endpoint = this;
|
|
1084
|
+
endpoint.getClusterServer(ColorControlCluster)?.setFeatureMapAttribute({ hueSaturation, enhancedHue: false, colorLoop: false, xy, colorTemperature });
|
|
1085
|
+
endpoint.getClusterServer(ColorControlCluster)?.setColorCapabilitiesAttribute({ hueSaturation, enhancedHue: false, colorLoop: false, xy, colorTemperature });
|
|
1086
|
+
if (colorMode !== undefined && colorMode >= 0 && colorMode <= 2) {
|
|
1087
|
+
endpoint.getClusterServer(ColorControlCluster)?.setColorModeAttribute(colorMode);
|
|
1088
|
+
endpoint.getClusterServer(ColorControlCluster)?.setEnhancedColorModeAttribute(colorMode);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Configures the color control mode for the device.
|
|
1093
|
+
*
|
|
1094
|
+
* @param {ColorControl.ColorMode} colorMode - The color mode to set.
|
|
1095
|
+
* @param {Endpoint} endpoint - The optional endpoint to configure. If not provided, the method will configure the current endpoint.
|
|
1096
|
+
*/
|
|
1097
|
+
configureColorControlMode(colorMode, endpoint) {
|
|
1098
|
+
if (!endpoint)
|
|
1099
|
+
endpoint = this;
|
|
1100
|
+
if (colorMode !== undefined && colorMode >= ColorControl.ColorMode.CurrentHueAndCurrentSaturation && colorMode <= ColorControl.ColorMode.ColorTemperatureMireds) {
|
|
1101
|
+
endpoint.getClusterServer(ColorControlCluster)?.setColorModeAttribute(colorMode);
|
|
1102
|
+
endpoint.getClusterServer(ColorControlCluster)?.setEnhancedColorModeAttribute(colorMode);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Get a default window covering cluster server.
|
|
1107
|
+
*
|
|
1108
|
+
* @param positionPercent100ths - The position percentage in 100ths (0-10000). Defaults to 0.
|
|
1109
|
+
*/
|
|
1110
|
+
getDefaultWindowCoveringClusterServer(positionPercent100ths) {
|
|
1111
|
+
return ClusterServer(WindowCoveringCluster.with(WindowCovering.Feature.Lift, WindowCovering.Feature.PositionAwareLift), {
|
|
1112
|
+
type: WindowCovering.WindowCoveringType.Rollershade,
|
|
1113
|
+
configStatus: {
|
|
1114
|
+
operational: true,
|
|
1115
|
+
onlineReserved: true,
|
|
1116
|
+
liftMovementReversed: false,
|
|
1117
|
+
liftPositionAware: true,
|
|
1118
|
+
tiltPositionAware: false,
|
|
1119
|
+
liftEncoderControlled: false,
|
|
1120
|
+
tiltEncoderControlled: false,
|
|
1121
|
+
},
|
|
1122
|
+
operationalStatus: { global: WindowCovering.MovementStatus.Stopped, lift: WindowCovering.MovementStatus.Stopped, tilt: WindowCovering.MovementStatus.Stopped },
|
|
1123
|
+
endProductType: WindowCovering.EndProductType.RollerShade,
|
|
1124
|
+
mode: { motorDirectionReversed: false, calibrationMode: false, maintenanceMode: false, ledFeedback: false },
|
|
1125
|
+
targetPositionLiftPercent100ths: positionPercent100ths ?? 0, // 0 Fully open 10000 fully closed
|
|
1126
|
+
currentPositionLiftPercent100ths: positionPercent100ths ?? 0, // 0 Fully open 10000 fully closed
|
|
1127
|
+
// installedClosedLimitLift: 10000,
|
|
1128
|
+
// installedOpenLimitLift: 0,
|
|
1129
|
+
}, {
|
|
1130
|
+
upOrOpen: async (data) => {
|
|
1131
|
+
this.log.debug('Matter command: upOrOpen');
|
|
1132
|
+
await this.commandHandler.executeHandler('upOrOpen', data);
|
|
1133
|
+
},
|
|
1134
|
+
downOrClose: async (data) => {
|
|
1135
|
+
this.log.debug('Matter command: downOrClose');
|
|
1136
|
+
await this.commandHandler.executeHandler('downOrClose', data);
|
|
1137
|
+
},
|
|
1138
|
+
stopMotion: async (data) => {
|
|
1139
|
+
this.log.debug('Matter command: stopMotion');
|
|
1140
|
+
await this.commandHandler.executeHandler('stopMotion', data);
|
|
1141
|
+
},
|
|
1142
|
+
goToLiftPercentage: async (data) => {
|
|
1143
|
+
this.log.debug(`Matter command: goToLiftPercentage: ${data.request.liftPercent100thsValue} current: ${data.attributes.currentPositionLiftPercent100ths?.getLocal()} ` +
|
|
1144
|
+
`target: ${data.attributes.targetPositionLiftPercent100ths?.getLocal()} status: ${data.attributes.operationalStatus.getLocal().lift}`);
|
|
1145
|
+
await this.commandHandler.executeHandler('goToLiftPercentage', data);
|
|
1146
|
+
},
|
|
1147
|
+
}, {});
|
|
1148
|
+
}
|
|
1149
|
+
/**
|
|
1150
|
+
* Creates a default window covering cluster server.
|
|
1151
|
+
*
|
|
1152
|
+
* @param positionPercent100ths - The position percentage in 100ths (0-10000). Defaults to 0.
|
|
1153
|
+
*/
|
|
1154
|
+
createDefaultWindowCoveringClusterServer(positionPercent100ths) {
|
|
1155
|
+
this.addClusterServer(this.getDefaultWindowCoveringClusterServer(positionPercent100ths));
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* Sets the window covering target position as the current position and stops the movement.
|
|
1159
|
+
* @param {Endpoint} endpoint - The endpoint on which to set the window covering (default the device endpoint).
|
|
1160
|
+
*/
|
|
1161
|
+
setWindowCoveringTargetAsCurrentAndStopped(endpoint) {
|
|
1162
|
+
if (!endpoint)
|
|
1163
|
+
endpoint = this;
|
|
1164
|
+
const windowCoveringCluster = endpoint.getClusterServer(WindowCoveringCluster.with(WindowCovering.Feature.Lift, WindowCovering.Feature.PositionAwareLift));
|
|
1165
|
+
if (windowCoveringCluster) {
|
|
1166
|
+
const position = windowCoveringCluster.getCurrentPositionLiftPercent100thsAttribute();
|
|
1167
|
+
if (position !== null) {
|
|
1168
|
+
windowCoveringCluster.setTargetPositionLiftPercent100thsAttribute(position);
|
|
1169
|
+
windowCoveringCluster.setOperationalStatusAttribute({
|
|
1170
|
+
global: WindowCovering.MovementStatus.Stopped,
|
|
1171
|
+
lift: WindowCovering.MovementStatus.Stopped,
|
|
1172
|
+
tilt: WindowCovering.MovementStatus.Stopped,
|
|
1173
|
+
});
|
|
1174
|
+
}
|
|
1175
|
+
this.log.debug(`Set WindowCovering currentPositionLiftPercent100ths and targetPositionLiftPercent100ths to ${position} and operationalStatus to Stopped.`);
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Sets the current and target status of a window covering.
|
|
1180
|
+
* @param {number} current - The current position of the window covering.
|
|
1181
|
+
* @param {number} target - The target position of the window covering.
|
|
1182
|
+
* @param {WindowCovering.MovementStatus} status - The movement status of the window covering.
|
|
1183
|
+
* @param {Endpoint} endpoint - The endpoint on which to set the window covering (default the device endpoint).
|
|
1184
|
+
*/
|
|
1185
|
+
setWindowCoveringCurrentTargetStatus(current, target, status, endpoint) {
|
|
1186
|
+
if (!endpoint)
|
|
1187
|
+
endpoint = this;
|
|
1188
|
+
const windowCoveringCluster = endpoint.getClusterServer(WindowCoveringCluster.with(WindowCovering.Feature.Lift, WindowCovering.Feature.PositionAwareLift));
|
|
1189
|
+
if (windowCoveringCluster) {
|
|
1190
|
+
windowCoveringCluster.setCurrentPositionLiftPercent100thsAttribute(current);
|
|
1191
|
+
windowCoveringCluster.setTargetPositionLiftPercent100thsAttribute(target);
|
|
1192
|
+
windowCoveringCluster.setOperationalStatusAttribute({
|
|
1193
|
+
global: status,
|
|
1194
|
+
lift: status,
|
|
1195
|
+
tilt: status,
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
this.log.debug(`Set WindowCovering currentPositionLiftPercent100ths: ${current}, targetPositionLiftPercent100ths: ${target} and operationalStatus: ${status}.`);
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Sets the status of the window covering.
|
|
1202
|
+
* @param {WindowCovering.MovementStatus} status - The movement status to set.
|
|
1203
|
+
* @param {Endpoint} endpoint - The endpoint on which to set the window covering (default the device endpoint).
|
|
1204
|
+
*/
|
|
1205
|
+
setWindowCoveringStatus(status, endpoint) {
|
|
1206
|
+
if (!endpoint)
|
|
1207
|
+
endpoint = this;
|
|
1208
|
+
const windowCovering = endpoint.getClusterServer(WindowCoveringCluster.with(WindowCovering.Feature.Lift, WindowCovering.Feature.PositionAwareLift));
|
|
1209
|
+
if (!windowCovering)
|
|
1210
|
+
return;
|
|
1211
|
+
windowCovering.setOperationalStatusAttribute({ global: status, lift: status, tilt: status });
|
|
1212
|
+
this.log.debug(`Set WindowCovering operationalStatus: ${status}`);
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* Retrieves the status of the window covering.
|
|
1216
|
+
* @param {Endpoint} endpoint - The endpoint on which to get the window covering (default the device endpoint).
|
|
1217
|
+
*
|
|
1218
|
+
* @returns The global operational status of the window covering.
|
|
1219
|
+
*/
|
|
1220
|
+
getWindowCoveringStatus(endpoint) {
|
|
1221
|
+
if (!endpoint)
|
|
1222
|
+
endpoint = this;
|
|
1223
|
+
const windowCovering = endpoint.getClusterServer(WindowCoveringCluster.with(WindowCovering.Feature.Lift, WindowCovering.Feature.PositionAwareLift));
|
|
1224
|
+
if (!windowCovering)
|
|
1225
|
+
return undefined;
|
|
1226
|
+
const status = windowCovering.getOperationalStatusAttribute();
|
|
1227
|
+
this.log.debug(`Get WindowCovering operationalStatus: ${status.global}`);
|
|
1228
|
+
return status.global;
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1231
|
+
* Sets the target and current position of the window covering.
|
|
1232
|
+
*
|
|
1233
|
+
* @param position - The position to set, specified as a number.
|
|
1234
|
+
* @param {Endpoint} endpoint - The endpoint on which to set the window covering (default the device endpoint).
|
|
1235
|
+
*/
|
|
1236
|
+
setWindowCoveringTargetAndCurrentPosition(position, endpoint) {
|
|
1237
|
+
if (!endpoint)
|
|
1238
|
+
endpoint = this;
|
|
1239
|
+
const windowCovering = endpoint.getClusterServer(WindowCoveringCluster.with(WindowCovering.Feature.Lift, WindowCovering.Feature.PositionAwareLift));
|
|
1240
|
+
if (!windowCovering)
|
|
1241
|
+
return;
|
|
1242
|
+
windowCovering.setCurrentPositionLiftPercent100thsAttribute(position);
|
|
1243
|
+
windowCovering.setTargetPositionLiftPercent100thsAttribute(position);
|
|
1244
|
+
this.log.debug(`Set WindowCovering currentPositionLiftPercent100ths: ${position} and targetPositionLiftPercent100ths: ${position}.`);
|
|
1245
|
+
}
|
|
1246
|
+
/**
|
|
1247
|
+
* Get a default door lock cluster server.
|
|
1248
|
+
*
|
|
1249
|
+
* @remarks
|
|
1250
|
+
* This method adds a cluster server for a door lock cluster with default settings.
|
|
1251
|
+
*
|
|
1252
|
+
*/
|
|
1253
|
+
getDefaultDoorLockClusterServer(lockState = DoorLock.LockState.Locked, lockType = DoorLock.LockType.DeadBolt) {
|
|
1254
|
+
return ClusterServer(DoorLockCluster, {
|
|
1255
|
+
operatingMode: DoorLock.OperatingMode.Normal,
|
|
1256
|
+
lockState,
|
|
1257
|
+
lockType,
|
|
1258
|
+
actuatorEnabled: false,
|
|
1259
|
+
supportedOperatingModes: { normal: true, vacation: false, privacy: false, noRemoteLockUnlock: false, passage: false },
|
|
1260
|
+
}, {
|
|
1261
|
+
lockDoor: async (data) => {
|
|
1262
|
+
this.log.debug('Matter command: lockDoor', data.request);
|
|
1263
|
+
await this.commandHandler.executeHandler('lockDoor', data);
|
|
1264
|
+
},
|
|
1265
|
+
unlockDoor: async (data) => {
|
|
1266
|
+
this.log.debug('Matter command: unlockDoor', data.request);
|
|
1267
|
+
await this.commandHandler.executeHandler('unlockDoor', data);
|
|
1268
|
+
},
|
|
1269
|
+
}, {
|
|
1270
|
+
doorLockAlarm: true,
|
|
1271
|
+
lockOperation: true,
|
|
1272
|
+
lockOperationError: true,
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Creates a default door lock cluster server.
|
|
1277
|
+
*
|
|
1278
|
+
* @remarks
|
|
1279
|
+
* This method adds a cluster server for a door lock cluster with default settings.
|
|
1280
|
+
*
|
|
1281
|
+
*/
|
|
1282
|
+
createDefaultDoorLockClusterServer(lockState = DoorLock.LockState.Locked, lockType = DoorLock.LockType.DeadBolt) {
|
|
1283
|
+
this.addClusterServer(this.getDefaultDoorLockClusterServer(lockState, lockType));
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Get a default momentary switch cluster server.
|
|
1287
|
+
*
|
|
1288
|
+
* @remarks
|
|
1289
|
+
* This method adds a cluster server with default momentary switch features and configurations suitable for (AppleHome) Single Double Long automations.
|
|
1290
|
+
*/
|
|
1291
|
+
getDefaultSwitchClusterServer() {
|
|
1292
|
+
return ClusterServer(SwitchCluster.with(Switch.Feature.MomentarySwitch, Switch.Feature.MomentarySwitchRelease, Switch.Feature.MomentarySwitchLongPress, Switch.Feature.MomentarySwitchMultiPress), {
|
|
1293
|
+
numberOfPositions: 2,
|
|
1294
|
+
currentPosition: 0,
|
|
1295
|
+
multiPressMax: 2,
|
|
1296
|
+
}, {}, {
|
|
1297
|
+
initialPress: true,
|
|
1298
|
+
longPress: true,
|
|
1299
|
+
shortRelease: true,
|
|
1300
|
+
longRelease: true,
|
|
1301
|
+
multiPressOngoing: true,
|
|
1302
|
+
multiPressComplete: true,
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1305
|
+
/**
|
|
1306
|
+
* Creates a default momentary switch cluster server.
|
|
1307
|
+
*
|
|
1308
|
+
* @remarks
|
|
1309
|
+
* This method adds a cluster server with default momentary switch features and configurations.
|
|
1310
|
+
*/
|
|
1311
|
+
createDefaultSwitchClusterServer() {
|
|
1312
|
+
this.addClusterServer(this.getDefaultSwitchClusterServer());
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Get a default latching switch cluster server.
|
|
1316
|
+
*
|
|
1317
|
+
* @remarks
|
|
1318
|
+
* This method adds a cluster server with default latching switch features and configuration.
|
|
1319
|
+
*/
|
|
1320
|
+
getDefaultLatchingSwitchClusterServer() {
|
|
1321
|
+
return ClusterServer(SwitchCluster.with(Switch.Feature.LatchingSwitch), {
|
|
1322
|
+
numberOfPositions: 2,
|
|
1323
|
+
currentPosition: 0,
|
|
1324
|
+
}, {}, {
|
|
1325
|
+
switchLatched: true,
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
/**
|
|
1329
|
+
* Creates a default latching switch cluster server.
|
|
1330
|
+
*
|
|
1331
|
+
* @remarks
|
|
1332
|
+
* This method adds a cluster server with default latching switch features and configuration.
|
|
1333
|
+
*/
|
|
1334
|
+
createDefaultLatchingSwitchClusterServer() {
|
|
1335
|
+
this.addClusterServer(this.getDefaultLatchingSwitchClusterServer());
|
|
1336
|
+
}
|
|
1337
|
+
/**
|
|
1338
|
+
* Triggers a switch event on the specified endpoint.
|
|
1339
|
+
*
|
|
1340
|
+
* @param {string} event - The type of event to trigger. Possible values are 'Single', 'Double', 'Long' for momentarySwitch and 'Press', 'Release' for latchingSwitch.
|
|
1341
|
+
* @param {Endpoint} endpoint - The endpoint on which to trigger the event (default the device endpoint).
|
|
1342
|
+
* @returns {void}
|
|
1343
|
+
*/
|
|
1344
|
+
triggerSwitchEvent(event, log, endpoint) {
|
|
1345
|
+
if (!endpoint)
|
|
1346
|
+
endpoint = this;
|
|
1347
|
+
if (['Single', 'Double', 'Long'].includes(event)) {
|
|
1348
|
+
const cluster = endpoint.getClusterServer(SwitchCluster.with(Switch.Feature.MomentarySwitch, Switch.Feature.MomentarySwitchRelease, Switch.Feature.MomentarySwitchLongPress, Switch.Feature.MomentarySwitchMultiPress));
|
|
1349
|
+
if (!cluster || !cluster.getFeatureMapAttribute().momentarySwitch) {
|
|
1350
|
+
log?.error(`triggerSwitchEvent ${event} error: Switch cluster with MomentarySwitch not found on endpoint ${endpoint.id}:${endpoint.number}`);
|
|
1351
|
+
return false;
|
|
1352
|
+
}
|
|
1353
|
+
if (endpoint.number === undefined) {
|
|
1354
|
+
log?.error(`triggerSwitchEvent ${event} error: Endpoint number not assigned on endpoint ${endpoint.id}:${endpoint.number}`);
|
|
1355
|
+
return false;
|
|
1356
|
+
}
|
|
1357
|
+
if (event === 'Single') {
|
|
1358
|
+
cluster.setCurrentPositionAttribute(1);
|
|
1359
|
+
cluster.triggerInitialPressEvent({ newPosition: 1 });
|
|
1360
|
+
cluster.setCurrentPositionAttribute(0);
|
|
1361
|
+
cluster.triggerShortReleaseEvent({ previousPosition: 1 });
|
|
1362
|
+
cluster.setCurrentPositionAttribute(0);
|
|
1363
|
+
cluster.triggerMultiPressCompleteEvent({ previousPosition: 1, totalNumberOfPressesCounted: 1 });
|
|
1364
|
+
log?.info(`${db}Trigger endpoint ${or}${endpoint.id}:${endpoint.number}${db} event ${hk}${cluster.name}.SinglePress${db}`);
|
|
1365
|
+
}
|
|
1366
|
+
if (event === 'Double') {
|
|
1367
|
+
cluster.setCurrentPositionAttribute(1);
|
|
1368
|
+
cluster.triggerInitialPressEvent({ newPosition: 1 });
|
|
1369
|
+
cluster.setCurrentPositionAttribute(0);
|
|
1370
|
+
cluster.triggerShortReleaseEvent({ previousPosition: 1 });
|
|
1371
|
+
cluster.setCurrentPositionAttribute(1);
|
|
1372
|
+
cluster.triggerInitialPressEvent({ newPosition: 1 });
|
|
1373
|
+
cluster.triggerMultiPressOngoingEvent({ newPosition: 1, currentNumberOfPressesCounted: 2 });
|
|
1374
|
+
cluster.setCurrentPositionAttribute(0);
|
|
1375
|
+
cluster.triggerShortReleaseEvent({ previousPosition: 1 });
|
|
1376
|
+
cluster.triggerMultiPressCompleteEvent({ previousPosition: 1, totalNumberOfPressesCounted: 2 });
|
|
1377
|
+
log?.info(`${db}Trigger endpoint ${or}${endpoint.id}:${endpoint.number}${db} event ${hk}${cluster.name}.DoublePress${db}`);
|
|
1378
|
+
}
|
|
1379
|
+
if (event === 'Long') {
|
|
1380
|
+
cluster.setCurrentPositionAttribute(1);
|
|
1381
|
+
cluster.triggerInitialPressEvent({ newPosition: 1 });
|
|
1382
|
+
cluster.triggerLongPressEvent({ newPosition: 1 });
|
|
1383
|
+
cluster.setCurrentPositionAttribute(0);
|
|
1384
|
+
cluster.triggerLongReleaseEvent({ previousPosition: 1 });
|
|
1385
|
+
log?.info(`${db}Trigger endpoint ${or}${endpoint.id}:${endpoint.number}${db} event ${hk}${cluster.name}.LongPress${db}`);
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
if (['Press', 'Release'].includes(event)) {
|
|
1389
|
+
const cluster = endpoint.getClusterServer(Switch.Complete);
|
|
1390
|
+
if (!cluster || !cluster.getFeatureMapAttribute().latchingSwitch) {
|
|
1391
|
+
log?.error(`triggerSwitchEvent ${event} error: Switch cluster with LatchingSwitch not found on endpoint ${endpoint.id}:${endpoint.number}`);
|
|
1392
|
+
return false;
|
|
1393
|
+
}
|
|
1394
|
+
if (endpoint.number === undefined) {
|
|
1395
|
+
log?.error(`triggerSwitchEvent ${event} error: Endpoint number not assigned on endpoint ${endpoint.id}:${endpoint.number}`);
|
|
1396
|
+
return false;
|
|
1397
|
+
}
|
|
1398
|
+
if (event === 'Press') {
|
|
1399
|
+
cluster.setCurrentPositionAttribute(1);
|
|
1400
|
+
log?.info(`${db}Update endpoint ${or}${endpoint.id}:${endpoint.number}${db} attribute ${hk}${cluster.name}.CurrentPosition${db} to ${YELLOW}1${db}`);
|
|
1401
|
+
if (cluster.triggerSwitchLatchedEvent)
|
|
1402
|
+
cluster.triggerSwitchLatchedEvent({ newPosition: 1 });
|
|
1403
|
+
log?.info(`${db}Trigger endpoint ${or}${endpoint.id}:${endpoint.number}${db} event ${hk}${cluster.name}.Press${db}`);
|
|
1404
|
+
}
|
|
1405
|
+
if (event === 'Release') {
|
|
1406
|
+
cluster.setCurrentPositionAttribute(0);
|
|
1407
|
+
log?.info(`${db}Update endpoint ${or}${endpoint.id}:${endpoint.number}${db} attribute ${hk}${cluster.name}.CurrentPosition${db} to ${YELLOW}0${db}`);
|
|
1408
|
+
if (cluster.triggerSwitchLatchedEvent)
|
|
1409
|
+
cluster.triggerSwitchLatchedEvent({ newPosition: 0 });
|
|
1410
|
+
log?.info(`${db}Trigger endpoint ${or}${endpoint.id}:${endpoint.number}${db} event ${hk}${cluster.name}.Release${db}`);
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
return true;
|
|
1414
|
+
}
|
|
1415
|
+
/**
|
|
1416
|
+
* Retrieves the default mode select cluster server.
|
|
1417
|
+
*
|
|
1418
|
+
* @param description - The description of the cluster server.
|
|
1419
|
+
* @param supportedModes - The supported modes for the cluster server.
|
|
1420
|
+
* @param currentMode - The current mode of the cluster server. Defaults to 0.
|
|
1421
|
+
* @param startUpMode - The startup mode of the cluster server. Defaults to 0.
|
|
1422
|
+
* @returns The default mode select cluster server.
|
|
1423
|
+
*/
|
|
1424
|
+
getDefaultModeSelectClusterServer(description, supportedModes, currentMode = 0, startUpMode = 0) {
|
|
1425
|
+
return ClusterServer(ModeSelectCluster, {
|
|
1426
|
+
description: description,
|
|
1427
|
+
standardNamespace: null,
|
|
1428
|
+
supportedModes: supportedModes,
|
|
1429
|
+
currentMode: currentMode,
|
|
1430
|
+
startUpMode: startUpMode,
|
|
1431
|
+
}, {
|
|
1432
|
+
changeToMode: async (data) => {
|
|
1433
|
+
this.log.debug('Matter command: ModeSelectCluster.changeToMode', data.request);
|
|
1434
|
+
await this.commandHandler.executeHandler('changeToMode', data);
|
|
1435
|
+
},
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Creates a default mode select cluster server.
|
|
1440
|
+
*
|
|
1441
|
+
* @remarks
|
|
1442
|
+
* This method adds a cluster server for a mode select cluster with default settings.
|
|
1443
|
+
*
|
|
1444
|
+
* @param endpoint - The endpoint to add the cluster server to. Defaults to `this` if not provided.
|
|
1445
|
+
*/
|
|
1446
|
+
createDefaultModeSelectClusterServer(description, supportedModes, currentMode = 0, startUpMode = 0, endpoint) {
|
|
1447
|
+
if (!endpoint)
|
|
1448
|
+
endpoint = this;
|
|
1449
|
+
endpoint.addClusterServer(this.getDefaultModeSelectClusterServer(description, supportedModes, currentMode, startUpMode));
|
|
1450
|
+
}
|
|
1451
|
+
/**
|
|
1452
|
+
* Get a default occupancy sensing cluster server.
|
|
1453
|
+
*
|
|
1454
|
+
* @param occupied - A boolean indicating whether the occupancy is occupied or not. Default is false.
|
|
1455
|
+
*/
|
|
1456
|
+
getDefaultOccupancySensingClusterServer(occupied = false) {
|
|
1457
|
+
return ClusterServer(OccupancySensingCluster, {
|
|
1458
|
+
occupancy: { occupied },
|
|
1459
|
+
occupancySensorType: OccupancySensing.OccupancySensorType.Pir,
|
|
1460
|
+
occupancySensorTypeBitmap: { pir: true, ultrasonic: false, physicalContact: false },
|
|
1461
|
+
pirOccupiedToUnoccupiedDelay: 30,
|
|
1462
|
+
}, {});
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* Creates a default occupancy sensing cluster server.
|
|
1466
|
+
*
|
|
1467
|
+
* @param occupied - A boolean indicating whether the occupancy is occupied or not. Default is false.
|
|
1468
|
+
*/
|
|
1469
|
+
createDefaultOccupancySensingClusterServer(occupied = false) {
|
|
1470
|
+
this.addClusterServer(this.getDefaultOccupancySensingClusterServer(occupied));
|
|
1471
|
+
}
|
|
1472
|
+
/**
|
|
1473
|
+
* Get a default Illuminance Measurement Cluster Server.
|
|
1474
|
+
*
|
|
1475
|
+
* @param measuredValue - The measured value of illuminance.
|
|
1476
|
+
*/
|
|
1477
|
+
getDefaultIlluminanceMeasurementClusterServer(measuredValue = 0) {
|
|
1478
|
+
return ClusterServer(IlluminanceMeasurementCluster, {
|
|
1479
|
+
measuredValue,
|
|
1480
|
+
minMeasuredValue: null,
|
|
1481
|
+
maxMeasuredValue: null,
|
|
1482
|
+
tolerance: 0,
|
|
1483
|
+
}, {}, {});
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Creates a default Illuminance Measurement Cluster Server.
|
|
1487
|
+
*
|
|
1488
|
+
* @param measuredValue - The measured value of illuminance.
|
|
1489
|
+
*/
|
|
1490
|
+
createDefaultIlluminanceMeasurementClusterServer(measuredValue = 0) {
|
|
1491
|
+
this.addClusterServer(this.getDefaultIlluminanceMeasurementClusterServer(measuredValue));
|
|
1492
|
+
}
|
|
1493
|
+
/**
|
|
1494
|
+
* Get a default flow measurement cluster server.
|
|
1495
|
+
*
|
|
1496
|
+
* @param measuredValue - The measured value of the temperature.
|
|
1497
|
+
*/
|
|
1498
|
+
getDefaultFlowMeasurementClusterServer(measuredValue = 0) {
|
|
1499
|
+
return ClusterServer(FlowMeasurementCluster, {
|
|
1500
|
+
measuredValue,
|
|
1501
|
+
minMeasuredValue: null,
|
|
1502
|
+
maxMeasuredValue: null,
|
|
1503
|
+
tolerance: 0,
|
|
1504
|
+
}, {}, {});
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Creates a default flow measurement cluster server.
|
|
1508
|
+
*
|
|
1509
|
+
* @param measuredValue - The measured value of the temperature.
|
|
1510
|
+
*/
|
|
1511
|
+
createDefaultFlowMeasurementClusterServer(measuredValue = 0) {
|
|
1512
|
+
this.addClusterServer(this.getDefaultFlowMeasurementClusterServer(measuredValue));
|
|
1513
|
+
}
|
|
1514
|
+
/**
|
|
1515
|
+
* Get a default temperature measurement cluster server.
|
|
1516
|
+
*
|
|
1517
|
+
* @param measuredValue - The measured value of the temperature.
|
|
1518
|
+
*/
|
|
1519
|
+
getDefaultTemperatureMeasurementClusterServer(measuredValue = 0) {
|
|
1520
|
+
return ClusterServer(TemperatureMeasurementCluster, {
|
|
1521
|
+
measuredValue,
|
|
1522
|
+
minMeasuredValue: null,
|
|
1523
|
+
maxMeasuredValue: null,
|
|
1524
|
+
tolerance: 0,
|
|
1525
|
+
}, {}, {});
|
|
1526
|
+
}
|
|
1527
|
+
/**
|
|
1528
|
+
* Creates a default temperature measurement cluster server.
|
|
1529
|
+
*
|
|
1530
|
+
* @param measuredValue - The measured value of the temperature.
|
|
1531
|
+
*/
|
|
1532
|
+
createDefaultTemperatureMeasurementClusterServer(measuredValue = 0) {
|
|
1533
|
+
this.addClusterServer(this.getDefaultTemperatureMeasurementClusterServer(measuredValue));
|
|
1534
|
+
}
|
|
1535
|
+
/**
|
|
1536
|
+
* Get a default RelativeHumidityMeasurementCluster server.
|
|
1537
|
+
*
|
|
1538
|
+
* @param measuredValue - The measured value of the relative humidity.
|
|
1539
|
+
*/
|
|
1540
|
+
getDefaultRelativeHumidityMeasurementClusterServer(measuredValue = 0) {
|
|
1541
|
+
return ClusterServer(RelativeHumidityMeasurementCluster, {
|
|
1542
|
+
measuredValue,
|
|
1543
|
+
minMeasuredValue: null,
|
|
1544
|
+
maxMeasuredValue: null,
|
|
1545
|
+
tolerance: 0,
|
|
1546
|
+
}, {}, {});
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* Creates a default RelativeHumidityMeasurementCluster server.
|
|
1550
|
+
*
|
|
1551
|
+
* @param measuredValue - The measured value of the relative humidity.
|
|
1552
|
+
*/
|
|
1553
|
+
createDefaultRelativeHumidityMeasurementClusterServer(measuredValue = 0) {
|
|
1554
|
+
this.addClusterServer(this.getDefaultRelativeHumidityMeasurementClusterServer(measuredValue));
|
|
1555
|
+
}
|
|
1556
|
+
/**
|
|
1557
|
+
* Get a default Pressure Measurement Cluster Server.
|
|
1558
|
+
*
|
|
1559
|
+
* @param measuredValue - The measured value for the pressure.
|
|
1560
|
+
*/
|
|
1561
|
+
getDefaultPressureMeasurementClusterServer(measuredValue = 1000) {
|
|
1562
|
+
return ClusterServer(PressureMeasurementCluster, {
|
|
1563
|
+
measuredValue,
|
|
1564
|
+
minMeasuredValue: null,
|
|
1565
|
+
maxMeasuredValue: null,
|
|
1566
|
+
tolerance: 0,
|
|
1567
|
+
}, {}, {});
|
|
1568
|
+
}
|
|
1569
|
+
/**
|
|
1570
|
+
* Creates a default Pressure Measurement Cluster Server.
|
|
1571
|
+
*
|
|
1572
|
+
* @param measuredValue - The measured value for the pressure.
|
|
1573
|
+
*/
|
|
1574
|
+
createDefaultPressureMeasurementClusterServer(measuredValue = 1000) {
|
|
1575
|
+
this.addClusterServer(this.getDefaultPressureMeasurementClusterServer(measuredValue));
|
|
1576
|
+
}
|
|
1577
|
+
/**
|
|
1578
|
+
* Get a default boolean state cluster server.
|
|
1579
|
+
*
|
|
1580
|
+
* @param contact - Optional boolean value indicating the contact state. Defaults to `true` if not provided.
|
|
1581
|
+
*/
|
|
1582
|
+
getDefaultBooleanStateClusterServer(contact) {
|
|
1583
|
+
return ClusterServer(BooleanStateCluster, {
|
|
1584
|
+
stateValue: contact ?? true, // true=contact false=no_contact
|
|
1585
|
+
}, {}, {
|
|
1586
|
+
stateChange: true,
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
/**
|
|
1590
|
+
* Creates a default boolean state configuration cluster server.
|
|
1591
|
+
*
|
|
1592
|
+
* @param contact - Optional boolean value indicating the contact state. Defaults to `true` if not provided.
|
|
1593
|
+
*/
|
|
1594
|
+
createDefaultBooleanStateClusterServer(contact) {
|
|
1595
|
+
this.addClusterServer(this.getDefaultBooleanStateClusterServer(contact));
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* Get a default boolean state configuration cluster server.
|
|
1599
|
+
*
|
|
1600
|
+
* @param contact - Optional boolean value indicating the sensor fault state. Defaults to `false` if not provided.
|
|
1601
|
+
*/
|
|
1602
|
+
getDefaultBooleanStateConfigurationClusterServer(sensorFault = false) {
|
|
1603
|
+
return ClusterServer(BooleanStateConfigurationCluster.with(BooleanStateConfiguration.Feature.Visual, BooleanStateConfiguration.Feature.Audible, BooleanStateConfiguration.Feature.SensitivityLevel), {
|
|
1604
|
+
currentSensitivityLevel: 0,
|
|
1605
|
+
supportedSensitivityLevels: 2,
|
|
1606
|
+
defaultSensitivityLevel: 0,
|
|
1607
|
+
alarmsActive: { visual: false, audible: false },
|
|
1608
|
+
alarmsEnabled: { visual: false, audible: false },
|
|
1609
|
+
alarmsSupported: { visual: true, audible: true },
|
|
1610
|
+
// alarmsSuppressed: { visual: false, audible: false },
|
|
1611
|
+
sensorFault: { generalFault: sensorFault },
|
|
1612
|
+
}, {
|
|
1613
|
+
enableDisableAlarm: async (data) => {
|
|
1614
|
+
this.log.debug('Matter command: enableDisableAlarm', data.request);
|
|
1615
|
+
await this.commandHandler.executeHandler('enableDisableAlarm', data);
|
|
1616
|
+
},
|
|
1617
|
+
}, {
|
|
1618
|
+
alarmsStateChanged: true,
|
|
1619
|
+
sensorFault: true,
|
|
1620
|
+
});
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Creates a default boolean state configuration cluster server.
|
|
1624
|
+
*
|
|
1625
|
+
* @param contact - Optional boolean value indicating the sensor fault state. Defaults to `false` if not provided.
|
|
1626
|
+
*/
|
|
1627
|
+
createDefaultBooleanStateConfigurationClusterServer(sensorFault = false) {
|
|
1628
|
+
this.addClusterServer(this.getDefaultBooleanStateConfigurationClusterServer(sensorFault));
|
|
1629
|
+
}
|
|
1630
|
+
/**
|
|
1631
|
+
* Get a default power source replaceable battery cluster server.
|
|
1632
|
+
*
|
|
1633
|
+
* @param batPercentRemaining - The remaining battery percentage (default: 100).
|
|
1634
|
+
* @param batChargeLevel - The battery charge level (default: PowerSource.BatChargeLevel.Ok).
|
|
1635
|
+
* @param batVoltage - The battery voltage (default: 1500).
|
|
1636
|
+
* @param batReplacementDescription - The battery replacement description (default: 'Battery type').
|
|
1637
|
+
* @param batQuantity - The battery quantity (default: 1).
|
|
1638
|
+
*/
|
|
1639
|
+
getDefaultPowerSourceReplaceableBatteryClusterServer(batPercentRemaining = 100, batChargeLevel = PowerSource.BatChargeLevel.Ok, batVoltage = 1500, batReplacementDescription = 'Battery type', batQuantity = 1) {
|
|
1640
|
+
return ClusterServer(PowerSourceCluster.with(PowerSource.Feature.Battery, PowerSource.Feature.Replaceable), {
|
|
1641
|
+
status: PowerSource.PowerSourceStatus.Active,
|
|
1642
|
+
order: 0,
|
|
1643
|
+
description: 'Primary battery',
|
|
1644
|
+
batVoltage,
|
|
1645
|
+
batPercentRemaining: Math.min(Math.max(batPercentRemaining * 2, 0), 200),
|
|
1646
|
+
batChargeLevel,
|
|
1647
|
+
batReplacementNeeded: false,
|
|
1648
|
+
batReplaceability: PowerSource.BatReplaceability.UserReplaceable,
|
|
1649
|
+
activeBatFaults: undefined,
|
|
1650
|
+
batReplacementDescription,
|
|
1651
|
+
batQuantity,
|
|
1652
|
+
endpointList: [],
|
|
1653
|
+
}, {}, {});
|
|
1654
|
+
}
|
|
1655
|
+
/**
|
|
1656
|
+
* Creates a default power source replaceable battery cluster server.
|
|
1657
|
+
*
|
|
1658
|
+
* @param batPercentRemaining - The remaining battery percentage (default: 100).
|
|
1659
|
+
* @param batChargeLevel - The battery charge level (default: PowerSource.BatChargeLevel.Ok).
|
|
1660
|
+
* @param batVoltage - The battery voltage (default: 1500).
|
|
1661
|
+
* @param batReplacementDescription - The battery replacement description (default: 'Battery type').
|
|
1662
|
+
* @param batQuantity - The battery quantity (default: 1).
|
|
1663
|
+
*/
|
|
1664
|
+
createDefaultPowerSourceReplaceableBatteryClusterServer(batPercentRemaining = 100, batChargeLevel = PowerSource.BatChargeLevel.Ok, batVoltage = 1500, batReplacementDescription = 'Battery type', batQuantity = 1) {
|
|
1665
|
+
this.addClusterServer(this.getDefaultPowerSourceReplaceableBatteryClusterServer(batPercentRemaining, batChargeLevel, batVoltage, batReplacementDescription, batQuantity));
|
|
1666
|
+
}
|
|
1667
|
+
/**
|
|
1668
|
+
* Get a default power source rechargeable battery cluster server.
|
|
1669
|
+
*
|
|
1670
|
+
* @param batPercentRemaining - The remaining battery percentage (default: 100).
|
|
1671
|
+
* @param batChargeLevel - The battery charge level (default: PowerSource.BatChargeLevel.Ok).
|
|
1672
|
+
* @param batVoltage - The battery voltage (default: 1500).
|
|
1673
|
+
*/
|
|
1674
|
+
getDefaultPowerSourceRechargeableBatteryClusterServer(batPercentRemaining = 100, batChargeLevel = PowerSource.BatChargeLevel.Ok, batVoltage = 1500) {
|
|
1675
|
+
return ClusterServer(PowerSourceCluster.with(PowerSource.Feature.Battery, PowerSource.Feature.Rechargeable), {
|
|
1676
|
+
status: PowerSource.PowerSourceStatus.Active,
|
|
1677
|
+
order: 0,
|
|
1678
|
+
description: 'Primary battery',
|
|
1679
|
+
batVoltage,
|
|
1680
|
+
batPercentRemaining: Math.min(Math.max(batPercentRemaining * 2, 0), 200),
|
|
1681
|
+
batTimeRemaining: 1,
|
|
1682
|
+
batChargeLevel,
|
|
1683
|
+
batReplacementNeeded: false,
|
|
1684
|
+
batReplaceability: PowerSource.BatReplaceability.Unspecified,
|
|
1685
|
+
activeBatFaults: undefined,
|
|
1686
|
+
batChargeState: PowerSource.BatChargeState.IsNotCharging,
|
|
1687
|
+
batFunctionalWhileCharging: true,
|
|
1688
|
+
endpointList: [],
|
|
1689
|
+
}, {}, {});
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Creates a default power source rechargeable battery cluster server.
|
|
1693
|
+
*
|
|
1694
|
+
* @param batPercentRemaining - The remaining battery percentage (default: 100).
|
|
1695
|
+
* @param batChargeLevel - The battery charge level (default: PowerSource.BatChargeLevel.Ok).
|
|
1696
|
+
* @param batVoltage - The battery voltage (default: 1500).
|
|
1697
|
+
*/
|
|
1698
|
+
createDefaultPowerSourceRechargeableBatteryClusterServer(batPercentRemaining = 100, batChargeLevel = PowerSource.BatChargeLevel.Ok, batVoltage = 1500) {
|
|
1699
|
+
this.addClusterServer(this.getDefaultPowerSourceRechargeableBatteryClusterServer(batPercentRemaining, batChargeLevel, batVoltage));
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Get a default power source wired cluster server.
|
|
1703
|
+
*
|
|
1704
|
+
* @param wiredCurrentType - The type of wired current (default: PowerSource.WiredCurrentType.Ac)
|
|
1705
|
+
*/
|
|
1706
|
+
getDefaultPowerSourceWiredClusterServer(wiredCurrentType = PowerSource.WiredCurrentType.Ac) {
|
|
1707
|
+
return ClusterServer(PowerSourceCluster.with(PowerSource.Feature.Wired), {
|
|
1708
|
+
wiredCurrentType,
|
|
1709
|
+
description: wiredCurrentType === PowerSource.WiredCurrentType.Ac ? 'AC Power' : 'DC Power',
|
|
1710
|
+
status: PowerSource.PowerSourceStatus.Active,
|
|
1711
|
+
order: 0,
|
|
1712
|
+
endpointList: [],
|
|
1713
|
+
}, {}, {});
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Creates a default power source wired cluster server.
|
|
1717
|
+
*
|
|
1718
|
+
* @param wiredCurrentType - The type of wired current (default: PowerSource.WiredCurrentType.Ac)
|
|
1719
|
+
*/
|
|
1720
|
+
createDefaultPowerSourceWiredClusterServer(wiredCurrentType = PowerSource.WiredCurrentType.Ac) {
|
|
1721
|
+
this.addClusterServer(this.getDefaultPowerSourceWiredClusterServer(wiredCurrentType));
|
|
1722
|
+
}
|
|
1723
|
+
/**
|
|
1724
|
+
* @deprecated This function is deprecated by Matter 1.3 spec and will be removed in a future version.
|
|
1725
|
+
*/
|
|
1726
|
+
createDefaultPowerSourceConfigurationClusterServer(endpointNumber) {
|
|
1727
|
+
this.addClusterServer(ClusterServer(PowerSourceConfigurationCluster, {
|
|
1728
|
+
sources: endpointNumber ? [EndpointNumber(endpointNumber)] : [],
|
|
1729
|
+
}, {}, {}));
|
|
1730
|
+
}
|
|
1731
|
+
/**
|
|
1732
|
+
* Get a default air quality cluster server.
|
|
1733
|
+
*
|
|
1734
|
+
* @param airQuality The air quality type. Defaults to `AirQuality.AirQualityType.Unknown`.
|
|
1735
|
+
*/
|
|
1736
|
+
getDefaultAirQualityClusterServer(airQuality = AirQuality.AirQualityEnum.Unknown) {
|
|
1737
|
+
return ClusterServer(AirQualityCluster.with(AirQuality.Feature.Fair, AirQuality.Feature.Moderate, AirQuality.Feature.VeryPoor, AirQuality.Feature.ExtremelyPoor), {
|
|
1738
|
+
airQuality,
|
|
1739
|
+
}, {}, {});
|
|
1740
|
+
}
|
|
1741
|
+
/**
|
|
1742
|
+
* Creates a default air quality cluster server.
|
|
1743
|
+
*
|
|
1744
|
+
* @param airQuality The air quality type. Defaults to `AirQuality.AirQualityType.Unknown`.
|
|
1745
|
+
*/
|
|
1746
|
+
createDefaultAirQualityClusterServer(airQuality = AirQuality.AirQualityEnum.Unknown) {
|
|
1747
|
+
this.addClusterServer(this.getDefaultAirQualityClusterServer(airQuality));
|
|
1748
|
+
}
|
|
1749
|
+
/**
|
|
1750
|
+
* Get a default TVOC measurement cluster server.
|
|
1751
|
+
*
|
|
1752
|
+
* @param measuredValue - The measured value for TVOC.
|
|
1753
|
+
*/
|
|
1754
|
+
getDefaultTvocMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
1755
|
+
return ClusterServer(TotalVolatileOrganicCompoundsConcentrationMeasurementCluster.with('NumericMeasurement'), {
|
|
1756
|
+
measuredValue,
|
|
1757
|
+
minMeasuredValue: null,
|
|
1758
|
+
maxMeasuredValue: null,
|
|
1759
|
+
uncertainty: 0,
|
|
1760
|
+
measurementUnit,
|
|
1761
|
+
measurementMedium,
|
|
1762
|
+
}, {}, {});
|
|
1763
|
+
}
|
|
1764
|
+
/**
|
|
1765
|
+
* Creates a default TVOC measurement cluster server.
|
|
1766
|
+
*
|
|
1767
|
+
* @param measuredValue - The measured value for TVOC.
|
|
1768
|
+
*/
|
|
1769
|
+
createDefaultTvocMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
1770
|
+
this.addClusterServer(this.getDefaultTvocMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
|
|
1771
|
+
}
|
|
1772
|
+
/**
|
|
1773
|
+
* Get a default thermostat cluster server with the specified parameters.
|
|
1774
|
+
*
|
|
1775
|
+
* @param {number} [localTemperature=23] - The local temperature value in degrees Celsius. Defaults to 23°.
|
|
1776
|
+
* @param {number} [occupiedHeatingSetpoint=21] - The occupied heating setpoint value in degrees Celsius. Defaults to 21°.
|
|
1777
|
+
* @param {number} [occupiedCoolingSetpoint=25] - The occupied cooling setpoint value in degrees Celsius. Defaults to 25°.
|
|
1778
|
+
* @param {number} [minSetpointDeadBand=1] - The minimum setpoint dead band value. Defaults to 1°.
|
|
1779
|
+
* @param {number} [minHeatSetpointLimit=0] - The minimum heat setpoint limit value. Defaults to 0°.
|
|
1780
|
+
* @param {number} [maxHeatSetpointLimit=50] - The maximum heat setpoint limit value. Defaults to 50°.
|
|
1781
|
+
* @param {number} [minCoolSetpointLimit=0] - The minimum cool setpoint limit value. Defaults to 0°.
|
|
1782
|
+
* @param {number} [maxCoolSetpointLimit=50] - The maximum cool setpoint limit value. Defaults to 50°.
|
|
1783
|
+
* @returns {ThermostatClusterServer} A default thermostat cluster server configured with the specified parameters.
|
|
1784
|
+
*/
|
|
1785
|
+
getDefaultThermostatClusterServer(localTemperature = 23, occupiedHeatingSetpoint = 21, occupiedCoolingSetpoint = 25, minSetpointDeadBand = 1, minHeatSetpointLimit = 0, maxHeatSetpointLimit = 50, minCoolSetpointLimit = 0, maxCoolSetpointLimit = 50) {
|
|
1786
|
+
return ClusterServer(ThermostatCluster.with(Thermostat.Feature.Heating, Thermostat.Feature.Cooling, Thermostat.Feature.AutoMode), {
|
|
1787
|
+
localTemperature: localTemperature * 100,
|
|
1788
|
+
occupiedHeatingSetpoint: occupiedHeatingSetpoint * 100,
|
|
1789
|
+
occupiedCoolingSetpoint: occupiedCoolingSetpoint * 100,
|
|
1790
|
+
minHeatSetpointLimit: minHeatSetpointLimit * 100,
|
|
1791
|
+
maxHeatSetpointLimit: maxHeatSetpointLimit * 100,
|
|
1792
|
+
absMinHeatSetpointLimit: minHeatSetpointLimit * 100,
|
|
1793
|
+
absMaxHeatSetpointLimit: maxHeatSetpointLimit * 100,
|
|
1794
|
+
minCoolSetpointLimit: minCoolSetpointLimit * 100,
|
|
1795
|
+
maxCoolSetpointLimit: maxCoolSetpointLimit * 100,
|
|
1796
|
+
absMinCoolSetpointLimit: minCoolSetpointLimit * 100,
|
|
1797
|
+
absMaxCoolSetpointLimit: maxCoolSetpointLimit * 100,
|
|
1798
|
+
minSetpointDeadBand: minSetpointDeadBand * 100,
|
|
1799
|
+
systemMode: Thermostat.SystemMode.Off,
|
|
1800
|
+
controlSequenceOfOperation: Thermostat.ControlSequenceOfOperation.CoolingAndHeating,
|
|
1801
|
+
thermostatRunningMode: Thermostat.ThermostatRunningMode.Off,
|
|
1802
|
+
}, {
|
|
1803
|
+
setpointRaiseLower: async (data) => {
|
|
1804
|
+
this.log.debug('Matter command: setpointRaiseLower', data.request);
|
|
1805
|
+
await this.commandHandler.executeHandler('setpointRaiseLower', data);
|
|
1806
|
+
},
|
|
1807
|
+
}, {});
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* Creates and adds a default thermostat cluster server to the device.
|
|
1811
|
+
*
|
|
1812
|
+
* @param {number} [localTemperature=23] - The local temperature value in degrees Celsius. Defaults to 23°.
|
|
1813
|
+
* @param {number} [occupiedHeatingSetpoint=21] - The occupied heating setpoint value in degrees Celsius. Defaults to 21°.
|
|
1814
|
+
* @param {number} [occupiedCoolingSetpoint=25] - The occupied cooling setpoint value in degrees Celsius. Defaults to 25°.
|
|
1815
|
+
* @param {number} [minSetpointDeadBand=1] - The minimum setpoint dead band value. Defaults to 1°.
|
|
1816
|
+
* @param {number} [minHeatSetpointLimit=0] - The minimum heat setpoint limit value. Defaults to 0°.
|
|
1817
|
+
* @param {number} [maxHeatSetpointLimit=50] - The maximum heat setpoint limit value. Defaults to 50°.
|
|
1818
|
+
* @param {number} [minCoolSetpointLimit=0] - The minimum cool setpoint limit value. Defaults to 0°.
|
|
1819
|
+
* @param {number} [maxCoolSetpointLimit=50] - The maximum cool setpoint limit value. Defaults to 50°.
|
|
1820
|
+
*/
|
|
1821
|
+
createDefaultThermostatClusterServer(localTemperature = 23, occupiedHeatingSetpoint = 21, occupiedCoolingSetpoint = 25, minSetpointDeadBand = 1, minHeatSetpointLimit = 0, maxHeatSetpointLimit = 50, minCoolSetpointLimit = 0, maxCoolSetpointLimit = 50) {
|
|
1822
|
+
this.addClusterServer(this.getDefaultThermostatClusterServer(localTemperature, occupiedHeatingSetpoint, occupiedCoolingSetpoint, minSetpointDeadBand, minHeatSetpointLimit, maxHeatSetpointLimit, minCoolSetpointLimit, maxCoolSetpointLimit));
|
|
1823
|
+
}
|
|
1824
|
+
/**
|
|
1825
|
+
* Get a default dummy time sync cluster server. Only needed to create a thermostat.
|
|
1826
|
+
*/
|
|
1827
|
+
getDefaultTimeSyncClusterServer() {
|
|
1828
|
+
return ClusterServer(TimeSynchronizationCluster.with(TimeSynchronization.Feature.TimeZone), {
|
|
1829
|
+
utcTime: null,
|
|
1830
|
+
granularity: TimeSynchronization.Granularity.NoTimeGranularity,
|
|
1831
|
+
timeZone: [{ offset: 0, validAt: 0 }],
|
|
1832
|
+
dstOffset: [],
|
|
1833
|
+
localTime: null,
|
|
1834
|
+
timeZoneDatabase: TimeSynchronization.TimeZoneDatabase.None,
|
|
1835
|
+
timeZoneListMaxSize: 1,
|
|
1836
|
+
dstOffsetListMaxSize: 1,
|
|
1837
|
+
}, {
|
|
1838
|
+
setTimeZone: async (data) => {
|
|
1839
|
+
this.log.debug('Matter command: setTimeZone', data.request);
|
|
1840
|
+
await this.commandHandler.executeHandler('setTimeZone', data);
|
|
1841
|
+
return { dstOffsetsRequired: false };
|
|
1842
|
+
},
|
|
1843
|
+
setDstOffset: async (data) => {
|
|
1844
|
+
this.log.debug('Matter command: setDstOffset', data.request);
|
|
1845
|
+
await this.commandHandler.executeHandler('setDstOffset', data);
|
|
1846
|
+
},
|
|
1847
|
+
setUtcTime: async (data) => {
|
|
1848
|
+
this.log.debug('Matter command: setUtcTime', data.request);
|
|
1849
|
+
await this.commandHandler.executeHandler('setUtcTime', data);
|
|
1850
|
+
},
|
|
1851
|
+
}, {
|
|
1852
|
+
dstTableEmpty: true,
|
|
1853
|
+
dstStatus: true,
|
|
1854
|
+
timeZoneStatus: true,
|
|
1855
|
+
timeFailure: true,
|
|
1856
|
+
});
|
|
1857
|
+
}
|
|
1858
|
+
/**
|
|
1859
|
+
* Creates a default dummy time sync cluster server. Only needed to create a thermostat.
|
|
1860
|
+
*/
|
|
1861
|
+
createDefaultTimeSyncClusterServer() {
|
|
1862
|
+
this.addClusterServer(this.getDefaultTimeSyncClusterServer());
|
|
1863
|
+
}
|
|
1864
|
+
/**
|
|
1865
|
+
* Returns the default SmokeCOAlarm Cluster Server.
|
|
1866
|
+
*
|
|
1867
|
+
* @param smokeState - The state of the smoke alarm. Defaults to SmokeCoAlarm.AlarmState.Normal.
|
|
1868
|
+
* @param coState - The state of the CO alarm. Defaults to SmokeCoAlarm.AlarmState.Normal.
|
|
1869
|
+
* @returns The default SmokeCOAlarmClusterServer.
|
|
1870
|
+
*/
|
|
1871
|
+
getDefaultSmokeCOAlarmClusterServer(smokeState = SmokeCoAlarm.AlarmState.Normal, coState = SmokeCoAlarm.AlarmState.Normal) {
|
|
1872
|
+
return ClusterServer(SmokeCoAlarmCluster.with(SmokeCoAlarm.Feature.SmokeAlarm, SmokeCoAlarm.Feature.CoAlarm), {
|
|
1873
|
+
smokeState,
|
|
1874
|
+
coState,
|
|
1875
|
+
expressedState: SmokeCoAlarm.ExpressedState.Normal,
|
|
1876
|
+
batteryAlert: SmokeCoAlarm.AlarmState.Normal,
|
|
1877
|
+
deviceMuted: SmokeCoAlarm.MuteState.NotMuted,
|
|
1878
|
+
testInProgress: false,
|
|
1879
|
+
hardwareFaultAlert: false,
|
|
1880
|
+
endOfServiceAlert: SmokeCoAlarm.EndOfService.Normal,
|
|
1881
|
+
interconnectSmokeAlarm: SmokeCoAlarm.AlarmState.Normal,
|
|
1882
|
+
interconnectCoAlarm: SmokeCoAlarm.AlarmState.Normal,
|
|
1883
|
+
}, {
|
|
1884
|
+
selfTestRequest: async (data) => {
|
|
1885
|
+
this.log.debug('Matter command: selfTestRequest');
|
|
1886
|
+
await this.commandHandler.executeHandler('selfTestRequest', data);
|
|
1887
|
+
},
|
|
1888
|
+
}, {
|
|
1889
|
+
smokeAlarm: true,
|
|
1890
|
+
interconnectSmokeAlarm: true,
|
|
1891
|
+
coAlarm: true,
|
|
1892
|
+
interconnectCoAlarm: true,
|
|
1893
|
+
lowBattery: true,
|
|
1894
|
+
hardwareFault: true,
|
|
1895
|
+
endOfService: true,
|
|
1896
|
+
selfTestComplete: true,
|
|
1897
|
+
alarmMuted: true,
|
|
1898
|
+
muteEnded: true,
|
|
1899
|
+
allClear: true,
|
|
1900
|
+
});
|
|
1901
|
+
}
|
|
1902
|
+
/**
|
|
1903
|
+
* Create the default SmokeCOAlarm Cluster Server.
|
|
1904
|
+
*
|
|
1905
|
+
* @param smokeState - The state of the smoke alarm. Defaults to SmokeCoAlarm.AlarmState.Normal.
|
|
1906
|
+
* @param coState - The state of the CO alarm. Defaults to SmokeCoAlarm.AlarmState.Normal.
|
|
1907
|
+
* @returns The default SmokeCOAlarmClusterServer.
|
|
1908
|
+
*/
|
|
1909
|
+
createDefaultSmokeCOAlarmClusterServer(smokeState = SmokeCoAlarm.AlarmState.Normal, coState = SmokeCoAlarm.AlarmState.Normal) {
|
|
1910
|
+
this.addClusterServer(this.getDefaultSmokeCOAlarmClusterServer(smokeState, coState));
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Returns the default Carbon Monoxide Concentration Measurement Cluster Server.
|
|
1914
|
+
*
|
|
1915
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
1916
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
1917
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
1918
|
+
* @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
|
|
1919
|
+
*/
|
|
1920
|
+
getDefaultCarbonMonoxideConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
1921
|
+
return ClusterServer(CarbonMonoxideConcentrationMeasurementCluster.with('NumericMeasurement'), {
|
|
1922
|
+
measuredValue,
|
|
1923
|
+
minMeasuredValue: null,
|
|
1924
|
+
maxMeasuredValue: null,
|
|
1925
|
+
uncertainty: 0,
|
|
1926
|
+
measurementUnit,
|
|
1927
|
+
measurementMedium,
|
|
1928
|
+
}, {}, {});
|
|
1929
|
+
}
|
|
1930
|
+
/**
|
|
1931
|
+
* Create the default Carbon Monoxide Concentration Measurement Cluster Server.
|
|
1932
|
+
*
|
|
1933
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
1934
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
1935
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
1936
|
+
*/
|
|
1937
|
+
createDefaultCarbonMonoxideConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
1938
|
+
this.addClusterServer(this.getDefaultCarbonMonoxideConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
|
|
1939
|
+
}
|
|
1940
|
+
/**
|
|
1941
|
+
* Returns the default Carbon Dioxide Concentration Measurement Cluster Server.
|
|
1942
|
+
*
|
|
1943
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
1944
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
1945
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
1946
|
+
* @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
|
|
1947
|
+
*/
|
|
1948
|
+
getDefaultCarbonDioxideConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
1949
|
+
return ClusterServer(CarbonDioxideConcentrationMeasurementCluster.with('NumericMeasurement'), {
|
|
1950
|
+
measuredValue,
|
|
1951
|
+
minMeasuredValue: null,
|
|
1952
|
+
maxMeasuredValue: null,
|
|
1953
|
+
uncertainty: 0,
|
|
1954
|
+
measurementUnit,
|
|
1955
|
+
measurementMedium,
|
|
1956
|
+
}, {}, {});
|
|
1957
|
+
}
|
|
1958
|
+
/**
|
|
1959
|
+
* Create the default Carbon Dioxide Concentration Measurement Cluster Server.
|
|
1960
|
+
*
|
|
1961
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
1962
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
1963
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
1964
|
+
*/
|
|
1965
|
+
createDefaultCarbonDioxideConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
1966
|
+
this.addClusterServer(this.getDefaultCarbonDioxideConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
|
|
1967
|
+
}
|
|
1968
|
+
/**
|
|
1969
|
+
* Returns the default Formaldehyde Concentration Measurement Cluster Server.
|
|
1970
|
+
*
|
|
1971
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
1972
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
1973
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
1974
|
+
* @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
|
|
1975
|
+
*/
|
|
1976
|
+
getDefaultFormaldehydeConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
1977
|
+
return ClusterServer(FormaldehydeConcentrationMeasurementCluster.with('NumericMeasurement'), {
|
|
1978
|
+
measuredValue,
|
|
1979
|
+
minMeasuredValue: null,
|
|
1980
|
+
maxMeasuredValue: null,
|
|
1981
|
+
uncertainty: 0,
|
|
1982
|
+
measurementUnit,
|
|
1983
|
+
measurementMedium,
|
|
1984
|
+
}, {}, {});
|
|
1985
|
+
}
|
|
1986
|
+
/**
|
|
1987
|
+
* Create the default Formaldehyde Concentration Measurement Cluster Server.
|
|
1988
|
+
*
|
|
1989
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
1990
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
1991
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
1992
|
+
*/
|
|
1993
|
+
createDefaultFormaldehydeConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
1994
|
+
this.addClusterServer(this.getDefaultFormaldehydeConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
|
|
1995
|
+
}
|
|
1996
|
+
/**
|
|
1997
|
+
* Returns the default Pm1 Concentration Measurement Cluster Server.
|
|
1998
|
+
*
|
|
1999
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
2000
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
2001
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
2002
|
+
* @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
|
|
2003
|
+
*/
|
|
2004
|
+
getDefaultPm1ConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
2005
|
+
return ClusterServer(Pm1ConcentrationMeasurementCluster.with('NumericMeasurement'), {
|
|
2006
|
+
measuredValue,
|
|
2007
|
+
minMeasuredValue: null,
|
|
2008
|
+
maxMeasuredValue: null,
|
|
2009
|
+
uncertainty: 0,
|
|
2010
|
+
measurementUnit,
|
|
2011
|
+
measurementMedium,
|
|
2012
|
+
}, {}, {});
|
|
2013
|
+
}
|
|
2014
|
+
/**
|
|
2015
|
+
* Create the default Pm1 Concentration Measurement Cluster Server.
|
|
2016
|
+
*
|
|
2017
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
2018
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
2019
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
2020
|
+
*/
|
|
2021
|
+
createDefaulPm1ConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
2022
|
+
this.addClusterServer(this.getDefaultPm1ConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
|
|
2023
|
+
}
|
|
2024
|
+
/**
|
|
2025
|
+
* Returns the default Pm25 Concentration Measurement Cluster Server.
|
|
2026
|
+
*
|
|
2027
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
2028
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
2029
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
2030
|
+
* @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
|
|
2031
|
+
*/
|
|
2032
|
+
getDefaultPm25ConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
2033
|
+
return ClusterServer(Pm25ConcentrationMeasurementCluster.with('NumericMeasurement'), {
|
|
2034
|
+
measuredValue,
|
|
2035
|
+
minMeasuredValue: null,
|
|
2036
|
+
maxMeasuredValue: null,
|
|
2037
|
+
uncertainty: 0,
|
|
2038
|
+
measurementUnit,
|
|
2039
|
+
measurementMedium,
|
|
2040
|
+
}, {}, {});
|
|
2041
|
+
}
|
|
2042
|
+
/**
|
|
2043
|
+
* Create the default Pm25 Concentration Measurement Cluster Server.
|
|
2044
|
+
*
|
|
2045
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
2046
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
2047
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
2048
|
+
*/
|
|
2049
|
+
createDefaulPm25ConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
2050
|
+
this.addClusterServer(this.getDefaultPm25ConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
|
|
2051
|
+
}
|
|
2052
|
+
/**
|
|
2053
|
+
* Returns the default Pm10 Concentration Measurement Cluster Server.
|
|
2054
|
+
*
|
|
2055
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
2056
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
2057
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
2058
|
+
* @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
|
|
2059
|
+
*/
|
|
2060
|
+
getDefaultPm10ConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
2061
|
+
return ClusterServer(Pm10ConcentrationMeasurementCluster.with('NumericMeasurement'), {
|
|
2062
|
+
measuredValue,
|
|
2063
|
+
minMeasuredValue: null,
|
|
2064
|
+
maxMeasuredValue: null,
|
|
2065
|
+
uncertainty: 0,
|
|
2066
|
+
measurementUnit,
|
|
2067
|
+
measurementMedium,
|
|
2068
|
+
}, {}, {});
|
|
2069
|
+
}
|
|
2070
|
+
/**
|
|
2071
|
+
* Create the default Pm10 Concentration Measurement Cluster Server.
|
|
2072
|
+
*
|
|
2073
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
2074
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
2075
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
2076
|
+
*/
|
|
2077
|
+
createDefaulPm10ConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
2078
|
+
this.addClusterServer(this.getDefaultPm10ConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
|
|
2079
|
+
}
|
|
2080
|
+
/**
|
|
2081
|
+
* Returns the default Ozone Concentration Measurement Cluster Server.
|
|
2082
|
+
*
|
|
2083
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
2084
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
2085
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
2086
|
+
* @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
|
|
2087
|
+
*/
|
|
2088
|
+
getDefaultOzoneConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ugm3, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
2089
|
+
return ClusterServer(OzoneConcentrationMeasurementCluster.with('NumericMeasurement'), {
|
|
2090
|
+
measuredValue,
|
|
2091
|
+
minMeasuredValue: null,
|
|
2092
|
+
maxMeasuredValue: null,
|
|
2093
|
+
uncertainty: 0,
|
|
2094
|
+
measurementUnit,
|
|
2095
|
+
measurementMedium,
|
|
2096
|
+
}, {}, {});
|
|
2097
|
+
}
|
|
2098
|
+
/**
|
|
2099
|
+
* Create the default Ozone Concentration Measurement Cluster Server.
|
|
2100
|
+
*
|
|
2101
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
2102
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
2103
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
2104
|
+
*/
|
|
2105
|
+
createDefaulOzoneConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ugm3, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
2106
|
+
this.addClusterServer(this.getDefaultOzoneConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
|
|
2107
|
+
}
|
|
2108
|
+
/**
|
|
2109
|
+
* Returns the default Radon Concentration Measurement Cluster Server.
|
|
2110
|
+
*
|
|
2111
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
2112
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
2113
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
2114
|
+
* @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
|
|
2115
|
+
*/
|
|
2116
|
+
getDefaultRadonConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
2117
|
+
return ClusterServer(RadonConcentrationMeasurementCluster.with('NumericMeasurement'), {
|
|
2118
|
+
measuredValue,
|
|
2119
|
+
minMeasuredValue: null,
|
|
2120
|
+
maxMeasuredValue: null,
|
|
2121
|
+
uncertainty: 0,
|
|
2122
|
+
measurementUnit,
|
|
2123
|
+
measurementMedium,
|
|
2124
|
+
}, {}, {});
|
|
2125
|
+
}
|
|
2126
|
+
/**
|
|
2127
|
+
* Create the default Radon Concentration Measurement Cluster Server.
|
|
2128
|
+
*
|
|
2129
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
2130
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
2131
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
2132
|
+
*/
|
|
2133
|
+
createDefaulRadonConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
2134
|
+
this.addClusterServer(this.getDefaultRadonConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
|
|
2135
|
+
}
|
|
2136
|
+
/**
|
|
2137
|
+
* Returns the default Nitrogen Dioxide Concentration Measurement Cluster Server.
|
|
2138
|
+
*
|
|
2139
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
2140
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
2141
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
2142
|
+
* @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
|
|
2143
|
+
*/
|
|
2144
|
+
getDefaultNitrogenDioxideConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ugm3, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
2145
|
+
return ClusterServer(NitrogenDioxideConcentrationMeasurementCluster.with('NumericMeasurement'), {
|
|
2146
|
+
measuredValue,
|
|
2147
|
+
minMeasuredValue: null,
|
|
2148
|
+
maxMeasuredValue: null,
|
|
2149
|
+
uncertainty: 0,
|
|
2150
|
+
measurementUnit,
|
|
2151
|
+
measurementMedium,
|
|
2152
|
+
}, {}, {});
|
|
2153
|
+
}
|
|
2154
|
+
/**
|
|
2155
|
+
* Create the default Nitrogen Dioxide Concentration Measurement Cluster Server.
|
|
2156
|
+
*
|
|
2157
|
+
* @param {number} measuredValue - The measured value of the concentration.
|
|
2158
|
+
* @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
|
|
2159
|
+
* @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
|
|
2160
|
+
*/
|
|
2161
|
+
createDefaulNitrogenDioxideConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ugm3, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
|
|
2162
|
+
this.addClusterServer(this.getDefaultNitrogenDioxideConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
|
|
2163
|
+
}
|
|
2164
|
+
/**
|
|
2165
|
+
* Returns the default fan control cluster server rev 2.
|
|
2166
|
+
*
|
|
2167
|
+
* @param fanMode The fan mode to set. Defaults to `FanControl.FanMode.Off`.
|
|
2168
|
+
* @returns The default fan control cluster server.
|
|
2169
|
+
*/
|
|
2170
|
+
getDefaultFanControlClusterServer(fanMode = FanControl.FanMode.Off) {
|
|
2171
|
+
return ClusterServer(FanControlCluster.with(FanControl.Feature.MultiSpeed, FanControl.Feature.Auto, FanControl.Feature.Step), {
|
|
2172
|
+
fanMode,
|
|
2173
|
+
fanModeSequence: FanControl.FanModeSequence.OffLowMedHighAuto,
|
|
2174
|
+
percentSetting: 0,
|
|
2175
|
+
percentCurrent: 0,
|
|
2176
|
+
speedMax: 100,
|
|
2177
|
+
speedSetting: 0,
|
|
2178
|
+
speedCurrent: 0,
|
|
2179
|
+
}, {
|
|
2180
|
+
step: async (data) => {
|
|
2181
|
+
this.log.debug('Matter command: step', data.request);
|
|
2182
|
+
await this.commandHandler.executeHandler('step', data);
|
|
2183
|
+
},
|
|
2184
|
+
}, {});
|
|
2185
|
+
}
|
|
2186
|
+
/**
|
|
2187
|
+
* Create the default fan control cluster server rev 2.
|
|
2188
|
+
*
|
|
2189
|
+
* @param fanMode The fan mode to set. Defaults to `FanControl.FanMode.Off`.
|
|
2190
|
+
* @returns The default fan control cluster server.
|
|
2191
|
+
*/
|
|
2192
|
+
createDefaultFanControlClusterServer(fanMode = FanControl.FanMode.Off) {
|
|
2193
|
+
this.addClusterServer(this.getDefaultFanControlClusterServer(fanMode));
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
//# sourceMappingURL=matterbridgeEndpoint.js.map
|