matterbridge 2.0.0 → 2.1.0-dev.10

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.
Files changed (103) hide show
  1. package/CHANGELOG.md +26 -4
  2. package/README.md +1 -1
  3. package/dist/cli.js +0 -26
  4. package/dist/cluster/export.js +0 -2
  5. package/dist/defaultConfigSchema.js +0 -23
  6. package/dist/deviceManager.js +1 -26
  7. package/dist/frontend.js +143 -313
  8. package/dist/index.js +2 -30
  9. package/dist/logger/export.js +0 -1
  10. package/dist/matter/behaviors.js +1 -0
  11. package/dist/matter/clusters.js +1 -0
  12. package/dist/matter/devices.js +1 -0
  13. package/dist/matter/endpoints.js +1 -0
  14. package/dist/matter/export.js +1 -11
  15. package/dist/matter/types.js +2 -0
  16. package/dist/matterbridge.js +77 -715
  17. package/dist/matterbridgeAccessoryPlatform.js +0 -33
  18. package/dist/matterbridgeBehaviors.js +38 -38
  19. package/dist/matterbridgeDeviceTypes.js +11 -112
  20. package/dist/matterbridgeDynamicPlatform.js +0 -33
  21. package/dist/matterbridgeEndpoint.js +664 -2563
  22. package/dist/matterbridgeEndpointHelpers.js +513 -0
  23. package/dist/matterbridgePlatform.js +5 -125
  24. package/dist/matterbridgeTypes.js +0 -28
  25. package/dist/pluginManager.js +3 -240
  26. package/dist/storage/export.js +0 -1
  27. package/dist/utils/colorUtils.js +2 -205
  28. package/dist/utils/export.js +0 -1
  29. package/dist/utils/utils.js +7 -251
  30. package/frontend/build/asset-manifest.json +3 -3
  31. package/frontend/build/index.html +1 -1
  32. package/frontend/build/static/js/{main.6df4ebe4.js → main.26dbf9b9.js} +3 -3
  33. package/frontend/build/static/js/{main.6df4ebe4.js.map → main.26dbf9b9.js.map} +1 -1
  34. package/npm-shrinkwrap.json +86 -78
  35. package/package.json +22 -4
  36. package/dist/cli.d.ts +0 -25
  37. package/dist/cli.d.ts.map +0 -1
  38. package/dist/cli.js.map +0 -1
  39. package/dist/cluster/export.d.ts +0 -2
  40. package/dist/cluster/export.d.ts.map +0 -1
  41. package/dist/cluster/export.js.map +0 -1
  42. package/dist/defaultConfigSchema.d.ts +0 -27
  43. package/dist/defaultConfigSchema.d.ts.map +0 -1
  44. package/dist/defaultConfigSchema.js.map +0 -1
  45. package/dist/deviceManager.d.ts +0 -46
  46. package/dist/deviceManager.d.ts.map +0 -1
  47. package/dist/deviceManager.js.map +0 -1
  48. package/dist/frontend.d.ts +0 -98
  49. package/dist/frontend.d.ts.map +0 -1
  50. package/dist/frontend.js.map +0 -1
  51. package/dist/index.d.ts +0 -34
  52. package/dist/index.d.ts.map +0 -1
  53. package/dist/index.js.map +0 -1
  54. package/dist/logger/export.d.ts +0 -2
  55. package/dist/logger/export.d.ts.map +0 -1
  56. package/dist/logger/export.js.map +0 -1
  57. package/dist/matter/export.d.ts +0 -10
  58. package/dist/matter/export.d.ts.map +0 -1
  59. package/dist/matter/export.js.map +0 -1
  60. package/dist/matterbridge.d.ts +0 -356
  61. package/dist/matterbridge.d.ts.map +0 -1
  62. package/dist/matterbridge.js.map +0 -1
  63. package/dist/matterbridgeAccessoryPlatform.d.ts +0 -39
  64. package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
  65. package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
  66. package/dist/matterbridgeBehaviors.d.ts +0 -963
  67. package/dist/matterbridgeBehaviors.d.ts.map +0 -1
  68. package/dist/matterbridgeBehaviors.js.map +0 -1
  69. package/dist/matterbridgeDeviceTypes.d.ts +0 -177
  70. package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
  71. package/dist/matterbridgeDeviceTypes.js.map +0 -1
  72. package/dist/matterbridgeDynamicPlatform.d.ts +0 -39
  73. package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
  74. package/dist/matterbridgeDynamicPlatform.js.map +0 -1
  75. package/dist/matterbridgeEndpoint.d.ts +0 -10254
  76. package/dist/matterbridgeEndpoint.d.ts.map +0 -1
  77. package/dist/matterbridgeEndpoint.js.map +0 -1
  78. package/dist/matterbridgeEndpointDefault.d.ts +0 -2
  79. package/dist/matterbridgeEndpointDefault.d.ts.map +0 -1
  80. package/dist/matterbridgeEndpointDefault.js +0 -159
  81. package/dist/matterbridgeEndpointDefault.js.map +0 -1
  82. package/dist/matterbridgePlatform.d.ts +0 -164
  83. package/dist/matterbridgePlatform.d.ts.map +0 -1
  84. package/dist/matterbridgePlatform.js.map +0 -1
  85. package/dist/matterbridgeTypes.d.ts +0 -167
  86. package/dist/matterbridgeTypes.d.ts.map +0 -1
  87. package/dist/matterbridgeTypes.js.map +0 -1
  88. package/dist/pluginManager.d.ts +0 -238
  89. package/dist/pluginManager.d.ts.map +0 -1
  90. package/dist/pluginManager.js.map +0 -1
  91. package/dist/storage/export.d.ts +0 -2
  92. package/dist/storage/export.d.ts.map +0 -1
  93. package/dist/storage/export.js.map +0 -1
  94. package/dist/utils/colorUtils.d.ts +0 -61
  95. package/dist/utils/colorUtils.d.ts.map +0 -1
  96. package/dist/utils/colorUtils.js.map +0 -1
  97. package/dist/utils/export.d.ts +0 -3
  98. package/dist/utils/export.d.ts.map +0 -1
  99. package/dist/utils/export.js.map +0 -1
  100. package/dist/utils/utils.d.ts +0 -221
  101. package/dist/utils/utils.d.ts.map +0 -1
  102. package/dist/utils/utils.js.map +0 -1
  103. /package/frontend/build/static/js/{main.6df4ebe4.js.LICENSE.txt → main.26dbf9b9.js.LICENSE.txt} +0 -0
@@ -1,120 +1,62 @@
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, 2025, 2026 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
- // Node.js modules
25
- import { createHash } from 'crypto';
26
- // AnsiLogger module
27
- import { AnsiLogger, BLUE, CYAN, YELLOW, db, debugStringify, er, hk, or, rs, zb } from './logger/export.js';
28
- // Matterbridge behaviors
29
- import { MatterbridgeBehavior, MatterbridgeBehaviorDevice, MatterbridgeBooleanStateConfigurationServer, MatterbridgeColorControlServer, MatterbridgeDoorLockServer, MatterbridgeFanControlServer, MatterbridgeIdentifyServer, MatterbridgeLevelControlServer, MatterbridgeOnOffServer, MatterbridgeThermostatServer, MatterbridgeValveConfigurationAndControlServer, MatterbridgeWindowCoveringServer, } from './matterbridgeBehaviors.js';
1
+ import { AnsiLogger, BLUE, CYAN, YELLOW, db, debugStringify, er, hk, or, zb } from './logger/export.js';
30
2
  import { bridgedNode } from './matterbridgeDeviceTypes.js';
31
- import { deepCopy, isValidNumber } from './utils/utils.js';
32
- // @matter
33
- import { Endpoint, MutableEndpoint, SupportedBehaviors, NamedHandler, Lifecycle, VendorId } from '@matter/main';
34
- import { MeasurementType, getClusterNameById } from '@matter/main/types';
35
- import { Specification } from '@matter/main/model';
36
- // @matter clusters
37
- import { BasicInformation, BasicInformationCluster } from '@matter/main/clusters/basic-information';
38
- import { BooleanState, BooleanStateCluster } from '@matter/main/clusters/boolean-state';
39
- import { BooleanStateConfiguration, BooleanStateConfigurationCluster } from '@matter/main/clusters/boolean-state-configuration';
40
- import { BridgedDeviceBasicInformation, BridgedDeviceBasicInformationCluster } from '@matter/main/clusters/bridged-device-basic-information';
41
- import { CarbonDioxideConcentrationMeasurement, CarbonDioxideConcentrationMeasurementCluster } from '@matter/main/clusters/carbon-dioxide-concentration-measurement';
42
- import { CarbonMonoxideConcentrationMeasurement, CarbonMonoxideConcentrationMeasurementCluster } from '@matter/main/clusters/carbon-monoxide-concentration-measurement';
43
- import { ColorControl, ColorControlCluster } from '@matter/main/clusters/color-control';
44
- import { ConcentrationMeasurement } from '@matter/main/clusters/concentration-measurement';
3
+ import { isValidNumber, isValidObject } from './utils/utils.js';
4
+ import { MatterbridgeBehavior, MatterbridgeBehaviorDevice, MatterbridgeIdentifyServer, MatterbridgeOnOffServer, MatterbridgeLevelControlServer, MatterbridgeColorControlServer, MatterbridgeWindowCoveringServer, MatterbridgeThermostatServer, MatterbridgeFanControlServer, MatterbridgeDoorLockServer, MatterbridgeModeSelectServer, MatterbridgeValveConfigurationAndControlServer, MatterbridgeSmokeCoAlarmServer, MatterbridgeBooleanStateConfigurationServer, MatterbridgeSwitchServer, } from './matterbridgeBehaviors.js';
5
+ import { addClusterServers, addFixedLabel, addOptionalClusterServers, addRequiredClusterServers, addUserLabel, capitalizeFirstLetter, createUniqueId, getBehavior, getBehaviourTypesFromClusterClientIds, getBehaviourTypesFromClusterServerIds, getDefaultFlowMeasurementClusterServer, getDefaultIlluminanceMeasurementClusterServer, getDefaultPressureMeasurementClusterServer, getDefaultRelativeHumidityMeasurementClusterServer, getDefaultTemperatureMeasurementClusterServer, getDefaultOccupancySensingClusterServer, lowercaseFirstLetter, updateAttribute, getClusterId, getAttributeId, setAttribute, getAttribute, } from './matterbridgeEndpointHelpers.js';
6
+ import { Endpoint, Lifecycle, MutableEndpoint, NamedHandler, SupportedBehaviors, VendorId } from '@matter/main';
7
+ import { getClusterNameById, MeasurementType } from '@matter/main/types';
45
8
  import { Descriptor } from '@matter/main/clusters/descriptor';
46
- import { DoorLock, DoorLockCluster } from '@matter/main/clusters/door-lock';
47
- import { ElectricalEnergyMeasurement, ElectricalEnergyMeasurementCluster } from '@matter/main/clusters/electrical-energy-measurement';
48
- import { ElectricalPowerMeasurement, ElectricalPowerMeasurementCluster } from '@matter/main/clusters/electrical-power-measurement';
49
- import { FanControl, FanControlCluster } from '@matter/main/clusters/fan-control';
50
- import { FixedLabel, FixedLabelCluster } from '@matter/main/clusters/fixed-label';
51
- import { FlowMeasurement, FlowMeasurementCluster } from '@matter/main/clusters/flow-measurement';
52
- import { FormaldehydeConcentrationMeasurement, FormaldehydeConcentrationMeasurementCluster } from '@matter/main/clusters/formaldehyde-concentration-measurement';
53
- import { Groups, GroupsCluster } from '@matter/main/clusters/groups';
54
- import { Identify, IdentifyCluster } from '@matter/main/clusters/identify';
55
- import { IlluminanceMeasurement, IlluminanceMeasurementCluster } from '@matter/main/clusters/illuminance-measurement';
56
- import { LevelControl, LevelControlCluster } from '@matter/main/clusters/level-control';
57
- import { ModeSelect, ModeSelectCluster } from '@matter/main/clusters/mode-select';
58
- import { NitrogenDioxideConcentrationMeasurement, NitrogenDioxideConcentrationMeasurementCluster } from '@matter/main/clusters/nitrogen-dioxide-concentration-measurement';
59
- import { OccupancySensing, OccupancySensingCluster } from '@matter/main/clusters/occupancy-sensing';
60
- import { OnOff, OnOffCluster } from '@matter/main/clusters/on-off';
61
- import { OzoneConcentrationMeasurement, OzoneConcentrationMeasurementCluster } from '@matter/main/clusters/ozone-concentration-measurement';
62
- import { Pm10ConcentrationMeasurement, Pm10ConcentrationMeasurementCluster } from '@matter/main/clusters/pm10-concentration-measurement';
63
- import { Pm1ConcentrationMeasurement, Pm1ConcentrationMeasurementCluster } from '@matter/main/clusters/pm1-concentration-measurement';
64
- import { Pm25ConcentrationMeasurement, Pm25ConcentrationMeasurementCluster } from '@matter/main/clusters/pm25-concentration-measurement';
65
- import { PowerSource, PowerSourceCluster } from '@matter/main/clusters/power-source';
66
- import { PowerTopology, PowerTopologyCluster } from '@matter/main/clusters/power-topology';
67
- import { PressureMeasurement, PressureMeasurementCluster } from '@matter/main/clusters/pressure-measurement';
68
- import { PumpConfigurationAndControl, PumpConfigurationAndControlCluster } from '@matter/main/clusters/pump-configuration-and-control';
69
- import { RadonConcentrationMeasurement, RadonConcentrationMeasurementCluster } from '@matter/main/clusters/radon-concentration-measurement';
70
- import { RelativeHumidityMeasurement, RelativeHumidityMeasurementCluster } from '@matter/main/clusters/relative-humidity-measurement';
71
- import { SmokeCoAlarm, SmokeCoAlarmCluster } from '@matter/main/clusters/smoke-co-alarm';
72
- import { Switch, SwitchCluster } from '@matter/main/clusters/switch';
73
- import { TemperatureMeasurement, TemperatureMeasurementCluster } from '@matter/main/clusters/temperature-measurement';
74
- import { Thermostat, ThermostatCluster } from '@matter/main/clusters/thermostat';
75
- import { TotalVolatileOrganicCompoundsConcentrationMeasurement, TotalVolatileOrganicCompoundsConcentrationMeasurementCluster } from '@matter/main/clusters/total-volatile-organic-compounds-concentration-measurement';
76
- import { UserLabel, UserLabelCluster } from '@matter/main/clusters/user-label';
77
- import { ValveConfigurationAndControl, ValveConfigurationAndControlCluster } from '@matter/main/clusters/valve-configuration-and-control';
78
- import { WindowCovering, WindowCoveringCluster } from '@matter/main/clusters/window-covering';
79
- import { AirQuality, AirQualityCluster } from '@matter/main/clusters/air-quality';
80
- // @matter behaviors
81
- import { DescriptorServer } from '@matter/node/behaviors/descriptor';
82
- import { IdentifyBehavior } from '@matter/node/behaviors/identify';
83
- import { GroupsServer } from '@matter/node/behaviors/groups';
84
- import { TemperatureMeasurementServer } from '@matter/node/behaviors/temperature-measurement';
85
- import { RelativeHumidityMeasurementServer } from '@matter/node/behaviors/relative-humidity-measurement';
86
- import { PressureMeasurementServer } from '@matter/node/behaviors/pressure-measurement';
87
- import { BridgedDeviceBasicInformationServer } from '@matter/node/behaviors/bridged-device-basic-information';
88
- import { FlowMeasurementServer } from '@matter/node/behaviors/flow-measurement';
89
- import { IlluminanceMeasurementServer } from '@matter/node/behaviors/illuminance-measurement';
90
- import { BooleanStateServer } from '@matter/node/behaviors/boolean-state';
91
- import { OccupancySensingServer } from '@matter/node/behaviors/occupancy-sensing';
9
+ import { PowerSource } from '@matter/main/clusters/power-source';
10
+ import { BridgedDeviceBasicInformation } from '@matter/main/clusters/bridged-device-basic-information';
11
+ import { Identify } from '@matter/main/clusters/identify';
12
+ import { OnOff } from '@matter/main/clusters/on-off';
13
+ import { LevelControl } from '@matter/main/clusters/level-control';
14
+ import { ColorControl } from '@matter/main/clusters/color-control';
15
+ import { WindowCovering } from '@matter/main/clusters/window-covering';
16
+ import { Thermostat } from '@matter/main/clusters/thermostat';
17
+ import { FanControl } from '@matter/main/clusters/fan-control';
18
+ import { DoorLock } from '@matter/main/clusters/door-lock';
19
+ import { ValveConfigurationAndControl } from '@matter/main/clusters/valve-configuration-and-control';
20
+ import { PumpConfigurationAndControl } from '@matter/main/clusters/pump-configuration-and-control';
21
+ import { SmokeCoAlarm } from '@matter/main/clusters/smoke-co-alarm';
22
+ import { Switch } from '@matter/main/clusters/switch';
23
+ import { BooleanStateConfiguration } from '@matter/main/clusters/boolean-state-configuration';
24
+ import { PowerTopology } from '@matter/main/clusters/power-topology';
25
+ import { ElectricalPowerMeasurement } from '@matter/main/clusters/electrical-power-measurement';
26
+ import { ElectricalEnergyMeasurement } from '@matter/main/clusters/electrical-energy-measurement';
27
+ import { AirQuality } from '@matter/main/clusters/air-quality';
28
+ import { ConcentrationMeasurement } from '@matter/main/clusters/concentration-measurement';
29
+ import { DescriptorServer } from '@matter/main/behaviors/descriptor';
30
+ import { PowerSourceServer } from '@matter/main/behaviors/power-source';
31
+ import { BridgedDeviceBasicInformationServer } from '@matter/main/behaviors/bridged-device-basic-information';
32
+ import { GroupsServer } from '@matter/main/behaviors/groups';
33
+ import { ScenesManagementServer } from '@matter/main/behaviors/scenes-management';
34
+ import { PumpConfigurationAndControlServer } from '@matter/main/behaviors/pump-configuration-and-control';
35
+ import { SwitchServer } from '@matter/main/behaviors/switch';
36
+ import { BooleanStateServer } from '@matter/main/behaviors/boolean-state';
37
+ import { PowerTopologyServer } from '@matter/main/behaviors/power-topology';
38
+ import { ElectricalPowerMeasurementServer } from '@matter/main/behaviors/electrical-power-measurement';
39
+ import { ElectricalEnergyMeasurementServer } from '@matter/main/behaviors/electrical-energy-measurement';
40
+ import { TemperatureMeasurementServer } from '@matter/main/behaviors/temperature-measurement';
41
+ import { RelativeHumidityMeasurementServer } from '@matter/main/behaviors/relative-humidity-measurement';
42
+ import { PressureMeasurementServer } from '@matter/main/behaviors/pressure-measurement';
43
+ import { FlowMeasurementServer } from '@matter/main/behaviors/flow-measurement';
44
+ import { IlluminanceMeasurementServer } from '@matter/main/behaviors/illuminance-measurement';
45
+ import { OccupancySensingServer } from '@matter/main/behaviors/occupancy-sensing';
92
46
  import { AirQualityServer } from '@matter/main/behaviors/air-quality';
93
- import { BasicInformationServer } from '@matter/main/behaviors/basic-information';
94
- import { CarbonDioxideConcentrationMeasurementServer } from '@matter/main/behaviors/carbon-dioxide-concentration-measurement';
95
47
  import { CarbonMonoxideConcentrationMeasurementServer } from '@matter/main/behaviors/carbon-monoxide-concentration-measurement';
96
- import { ElectricalEnergyMeasurementServer } from '@matter/main/behaviors/electrical-energy-measurement';
97
- import { ElectricalPowerMeasurementServer } from '@matter/main/behaviors/electrical-power-measurement';
98
- import { FixedLabelServer } from '@matter/main/behaviors/fixed-label';
99
- import { FormaldehydeConcentrationMeasurementServer } from '@matter/main/behaviors/formaldehyde-concentration-measurement';
100
- import { ModeSelectServer } from '@matter/main/behaviors/mode-select';
48
+ import { CarbonDioxideConcentrationMeasurementServer } from '@matter/main/behaviors/carbon-dioxide-concentration-measurement';
101
49
  import { NitrogenDioxideConcentrationMeasurementServer } from '@matter/main/behaviors/nitrogen-dioxide-concentration-measurement';
102
50
  import { OzoneConcentrationMeasurementServer } from '@matter/main/behaviors/ozone-concentration-measurement';
103
- import { Pm10ConcentrationMeasurementServer } from '@matter/main/behaviors/pm10-concentration-measurement';
51
+ import { FormaldehydeConcentrationMeasurementServer } from '@matter/main/behaviors/formaldehyde-concentration-measurement';
104
52
  import { Pm1ConcentrationMeasurementServer } from '@matter/main/behaviors/pm1-concentration-measurement';
105
53
  import { Pm25ConcentrationMeasurementServer } from '@matter/main/behaviors/pm25-concentration-measurement';
106
- import { PowerSourceServer } from '@matter/main/behaviors/power-source';
107
- import { PowerTopologyServer } from '@matter/main/behaviors/power-topology';
54
+ import { Pm10ConcentrationMeasurementServer } from '@matter/main/behaviors/pm10-concentration-measurement';
108
55
  import { RadonConcentrationMeasurementServer } from '@matter/main/behaviors/radon-concentration-measurement';
109
- import { SmokeCoAlarmServer } from '@matter/main/behaviors/smoke-co-alarm';
110
- import { SwitchServer } from '@matter/main/behaviors/switch';
111
56
  import { TotalVolatileOrganicCompoundsConcentrationMeasurementServer } from '@matter/main/behaviors/total-volatile-organic-compounds-concentration-measurement';
112
- import { UserLabelServer } from '@matter/main/behaviors/user-label';
113
- // @project-chip
114
- import { ClusterServer, GroupsClusterHandler } from '@project-chip/matter.js/cluster';
115
57
  export class MatterbridgeEndpoint extends Endpoint {
116
58
  static bridgeMode = '';
117
- static logLevel = "info" /* LogLevel.INFO */;
59
+ static logLevel = "info";
118
60
  log;
119
61
  plugin = undefined;
120
62
  configUrl = undefined;
@@ -134,22 +76,10 @@ export class MatterbridgeEndpoint extends Endpoint {
134
76
  deviceType;
135
77
  uniqueStorageKey = undefined;
136
78
  tagList = undefined;
137
- subType = '';
138
- // Maps matter deviceTypes and endpoints
139
79
  deviceTypes = new Map();
140
- clusterServers = new Map();
141
- clusterClients = new Map();
142
80
  commandHandler = new NamedHandler();
143
- /**
144
- * Represents a MatterbridgeEndpoint.
145
- * @constructor
146
- * @param {DeviceTypeDefinition | AtLeastOne<DeviceTypeDefinition>} definition - The DeviceTypeDefinition(s) of the endpoint.
147
- * @param {MatterbridgeEndpointOptions} [options={}] - The options for the device.
148
- * @param {boolean} [debug=false] - Debug flag.
149
- */
150
81
  constructor(definition, options = {}, debug = false) {
151
82
  let deviceTypeList = [];
152
- // Get the first DeviceTypeDefinition
153
83
  let firstDefinition;
154
84
  if (Array.isArray(definition)) {
155
85
  firstDefinition = definition[0];
@@ -162,7 +92,6 @@ export class MatterbridgeEndpoint extends Endpoint {
162
92
  firstDefinition = definition;
163
93
  deviceTypeList = [{ deviceType: firstDefinition.code, revision: firstDefinition.revision }];
164
94
  }
165
- // Convert the first DeviceTypeDefinition to an EndpointType.Options
166
95
  const deviceTypeDefinitionV8 = {
167
96
  name: firstDefinition.name.replace('-', '_'),
168
97
  deviceType: firstDefinition.code,
@@ -170,18 +99,17 @@ export class MatterbridgeEndpoint extends Endpoint {
170
99
  deviceClass: firstDefinition.deviceClass.toLowerCase(),
171
100
  requirements: {
172
101
  server: {
173
- mandatory: SupportedBehaviors(...MatterbridgeEndpoint.getBehaviourTypesFromClusterServerIds(firstDefinition.requiredServerClusters)),
174
- optional: SupportedBehaviors(...MatterbridgeEndpoint.getBehaviourTypesFromClusterServerIds(firstDefinition.optionalServerClusters)),
102
+ mandatory: SupportedBehaviors(...getBehaviourTypesFromClusterServerIds(firstDefinition.requiredServerClusters)),
103
+ optional: SupportedBehaviors(...getBehaviourTypesFromClusterServerIds(firstDefinition.optionalServerClusters)),
175
104
  },
176
105
  client: {
177
- mandatory: SupportedBehaviors(...MatterbridgeEndpoint.getBehaviourTypesFromClusterClientIds(firstDefinition.requiredClientClusters)),
178
- optional: SupportedBehaviors(...MatterbridgeEndpoint.getBehaviourTypesFromClusterClientIds(firstDefinition.optionalClientClusters)),
106
+ mandatory: SupportedBehaviors(...getBehaviourTypesFromClusterClientIds(firstDefinition.requiredClientClusters)),
107
+ optional: SupportedBehaviors(...getBehaviourTypesFromClusterClientIds(firstDefinition.optionalClientClusters)),
179
108
  },
180
109
  },
181
110
  behaviors: options.tagList ? SupportedBehaviors(DescriptorServer.with(Descriptor.Feature.TagList)) : {},
182
111
  };
183
112
  const endpointV8 = MutableEndpoint(deviceTypeDefinitionV8);
184
- // Convert the options to an Endpoint.Options
185
113
  const optionsV8 = {
186
114
  id: options.uniqueStorageKey?.replace(/[ .]/g, ''),
187
115
  number: options.endpointId,
@@ -199,294 +127,145 @@ export class MatterbridgeEndpoint extends Endpoint {
199
127
  }
200
128
  else
201
129
  this.deviceTypes.set(firstDefinition.code, firstDefinition);
202
- // console.log('MatterbridgeEndpoint.option', options);
203
- // console.log('MatterbridgeEndpoint.endpointV8', endpointV8);
204
- // console.log('MatterbridgeEndpoint.optionsV8', optionsV8);
205
- // Create the logger
206
- this.log = new AnsiLogger({ logName: 'MatterbridgeEndpoint', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: debug === true ? "debug" /* LogLevel.DEBUG */ : MatterbridgeEndpoint.logLevel });
130
+ this.log = new AnsiLogger({ logName: 'MatterbridgeEndpoint', logTimestampFormat: 4, logLevel: debug === true ? "debug" : MatterbridgeEndpoint.logLevel });
207
131
  this.log.debug(`${YELLOW}new${db} MatterbridgeEndpoint: ${zb}${'0x' + firstDefinition.code.toString(16).padStart(4, '0')}${db}-${zb}${firstDefinition.name}${db} ` +
208
132
  `id: ${CYAN}${options.uniqueStorageKey}${db} number: ${CYAN}${options.endpointId}${db} taglist: ${CYAN}${options.tagList ? debugStringify(options.tagList) : 'undefined'}${db}`);
209
- // Add MatterbridgeBehavior with MatterbridgeBehaviorDevice
210
133
  this.behaviors.require(MatterbridgeBehavior, { deviceCommand: new MatterbridgeBehaviorDevice(this.log, this.commandHandler, undefined) });
211
134
  }
212
- /**
213
- * Loads an instance of the MatterbridgeEndpoint class.
214
- *
215
- * @param {DeviceTypeDefinition | AtLeastOne<DeviceTypeDefinition>} definition - The DeviceTypeDefinition(s) of the device.
216
- * @param {MatterbridgeEndpointOptions} [options={}] - The options for the device.
217
- * @param {boolean} [debug=false] - Debug flag.
218
- * @returns {Promise<MatterbridgeEndpoint>} MatterbridgeEndpoint instance.
219
- */
220
135
  static async loadInstance(definition, options = {}, debug = false) {
221
136
  return new MatterbridgeEndpoint(definition, options, debug);
222
137
  }
223
- static getBehaviourTypesFromClusterServerIds(clusterServerList) {
224
- // Map Server ClusterId to Behavior.Type
225
- const behaviorTypes = [];
226
- clusterServerList.forEach((clusterId) => {
227
- behaviorTypes.push(MatterbridgeEndpoint.getBehaviourTypeFromClusterServerId(clusterId));
228
- });
229
- return behaviorTypes;
138
+ getDeviceTypes() {
139
+ return Array.from(this.deviceTypes.values());
230
140
  }
231
- static getBehaviourTypesFromClusterClientIds(clusterClientList) {
232
- // Map Client ClusterId to Behavior.Type
233
- const behaviorTypes = [];
234
- clusterClientList.forEach((clusterId) => {
235
- // behaviorTypes.push(MatterbridgeEndpoint.getBehaviourTypeFromClusterClientId(clusterId));
236
- });
237
- return behaviorTypes;
238
- }
239
- static getBehaviourTypeFromClusterServerId(clusterId, subType) {
240
- // Map ClusterId to Behavior.Type
241
- if (clusterId === Identify.Cluster.id)
242
- return MatterbridgeIdentifyServer;
243
- if (clusterId === Groups.Cluster.id)
244
- return GroupsServer;
245
- if (clusterId === OnOff.Cluster.id && subType === undefined)
246
- return MatterbridgeOnOffServer.with('Lighting');
247
- if (clusterId === OnOff.Cluster.id && subType === '')
248
- return MatterbridgeOnOffServer;
249
- if (clusterId === OnOff.Cluster.id && subType === 'LightingOnOff')
250
- return MatterbridgeOnOffServer.with('Lighting');
251
- if (clusterId === OnOff.Cluster.id && subType === 'DeadFrontBehaviorOnOff')
252
- return MatterbridgeOnOffServer.with('DeadFrontBehavior');
253
- if (clusterId === LevelControl.Cluster.id)
254
- return MatterbridgeLevelControlServer.with('OnOff', 'Lighting');
255
- if (clusterId === ColorControl.Cluster.id && subType === undefined)
256
- return MatterbridgeColorControlServer;
257
- if (clusterId === ColorControl.Cluster.id && subType === 'CompleteColorControl')
258
- return MatterbridgeColorControlServer;
259
- if (clusterId === ColorControl.Cluster.id && subType === 'XyColorControl')
260
- return MatterbridgeColorControlServer.with('Xy', 'ColorTemperature');
261
- if (clusterId === ColorControl.Cluster.id && subType === 'HueSaturationColorControl')
262
- return MatterbridgeColorControlServer.with('HueSaturation', 'ColorTemperature');
263
- if (clusterId === ColorControl.Cluster.id && subType === 'ColorTemperatureColorControl')
264
- return MatterbridgeColorControlServer.with('ColorTemperature');
265
- if (clusterId === DoorLock.Cluster.id)
266
- return MatterbridgeDoorLockServer;
267
- if (clusterId === Thermostat.Cluster.id && subType === undefined)
268
- return MatterbridgeThermostatServer.with('AutoMode', 'Heating', 'Cooling');
269
- if (clusterId === Thermostat.Cluster.id && subType === 'AutoModeThermostat')
270
- return MatterbridgeThermostatServer.with('AutoMode', 'Heating', 'Cooling');
271
- if (clusterId === Thermostat.Cluster.id && subType === 'HeatingThermostat')
272
- return MatterbridgeThermostatServer.with('Heating');
273
- if (clusterId === Thermostat.Cluster.id && subType === 'CoolingThermostat')
274
- return MatterbridgeThermostatServer.with('Cooling');
275
- if (clusterId === WindowCovering.Cluster.id)
276
- return MatterbridgeWindowCoveringServer;
277
- if (clusterId === FanControl.Cluster.id)
278
- return MatterbridgeFanControlServer;
279
- if (clusterId === Switch.Cluster.id && subType === undefined)
280
- return SwitchServer.with('MomentarySwitch', 'MomentarySwitchRelease', 'MomentarySwitchLongPress', 'MomentarySwitchMultiPress');
281
- if (clusterId === Switch.Cluster.id && subType === 'MomentarySwitch')
282
- return SwitchServer.with('MomentarySwitch', 'MomentarySwitchRelease', 'MomentarySwitchLongPress', 'MomentarySwitchMultiPress');
283
- if (clusterId === Switch.Cluster.id && subType === 'LatchingSwitch')
284
- return SwitchServer.with('LatchingSwitch');
285
- if (clusterId === TemperatureMeasurement.Cluster.id)
286
- return TemperatureMeasurementServer;
287
- if (clusterId === RelativeHumidityMeasurement.Cluster.id)
288
- return RelativeHumidityMeasurementServer;
289
- if (clusterId === PressureMeasurement.Cluster.id)
290
- return PressureMeasurementServer;
291
- if (clusterId === FlowMeasurement.Cluster.id)
292
- return FlowMeasurementServer;
293
- if (clusterId === BooleanState.Cluster.id)
294
- return BooleanStateServer.enable({ events: { stateChange: true } });
295
- if (clusterId === BooleanStateConfiguration.Cluster.id)
296
- return MatterbridgeBooleanStateConfigurationServer;
297
- if (clusterId === OccupancySensing.Cluster.id)
298
- return OccupancySensingServer;
299
- if (clusterId === IlluminanceMeasurement.Cluster.id)
300
- return IlluminanceMeasurementServer;
301
- if (clusterId === SmokeCoAlarm.Cluster.id)
302
- return SmokeCoAlarmServer.with('SmokeAlarm', 'CoAlarm');
303
- if (clusterId === ValveConfigurationAndControl.Cluster.id)
304
- return MatterbridgeValveConfigurationAndControlServer.with('Level');
305
- if (clusterId === AirQuality.Cluster.id)
306
- return AirQualityServer.with('Fair', 'Moderate', 'VeryPoor', 'ExtremelyPoor');
307
- if (clusterId === CarbonMonoxideConcentrationMeasurement.Cluster.id)
308
- return CarbonMonoxideConcentrationMeasurementServer.with('NumericMeasurement');
309
- if (clusterId === CarbonDioxideConcentrationMeasurement.Cluster.id)
310
- return CarbonDioxideConcentrationMeasurementServer.with('NumericMeasurement');
311
- if (clusterId === NitrogenDioxideConcentrationMeasurement.Cluster.id)
312
- return NitrogenDioxideConcentrationMeasurementServer.with('NumericMeasurement');
313
- if (clusterId === OzoneConcentrationMeasurement.Cluster.id)
314
- return OzoneConcentrationMeasurementServer.with('NumericMeasurement');
315
- if (clusterId === FormaldehydeConcentrationMeasurement.Cluster.id)
316
- return FormaldehydeConcentrationMeasurementServer.with('NumericMeasurement');
317
- if (clusterId === Pm1ConcentrationMeasurement.Cluster.id)
318
- return Pm1ConcentrationMeasurementServer.with('NumericMeasurement');
319
- if (clusterId === Pm25ConcentrationMeasurement.Cluster.id)
320
- return Pm25ConcentrationMeasurementServer.with('NumericMeasurement');
321
- if (clusterId === Pm10ConcentrationMeasurement.Cluster.id)
322
- return Pm10ConcentrationMeasurementServer.with('NumericMeasurement');
323
- if (clusterId === RadonConcentrationMeasurement.Cluster.id)
324
- return RadonConcentrationMeasurementServer.with('NumericMeasurement');
325
- if (clusterId === TotalVolatileOrganicCompoundsConcentrationMeasurement.Cluster.id)
326
- return TotalVolatileOrganicCompoundsConcentrationMeasurementServer.with('NumericMeasurement');
327
- if (clusterId === ModeSelect.Cluster.id)
328
- return ModeSelectServer;
329
- if (clusterId === UserLabel.Cluster.id)
330
- return UserLabelServer;
331
- if (clusterId === FixedLabel.Cluster.id)
332
- return FixedLabelServer;
333
- if (clusterId === PowerTopology.Cluster.id)
334
- return PowerTopologyServer.with('TreeTopology');
335
- if (clusterId === ElectricalPowerMeasurement.Cluster.id)
336
- return ElectricalPowerMeasurementServer.with('AlternatingCurrent');
337
- if (clusterId === ElectricalEnergyMeasurement.Cluster.id)
338
- return ElectricalEnergyMeasurementServer.with('ImportedEnergy', 'ExportedEnergy', 'CumulativeEnergy');
339
- if (clusterId === PowerSource.Cluster.id && subType === undefined)
340
- return PowerSourceServer;
341
- if (clusterId === PowerSource.Cluster.id && subType === 'WiredPowerSource')
342
- return PowerSourceServer.with(PowerSource.Feature.Wired);
343
- if (clusterId === PowerSource.Cluster.id && subType === 'BatteryReplaceablePowerSource')
344
- return PowerSourceServer.with(PowerSource.Feature.Battery, PowerSource.Feature.Replaceable);
345
- if (clusterId === PowerSource.Cluster.id && subType === 'BatteryRechargeablePowerSource')
346
- return PowerSourceServer.with(PowerSource.Feature.Battery, PowerSource.Feature.Rechargeable);
347
- if (clusterId === BasicInformation.Cluster.id)
348
- return BasicInformationServer;
349
- if (clusterId === BridgedDeviceBasicInformation.Cluster.id)
350
- return BridgedDeviceBasicInformationServer;
351
- return MatterbridgeIdentifyServer;
352
- }
353
- static getBehaviourTypeFromClusterClientId(clusterId) {
354
- // Map ClusterId to Behavior.Type
355
- return IdentifyBehavior;
356
- }
357
- /**
358
- * Adds a device type to the list of device types.
359
- * If the device type is not already present in the list, it will be added.
360
- *
361
- * @param {DeviceTypeDefinition} deviceType - The device type to add.
362
- *
363
- * @deprecated This method is deprecated and will be removed in future versions. Use the constructor options instead.
364
- */
365
- addDeviceType(deviceType) {
366
- if (!this.deviceTypes.has(deviceType.code)) {
367
- // Keep the Matterbridge internal map
368
- this.log.debug(`addDeviceType: ${zb}${'0x' + deviceType.code.toString(16).padStart(4, '0')}${db}-${zb}${deviceType.name}${db}`);
369
- this.deviceTypes.set(deviceType.code, deviceType);
370
- // Add the device types to the descriptor server
371
- const deviceTypeList = Array.from(this.deviceTypes.values()).map((dt) => ({
372
- deviceType: dt.code,
373
- revision: dt.revision,
374
- }));
375
- if (this.tagList) {
376
- this.behaviors.require(DescriptorServer.with(Descriptor.Feature.TagList), {
377
- tagList: this.tagList,
378
- deviceTypeList,
379
- });
380
- }
381
- else {
382
- this.behaviors.require(DescriptorServer, {
383
- deviceTypeList,
384
- });
385
- }
141
+ hasClusterServer(cluster) {
142
+ const behavior = getBehavior(this, cluster);
143
+ if (behavior)
144
+ return this.behaviors.supported[behavior.id] !== undefined;
145
+ else
146
+ return false;
147
+ }
148
+ hasAttributeServer(cluster, attribute) {
149
+ const behavior = getBehavior(this, cluster);
150
+ if (!behavior || !this.behaviors.supported[behavior.id])
151
+ return false;
152
+ const options = this.behaviors.optionsFor(behavior);
153
+ const defaults = this.behaviors.defaultsFor(behavior);
154
+ return lowercaseFirstLetter(attribute) in options || lowercaseFirstLetter(attribute) in defaults;
155
+ }
156
+ getClusterServerOptions(cluster) {
157
+ const behavior = getBehavior(this, cluster);
158
+ if (!behavior)
159
+ return undefined;
160
+ return this.behaviors.optionsFor(behavior);
161
+ }
162
+ getAttribute(cluster, attribute, log) {
163
+ return getAttribute(this, cluster, attribute, log);
164
+ }
165
+ async setAttribute(clusterId, attribute, value, log) {
166
+ return await setAttribute(this, clusterId, attribute, value, log);
167
+ }
168
+ async updateAttribute(cluster, attribute, value, log) {
169
+ return await updateAttribute(this, cluster, attribute, value, log);
170
+ }
171
+ async subscribeAttribute(clusterId, attribute, listener, log) {
172
+ const clusterName = lowercaseFirstLetter(getClusterNameById(clusterId));
173
+ if (this.construction.status !== Lifecycle.Status.Active) {
174
+ await this.construction.ready;
175
+ }
176
+ const events = this.events;
177
+ if (!(clusterName in events)) {
178
+ this.log.error(`subscribeAttribute ${hk}${attribute}${er} error: Cluster ${'0x' + clusterId.toString(16).padStart(4, '0')}:${clusterName} not found on endpoint ${or}${this.maybeId}${er}:${or}${this.maybeNumber}${er}`);
179
+ return false;
180
+ }
181
+ attribute = lowercaseFirstLetter(attribute) + '$Changed';
182
+ if (!(attribute in events[clusterName])) {
183
+ this.log.error(`subscribeAttribute error: Attribute ${hk}${attribute}${er} not found on Cluster ${'0x' + clusterId.toString(16).padStart(4, '0')}:${clusterName} on endpoint ${or}${this.maybeId}${er}:${or}${this.maybeNumber}${er}`);
184
+ return false;
185
+ }
186
+ events[clusterName][attribute].on(listener);
187
+ log?.info(`${db}Subscribed endpoint ${or}${this.id}${db}:${or}${this.number}${db} attribute ${hk}${capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db}`);
188
+ return true;
189
+ }
190
+ async triggerEvent(clusterId, event, payload, log) {
191
+ const clusterName = lowercaseFirstLetter(getClusterNameById(clusterId));
192
+ if (this.construction.status !== Lifecycle.Status.Active) {
193
+ this.log.error(`triggerEvent ${hk}${clusterName}.${event}${er} error: Endpoint ${or}${this.maybeId}${er}:${or}${this.maybeNumber}${er} is in the ${BLUE}${this.construction.status}${er} state`);
194
+ return false;
386
195
  }
196
+ const events = this.events;
197
+ if (!(clusterName in events) || !(event in events[clusterName])) {
198
+ this.log.error(`triggerEvent ${hk}${event}${er} error: Cluster ${'0x' + clusterId.toString(16).padStart(4, '0')}:${clusterName} not found on endpoint ${or}${this.id}${er}:${or}${this.number}${er}`);
199
+ return false;
200
+ }
201
+ await this.act((agent) => agent[clusterName].events[event].emit(payload, agent.context));
202
+ log?.info(`${db}Trigger event ${hk}${capitalizeFirstLetter(clusterName)}${db}.${hk}${event}${db} with ${debugStringify(payload)}${db} on endpoint ${or}${this.id}${db}:${or}${this.number}${db} `);
203
+ return true;
387
204
  }
388
- /**
389
- * Adds one or more device types with the required cluster servers and the specified cluster servers.
390
- *
391
- * @param {AtLeastOne<DeviceTypeDefinition>} deviceTypes - The device types to add.
392
- * @param {ClusterId[]} includeServerList - The list of cluster IDs to include.
393
- *
394
- * @deprecated This method is deprecated and will be removed in future versions. Use the constructor options instead.
395
- */
396
- addDeviceTypeWithClusterServer(deviceTypes, includeServerList) {
397
- this.log.debug('addDeviceTypeWithClusterServer:');
398
- deviceTypes.forEach((deviceType) => {
399
- this.log.debug(`- with deviceType: ${zb}${'0x' + deviceType.code.toString(16).padStart(4, '0')}${db}-${zb}${deviceType.name}${db}`);
400
- deviceType.requiredServerClusters.forEach((clusterId) => {
401
- if (!includeServerList.includes(clusterId))
402
- includeServerList.push(clusterId);
403
- });
404
- });
405
- includeServerList.forEach((clusterId) => {
406
- if (!this.getClusterServerById(clusterId)) {
407
- this.log.debug(`- with cluster: ${hk}${'0x' + clusterId.toString(16).padStart(4, '0')}${db}-${hk}${getClusterNameById(clusterId)}${db}`);
408
- }
409
- else {
410
- includeServerList.splice(includeServerList.indexOf(clusterId), 1);
205
+ addClusterServers(serverList) {
206
+ addClusterServers(this, serverList);
207
+ }
208
+ async addFixedLabel(label, value) {
209
+ await addFixedLabel(this, label, value);
210
+ return this;
211
+ }
212
+ async addUserLabel(label, value) {
213
+ await addUserLabel(this, label, value);
214
+ return this;
215
+ }
216
+ addCommandHandler(command, handler) {
217
+ this.commandHandler.addHandler(command, handler);
218
+ return this;
219
+ }
220
+ async executeCommandHandler(command, request) {
221
+ await this.commandHandler.executeHandler(command, { request });
222
+ }
223
+ addRequiredClusterServers() {
224
+ addRequiredClusterServers(this);
225
+ return this;
226
+ }
227
+ addOptionalClusterServers() {
228
+ addOptionalClusterServers(this);
229
+ return this;
230
+ }
231
+ getAllClusterServers() {
232
+ return Object.values(this.behaviors.supported);
233
+ }
234
+ getAllClusterServerNames() {
235
+ return Object.keys(this.behaviors.supported);
236
+ }
237
+ forEachAttribute(callback) {
238
+ for (const [clusterName, clusterAttributes] of Object.entries(this.state)) {
239
+ for (const [attributeName, attributeValue] of Object.entries(clusterAttributes)) {
240
+ const clusterId = getClusterId(this, clusterName);
241
+ if (clusterId === undefined) {
242
+ continue;
243
+ }
244
+ const attributeId = getAttributeId(this, clusterName, attributeName);
245
+ if (attributeId === undefined) {
246
+ continue;
247
+ }
248
+ callback(clusterName, clusterId, attributeName, attributeId, attributeValue);
411
249
  }
412
- });
413
- deviceTypes.forEach((deviceType) => {
414
- this.addDeviceType(deviceType);
415
- });
416
- this.addClusterServerFromList(this, includeServerList);
417
- }
418
- /**
419
- * Adds the required cluster servers (only if they are not present) for the device types of the specified endpoint.
420
- *
421
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to add the required cluster servers to.
422
- * @returns {MatterbridgeEndpoint} The updated endpoint with the required cluster servers added.
423
- */
424
- addRequiredClusterServers(endpoint) {
425
- const requiredServerList = [];
426
- this.log.debug(`addRequiredClusterServer for ${CYAN}${endpoint.maybeId}${db}`);
427
- endpoint.getDeviceTypes().forEach((deviceType) => {
428
- this.log.debug(`- for deviceType: ${zb}${'0x' + deviceType.code.toString(16).padStart(4, '0')}${db}-${zb}${deviceType.name}${db}`);
429
- deviceType.requiredServerClusters.forEach((clusterId) => {
430
- if (!requiredServerList.includes(clusterId) && !endpoint.getClusterServerById(clusterId))
431
- requiredServerList.push(clusterId);
432
- });
433
- });
434
- requiredServerList.forEach((clusterId) => {
435
- this.log.debug(`- with cluster: ${hk}${'0x' + clusterId.toString(16).padStart(4, '0')}${db}-${hk}${getClusterNameById(clusterId)}${db}`);
436
- });
437
- this.addClusterServerFromList(endpoint, requiredServerList);
438
- return endpoint;
439
- }
440
- /**
441
- * Adds the optional cluster servers (only if they are not present) for the device types of the specified endpoint.
442
- *
443
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to add the required cluster servers to.
444
- * @returns {MatterbridgeEndpoint} The updated endpoint with the required cluster servers added.
445
- */
446
- addOptionalClusterServers(endpoint) {
447
- const optionalServerList = [];
448
- this.log.debug(`addRequiredClusterServer for ${CYAN}${endpoint.id}${db}`);
449
- endpoint.getDeviceTypes().forEach((deviceType) => {
450
- this.log.debug(`- for deviceType: ${zb}${'0x' + deviceType.code.toString(16).padStart(4, '0')}${db}-${zb}${deviceType.name}${db}`);
451
- deviceType.optionalServerClusters.forEach((clusterId) => {
452
- if (!optionalServerList.includes(clusterId) && !endpoint.getClusterServerById(clusterId))
453
- optionalServerList.push(clusterId);
454
- });
455
- });
456
- optionalServerList.forEach((clusterId) => {
457
- this.log.debug(`- with cluster: ${hk}${'0x' + clusterId.toString(16).padStart(4, '0')}${db}-${hk}${getClusterNameById(clusterId)}${db}`);
458
- });
459
- this.addClusterServerFromList(endpoint, optionalServerList);
460
- return endpoint;
461
- }
462
- /**
463
- * Adds a child endpoint with the specified device types and options.
464
- * If the child endpoint is not already present, it will be created and added.
465
- * If the child endpoint is already present, the device types will be added to the existing child endpoint.
466
- *
467
- * @param {string} endpointName - The name of the new endpoint to add.
468
- * @param {DeviceTypeDefinition | AtLeastOne<DeviceTypeDefinition>} definition - The device types to add.
469
- * @param {MatterbridgeEndpointOptions} [options={}] - The options for the endpoint.
470
- * @param {boolean} [debug=false] - Whether to enable debug logging.
471
- * @returns {MatterbridgeEndpoint} - The child endpoint that was found or added.
472
- *
473
- * @example
474
- * ```typescript
475
- * const endpoint = device.addChildDeviceType('Temperature', [temperatureSensor], { tagList: [{ mfgCode: null, namespaceId: LocationTag.Indoor.namespaceId, tag: LocationTag.Indoor.tag, label: null }] }, true);
476
- * ```
477
- */
250
+ }
251
+ }
478
252
  addChildDeviceType(endpointName, definition, options = {}, debug = false) {
479
253
  this.log.debug(`addChildDeviceType: ${CYAN}${endpointName}${db}`);
254
+ let alreadyAdded = false;
480
255
  let child = this.getChildEndpointByName(endpointName);
481
- if (!child) {
256
+ if (child) {
257
+ this.log.debug(`****- endpoint ${CYAN}${endpointName}${db} already added!`);
258
+ alreadyAdded = true;
259
+ }
260
+ else {
482
261
  if ('tagList' in options) {
483
262
  for (const tag of options.tagList) {
484
263
  this.log.debug(`- with tagList: mfgCode ${CYAN}${tag.mfgCode}${db} namespaceId ${CYAN}${tag.namespaceId}${db} tag ${CYAN}${tag.tag}${db} label ${CYAN}${tag.label}${db}`);
485
264
  }
486
- child = new MatterbridgeEndpoint(definition, { uniqueStorageKey: endpointName, tagList: options.tagList }, debug);
265
+ child = new MatterbridgeEndpoint(definition, { uniqueStorageKey: endpointName, endpointId: options.endpointId, tagList: options.tagList }, debug);
487
266
  }
488
267
  else {
489
- child = new MatterbridgeEndpoint(definition, { uniqueStorageKey: endpointName }, debug);
268
+ child = new MatterbridgeEndpoint(definition, { uniqueStorageKey: endpointName, endpointId: options.endpointId }, debug);
490
269
  }
491
270
  }
492
271
  if (Array.isArray(definition)) {
@@ -497,6 +276,8 @@ export class MatterbridgeEndpoint extends Endpoint {
497
276
  else {
498
277
  this.log.debug(`- with deviceType: ${zb}${'0x' + definition.code.toString(16).padStart(4, '0')}${db}-${zb}${definition.name}${db}`);
499
278
  }
279
+ if (alreadyAdded)
280
+ return child;
500
281
  if (this.lifecycle.isInstalled) {
501
282
  this.log.debug(`- with lifecycle installed`);
502
283
  this.add(child);
@@ -507,62 +288,58 @@ export class MatterbridgeEndpoint extends Endpoint {
507
288
  }
508
289
  return child;
509
290
  }
510
- /**
511
- * Adds a child endpoint with one or more device types with the required cluster servers and the specified cluster servers.
512
- * If the child endpoint is not already present in the childEndpoints, it will be added.
513
- * If the child endpoint is already present in the childEndpoints, the device types and cluster servers will be added to the existing child endpoint.
514
- *
515
- * @param {string} endpointName - The name of the new enpoint to add.
516
- * @param {DeviceTypeDefinition | AtLeastOne<DeviceTypeDefinition>} definition - The device types to add.
517
- * @param {ClusterId[]} [includeServerList=[]] - The list of cluster IDs to include.
518
- * @param {MatterbridgeEndpointOptions} [options={}] - The options for the device.
519
- * @param {boolean} [debug=false] - Whether to enable debug logging.
520
- * @returns {MatterbridgeEndpoint} - The child endpoint that was found or added.
521
- *
522
- * @example
523
- * ```typescript
524
- * const endpoint = device.addChildDeviceTypeWithClusterServer('Temperature', [temperatureSensor], [], { tagList: [{ mfgCode: null, namespaceId: LocationTag.Indoor.namespaceId, tag: LocationTag.Indoor.tag, label: null }] }, true);
525
- * ```
526
- */
527
- addChildDeviceTypeWithClusterServer(endpointName, definition, includeServerList = [], options = {}, debug = false) {
291
+ addChildDeviceTypeWithClusterServer(endpointName, definition, serverList = [], options = {}, debug = false) {
528
292
  this.log.debug(`addChildDeviceTypeWithClusterServer: ${CYAN}${endpointName}${db}`);
293
+ let alreadyAdded = false;
529
294
  let child = this.getChildEndpointByName(endpointName);
530
- if (!child) {
295
+ if (child) {
296
+ this.log.debug(`****- endpoint ${CYAN}${endpointName}${db} already added!`);
297
+ alreadyAdded = true;
298
+ }
299
+ else {
531
300
  if ('tagList' in options) {
532
301
  for (const tag of options.tagList) {
533
302
  this.log.debug(`- with tagList: mfgCode ${CYAN}${tag.mfgCode}${db} namespaceId ${CYAN}${tag.namespaceId}${db} tag ${CYAN}${tag.tag}${db} label ${CYAN}${tag.label}${db}`);
534
303
  }
535
- child = new MatterbridgeEndpoint(definition, { uniqueStorageKey: endpointName, tagList: options.tagList }, debug);
304
+ child = new MatterbridgeEndpoint(definition, { uniqueStorageKey: endpointName, endpointId: options.endpointId, tagList: options.tagList }, debug);
536
305
  }
537
306
  else {
538
- child = new MatterbridgeEndpoint(definition, { uniqueStorageKey: endpointName }, debug);
307
+ child = new MatterbridgeEndpoint(definition, { uniqueStorageKey: endpointName, endpointId: options.endpointId }, debug);
539
308
  }
540
309
  }
541
310
  if (Array.isArray(definition)) {
542
311
  definition.forEach((deviceType) => {
543
312
  this.log.debug(`- with deviceType: ${zb}${'0x' + deviceType.code.toString(16).padStart(4, '0')}${db}-${zb}${deviceType.name}${db}`);
544
313
  deviceType.requiredServerClusters.forEach((clusterId) => {
545
- if (!includeServerList.includes(clusterId))
546
- includeServerList.push(clusterId);
314
+ if (!serverList.includes(clusterId))
315
+ serverList.push(clusterId);
547
316
  });
548
317
  });
549
318
  }
550
319
  else {
551
320
  this.log.debug(`- with deviceType: ${zb}${'0x' + definition.code.toString(16).padStart(4, '0')}${db}-${zb}${definition.name}${db}`);
552
321
  definition.requiredServerClusters.forEach((clusterId) => {
553
- if (!includeServerList.includes(clusterId))
554
- includeServerList.push(clusterId);
322
+ if (!serverList.includes(clusterId))
323
+ serverList.push(clusterId);
555
324
  });
556
325
  }
557
- includeServerList.forEach((clusterId) => {
558
- if (!child.getClusterServerById(clusterId)) {
326
+ serverList.forEach((clusterId) => {
327
+ if (!child.hasClusterServer(clusterId)) {
559
328
  this.log.debug(`- with cluster: ${hk}${'0x' + clusterId.toString(16).padStart(4, '0')}${db}-${hk}${getClusterNameById(clusterId)}${db}`);
560
329
  }
561
330
  else {
562
- includeServerList.splice(includeServerList.indexOf(clusterId), 1);
331
+ serverList.splice(serverList.indexOf(clusterId), 1);
563
332
  }
564
333
  });
565
- this.addClusterServerFromList(child, includeServerList);
334
+ if (alreadyAdded) {
335
+ serverList.forEach((clusterId) => {
336
+ if (child.hasClusterServer(clusterId))
337
+ serverList.splice(serverList.indexOf(clusterId), 1);
338
+ });
339
+ }
340
+ addClusterServers(child, serverList);
341
+ if (alreadyAdded)
342
+ return child;
566
343
  if (this.lifecycle.isInstalled) {
567
344
  this.log.debug(`- with lifecycle installed`);
568
345
  this.add(child);
@@ -573,596 +350,108 @@ export class MatterbridgeEndpoint extends Endpoint {
573
350
  }
574
351
  return child;
575
352
  }
576
- /**
577
- * Retrieves a child endpoint by its name.
578
- *
579
- * @param {string} endpointName - The name of the endpoint to retrieve.
580
- * @returns {Endpoint | undefined} The child endpoint with the specified name, or undefined if not found.
581
- */
582
353
  getChildEndpointByName(endpointName) {
583
354
  return this.parts.find((part) => part.id === endpointName);
584
355
  }
585
- /**
586
- * Retrieves a child endpoint by its EndpointNumber.
587
- *
588
- * @param {EndpointNumber} endpointNumber - The EndpointNumber of the endpoint to retrieve.
589
- * @returns {MatterbridgeEndpoint | undefined} The child endpoint with the specified EndpointNumber, or undefined if not found.
590
- */
591
356
  getChildEndpoint(endpointNumber) {
592
357
  return this.parts.find((part) => part.number === endpointNumber);
593
358
  }
594
- /**
595
- * Get all the child endpoints of this endpoint.
596
- *
597
- * @returns {MatterbridgeEndpoint[]} The child endpoints.
598
- */
599
359
  getChildEndpoints() {
600
360
  return Array.from(this.parts);
601
361
  }
602
- /**
603
- * Get all the device types of this endpoint.
604
- *
605
- * @returns {DeviceTypeDefinition[]} The device types of this endpoint.
606
- */
607
- getDeviceTypes() {
608
- return Array.from(this.deviceTypes.values());
609
- }
610
- /**
611
- * Sets the device types.
612
- *
613
- * @param {AtLeastOne<DeviceTypeDefinition>} deviceTypes - The device types to set.
614
- *
615
- * @deprecated This method is deprecated and will be removed in future versions.
616
- */
617
- setDeviceTypes(deviceTypes) {
618
- deviceTypes.forEach((deviceType) => {
619
- this.addDeviceType(deviceType);
620
- });
621
- }
622
- /**
623
- * Sets the device reachable attribute and trigger the event.
624
- *
625
- * @param {boolean} reachable - The device types to set.
626
- *
627
- * @deprecated This method is deprecated and will be removed in future versions.
628
- */
629
- async setBridgedDeviceReachability(reachable) {
630
- // await this.setAttribute(BridgedDeviceBasicInformationCluster.id, 'reachable', reachable, this.log);
631
- // await this.triggerEvent(BridgedDeviceBasicInformationCluster.id, 'reachableChanged', { reachableNewValue: reachable }, this.log);
632
- }
633
- /**
634
- * @deprecated This method is deprecated and will be removed in future versions.
635
- */
636
- hasClusterServer(cluster) {
637
- // const clusterName = this.lowercaseFirstLetter(getClusterNameById(cluster.id));
638
- // return this.behaviors.supported[clusterName] !== undefined;
639
- return this.clusterServers.has(cluster.id);
640
- }
641
- /**
642
- * @deprecated This method is deprecated and will be removed in future versions.
643
- */
644
- getClusterServer(cluster) {
645
- const clusterServer = this.clusterServers.get(cluster.id);
646
- if (clusterServer !== undefined) {
647
- return clusterServer;
648
- }
649
- }
650
- /**
651
- * @deprecated This method is deprecated and will be removed in future versions.
652
- */
653
- getClusterServerById(clusterId) {
654
- return this.clusterServers.get(clusterId);
655
- }
656
- /**
657
- * @deprecated This method is deprecated and will be removed in future versions.
658
- */
659
- getAllClusterServers() {
660
- return [...this.clusterServers.values()];
661
- }
662
- /**
663
- * Add a tagList.
664
- *
665
- * @deprecated This method is deprecated and will be removed in future versions. Use the constructor options instead.
666
- */
667
- addTagList(endpoint, mfgCode, namespaceId, tag, label) {
668
- // Do nothing here only for old api compatibility
669
- }
670
- addClusterServer(cluster) {
671
- // console.log('addClusterServer:', cluster.id, cluster.name, cluster.attributes, cluster.events, cluster.commands);
672
- let features = {};
673
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
674
- const options = {};
675
- for (const attribute of Object.values(cluster.attributes)) {
676
- // console.error('Attribute:', (attribute as any).id, (attribute as any).name, (attribute as any).value);
677
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
678
- if (attribute.name === 'featureMap') {
679
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
680
- features = attribute.value;
681
- // console.log('Cluster', cluster.name, 'FeatureMap:', features);
682
- // options[(attribute as any).name] = (attribute as any).value;
683
- }
684
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
685
- if (attribute.id < 0xfff0) {
686
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
687
- options[attribute.name] = attribute.value;
688
- }
689
- }
690
- this.log.debug(`addClusterServer: ${hk}${'0x' + cluster.id.toString(16).padStart(4, '0')}${db}-${hk}${getClusterNameById(cluster.id)}${db} with options: ${debugStringify(options)}${rs}`);
691
- if (this.clusterServers.has(cluster.id)) {
692
- this.log.debug(`****cluster ${hk}${'0x' + cluster.id.toString(16).padStart(4, '0')}${db}-${hk}${getClusterNameById(cluster.id)}${db} already added`);
693
- }
694
- this.subType = '';
695
- if (cluster.id === OnOffCluster.id && features['lighting'])
696
- this.subType = 'LightingOnOff';
697
- if (cluster.id === OnOffCluster.id && features['deadFrontBehavior'])
698
- this.subType = 'DeadFrontBehaviorOnOff';
699
- if (cluster.id === ColorControl.Cluster.id && cluster.isAttributeSupportedByName('currentX') && !cluster.isAttributeSupportedByName('currentHue'))
700
- this.subType = 'XyColorControl';
701
- else if (cluster.id === ColorControl.Cluster.id && cluster.isAttributeSupportedByName('currentHue') && !cluster.isAttributeSupportedByName('currentX'))
702
- this.subType = 'HueSaturationColorControl';
703
- else if (cluster.id === ColorControl.Cluster.id && cluster.isAttributeSupportedByName('colorTemperatureMireds') && !cluster.isAttributeSupportedByName('currentHue') && !cluster.isAttributeSupportedByName('currentX'))
704
- this.subType = 'ColorTemperatureColorControl';
705
- else if (cluster.id === ColorControl.Cluster.id)
706
- this.subType = 'CompleteColorControl';
707
- if (cluster.id === SwitchCluster.id && cluster.isEventSupportedByName('multiPressComplete'))
708
- this.subType = 'MomentarySwitch';
709
- if (cluster.id === SwitchCluster.id && cluster.isEventSupportedByName('switchLatched'))
710
- this.subType = 'LatchingSwitch';
711
- if (cluster.id === PowerSourceCluster.id && cluster.isAttributeSupportedByName('wiredCurrentType'))
712
- this.subType = 'WiredPowerSource';
713
- if (cluster.id === PowerSourceCluster.id && cluster.isAttributeSupportedByName('batReplacementDescription'))
714
- this.subType = 'BatteryReplaceablePowerSource';
715
- if (cluster.id === PowerSourceCluster.id && cluster.isAttributeSupportedByName('batChargeState'))
716
- this.subType = 'BatteryRechargeablePowerSource';
717
- if (cluster.id === ThermostatCluster.id && cluster.isAttributeSupportedByName('occupiedCoolingSetpoint'))
718
- this.subType = 'CoolingThermostat';
719
- if (cluster.id === ThermostatCluster.id && cluster.isAttributeSupportedByName('occupiedHeatingSetpoint'))
720
- this.subType = 'HeatingThermostat';
721
- if (cluster.id === ThermostatCluster.id && cluster.isAttributeSupportedByName('minSetpointDeadBand'))
722
- this.subType = 'AutoModeThermostat';
723
- const behavior = MatterbridgeEndpoint.getBehaviourTypeFromClusterServerId(cluster.id, this.subType);
724
- this.clusterServers.set(cluster.id, cluster);
725
- if (cluster.id === BasicInformationCluster.id)
726
- return; // Not used in Matterbridge edge for devices. Only on server node.
727
- this.behaviors.require(behavior, options);
728
- }
729
- /**
730
- * Adds cluster servers to the specified endpoint based on the provided server list.
731
- *
732
- * @param {MatterbridgeEndpoint} endpoint - The endpoint to add cluster servers to.
733
- * @param {ClusterId[]} includeServerList - The list of cluster IDs to include.
734
- * @returns void
735
- */
736
- addClusterServerFromList(endpoint, includeServerList) {
737
- if (includeServerList.includes(Identify.Cluster.id))
738
- endpoint.addClusterServer(this.getDefaultIdentifyClusterServer());
739
- if (includeServerList.includes(Groups.Cluster.id))
740
- endpoint.addClusterServer(this.getDefaultGroupsClusterServer());
741
- if (includeServerList.includes(OnOff.Cluster.id))
742
- endpoint.addClusterServer(this.getDefaultOnOffClusterServer());
743
- if (includeServerList.includes(LevelControl.Cluster.id))
744
- endpoint.addClusterServer(this.getDefaultLevelControlClusterServer());
745
- if (includeServerList.includes(ColorControl.Cluster.id))
746
- endpoint.addClusterServer(this.getDefaultColorControlClusterServer());
747
- if (includeServerList.includes(Switch.Cluster.id))
748
- endpoint.addClusterServer(this.getDefaultSwitchClusterServer());
749
- if (includeServerList.includes(DoorLock.Cluster.id))
750
- endpoint.addClusterServer(this.getDefaultDoorLockClusterServer());
751
- if (includeServerList.includes(Thermostat.Cluster.id))
752
- endpoint.addClusterServer(this.getDefaultThermostatClusterServer());
753
- if (includeServerList.includes(WindowCovering.Cluster.id))
754
- endpoint.addClusterServer(this.getDefaultWindowCoveringClusterServer());
755
- if (includeServerList.includes(FanControl.Cluster.id))
756
- endpoint.addClusterServer(this.getDefaultFanControlClusterServer());
757
- if (includeServerList.includes(TemperatureMeasurement.Cluster.id))
758
- endpoint.addClusterServer(this.getDefaultTemperatureMeasurementClusterServer());
759
- if (includeServerList.includes(RelativeHumidityMeasurement.Cluster.id))
760
- endpoint.addClusterServer(this.getDefaultRelativeHumidityMeasurementClusterServer());
761
- if (includeServerList.includes(PressureMeasurement.Cluster.id))
762
- endpoint.addClusterServer(this.getDefaultPressureMeasurementClusterServer());
763
- if (includeServerList.includes(FlowMeasurement.Cluster.id))
764
- endpoint.addClusterServer(this.getDefaultFlowMeasurementClusterServer());
765
- if (includeServerList.includes(BooleanState.Cluster.id))
766
- endpoint.addClusterServer(this.getDefaultBooleanStateClusterServer());
767
- if (includeServerList.includes(BooleanStateConfiguration.Cluster.id))
768
- endpoint.addClusterServer(this.getDefaultBooleanStateConfigurationClusterServer());
769
- if (includeServerList.includes(OccupancySensing.Cluster.id))
770
- endpoint.addClusterServer(this.getDefaultOccupancySensingClusterServer());
771
- if (includeServerList.includes(IlluminanceMeasurement.Cluster.id))
772
- endpoint.addClusterServer(this.getDefaultIlluminanceMeasurementClusterServer());
773
- if (includeServerList.includes(PowerSource.Cluster.id))
774
- endpoint.addClusterServer(this.getDefaultPowerSourceWiredClusterServer());
775
- if (includeServerList.includes(PowerTopology.Cluster.id))
776
- endpoint.addClusterServer(this.getDefaultPowerTopologyClusterServer());
777
- if (includeServerList.includes(ElectricalPowerMeasurement.Cluster.id))
778
- endpoint.addClusterServer(this.getDefaultElectricalPowerMeasurementClusterServer());
779
- if (includeServerList.includes(ElectricalEnergyMeasurement.Cluster.id))
780
- endpoint.addClusterServer(this.getDefaultElectricalEnergyMeasurementClusterServer());
781
- if (includeServerList.includes(SmokeCoAlarm.Cluster.id))
782
- endpoint.addClusterServer(this.getDefaultSmokeCOAlarmClusterServer());
783
- if (includeServerList.includes(AirQuality.Cluster.id))
784
- endpoint.addClusterServer(this.getDefaultAirQualityClusterServer());
785
- if (includeServerList.includes(CarbonMonoxideConcentrationMeasurement.Cluster.id))
786
- endpoint.addClusterServer(this.getDefaultCarbonMonoxideConcentrationMeasurementClusterServer());
787
- if (includeServerList.includes(CarbonDioxideConcentrationMeasurement.Cluster.id))
788
- endpoint.addClusterServer(this.getDefaultCarbonDioxideConcentrationMeasurementClusterServer());
789
- if (includeServerList.includes(NitrogenDioxideConcentrationMeasurement.Cluster.id))
790
- endpoint.addClusterServer(this.getDefaultNitrogenDioxideConcentrationMeasurementClusterServer());
791
- if (includeServerList.includes(OzoneConcentrationMeasurement.Cluster.id))
792
- endpoint.addClusterServer(this.getDefaultOzoneConcentrationMeasurementClusterServer());
793
- if (includeServerList.includes(FormaldehydeConcentrationMeasurement.Cluster.id))
794
- endpoint.addClusterServer(this.getDefaultFormaldehydeConcentrationMeasurementClusterServer());
795
- if (includeServerList.includes(Pm1ConcentrationMeasurement.Cluster.id))
796
- endpoint.addClusterServer(this.getDefaultPm1ConcentrationMeasurementClusterServer());
797
- if (includeServerList.includes(Pm25ConcentrationMeasurement.Cluster.id))
798
- endpoint.addClusterServer(this.getDefaultPm25ConcentrationMeasurementClusterServer());
799
- if (includeServerList.includes(Pm10ConcentrationMeasurement.Cluster.id))
800
- endpoint.addClusterServer(this.getDefaultPm10ConcentrationMeasurementClusterServer());
801
- if (includeServerList.includes(RadonConcentrationMeasurement.Cluster.id))
802
- endpoint.addClusterServer(this.getDefaultRadonConcentrationMeasurementClusterServer());
803
- if (includeServerList.includes(TotalVolatileOrganicCompoundsConcentrationMeasurement.Cluster.id))
804
- endpoint.addClusterServer(this.getDefaultTvocMeasurementClusterServer());
805
- // if (includeServerList.includes(DeviceEnergyManagement.Cluster.id)) endpoint.addClusterServer(this.getDefaultDeviceEnergyManagementClusterServer());
806
- // if (includeServerList.includes(DeviceEnergyManagementMode.Cluster.id)) endpoint.addClusterServer(this.getDefaultDeviceEnergyManagementModeClusterServer());
807
- }
808
- async addFixedLabel(label, value) {
809
- if (!this.clusterServers.get(FixedLabelCluster.id)) {
810
- this.log.debug(`addFixedLabel: add cluster ${hk}FixedLabelCluster${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
811
- this.addClusterServer(ClusterServer(FixedLabelCluster, {
812
- labelList: [{ label, value }],
813
- }, {}));
814
- return;
815
- }
816
- this.log.debug(`addFixedLabel: add label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
817
- const labelList = (this.getAttribute(FixedLabelCluster.id, 'labelList', this.log) ?? []).filter((entryLabel) => entryLabel.label !== label);
818
- labelList.push({ label, value });
819
- await this.setAttribute(FixedLabelCluster.id, 'labelList', labelList, this.log);
820
- }
821
- async addUserLabel(label, value) {
822
- if (!this.clusterServers.get(UserLabelCluster.id)) {
823
- this.log.debug(`addUserLabel: add cluster ${hk}UserLabelCluster${db} with label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
824
- this.addClusterServer(ClusterServer(UserLabelCluster, {
825
- labelList: [{ label, value }],
826
- }, {}));
362
+ static serialize(device) {
363
+ if (!device.serialNumber || !device.deviceName || !device.uniqueId)
827
364
  return;
828
- }
829
- this.log.debug(`addUserLabel: add label ${CYAN}${label}${db} value ${CYAN}${value}${db}`);
830
- const labelList = (this.getAttribute(UserLabelCluster.id, 'labelList', this.log) ?? []).filter((entryLabel) => entryLabel.label !== label);
831
- labelList.push({ label, value });
832
- await this.setAttribute(UserLabelCluster.id, 'labelList', labelList, this.log);
833
- }
834
- capitalizeFirstLetter(name) {
835
- if (!name)
836
- return name;
837
- return name.charAt(0).toUpperCase() + name.slice(1);
838
- }
839
- lowercaseFirstLetter(name) {
840
- if (!name)
841
- return name;
842
- return name.charAt(0).toLowerCase() + name.slice(1);
843
- }
844
- /**
845
- * Retrieves the value of the specified attribute from the given endpoint and cluster.
846
- *
847
- * @param {ClusterId} clusterId - The ID of the cluster to retrieve the attribute from.
848
- * @param {string} attribute - The name of the attribute to retrieve.
849
- * @param {AnsiLogger} [log] - Optional logger for error and info messages.
850
- * @param {MatterbridgeEndpoint} [endpoint] - Optional the child endpoint to retrieve the attribute from.
851
- * @returns {any} The value of the attribute, or undefined if the attribute is not found.
852
- */
853
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
854
- getAttribute(clusterId, attribute, log, endpoint) {
855
- if (!endpoint)
856
- endpoint = this;
857
- const clusterName = this.lowercaseFirstLetter(getClusterNameById(clusterId));
858
- if (endpoint.construction.status !== Lifecycle.Status.Active) {
859
- this.log.error(`getAttribute ${hk}${clusterName}.${attribute}${er} error: Endpoint ${or}${endpoint.id}${er} is in the ${BLUE}${endpoint.construction.status}${er} state`);
860
- return undefined;
861
- }
862
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
863
- const state = endpoint.state;
864
- if (!(clusterName in state)) {
865
- this.log.error(`getAttribute error: Cluster ${'0x' + clusterId.toString(16).padStart(4, '0')}:${clusterName} not found on endpoint ${or}${endpoint.id}${er}:${or}${endpoint.number}${er}`);
866
- return undefined;
867
- }
868
- attribute = this.lowercaseFirstLetter(attribute);
869
- if (!(attribute in state[clusterName])) {
870
- this.log.error(`getAttribute error: Attribute ${hk}${attribute}${er} not found on Cluster ${'0x' + clusterId.toString(16).padStart(4, '0')}:${clusterName} on endpoint ${or}${endpoint.id}${er}:${or}${endpoint.number}${er}`);
871
- return undefined;
872
- }
873
- const value = state[clusterName][attribute];
874
- log?.info(`${db}Get endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} attribute ${hk}${this.capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db} value ${YELLOW}${typeof value === 'object' ? debugStringify(value) : value}${db}`);
875
- return value;
876
- }
877
- /**
878
- * Sets the value of an attribute on a cluster server endpoint.
879
- *
880
- * @param {ClusterId} clusterId - The ID of the cluster.
881
- * @param {string} attribute - The name of the attribute.
882
- * @param {any} value - The value to set for the attribute.
883
- * @param {AnsiLogger} [log] - (Optional) The logger to use for logging errors and information.
884
- * @param {MatterbridgeEndpoint} [endpoint] - (Optional) The endpoint to set the attribute on. If not provided, the attribute will be set on the current endpoint.
885
- * @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the attribute was successfully set.
886
- */
887
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
888
- async setAttribute(clusterId, attribute, value, log, endpoint) {
889
- if (!endpoint)
890
- endpoint = this;
891
- const clusterName = this.lowercaseFirstLetter(getClusterNameById(clusterId));
892
- if (endpoint.construction.status !== Lifecycle.Status.Active) {
893
- this.log.error(`setAttribute ${hk}${clusterName}.${attribute}${er} error: Endpoint ${or}${endpoint.id}${er} is in the ${BLUE}${endpoint.construction.status}${er} state`);
894
- return false;
895
- }
896
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
897
- const state = endpoint.state;
898
- if (!(clusterName in state)) {
899
- this.log.error(`setAttribute ${hk}${attribute}${er} error: Cluster ${'0x' + clusterId.toString(16).padStart(4, '0')}:${clusterName} not found on endpoint ${or}${endpoint.id}${er}:${or}${endpoint.number}${er}`);
900
- return false;
901
- }
902
- attribute = this.lowercaseFirstLetter(attribute);
903
- if (!(attribute in state[clusterName])) {
904
- this.log.error(`setAttribute error: Attribute ${hk}${attribute}${er} not found on Cluster ${'0x' + clusterId.toString(16).padStart(4, '0')}:${clusterName} on endpoint ${or}${endpoint.id}${er}:${or}${endpoint.number}${er}`);
905
- return false;
906
- }
907
- let oldValue = state[clusterName][attribute];
908
- if (typeof oldValue === 'object')
909
- oldValue = deepCopy(oldValue);
910
- await endpoint.setStateOf(endpoint.behaviors.supported[clusterName], { [attribute]: value });
911
- log?.info(`${db}Set endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} attribute ${hk}${this.capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db} ` +
912
- `from ${YELLOW}${typeof oldValue === 'object' ? debugStringify(oldValue) : oldValue}${db} ` +
913
- `to ${YELLOW}${typeof value === 'object' ? debugStringify(value) : value}${db}`);
914
- return true;
915
- }
916
- /**
917
- * Subscribes to an attribute on a cluster.
918
- *
919
- * @param {ClusterId} clusterId - The ID of the cluster.
920
- * @param {string} attribute - The name of the attribute to subscribe to.
921
- * @param {(newValue: any, oldValue: any) => void} listener - A callback function that will be called when the attribute value changes.
922
- * @param {AnsiLogger} [log] - Optional logger for logging errors and information.
923
- * @param {MatterbridgeEndpoint} [endpoint] - Optional endpoint to subscribe the attribute on. Defaults to the current endpoint.
924
- * @returns {boolean} - A boolean indicating whether the subscription was successful.
925
- */
926
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
927
- async subscribeAttribute(clusterId, attribute, listener, log, endpoint) {
928
- if (!endpoint)
929
- endpoint = this;
930
- const clusterName = this.lowercaseFirstLetter(getClusterNameById(clusterId));
931
- if (endpoint.construction.status !== Lifecycle.Status.Active) {
932
- // this.log.error(`subscribeAttribute ${hk}${clusterName}.${attribute}${er} error: Endpoint ${or}${endpoint.id}${er} is in the ${BLUE}${endpoint.construction.status}${er} state`);
933
- await endpoint.construction.ready;
934
- }
935
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
936
- const events = endpoint.events;
937
- if (!(clusterName in events)) {
938
- this.log.error(`subscribeAttribute ${hk}${attribute}${er} error: Cluster ${'0x' + clusterId.toString(16).padStart(4, '0')}:${clusterName} not found on endpoint ${or}${endpoint.id}${er}:${or}${endpoint.number}${er}`);
939
- return false;
940
- }
941
- attribute = this.lowercaseFirstLetter(attribute) + '$Changed';
942
- if (!(attribute in events[clusterName])) {
943
- this.log.error(`subscribeAttribute error: Attribute ${hk}${attribute}${er} not found on Cluster ${'0x' + clusterId.toString(16).padStart(4, '0')}:${clusterName} on endpoint ${or}${endpoint.id}${er}:${or}${endpoint.number}${er}`);
944
- return false;
945
- }
946
- events[clusterName][attribute].on(listener);
947
- log?.info(`${db}Subscribe endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} attribute ${hk}${this.capitalizeFirstLetter(clusterName)}${db}.${hk}${attribute}${db}`);
948
- return true;
949
- }
950
- /**
951
- * Triggers an event on the specified cluster.
952
- *
953
- * @param {ClusterId} clusterId - The ID of the cluster.
954
- * @param {string} event - The name of the event to trigger.
955
- * @param {Record<string, boolean | number | bigint | string | object | undefined | null>} payload - The payload to pass to the event.
956
- * @param {AnsiLogger} [log] - Optional logger for logging information.
957
- * @param {MatterbridgeEndpoint} [endpoint] - Optional endpoint to trigger the event on. Defaults to the current endpoint.
958
- * @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the event was successfully triggered.
959
- */
960
- async triggerEvent(clusterId, event, payload, log, endpoint) {
961
- if (!endpoint)
962
- endpoint = this;
963
- const clusterName = this.lowercaseFirstLetter(getClusterNameById(clusterId));
964
- if (endpoint.construction.status !== Lifecycle.Status.Active) {
965
- // this.log.error(`triggerEvent ${hk}${clusterName}.${event}${er} error: Endpoint ${or}${endpoint.id}${er} is in the ${BLUE}${endpoint.construction.status}${er} state`);
966
- await endpoint.construction.ready;
967
- // return false;
968
- }
969
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
970
- const events = endpoint.events;
971
- if (!(clusterName in events) || !(event in events[clusterName])) {
972
- this.log.error(`triggerEvent ${hk}${event}${er} error: Cluster ${'0x' + clusterId.toString(16).padStart(4, '0')}:${clusterName} not found on endpoint ${or}${endpoint.id}${er}:${or}${endpoint.number}${er}`);
973
- return false;
974
- }
975
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
976
- // @ts-ignore
977
- await endpoint.act((agent) => agent[clusterName].events[event].emit(payload, agent.context));
978
- log?.info(`${db}Trigger event ${hk}${this.capitalizeFirstLetter(clusterName)}${db}.${hk}${event}${db} with ${debugStringify(payload)}${db} on endpoint ${or}${endpoint.id}${db}:${or}${endpoint.number}${db} `);
979
- return true;
980
- }
981
- /**
982
- * Adds a command handler for the specified command.
983
- *
984
- * @param {keyof MatterbridgeEndpointCommands} command - The command to add the handler for.
985
- * @param {(data: any) => void} handler - The handler function to execute when the command is received.
986
- * @returns {void}
987
- */
988
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
989
- addCommandHandler(command, handler) {
990
- this.commandHandler.addHandler(command, handler);
991
- }
992
- /**
993
- * Serializes the Matterbridge device into a serialized object.
994
- *
995
- * @param pluginName - The name of the plugin.
996
- * @returns The serialized Matterbridge device object.
997
- */
998
- serialize() {
999
- return undefined;
1000
- /*
1001
- if (!this.serialNumber || !this.deviceName || !this.uniqueId) return;
1002
- const cluster = this.getClusterServer(BasicInformationCluster) ?? this.getClusterServer(BridgedDeviceBasicInformationCluster);
1003
- if (!cluster) return;
1004
- const serialized: SerializedMatterbridgeDevice = {
1005
- pluginName: this.plugin ?? 'Unknown',
1006
- serialNumber: this.serialNumber,
1007
- deviceName: this.deviceName,
1008
- uniqueId: this.uniqueId,
1009
- productName: cluster.attributes.productName?.getLocal(),
1010
- vendorId: cluster.attributes.vendorId?.getLocal(),
1011
- vendorName: cluster.attributes.vendorName?.getLocal(),
1012
- deviceTypes: Array.from(this.deviceTypes.values()),
1013
- endpoint: this.number,
1014
- endpointName: this.id,
1015
- clusterServersId: [],
365
+ const serialized = {
366
+ pluginName: device.plugin ?? '',
367
+ deviceName: device.deviceName,
368
+ serialNumber: device.serialNumber,
369
+ uniqueId: device.uniqueId,
370
+ productId: device.productId,
371
+ productName: device.productName,
372
+ vendorId: device.vendorId,
373
+ vendorName: device.vendorName,
374
+ deviceTypes: Array.from(device.deviceTypes.values()),
375
+ endpoint: device.maybeNumber,
376
+ endpointName: device.maybeId ?? device.deviceName,
377
+ clusterServersId: [],
1016
378
  };
1017
- this.getAllClusterServers().forEach((clusterServer) => {
1018
- serialized.clusterServersId.push(clusterServer.id);
379
+ Object.keys(device.behaviors.supported).forEach((behaviorName) => {
380
+ if (behaviorName === 'bridgedDeviceBasicInformation')
381
+ serialized.clusterServersId.push(BridgedDeviceBasicInformation.Cluster.id);
382
+ if (behaviorName === 'powerSource')
383
+ serialized.clusterServersId.push(PowerSource.Cluster.id);
1019
384
  });
1020
385
  return serialized;
1021
- */
1022
386
  }
1023
- /**
1024
- * Deserializes the device into a serialized object.
1025
- *
1026
- * @returns The deserialized MatterbridgeDevice.
1027
- */
1028
387
  static deserialize(serializedDevice) {
1029
- return undefined;
1030
- /*
1031
- const device = new MatterbridgeDevice(serializedDevice.deviceTypes);
1032
- device.serialNumber = serializedDevice.serialNumber;
388
+ const device = new MatterbridgeEndpoint(serializedDevice.deviceTypes, { uniqueStorageKey: serializedDevice.endpointName, endpointId: serializedDevice.endpoint }, false);
389
+ device.plugin = serializedDevice.pluginName;
1033
390
  device.deviceName = serializedDevice.deviceName;
391
+ device.serialNumber = serializedDevice.serialNumber;
1034
392
  device.uniqueId = serializedDevice.uniqueId;
393
+ device.vendorId = serializedDevice.vendorId;
394
+ device.vendorName = serializedDevice.vendorName;
395
+ device.productId = serializedDevice.productId;
396
+ device.productName = serializedDevice.productName;
1035
397
  for (const clusterId of serializedDevice.clusterServersId) {
1036
- if (clusterId === BasicInformationCluster.id)
1037
- device.createDefaultBasicInformationClusterServer(
1038
- serializedDevice.deviceName,
1039
- serializedDevice.serialNumber,
1040
- serializedDevice.vendorId ?? 0xfff1,
1041
- serializedDevice.vendorName ?? 'Matterbridge',
1042
- serializedDevice.productId ?? 0x8000,
1043
- serializedDevice.productName ?? 'Matterbridge device',
1044
- );
1045
- else if (clusterId === BridgedDeviceBasicInformationCluster.id)
1046
- device.createDefaultBridgedDeviceBasicInformationClusterServer(
1047
- serializedDevice.deviceName,
1048
- serializedDevice.serialNumber,
1049
- serializedDevice.vendorId ?? 0xfff1,
1050
- serializedDevice.vendorName ?? 'Matterbridge',
1051
- serializedDevice.productName ?? 'Matterbridge device',
1052
- );
1053
- else device.addClusterServerFromList(device, [clusterId]);
398
+ if (clusterId === BridgedDeviceBasicInformation.Cluster.id)
399
+ device.createDefaultBridgedDeviceBasicInformationClusterServer(serializedDevice.deviceName, serializedDevice.serialNumber, serializedDevice.vendorId ?? 0xfff1, serializedDevice.vendorName ?? 'Matterbridge', serializedDevice.productName ?? 'Matterbridge device');
400
+ else if (clusterId === PowerSource.Cluster.id)
401
+ device.createDefaultPowerSourceWiredClusterServer();
1054
402
  }
1055
403
  return device;
1056
- */
1057
- }
1058
- /**
1059
- * From here copy paste from MatterbridgeDevice
1060
- */
1061
- /**
1062
- * Get a default IdentifyCluster server.
1063
- */
1064
- getDefaultIdentifyClusterServer(identifyTime = 0, identifyType = Identify.IdentifyType.None) {
1065
- return ClusterServer(IdentifyCluster, {
1066
- identifyTime,
1067
- identifyType,
1068
- }, {
1069
- identify: async (data) => {
1070
- // Never called in edge
1071
- },
1072
- triggerEffect: async (data) => {
1073
- // Never called in edge
1074
- },
1075
- });
1076
404
  }
1077
- /**
1078
- * Creates a default IdentifyCluster server.
1079
- */
1080
- createDefaultIdentifyClusterServer(identifyTime = 0, identifyType = Identify.IdentifyType.None) {
1081
- this.addClusterServer(this.getDefaultIdentifyClusterServer(identifyTime, identifyType));
405
+ createDefaultPowerSourceWiredClusterServer(wiredCurrentType = PowerSource.WiredCurrentType.Ac) {
406
+ this.behaviors.require(PowerSourceServer.with(PowerSource.Feature.Wired), {
407
+ wiredCurrentType,
408
+ description: wiredCurrentType === PowerSource.WiredCurrentType.Ac ? 'AC Power' : 'DC Power',
409
+ status: PowerSource.PowerSourceStatus.Active,
410
+ order: 0,
411
+ endpointList: [],
412
+ });
1082
413
  return this;
1083
414
  }
1084
- /**
1085
- * Get a default IdentifyCluster server.
1086
- */
1087
- getDefaultGroupsClusterServer() {
1088
- return ClusterServer(GroupsCluster, {
1089
- nameSupport: {
1090
- nameSupport: true,
1091
- },
1092
- }, GroupsClusterHandler());
1093
- }
1094
- /**
1095
- * Creates a default groups cluster server and adds it to the device.
1096
- */
1097
- createDefaultGroupsClusterServer() {
1098
- this.addClusterServer(this.getDefaultGroupsClusterServer());
415
+ createDefaultPowerSourceReplaceableBatteryClusterServer(batPercentRemaining = 100, batChargeLevel = PowerSource.BatChargeLevel.Ok, batVoltage = 1500, batReplacementDescription = 'Battery type', batQuantity = 1) {
416
+ this.behaviors.require(PowerSourceServer.with(PowerSource.Feature.Battery, PowerSource.Feature.Replaceable), {
417
+ status: PowerSource.PowerSourceStatus.Active,
418
+ order: 0,
419
+ description: 'Primary battery',
420
+ batVoltage,
421
+ batPercentRemaining: Math.min(Math.max(batPercentRemaining * 2, 0), 200),
422
+ batChargeLevel,
423
+ batReplacementNeeded: false,
424
+ batReplaceability: PowerSource.BatReplaceability.UserReplaceable,
425
+ activeBatFaults: undefined,
426
+ batReplacementDescription,
427
+ batQuantity,
428
+ endpointList: [],
429
+ });
1099
430
  return this;
1100
431
  }
1101
- /**
1102
- * Get a default scenes cluster server and adds it to the current instance.
1103
- * @deprecated This method is deprecated.
1104
- *
1105
- */
1106
- getDefaultScenesClusterServer() {
1107
- /*
1108
- return ClusterServer(
1109
- ScenesCluster,
1110
- {
1111
- sceneCount: 0,
1112
- currentScene: 0,
1113
- currentGroup: GroupId(0),
1114
- sceneValid: false,
1115
- nameSupport: {
1116
- nameSupport: true,
1117
- },
1118
- lastConfiguredBy: null,
1119
- },
1120
- {},
1121
- );
1122
- */
1123
- }
1124
- /**
1125
- * Creates a default scenes cluster server and adds it to the current instance.
1126
- * @deprecated This method is deprecated.
1127
- */
1128
- createDefaultScenesClusterServer() {
1129
- /*
1130
- this.addClusterServer(this.getDefaultScenesClusterServer());
1131
- */
432
+ createDefaultPowerSourceRechargeableBatteryClusterServer(batPercentRemaining = 100, batChargeLevel = PowerSource.BatChargeLevel.Ok, batVoltage = 1500) {
433
+ this.behaviors.require(PowerSourceServer.with(PowerSource.Feature.Battery, PowerSource.Feature.Rechargeable), {
434
+ status: PowerSource.PowerSourceStatus.Active,
435
+ order: 0,
436
+ description: 'Primary battery',
437
+ batVoltage,
438
+ batPercentRemaining: Math.min(Math.max(batPercentRemaining * 2, 0), 200),
439
+ batTimeRemaining: 1,
440
+ batChargeLevel,
441
+ batReplacementNeeded: false,
442
+ batReplaceability: PowerSource.BatReplaceability.Unspecified,
443
+ activeBatFaults: undefined,
444
+ batChargeState: PowerSource.BatChargeState.IsNotCharging,
445
+ batFunctionalWhileCharging: true,
446
+ endpointList: [],
447
+ });
1132
448
  return this;
1133
449
  }
1134
- /**
1135
- * Creates a unique identifier based on the provided parameters.
1136
- * @param param1 - The first parameter.
1137
- * @param param2 - The second parameter.
1138
- * @param param3 - The third parameter.
1139
- * @param param4 - The fourth parameter.
1140
- * @returns A unique identifier generated using the MD5 hash algorithm.
1141
- */
1142
- createUniqueId(param1, param2, param3, param4) {
1143
- const hash = createHash('md5');
1144
- hash.update(param1 + param2 + param3 + param4);
1145
- return hash.digest('hex');
1146
- }
1147
- /**
1148
- * Get a default Basic Information Cluster Server.
1149
- *
1150
- * @param deviceName - The name of the device.
1151
- * @param serialNumber - The serial number of the device.
1152
- * @param vendorId - The vendor ID of the device.
1153
- * @param vendorName - The vendor name of the device.
1154
- * @param productId - The product ID of the device.
1155
- * @param productName - The product name of the device.
1156
- * @param softwareVersion - The software version of the device. Default is 1.
1157
- * @param softwareVersionString - The software version string of the device. Default is 'v.1.0.0'.
1158
- * @param hardwareVersion - The hardware version of the device. Default is 1.
1159
- * @param hardwareVersionString - The hardware version string of the device. Default is 'v.1.0.0'.
1160
- */
1161
- getDefaultBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productId, productName, softwareVersion = 1, softwareVersionString = '1.0.0', hardwareVersion = 1, hardwareVersionString = '1.0.0') {
450
+ createDefaultBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productId, productName, softwareVersion = 1, softwareVersionString = '1.0.0', hardwareVersion = 1, hardwareVersionString = '1.0.0') {
1162
451
  this.log.logName = deviceName;
1163
452
  this.deviceName = deviceName;
1164
453
  this.serialNumber = serialNumber;
1165
- this.uniqueId = this.createUniqueId(deviceName, serialNumber, vendorName, productName);
454
+ this.uniqueId = createUniqueId(deviceName, serialNumber, vendorName, productName);
1166
455
  this.productId = productId;
1167
456
  this.productName = productName;
1168
457
  this.vendorId = vendorId;
@@ -1171,74 +460,21 @@ export class MatterbridgeEndpoint extends Endpoint {
1171
460
  this.softwareVersionString = softwareVersionString;
1172
461
  this.hardwareVersion = hardwareVersion;
1173
462
  this.hardwareVersionString = hardwareVersionString;
1174
- return ClusterServer(BasicInformationCluster, {
1175
- dataModelRevision: 1,
1176
- location: 'XX',
1177
- vendorId: VendorId(vendorId),
1178
- vendorName: vendorName.slice(0, 32),
1179
- productId: productId,
1180
- productName: productName.slice(0, 32),
1181
- productUrl: this.productUrl,
1182
- productLabel: deviceName.slice(0, 64),
1183
- nodeLabel: deviceName.slice(0, 32),
1184
- serialNumber: serialNumber.slice(0, 32),
1185
- uniqueId: this.createUniqueId(deviceName, serialNumber, vendorName, productName),
1186
- softwareVersion,
1187
- softwareVersionString: softwareVersionString.slice(0, 64),
1188
- hardwareVersion,
1189
- hardwareVersionString: hardwareVersionString.slice(0, 64),
1190
- reachable: true,
1191
- capabilityMinima: { caseSessionsPerFabric: 3, subscriptionsPerFabric: 3 },
1192
- specificationVersion: Specification.SPECIFICATION_VERSION,
1193
- maxPathsPerInvoke: 1,
1194
- }, {}, {
1195
- startUp: true,
1196
- shutDown: true,
1197
- leave: true,
1198
- reachableChanged: true,
1199
- });
1200
- }
1201
- /**
1202
- * Creates a default Basic Information Cluster Server.
1203
- *
1204
- * @param deviceName - The name of the device.
1205
- * @param serialNumber - The serial number of the device.
1206
- * @param vendorId - The vendor ID of the device.
1207
- * @param vendorName - The vendor name of the device.
1208
- * @param productId - The product ID of the device.
1209
- * @param productName - The product name of the device.
1210
- * @param softwareVersion - The software version of the device. Default is 1.
1211
- * @param softwareVersionString - The software version string of the device. Default is 'v.1.0.0'.
1212
- * @param hardwareVersion - The hardware version of the device. Default is 1.
1213
- * @param hardwareVersionString - The hardware version string of the device. Default is 'v.1.0.0'.
1214
- */
1215
- createDefaultBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productId, productName, softwareVersion = 1, softwareVersionString = '1.0.0', hardwareVersion = 1, hardwareVersionString = '1.0.0') {
1216
463
  if (MatterbridgeEndpoint.bridgeMode === 'bridge') {
1217
- this.addDeviceType(bridgedNode);
464
+ const options = this.getClusterServerOptions(Descriptor.Cluster.id);
465
+ if (options) {
466
+ const deviceTypeList = options.deviceTypeList;
467
+ deviceTypeList.push({ deviceType: bridgedNode.code, revision: bridgedNode.revision });
468
+ }
1218
469
  this.createDefaultBridgedDeviceBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productName, softwareVersion, softwareVersionString, hardwareVersion, hardwareVersionString);
1219
- return;
1220
470
  }
1221
- this.addClusterServer(this.getDefaultBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productId, productName, softwareVersion, softwareVersionString, hardwareVersion, hardwareVersionString));
1222
471
  return this;
1223
472
  }
1224
- /**
1225
- * Get a default BridgedDeviceBasicInformationClusterServer.
1226
- *
1227
- * @param deviceName - The name of the device.
1228
- * @param serialNumber - The serial number of the device.
1229
- * @param vendorId - The vendor ID of the device.
1230
- * @param vendorName - The name of the vendor.
1231
- * @param productName - The name of the product.
1232
- * @param softwareVersion - The software version of the device. Default is 1.
1233
- * @param softwareVersionString - The software version string of the device. Default is 'v.1.0.0'.
1234
- * @param hardwareVersion - The hardware version of the device. Default is 1.
1235
- * @param hardwareVersionString - The hardware version string of the device. Default is 'v.1.0.0'.
1236
- */
1237
- getDefaultBridgedDeviceBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productName, softwareVersion = 1, softwareVersionString = '1.0.0', hardwareVersion = 1, hardwareVersionString = '1.0.0') {
473
+ createDefaultBridgedDeviceBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productName, softwareVersion = 1, softwareVersionString = '1.0.0', hardwareVersion = 1, hardwareVersionString = '1.0.0') {
1238
474
  this.log.logName = deviceName;
1239
475
  this.deviceName = deviceName;
1240
476
  this.serialNumber = serialNumber;
1241
- this.uniqueId = this.createUniqueId(deviceName, serialNumber, vendorName, productName);
477
+ this.uniqueId = createUniqueId(deviceName, serialNumber, vendorName, productName);
1242
478
  this.productId = undefined;
1243
479
  this.productName = productName;
1244
480
  this.vendorId = vendorId;
@@ -1247,248 +483,64 @@ export class MatterbridgeEndpoint extends Endpoint {
1247
483
  this.softwareVersionString = softwareVersionString;
1248
484
  this.hardwareVersion = hardwareVersion;
1249
485
  this.hardwareVersionString = hardwareVersionString;
1250
- return ClusterServer(BridgedDeviceBasicInformationCluster, {
1251
- vendorId: vendorId !== undefined ? VendorId(vendorId) : undefined, // 4874
486
+ this.behaviors.require(BridgedDeviceBasicInformationServer.enable({
487
+ events: { leave: true, reachableChanged: true },
488
+ }), {
489
+ vendorId: vendorId !== undefined ? VendorId(vendorId) : undefined,
1252
490
  vendorName: vendorName.slice(0, 32),
1253
491
  productName: productName.slice(0, 32),
1254
492
  productUrl: this.productUrl,
1255
493
  productLabel: deviceName.slice(0, 64),
1256
494
  nodeLabel: deviceName.slice(0, 32),
1257
495
  serialNumber: serialNumber.slice(0, 32),
1258
- uniqueId: this.createUniqueId(deviceName, serialNumber, vendorName, productName),
496
+ uniqueId: this.uniqueId,
1259
497
  softwareVersion,
1260
498
  softwareVersionString: softwareVersionString.slice(0, 64),
1261
499
  hardwareVersion,
1262
500
  hardwareVersionString: hardwareVersionString.slice(0, 64),
1263
501
  reachable: true,
1264
- }, {}, {
1265
- startUp: true,
1266
- shutDown: true,
1267
- leave: true,
1268
- reachableChanged: true,
1269
502
  });
503
+ return this;
1270
504
  }
1271
- /**
1272
- * Creates a default BridgedDeviceBasicInformationClusterServer.
1273
- *
1274
- * @param deviceName - The name of the device.
1275
- * @param serialNumber - The serial number of the device.
1276
- * @param vendorId - The vendor ID of the device.
1277
- * @param vendorName - The name of the vendor.
1278
- * @param productName - The name of the product.
1279
- * @param softwareVersion - The software version of the device. Default is 1.
1280
- * @param softwareVersionString - The software version string of the device. Default is 'v.1.0.0'.
1281
- * @param hardwareVersion - The hardware version of the device. Default is 1.
1282
- * @param hardwareVersionString - The hardware version string of the device. Default is 'v.1.0.0'.
1283
- */
1284
- createDefaultBridgedDeviceBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productName, softwareVersion = 1, softwareVersionString = '1.0.0', hardwareVersion = 1, hardwareVersionString = '1.0.0') {
1285
- this.addClusterServer(this.getDefaultBridgedDeviceBasicInformationClusterServer(deviceName, serialNumber, vendorId, vendorName, productName, softwareVersion, softwareVersionString, hardwareVersion, hardwareVersionString));
505
+ createDefaultIdentifyClusterServer(identifyTime = 0, identifyType = Identify.IdentifyType.None) {
506
+ this.behaviors.require(MatterbridgeIdentifyServer, {
507
+ identifyTime,
508
+ identifyType,
509
+ });
1286
510
  return this;
1287
511
  }
1288
- /**
1289
- * Get a default Power Topology Cluster Server. Only needed for an electricalSensor device type.
1290
- *
1291
- * @returns {ClusterServer} - The configured Power Topology Cluster Server.
1292
- */
1293
- getDefaultPowerTopologyClusterServer() {
1294
- return ClusterServer(PowerTopologyCluster.with(PowerTopology.Feature.TreeTopology), {}, {}, {});
1295
- }
1296
- /**
1297
- * Get a default Electrical Energy Measurement Cluster Server.
1298
- *
1299
- * @param {number} energy - The total consumption value in mW/h.
1300
- * @returns {ClusterServer} - The configured Electrical Energy Measurement Cluster Server.
1301
- */
1302
- getDefaultElectricalEnergyMeasurementClusterServer(energy = null) {
1303
- return ClusterServer(ElectricalEnergyMeasurementCluster.with(ElectricalEnergyMeasurement.Feature.ImportedEnergy, ElectricalEnergyMeasurement.Feature.ExportedEnergy, ElectricalEnergyMeasurement.Feature.CumulativeEnergy), {
1304
- accuracy: {
1305
- measurementType: MeasurementType.ElectricalEnergy,
1306
- measured: true,
1307
- minMeasuredValue: Number.MIN_SAFE_INTEGER,
1308
- maxMeasuredValue: Number.MAX_SAFE_INTEGER,
1309
- accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
1310
- },
1311
- cumulativeEnergyReset: null,
1312
- cumulativeEnergyImported: energy ? { energy } : null,
1313
- cumulativeEnergyExported: null,
1314
- }, {}, {
1315
- cumulativeEnergyMeasured: true,
512
+ createDefaultGroupsClusterServer() {
513
+ this.behaviors.require(GroupsServer);
514
+ return this;
515
+ }
516
+ createDefaultScenesClusterServer() {
517
+ this.behaviors.require(ScenesManagementServer);
518
+ return this;
519
+ }
520
+ createDefaultOnOffClusterServer(onOff = false, globalSceneControl = false, onTime = 0, offWaitTime = 0, startUpOnOff = null) {
521
+ this.behaviors.require(MatterbridgeOnOffServer.with(OnOff.Feature.Lighting), {
522
+ onOff,
523
+ globalSceneControl,
524
+ onTime,
525
+ offWaitTime,
526
+ startUpOnOff,
1316
527
  });
528
+ return this;
1317
529
  }
1318
- /**
1319
- * Get a default Electrical Power Measurement Cluster Server.
1320
- *
1321
- * @param {number} voltage - The voltage value in millivolts.
1322
- * @param {number} current - The current value in milliamperes.
1323
- * @param {number} power - The power value in milliwatts.
1324
- * @param {number} frequency - The frequency value in millihertz.
1325
- * @returns {ClusterServer} - The configured Electrical Power Measurement Cluster Server.
1326
- */
1327
- getDefaultElectricalPowerMeasurementClusterServer(voltage = null, current = null, power = null, frequency = null) {
1328
- return ClusterServer(ElectricalPowerMeasurementCluster.with(ElectricalPowerMeasurement.Feature.AlternatingCurrent), {
1329
- powerMode: ElectricalPowerMeasurement.PowerMode.Ac,
1330
- numberOfMeasurementTypes: 4,
1331
- accuracy: [
1332
- {
1333
- measurementType: MeasurementType.Voltage,
1334
- measured: true,
1335
- minMeasuredValue: Number.MIN_SAFE_INTEGER,
1336
- maxMeasuredValue: Number.MAX_SAFE_INTEGER,
1337
- accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
1338
- },
1339
- {
1340
- measurementType: MeasurementType.ActiveCurrent,
1341
- measured: true,
1342
- minMeasuredValue: Number.MIN_SAFE_INTEGER,
1343
- maxMeasuredValue: Number.MAX_SAFE_INTEGER,
1344
- accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
1345
- },
1346
- {
1347
- measurementType: MeasurementType.ActivePower,
1348
- measured: true,
1349
- minMeasuredValue: Number.MIN_SAFE_INTEGER,
1350
- maxMeasuredValue: Number.MAX_SAFE_INTEGER,
1351
- accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
1352
- },
1353
- {
1354
- measurementType: MeasurementType.Frequency,
1355
- measured: true,
1356
- minMeasuredValue: Number.MIN_SAFE_INTEGER,
1357
- maxMeasuredValue: Number.MAX_SAFE_INTEGER,
1358
- accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
1359
- },
1360
- ],
1361
- voltage: voltage,
1362
- activeCurrent: current,
1363
- activePower: power,
1364
- frequency: frequency,
1365
- }, {}, {});
1366
- }
1367
- /**
1368
- * Get a default OnOff cluster server for light devices.
1369
- *
1370
- * @param {boolean} [onOff=false] - The initial state of the OnOff cluster.
1371
- * @param {boolean} [globalSceneControl=false] - The global scene control state.
1372
- * @param {number} [onTime=0] - The on time value.
1373
- * @param {number} [offWaitTime=0] - The off wait time value.
1374
- * @param {OnOff.StartUpOnOff | null} [startUpOnOff=null] - The start-up OnOff state. Null means previous state.
1375
- * @returns {ClusterServer} - The configured OnOff cluster server.
1376
- */
1377
- getDefaultOnOffClusterServer(onOff = false, globalSceneControl = false, onTime = 0, offWaitTime = 0, startUpOnOff = null) {
1378
- return ClusterServer(OnOffCluster.with(OnOff.Feature.Lighting), {
1379
- onOff,
1380
- globalSceneControl,
1381
- onTime,
1382
- offWaitTime,
1383
- startUpOnOff,
1384
- }, {
1385
- on: async (data) => {
1386
- // Never called in edge
1387
- },
1388
- off: async (data) => {
1389
- // Never called in edge
1390
- },
1391
- toggle: async (data) => {
1392
- // Never called in edge
1393
- },
1394
- offWithEffect: async () => {
1395
- // Never called in edge
1396
- },
1397
- onWithRecallGlobalScene: async () => {
1398
- // Never called in edge
1399
- },
1400
- onWithTimedOff: async () => {
1401
- // Never called in edge
1402
- },
1403
- }, {});
1404
- }
1405
- /**
1406
- * Creates a default OnOff cluster server for light devices.
1407
- *
1408
- * @param {boolean} [onOff=false] - The initial state of the OnOff cluster.
1409
- * @param {boolean} [globalSceneControl=false] - The global scene control state.
1410
- * @param {number} [onTime=0] - The on time value.
1411
- * @param {number} [offWaitTime=0] - The off wait time value.
1412
- * @param {OnOff.StartUpOnOff | null} [startUpOnOff=null] - The start-up OnOff state. Null means previous state.
1413
- * @returns {void}
1414
- */
1415
- createDefaultOnOffClusterServer(onOff = false, globalSceneControl = false, onTime = 0, offWaitTime = 0, startUpOnOff = null) {
1416
- this.addClusterServer(this.getDefaultOnOffClusterServer(onOff, globalSceneControl, onTime, offWaitTime, startUpOnOff));
1417
- return this;
1418
- }
1419
- /**
1420
- * Get an OnOff cluster server without features.
1421
- *
1422
- * @param {boolean} [onOff=false] - The initial state of the OnOff cluster.
1423
- *
1424
- * @returns {ClusterServer} - The configured OnOff cluster server.
1425
- */
1426
- getOnOffClusterServer(onOff = false) {
1427
- return ClusterServer(OnOffCluster, {
1428
- onOff,
1429
- }, {
1430
- on: async (data) => {
1431
- // Never called in edge
1432
- },
1433
- off: async (data) => {
1434
- // Never called in edge
1435
- },
1436
- toggle: async (data) => {
1437
- // Never called in edge
1438
- },
1439
- }, {});
1440
- }
1441
- /**
1442
- * Creates an OnOff cluster server without features.
1443
- *
1444
- * @param {boolean} [onOff=false] - The initial state of the OnOff cluster.
1445
- */
1446
530
  createOnOffClusterServer(onOff = false) {
1447
- this.addClusterServer(this.getOnOffClusterServer(onOff));
1448
- return this;
1449
- }
1450
- /**
1451
- * Get a DeadFront OnOff cluster server.
1452
- *
1453
- * @param {boolean} [onOff=false] - The initial state of the OnOff cluster.
1454
- *
1455
- * @returns {ClusterServer} - The configured OnOff cluster server.
1456
- */
1457
- getDeadFrontOnOffClusterServer(onOff = false) {
1458
- return ClusterServer(OnOffCluster.with(OnOff.Feature.DeadFrontBehavior), {
531
+ this.behaviors.require(MatterbridgeOnOffServer, {
1459
532
  onOff,
1460
- }, {
1461
- on: async (data) => {
1462
- // Never called in edge
1463
- },
1464
- off: async (data) => {
1465
- // Never called in edge
1466
- },
1467
- toggle: async (data) => {
1468
- // Never called in edge
1469
- },
1470
- }, {});
533
+ });
534
+ return this;
1471
535
  }
1472
- /**
1473
- * Creates a DeadFront OnOff cluster server.
1474
- *
1475
- * @param {boolean} [onOff=false] - The initial state of the OnOff cluster.
1476
- */
1477
536
  createDeadFrontOnOffClusterServer(onOff = false) {
1478
- this.addClusterServer(this.getDeadFrontOnOffClusterServer(onOff));
537
+ this.behaviors.require(MatterbridgeOnOffServer.with(OnOff.Feature.DeadFrontBehavior), {
538
+ onOff,
539
+ });
1479
540
  return this;
1480
541
  }
1481
- /**
1482
- * Get a default level control cluster server.
1483
- *
1484
- * @param currentLevel - The current level (default: 254).
1485
- * @param minLevel - The minimum level (default: 1).
1486
- * @param maxLevel - The maximum level (default: 254).
1487
- * @param onLevel - The on level (default: null).
1488
- * @param startUpCurrentLevel - The startUp on level (default: null).
1489
- */
1490
- getDefaultLevelControlClusterServer(currentLevel = 254, minLevel = 1, maxLevel = 254, onLevel = null, startUpCurrentLevel = null) {
1491
- return ClusterServer(LevelControlCluster.with(LevelControl.Feature.OnOff, LevelControl.Feature.Lighting), {
542
+ createDefaultLevelControlClusterServer(currentLevel = 254, minLevel = 1, maxLevel = 254, onLevel = null, startUpCurrentLevel = null) {
543
+ this.behaviors.require(MatterbridgeLevelControlServer.with(LevelControl.Feature.OnOff, LevelControl.Feature.Lighting), {
1492
544
  currentLevel,
1493
545
  minLevel,
1494
546
  maxLevel,
@@ -1499,59 +551,11 @@ export class MatterbridgeEndpoint extends Endpoint {
1499
551
  executeIfOff: false,
1500
552
  coupleColorTempToLevel: false,
1501
553
  },
1502
- }, {
1503
- moveToLevel: async (data) => {
1504
- // Never called in edge
1505
- },
1506
- move: async () => {
1507
- // Never called in edge
1508
- },
1509
- step: async () => {
1510
- // Never called in edge
1511
- },
1512
- stop: async () => {
1513
- // Never called in edge
1514
- },
1515
- moveToLevelWithOnOff: async (data) => {
1516
- // Never called in edge
1517
- },
1518
- moveWithOnOff: async () => {
1519
- // Never called in edge
1520
- },
1521
- stepWithOnOff: async () => {
1522
- // Never called in edge
1523
- },
1524
- stopWithOnOff: async () => {
1525
- // Never called in edge
1526
- },
1527
554
  });
1528
- }
1529
- /**
1530
- * Creates a default level control cluster server.
1531
- *
1532
- * @param currentLevel - The current level (default: 254).
1533
- * @param minLevel - The minimum level (default: 1).
1534
- * @param maxLevel - The maximum level (default: 254).
1535
- * @param onLevel - The on level (default: null).
1536
- * @param startUpCurrentLevel - The startUp on level (default: null).
1537
- */
1538
- createDefaultLevelControlClusterServer(currentLevel = 254, minLevel = 1, maxLevel = 254, onLevel = null, startUpCurrentLevel = null) {
1539
- this.addClusterServer(this.getDefaultLevelControlClusterServer(currentLevel, minLevel, maxLevel, onLevel, startUpCurrentLevel));
1540
555
  return this;
1541
556
  }
1542
- /**
1543
- * Get a default color control cluster server with Xy, HueSaturation and ColorTemperature.
1544
- *
1545
- * @param currentX - The current X value.
1546
- * @param currentY - The current Y value.
1547
- * @param currentHue - The current hue value.
1548
- * @param currentSaturation - The current saturation value.
1549
- * @param colorTemperatureMireds - The color temperature in mireds.
1550
- * @param colorTempPhysicalMinMireds - The physical minimum color temperature in mireds.
1551
- * @param colorTempPhysicalMaxMireds - The physical maximum color temperature in mireds.
1552
- */
1553
- getDefaultColorControlClusterServer(currentX = 0, currentY = 0, currentHue = 0, currentSaturation = 0, colorTemperatureMireds = 500, colorTempPhysicalMinMireds = 147, colorTempPhysicalMaxMireds = 500) {
1554
- return ClusterServer(ColorControlCluster.with(ColorControl.Feature.Xy, ColorControl.Feature.HueSaturation, ColorControl.Feature.ColorTemperature), {
557
+ createDefaultColorControlClusterServer(currentX = 0, currentY = 0, currentHue = 0, currentSaturation = 0, colorTemperatureMireds = 500, colorTempPhysicalMinMireds = 147, colorTempPhysicalMaxMireds = 500) {
558
+ this.behaviors.require(MatterbridgeColorControlServer.with(ColorControl.Feature.Xy, ColorControl.Feature.HueSaturation, ColorControl.Feature.ColorTemperature), {
1555
559
  colorMode: ColorControl.ColorMode.CurrentHueAndCurrentSaturation,
1556
560
  enhancedColorMode: ColorControl.EnhancedColorMode.CurrentHueAndCurrentSaturation,
1557
561
  colorCapabilities: { xy: true, hueSaturation: true, colorLoop: false, enhancedHue: false, colorTemperature: true },
@@ -1569,77 +573,11 @@ export class MatterbridgeEndpoint extends Endpoint {
1569
573
  coupleColorTempToLevelMinMireds: colorTempPhysicalMinMireds,
1570
574
  remainingTime: 0,
1571
575
  startUpColorTemperatureMireds: null,
1572
- }, {
1573
- moveToColor: async (data) => {
1574
- // Never called in edge
1575
- },
1576
- moveColor: async () => {
1577
- // Never called in edge
1578
- },
1579
- stepColor: async () => {
1580
- // Never called in edge
1581
- },
1582
- moveToHue: async (data) => {
1583
- // Never called in edge
1584
- },
1585
- moveHue: async () => {
1586
- // Never called in edge
1587
- },
1588
- stepHue: async () => {
1589
- // Never called in edge
1590
- },
1591
- moveToSaturation: async (data) => {
1592
- // Never called in edge
1593
- },
1594
- moveSaturation: async () => {
1595
- // Never called in edge
1596
- },
1597
- stepSaturation: async () => {
1598
- // Never called in edge
1599
- },
1600
- moveToHueAndSaturation: async (data) => {
1601
- // Never called in edge
1602
- },
1603
- stopMoveStep: async () => {
1604
- // Never called in edge
1605
- },
1606
- moveToColorTemperature: async (data) => {
1607
- // Never called in edge
1608
- },
1609
- moveColorTemperature: async () => {
1610
- // Never called in edge
1611
- },
1612
- stepColorTemperature: async () => {
1613
- // Never called in edge
1614
- },
1615
- }, {});
1616
- }
1617
- /**
1618
- * Creates a default color control cluster server with Xy, HueSaturation and ColorTemperature.
1619
- *
1620
- * @param currentX - The current X value.
1621
- * @param currentY - The current Y value.
1622
- * @param currentHue - The current hue value.
1623
- * @param currentSaturation - The current saturation value.
1624
- * @param colorTemperatureMireds - The color temperature in mireds.
1625
- * @param colorTempPhysicalMinMireds - The physical minimum color temperature in mireds.
1626
- * @param colorTempPhysicalMaxMireds - The physical maximum color temperature in mireds.
1627
- */
1628
- createDefaultColorControlClusterServer(currentX = 0, currentY = 0, currentHue = 0, currentSaturation = 0, colorTemperatureMireds = 500, colorTempPhysicalMinMireds = 147, colorTempPhysicalMaxMireds = 500) {
1629
- this.addClusterServer(this.getDefaultColorControlClusterServer(currentX, currentY, currentHue, currentSaturation, colorTemperatureMireds, colorTempPhysicalMinMireds, colorTempPhysicalMaxMireds));
576
+ });
1630
577
  return this;
1631
578
  }
1632
- /**
1633
- * Get a Xy color control cluster server with Xy and ColorTemperature.
1634
- *
1635
- * @param currentX - The current X value.
1636
- * @param currentY - The current Y value.
1637
- * @param colorTemperatureMireds - The color temperature in mireds.
1638
- * @param colorTempPhysicalMinMireds - The physical minimum color temperature in mireds.
1639
- * @param colorTempPhysicalMaxMireds - The physical maximum color temperature in mireds.
1640
- */
1641
- getXyColorControlClusterServer(currentX = 0, currentY = 0, colorTemperatureMireds = 500, colorTempPhysicalMinMireds = 147, colorTempPhysicalMaxMireds = 500) {
1642
- return ClusterServer(ColorControlCluster.with(ColorControl.Feature.Xy, ColorControl.Feature.ColorTemperature), {
579
+ createXyColorControlClusterServer(currentX = 0, currentY = 0, colorTemperatureMireds = 500, colorTempPhysicalMinMireds = 147, colorTempPhysicalMaxMireds = 500) {
580
+ this.behaviors.require(MatterbridgeColorControlServer.with(ColorControl.Feature.Xy, ColorControl.Feature.ColorTemperature), {
1643
581
  colorMode: ColorControl.ColorMode.CurrentXAndCurrentY,
1644
582
  enhancedColorMode: ColorControl.EnhancedColorMode.CurrentXAndCurrentY,
1645
583
  colorCapabilities: { xy: true, hueSaturation: false, colorLoop: false, enhancedHue: false, colorTemperature: true },
@@ -1655,54 +593,11 @@ export class MatterbridgeEndpoint extends Endpoint {
1655
593
  coupleColorTempToLevelMinMireds: colorTempPhysicalMinMireds,
1656
594
  startUpColorTemperatureMireds: null,
1657
595
  remainingTime: 0,
1658
- }, {
1659
- moveToColor: async () => {
1660
- // Never called in edge
1661
- },
1662
- moveColor: async () => {
1663
- // Never called in edge
1664
- },
1665
- stepColor: async () => {
1666
- // Never called in edge
1667
- },
1668
- stopMoveStep: async () => {
1669
- // Never called in edge
1670
- },
1671
- moveToColorTemperature: async () => {
1672
- // Never called in edge
1673
- },
1674
- moveColorTemperature: async () => {
1675
- // Never called in edge
1676
- },
1677
- stepColorTemperature: async () => {
1678
- // Never called in edge
1679
- },
1680
- }, {});
1681
- }
1682
- /**
1683
- * Creates a Xy color control cluster server with Xy and ColorTemperature.
1684
- *
1685
- * @param currentX - The current X value.
1686
- * @param currentY - The current Y value.
1687
- * @param colorTemperatureMireds - The color temperature in mireds.
1688
- * @param colorTempPhysicalMinMireds - The physical minimum color temperature in mireds.
1689
- * @param colorTempPhysicalMaxMireds - The physical maximum color temperature in mireds.
1690
- */
1691
- createXyColorControlClusterServer(currentX = 0, currentY = 0, colorTemperatureMireds = 500, colorTempPhysicalMinMireds = 147, colorTempPhysicalMaxMireds = 500) {
1692
- this.addClusterServer(this.getXyColorControlClusterServer(currentX, currentY, colorTemperatureMireds, colorTempPhysicalMinMireds, colorTempPhysicalMaxMireds));
596
+ });
1693
597
  return this;
1694
598
  }
1695
- /**
1696
- * Get a default hue and saturation control cluster server with HueSaturation and ColorTemperature.
1697
- *
1698
- * @param currentHue - The current hue value.
1699
- * @param currentSaturation - The current saturation value.
1700
- * @param colorTemperatureMireds - The color temperature in mireds.
1701
- * @param colorTempPhysicalMinMireds - The physical minimum color temperature in mireds.
1702
- * @param colorTempPhysicalMaxMireds - The physical maximum color temperature in mireds.
1703
- */
1704
- getHsColorControlClusterServer(currentHue = 0, currentSaturation = 0, colorTemperatureMireds = 500, colorTempPhysicalMinMireds = 147, colorTempPhysicalMaxMireds = 500) {
1705
- return ClusterServer(ColorControlCluster.with(ColorControl.Feature.HueSaturation, ColorControl.Feature.ColorTemperature), {
599
+ createHsColorControlClusterServer(currentHue = 0, currentSaturation = 0, colorTemperatureMireds = 500, colorTempPhysicalMinMireds = 147, colorTempPhysicalMaxMireds = 500) {
600
+ this.behaviors.require(MatterbridgeColorControlServer.with(ColorControl.Feature.HueSaturation, ColorControl.Feature.ColorTemperature), {
1706
601
  colorMode: ColorControl.ColorMode.CurrentHueAndCurrentSaturation,
1707
602
  enhancedColorMode: ColorControl.EnhancedColorMode.CurrentHueAndCurrentSaturation,
1708
603
  colorCapabilities: { xy: false, hueSaturation: true, colorLoop: false, enhancedHue: false, colorTemperature: true },
@@ -1718,64 +613,11 @@ export class MatterbridgeEndpoint extends Endpoint {
1718
613
  coupleColorTempToLevelMinMireds: colorTempPhysicalMinMireds,
1719
614
  startUpColorTemperatureMireds: null,
1720
615
  remainingTime: 0,
1721
- }, {
1722
- moveToHue: async () => {
1723
- // Never called in edge
1724
- },
1725
- moveHue: async () => {
1726
- // Never called in edge
1727
- },
1728
- stepHue: async () => {
1729
- // Never called in edge
1730
- },
1731
- moveToSaturation: async () => {
1732
- // Never called in edge
1733
- },
1734
- moveSaturation: async () => {
1735
- // Never called in edge
1736
- },
1737
- stepSaturation: async () => {
1738
- // Never called in edge
1739
- },
1740
- moveToHueAndSaturation: async () => {
1741
- // Never called in edge
1742
- },
1743
- stopMoveStep: async () => {
1744
- // Never called in edge
1745
- },
1746
- moveToColorTemperature: async () => {
1747
- // Never called in edge
1748
- },
1749
- moveColorTemperature: async () => {
1750
- // Never called in edge
1751
- },
1752
- stepColorTemperature: async () => {
1753
- // Never called in edge
1754
- },
1755
- }, {});
1756
- }
1757
- /**
1758
- * Creates a hue and saturation color control cluster server with HueSaturation and ColorTemperature.
1759
- *
1760
- * @param currentHue - The current hue value.
1761
- * @param currentSaturation - The current saturation value.
1762
- * @param colorTemperatureMireds - The color temperature in mireds.
1763
- * @param colorTempPhysicalMinMireds - The physical minimum color temperature in mireds.
1764
- * @param colorTempPhysicalMaxMireds - The physical maximum color temperature in mireds.
1765
- */
1766
- createHsColorControlClusterServer(currentHue = 0, currentSaturation = 0, colorTemperatureMireds = 500, colorTempPhysicalMinMireds = 147, colorTempPhysicalMaxMireds = 500) {
1767
- this.addClusterServer(this.getHsColorControlClusterServer(currentHue, currentSaturation, colorTemperatureMireds, colorTempPhysicalMinMireds, colorTempPhysicalMaxMireds));
616
+ });
1768
617
  return this;
1769
618
  }
1770
- /**
1771
- * Get a color temperature color control cluster server.
1772
- *
1773
- * @param colorTemperatureMireds - The color temperature in mireds.
1774
- * @param colorTempPhysicalMinMireds - The physical minimum color temperature in mireds.
1775
- * @param colorTempPhysicalMaxMireds - The physical maximum color temperature in mireds.
1776
- */
1777
- getCtColorControlClusterServer(colorTemperatureMireds = 500, colorTempPhysicalMinMireds = 147, colorTempPhysicalMaxMireds = 500) {
1778
- return ClusterServer(ColorControlCluster.with(ColorControl.Feature.ColorTemperature), {
619
+ createCtColorControlClusterServer(colorTemperatureMireds = 500, colorTempPhysicalMinMireds = 147, colorTempPhysicalMaxMireds = 500) {
620
+ this.behaviors.require(MatterbridgeColorControlServer.with(ColorControl.Feature.ColorTemperature), {
1779
621
  colorMode: ColorControl.ColorMode.ColorTemperatureMireds,
1780
622
  enhancedColorMode: ColorControl.EnhancedColorMode.ColorTemperatureMireds,
1781
623
  colorCapabilities: { xy: false, hueSaturation: false, colorLoop: false, enhancedHue: false, colorTemperature: true },
@@ -1789,92 +631,17 @@ export class MatterbridgeEndpoint extends Endpoint {
1789
631
  coupleColorTempToLevelMinMireds: colorTempPhysicalMinMireds,
1790
632
  remainingTime: 0,
1791
633
  startUpColorTemperatureMireds: null,
1792
- }, {
1793
- stopMoveStep: async () => {
1794
- // Never called in edge
1795
- },
1796
- moveToColorTemperature: async () => {
1797
- // Never called in edge
1798
- },
1799
- moveColorTemperature: async () => {
1800
- // Never called in edge
1801
- },
1802
- stepColorTemperature: async () => {
1803
- // Never called in edge
1804
- },
1805
- }, {});
1806
- }
1807
- /**
1808
- * Creates a color temperature color control cluster server.
1809
- *
1810
- * @param colorTemperatureMireds - The color temperature in mireds.
1811
- * @param colorTempPhysicalMinMireds - The physical minimum color temperature in mireds.
1812
- * @param colorTempPhysicalMaxMireds - The physical maximum color temperature in mireds.
1813
- */
1814
- createCtColorControlClusterServer(colorTemperatureMireds = 500, colorTempPhysicalMinMireds = 147, colorTempPhysicalMaxMireds = 500) {
1815
- this.addClusterServer(this.getCtColorControlClusterServer(colorTemperatureMireds, colorTempPhysicalMinMireds, colorTempPhysicalMaxMireds));
1816
- return this;
1817
- }
1818
- isColorControlConfigured = false;
1819
- /**
1820
- * Configures the color control cluster for a device.
1821
- *
1822
- * @remark This method must be called only after creating the cluster with getDefaultColorControlClusterServer or createDefaultColorControlClusterServer
1823
- * and before starting the matter node.
1824
- *
1825
- * @deprecated Use configureColorControlMode instead.
1826
- *
1827
- * @param {boolean} hueSaturation - A boolean indicating whether the device supports hue and saturation control.
1828
- * @param {boolean} xy - A boolean indicating whether the device supports XY control.
1829
- * @param {boolean} colorTemperature - A boolean indicating whether the device supports color temperature control.
1830
- * @param {ColorControl.ColorMode} colorMode - An optional parameter specifying the color mode of the device.
1831
- * @param {Endpoint} endpoint - An optional parameter specifying the endpoint to configure. If not provided, the device endpoint will be used.
1832
- */
1833
- async configureColorControlCluster(hueSaturation, xy, colorTemperature, colorMode, endpoint) {
1834
- if (!endpoint)
1835
- endpoint = this;
1836
- if (this.isColorControlConfigured)
1837
- return;
1838
- if (endpoint.construction.status !== Lifecycle.Status.Active) {
1839
- this.log.debug(`**configureColorControlCluster() delaying for endpoint construction ${endpoint.construction.status}`);
1840
- setTimeout(async () => {
1841
- await endpoint.configureColorControlCluster(hueSaturation, xy, colorTemperature, colorMode, endpoint);
1842
- this.isColorControlConfigured = true;
1843
- }, 500);
1844
- return;
1845
- }
1846
- this.log.debug(`**configureColorControlCluster()`);
1847
- await endpoint.setAttribute(ColorControlCluster.id, 'featureMap', { hueSaturation, enhancedHue: false, colorLoop: false, xy, colorTemperature }, this.log, endpoint);
1848
- await endpoint.setAttribute(ColorControlCluster.id, 'colorCapabilities', { hueSaturation, enhancedHue: false, colorLoop: false, xy, colorTemperature }, this.log, endpoint);
1849
- if (isValidNumber(colorMode, ColorControl.ColorMode.CurrentHueAndCurrentSaturation, ColorControl.ColorMode.ColorTemperatureMireds)) {
1850
- await endpoint.setAttribute(ColorControlCluster.id, 'colorMode', colorMode, this.log, endpoint);
1851
- await endpoint.setAttribute(ColorControlCluster.id, 'enhancedColorMode', colorMode, this.log, endpoint);
1852
- }
1853
- this.isColorControlConfigured = true;
634
+ });
1854
635
  return this;
1855
636
  }
1856
- /**
1857
- * Configures the color control mode for the device.
1858
- *
1859
- * @param {ColorControl.ColorMode} colorMode - The color mode to set.
1860
- * @param {Endpoint} endpoint - The optional endpoint to configure. If not provided, the method will configure the current endpoint.
1861
- */
1862
- async configureColorControlMode(colorMode, endpoint) {
1863
- if (!endpoint)
1864
- endpoint = this;
637
+ async configureColorControlMode(colorMode) {
1865
638
  if (isValidNumber(colorMode, ColorControl.ColorMode.CurrentHueAndCurrentSaturation, ColorControl.ColorMode.ColorTemperatureMireds)) {
1866
- await endpoint.setAttribute(ColorControlCluster.id, 'colorMode', colorMode, this.log, endpoint);
1867
- await endpoint.setAttribute(ColorControlCluster.id, 'enhancedColorMode', colorMode, this.log, endpoint);
639
+ await this.setAttribute(ColorControl.Cluster.id, 'colorMode', colorMode, this.log);
640
+ await this.setAttribute(ColorControl.Cluster.id, 'enhancedColorMode', colorMode, this.log);
1868
641
  }
1869
- return this;
1870
642
  }
1871
- /**
1872
- * Get a default window covering cluster server.
1873
- *
1874
- * @param positionPercent100ths - The position percentage in 100ths (0-10000). Defaults to 0. Matter uses 10000 = fully closed 0 = fully opened.
1875
- */
1876
- getDefaultWindowCoveringClusterServer(positionPercent100ths) {
1877
- return ClusterServer(WindowCoveringCluster.with(WindowCovering.Feature.Lift, WindowCovering.Feature.PositionAwareLift), {
643
+ createDefaultWindowCoveringClusterServer(positionPercent100ths) {
644
+ this.behaviors.require(MatterbridgeWindowCoveringServer.with(WindowCovering.Feature.Lift, WindowCovering.Feature.PositionAwareLift), {
1878
645
  type: WindowCovering.WindowCoveringType.Rollershade,
1879
646
  configStatus: {
1880
647
  operational: true,
@@ -1888,1138 +655,472 @@ export class MatterbridgeEndpoint extends Endpoint {
1888
655
  operationalStatus: { global: WindowCovering.MovementStatus.Stopped, lift: WindowCovering.MovementStatus.Stopped, tilt: WindowCovering.MovementStatus.Stopped },
1889
656
  endProductType: WindowCovering.EndProductType.RollerShade,
1890
657
  mode: { motorDirectionReversed: false, calibrationMode: false, maintenanceMode: false, ledFeedback: false },
1891
- targetPositionLiftPercent100ths: positionPercent100ths ?? 0, // 0 Fully open 10000 fully closed
1892
- currentPositionLiftPercent100ths: positionPercent100ths ?? 0, // 0 Fully open 10000 fully closed
1893
- }, {
1894
- upOrOpen: async (data) => {
1895
- // Never called in edge
1896
- },
1897
- downOrClose: async (data) => {
1898
- // Never called in edge
1899
- },
1900
- stopMotion: async (data) => {
1901
- // Never called in edge
1902
- },
1903
- goToLiftPercentage: async (data) => {
1904
- // Never called in edge
1905
- },
1906
- }, {});
658
+ targetPositionLiftPercent100ths: positionPercent100ths ?? 0,
659
+ currentPositionLiftPercent100ths: positionPercent100ths ?? 0,
660
+ });
661
+ return this;
1907
662
  }
1908
- /**
1909
- * Creates a default window covering cluster server.
1910
- *
1911
- * @param positionPercent100ths - The position percentage in 100ths (0-10000). Defaults to 0. Matter uses 10000 = fully closed 0 = fully opened.
1912
- */
1913
- createDefaultWindowCoveringClusterServer(positionPercent100ths) {
1914
- this.addClusterServer(this.getDefaultWindowCoveringClusterServer(positionPercent100ths));
1915
- }
1916
- /**
1917
- * Sets the window covering target position as the current position and stops the movement.
1918
- * @param {Endpoint} endpoint - The endpoint on which to set the window covering (default the device endpoint).
1919
- */
1920
- async setWindowCoveringTargetAsCurrentAndStopped(endpoint) {
1921
- if (!endpoint)
1922
- endpoint = this;
1923
- const position = endpoint.getAttribute(WindowCoveringCluster.id, 'currentPositionLiftPercent100ths', this.log, endpoint);
1924
- if (position !== null) {
1925
- await endpoint.setAttribute(WindowCoveringCluster.id, 'targetPositionLiftPercent100ths', position, this.log, endpoint);
1926
- await endpoint.setAttribute(WindowCoveringCluster.id, 'operationalStatus', {
663
+ async setWindowCoveringTargetAsCurrentAndStopped() {
664
+ const position = this.getAttribute(WindowCovering.Cluster.id, 'currentPositionLiftPercent100ths', this.log);
665
+ if (isValidNumber(position, 0, 10000)) {
666
+ await this.setAttribute(WindowCovering.Cluster.id, 'targetPositionLiftPercent100ths', position, this.log);
667
+ await this.setAttribute(WindowCovering.Cluster.id, 'operationalStatus', {
1927
668
  global: WindowCovering.MovementStatus.Stopped,
1928
669
  lift: WindowCovering.MovementStatus.Stopped,
1929
670
  tilt: WindowCovering.MovementStatus.Stopped,
1930
- }, this.log, endpoint);
671
+ }, this.log);
1931
672
  }
1932
673
  this.log.debug(`Set WindowCovering currentPositionLiftPercent100ths and targetPositionLiftPercent100ths to ${position} and operationalStatus to Stopped.`);
1933
674
  }
1934
- /**
1935
- * Sets the current and target status of a window covering.
1936
- * @param {number} current - The current position of the window covering.
1937
- * @param {number} target - The target position of the window covering.
1938
- * @param {WindowCovering.MovementStatus} status - The movement status of the window covering.
1939
- * @param {Endpoint} endpoint - The endpoint on which to set the window covering (default the device endpoint).
1940
- */
1941
- async setWindowCoveringCurrentTargetStatus(current, target, status, endpoint) {
1942
- if (!endpoint)
1943
- endpoint = this;
1944
- await endpoint.setAttribute(WindowCoveringCluster.id, 'currentPositionLiftPercent100ths', current, this.log, endpoint);
1945
- await endpoint.setAttribute(WindowCoveringCluster.id, 'targetPositionLiftPercent100ths', target, this.log, endpoint);
1946
- await endpoint.setAttribute(WindowCoveringCluster.id, 'operationalStatus', {
675
+ async setWindowCoveringCurrentTargetStatus(current, target, status) {
676
+ await this.setAttribute(WindowCovering.Cluster.id, 'currentPositionLiftPercent100ths', current, this.log);
677
+ await this.setAttribute(WindowCovering.Cluster.id, 'targetPositionLiftPercent100ths', target, this.log);
678
+ await this.setAttribute(WindowCovering.Cluster.id, 'operationalStatus', {
1947
679
  global: status,
1948
680
  lift: status,
1949
681
  tilt: status,
1950
- }, this.log, endpoint);
682
+ }, this.log);
1951
683
  this.log.debug(`Set WindowCovering currentPositionLiftPercent100ths: ${current}, targetPositionLiftPercent100ths: ${target} and operationalStatus: ${status}.`);
1952
684
  }
1953
- /**
1954
- * Sets the status of the window covering.
1955
- * @param {WindowCovering.MovementStatus} status - The movement status to set.
1956
- * @param {Endpoint} endpoint - The endpoint on which to set the window covering (default the device endpoint).
1957
- */
1958
- async setWindowCoveringStatus(status, endpoint) {
1959
- if (!endpoint)
1960
- endpoint = this;
1961
- await endpoint.setAttribute(WindowCoveringCluster.id, 'operationalStatus', {
685
+ async setWindowCoveringStatus(status) {
686
+ await this.setAttribute(WindowCovering.Cluster.id, 'operationalStatus', {
1962
687
  global: status,
1963
688
  lift: status,
1964
689
  tilt: status,
1965
- }, this.log, endpoint);
690
+ }, this.log);
1966
691
  this.log.debug(`Set WindowCovering operationalStatus: ${status}`);
1967
692
  }
1968
- /**
1969
- * Retrieves the status of the window covering.
1970
- * @param {Endpoint} endpoint - The endpoint on which to get the window covering (default the device endpoint).
1971
- *
1972
- * @returns The global operational status of the window covering.
1973
- */
1974
- getWindowCoveringStatus(endpoint) {
1975
- if (!endpoint)
1976
- endpoint = this;
1977
- const status = endpoint.getAttribute(WindowCoveringCluster.id, 'operationalStatus', this.log, endpoint);
1978
- this.log.debug(`Get WindowCovering operationalStatus: ${status.global}`);
1979
- return status.global;
1980
- }
1981
- /**
1982
- * Sets the target and current position of the window covering.
1983
- *
1984
- * @param position - The position to set, specified as a number.
1985
- * @param {Endpoint} endpoint - The endpoint on which to set the window covering (default the device endpoint).
1986
- */
1987
- async setWindowCoveringTargetAndCurrentPosition(position, endpoint) {
1988
- if (!endpoint)
1989
- endpoint = this;
1990
- await endpoint.setAttribute(WindowCoveringCluster.id, 'currentPositionLiftPercent100ths', position, this.log, endpoint);
1991
- await endpoint.setAttribute(WindowCoveringCluster.id, 'targetPositionLiftPercent100ths', position, this.log, endpoint);
693
+ getWindowCoveringStatus() {
694
+ const status = this.getAttribute(WindowCovering.Cluster.id, 'operationalStatus', this.log);
695
+ if (isValidObject(status, 3) && 'global' in status && typeof status.global === 'number') {
696
+ this.log.debug(`Get WindowCovering operationalStatus: ${status.global}`);
697
+ return status.global;
698
+ }
699
+ }
700
+ async setWindowCoveringTargetAndCurrentPosition(position) {
701
+ await this.setAttribute(WindowCovering.Cluster.id, 'currentPositionLiftPercent100ths', position, this.log);
702
+ await this.setAttribute(WindowCovering.Cluster.id, 'targetPositionLiftPercent100ths', position, this.log);
1992
703
  this.log.debug(`Set WindowCovering currentPositionLiftPercent100ths: ${position} and targetPositionLiftPercent100ths: ${position}.`);
1993
704
  }
1994
- /**
1995
- * Get a default door lock cluster server.
1996
- *
1997
- * @remarks
1998
- * This method adds a cluster server for a door lock cluster with default settings.
1999
- *
2000
- */
2001
- getDefaultDoorLockClusterServer(lockState = DoorLock.LockState.Locked, lockType = DoorLock.LockType.DeadBolt) {
2002
- return ClusterServer(DoorLockCluster, {
705
+ createDefaultThermostatClusterServer(localTemperature = 23, occupiedHeatingSetpoint = 21, occupiedCoolingSetpoint = 25, minSetpointDeadBand = 1, minHeatSetpointLimit = 0, maxHeatSetpointLimit = 50, minCoolSetpointLimit = 0, maxCoolSetpointLimit = 50) {
706
+ this.behaviors.require(MatterbridgeThermostatServer.with(Thermostat.Feature.Heating, Thermostat.Feature.Cooling, Thermostat.Feature.AutoMode), {
707
+ localTemperature: localTemperature * 100,
708
+ systemMode: Thermostat.SystemMode.Auto,
709
+ controlSequenceOfOperation: Thermostat.ControlSequenceOfOperation.CoolingAndHeating,
710
+ occupiedHeatingSetpoint: occupiedHeatingSetpoint * 100,
711
+ minHeatSetpointLimit: minHeatSetpointLimit * 100,
712
+ maxHeatSetpointLimit: maxHeatSetpointLimit * 100,
713
+ absMinHeatSetpointLimit: minHeatSetpointLimit * 100,
714
+ absMaxHeatSetpointLimit: maxHeatSetpointLimit * 100,
715
+ occupiedCoolingSetpoint: occupiedCoolingSetpoint * 100,
716
+ minCoolSetpointLimit: minCoolSetpointLimit * 100,
717
+ maxCoolSetpointLimit: maxCoolSetpointLimit * 100,
718
+ absMinCoolSetpointLimit: minCoolSetpointLimit * 100,
719
+ absMaxCoolSetpointLimit: maxCoolSetpointLimit * 100,
720
+ minSetpointDeadBand: minSetpointDeadBand * 100,
721
+ thermostatRunningMode: Thermostat.ThermostatRunningMode.Off,
722
+ });
723
+ return this;
724
+ }
725
+ createDefaultHeatingThermostatClusterServer(localTemperature = 23, occupiedHeatingSetpoint = 21, minHeatSetpointLimit = 0, maxHeatSetpointLimit = 50) {
726
+ this.behaviors.require(MatterbridgeThermostatServer.with(Thermostat.Feature.Heating), {
727
+ localTemperature: localTemperature * 100,
728
+ systemMode: Thermostat.SystemMode.Heat,
729
+ controlSequenceOfOperation: Thermostat.ControlSequenceOfOperation.HeatingOnly,
730
+ occupiedHeatingSetpoint: occupiedHeatingSetpoint * 100,
731
+ minHeatSetpointLimit: minHeatSetpointLimit * 100,
732
+ maxHeatSetpointLimit: maxHeatSetpointLimit * 100,
733
+ absMinHeatSetpointLimit: minHeatSetpointLimit * 100,
734
+ absMaxHeatSetpointLimit: maxHeatSetpointLimit * 100,
735
+ });
736
+ return this;
737
+ }
738
+ createDefaultCoolingThermostatClusterServer(localTemperature = 23, occupiedCoolingSetpoint = 25, minCoolSetpointLimit = 0, maxCoolSetpointLimit = 50) {
739
+ this.behaviors.require(MatterbridgeThermostatServer.with(Thermostat.Feature.Cooling), {
740
+ localTemperature: localTemperature * 100,
741
+ systemMode: Thermostat.SystemMode.Cool,
742
+ controlSequenceOfOperation: Thermostat.ControlSequenceOfOperation.CoolingOnly,
743
+ occupiedCoolingSetpoint: occupiedCoolingSetpoint * 100,
744
+ minCoolSetpointLimit: minCoolSetpointLimit * 100,
745
+ maxCoolSetpointLimit: maxCoolSetpointLimit * 100,
746
+ absMinCoolSetpointLimit: minCoolSetpointLimit * 100,
747
+ absMaxCoolSetpointLimit: maxCoolSetpointLimit * 100,
748
+ });
749
+ return this;
750
+ }
751
+ createDefaultFanControlClusterServer(fanMode = FanControl.FanMode.Off) {
752
+ this.behaviors.require(MatterbridgeFanControlServer.with(FanControl.Feature.MultiSpeed, FanControl.Feature.Auto, FanControl.Feature.Step), {
753
+ fanMode,
754
+ fanModeSequence: FanControl.FanModeSequence.OffLowMedHighAuto,
755
+ percentSetting: 0,
756
+ percentCurrent: 0,
757
+ speedMax: 100,
758
+ speedSetting: 0,
759
+ speedCurrent: 0,
760
+ });
761
+ return this;
762
+ }
763
+ createDefaultDoorLockClusterServer(lockState = DoorLock.LockState.Locked, lockType = DoorLock.LockType.DeadBolt) {
764
+ this.behaviors.require(MatterbridgeDoorLockServer.enable({ events: { doorLockAlarm: true, lockOperation: true, lockOperationError: true } }), {
2003
765
  operatingMode: DoorLock.OperatingMode.Normal,
2004
766
  lockState,
2005
767
  lockType,
2006
768
  actuatorEnabled: false,
2007
769
  supportedOperatingModes: { normal: true, vacation: false, privacy: false, noRemoteLockUnlock: false, passage: false },
2008
- }, {
2009
- lockDoor: async (data) => {
2010
- // Never called in edge
2011
- },
2012
- unlockDoor: async (data) => {
2013
- // Never called in edge
2014
- },
2015
- }, {
2016
- doorLockAlarm: true,
2017
- lockOperation: true,
2018
- lockOperationError: true,
2019
770
  });
771
+ return this;
2020
772
  }
2021
- /**
2022
- * Creates a default door lock cluster server.
2023
- *
2024
- * @remarks
2025
- * This method adds a cluster server for a door lock cluster with default settings.
2026
- *
2027
- */
2028
- createDefaultDoorLockClusterServer(lockState = DoorLock.LockState.Locked, lockType = DoorLock.LockType.DeadBolt) {
2029
- this.addClusterServer(this.getDefaultDoorLockClusterServer(lockState, lockType));
2030
- }
2031
- /**
2032
- * Get a default momentary switch cluster server.
2033
- *
2034
- * @remarks
2035
- * This method adds a cluster server with default momentary switch features and configurations suitable for (AppleHome) Single Double Long automations.
2036
- */
2037
- getDefaultSwitchClusterServer() {
2038
- return ClusterServer(SwitchCluster.with(Switch.Feature.MomentarySwitch, Switch.Feature.MomentarySwitchRelease, Switch.Feature.MomentarySwitchLongPress, Switch.Feature.MomentarySwitchMultiPress), {
773
+ createDefaultModeSelectClusterServer(description, supportedModes, currentMode = 0, startUpMode = 0) {
774
+ this.behaviors.require(MatterbridgeModeSelectServer, {
775
+ description: description,
776
+ standardNamespace: null,
777
+ supportedModes: supportedModes,
778
+ currentMode: currentMode,
779
+ startUpMode: startUpMode,
780
+ });
781
+ return this;
782
+ }
783
+ createDefaultValveConfigurationAndControlClusterServer(valveState = ValveConfigurationAndControl.ValveState.Closed, valveLevel = 0) {
784
+ this.behaviors.require(MatterbridgeValveConfigurationAndControlServer.with(ValveConfigurationAndControl.Feature.Level), {
785
+ currentState: valveState,
786
+ targetState: valveState,
787
+ currentLevel: valveLevel,
788
+ targetLevel: valveLevel,
789
+ openDuration: null,
790
+ defaultOpenDuration: null,
791
+ remainingDuration: null,
792
+ });
793
+ return this;
794
+ }
795
+ createDefaultPumpConfigurationAndControlClusterServer(pumpMode = PumpConfigurationAndControl.OperationMode.Normal) {
796
+ this.behaviors.require(PumpConfigurationAndControlServer.with(PumpConfigurationAndControl.Feature.ConstantSpeed), {
797
+ minConstSpeed: null,
798
+ maxConstSpeed: null,
799
+ maxPressure: null,
800
+ maxSpeed: null,
801
+ maxFlow: null,
802
+ effectiveOperationMode: pumpMode,
803
+ effectiveControlMode: PumpConfigurationAndControl.ControlMode.ConstantSpeed,
804
+ capacity: null,
805
+ operationMode: pumpMode,
806
+ });
807
+ return this;
808
+ }
809
+ createDefaultSmokeCOAlarmClusterServer(smokeState = SmokeCoAlarm.AlarmState.Normal, coState = SmokeCoAlarm.AlarmState.Normal) {
810
+ this.behaviors.require(MatterbridgeSmokeCoAlarmServer.with(SmokeCoAlarm.Feature.SmokeAlarm, SmokeCoAlarm.Feature.CoAlarm).enable({
811
+ events: { smokeAlarm: true, interconnectSmokeAlarm: true, coAlarm: true, interconnectCoAlarm: true, lowBattery: true, hardwareFault: true, endOfService: true, selfTestComplete: true, alarmMuted: true, muteEnded: true, allClear: true },
812
+ }), {
813
+ smokeState,
814
+ coState,
815
+ expressedState: SmokeCoAlarm.ExpressedState.Normal,
816
+ batteryAlert: SmokeCoAlarm.AlarmState.Normal,
817
+ deviceMuted: SmokeCoAlarm.MuteState.NotMuted,
818
+ testInProgress: false,
819
+ hardwareFaultAlert: false,
820
+ endOfServiceAlert: SmokeCoAlarm.EndOfService.Normal,
821
+ interconnectSmokeAlarm: SmokeCoAlarm.AlarmState.Normal,
822
+ interconnectCoAlarm: SmokeCoAlarm.AlarmState.Normal,
823
+ });
824
+ return this;
825
+ }
826
+ createDefaultSwitchClusterServer() {
827
+ this.behaviors.require(MatterbridgeSwitchServer.with(Switch.Feature.MomentarySwitch, Switch.Feature.MomentarySwitchRelease, Switch.Feature.MomentarySwitchLongPress, Switch.Feature.MomentarySwitchMultiPress).enable({
828
+ events: { initialPress: true, longPress: true, shortRelease: true, longRelease: true, multiPressOngoing: true, multiPressComplete: true },
829
+ }), {
2039
830
  numberOfPositions: 2,
2040
831
  currentPosition: 0,
2041
832
  multiPressMax: 2,
2042
- }, {}, {
2043
- initialPress: true,
2044
- longPress: true,
2045
- shortRelease: true,
2046
- longRelease: true,
2047
- multiPressOngoing: true,
2048
- multiPressComplete: true,
2049
833
  });
834
+ return this;
2050
835
  }
2051
- /**
2052
- * Creates a default momentary switch cluster server.
2053
- *
2054
- * @remarks
2055
- * This method adds a cluster server with default momentary switch features and configurations.
2056
- */
2057
- createDefaultSwitchClusterServer() {
2058
- this.addClusterServer(this.getDefaultSwitchClusterServer());
2059
- }
2060
- /**
2061
- * Get a default latching switch cluster server.
2062
- *
2063
- * @remarks
2064
- * This method adds a cluster server with default latching switch features and configuration.
2065
- */
2066
- getDefaultLatchingSwitchClusterServer() {
2067
- return ClusterServer(SwitchCluster.with(Switch.Feature.LatchingSwitch), {
836
+ createDefaultLatchingSwitchClusterServer() {
837
+ this.behaviors.require(SwitchServer.with(Switch.Feature.LatchingSwitch).enable({
838
+ events: { switchLatched: true },
839
+ }), {
2068
840
  numberOfPositions: 2,
2069
841
  currentPosition: 0,
2070
- }, {}, {
2071
- switchLatched: true,
2072
842
  });
843
+ return this;
2073
844
  }
2074
- /**
2075
- * Creates a default latching switch cluster server.
2076
- *
2077
- * @remarks
2078
- * This method adds a cluster server with default latching switch features and configuration.
2079
- */
2080
- createDefaultLatchingSwitchClusterServer() {
2081
- this.addClusterServer(this.getDefaultLatchingSwitchClusterServer());
2082
- }
2083
- /**
2084
- * Triggers a switch event on the specified endpoint.
2085
- *
2086
- * @param {string} event - The type of event to trigger. Possible values are 'Single', 'Double', 'Long' for momentarySwitch and 'Press', 'Release' for latchingSwitch.
2087
- * @param {Endpoint} endpoint - The endpoint on which to trigger the event (default the device endpoint).
2088
- * @returns {void}
2089
- */
2090
- async triggerSwitchEvent(event, log, endpoint) {
2091
- if (!endpoint)
2092
- endpoint = this;
845
+ async triggerSwitchEvent(event, log) {
846
+ if (this.maybeNumber === undefined) {
847
+ this.log.error(`triggerSwitchEvent ${event} error: Endpoint number not assigned on endpoint ${this.maybeId}:${this.maybeNumber}`);
848
+ return false;
849
+ }
2093
850
  if (['Single', 'Double', 'Long'].includes(event)) {
2094
- const cluster = endpoint.getClusterServer(SwitchCluster.with(Switch.Feature.MomentarySwitch, Switch.Feature.MomentarySwitchRelease, Switch.Feature.MomentarySwitchLongPress, Switch.Feature.MomentarySwitchMultiPress));
2095
- if (!cluster || !cluster.getFeatureMapAttribute().momentarySwitch) {
2096
- log?.error(`triggerSwitchEvent ${event} error: Switch cluster with MomentarySwitch not found on endpoint ${endpoint.id}:${endpoint.number}`);
2097
- return false;
2098
- }
2099
- if (endpoint.number === undefined) {
2100
- log?.error(`triggerSwitchEvent ${event} error: Endpoint number not assigned on endpoint ${endpoint.id}:${endpoint.number}`);
851
+ if (!this.hasClusterServer(Switch.Cluster.id) || this.getAttribute(Switch.Cluster.id, 'featureMap').momentarySwitch === false) {
852
+ this.log.error(`triggerSwitchEvent ${event} error: Switch cluster with MomentarySwitch not found on endpoint ${this.maybeId}:${this.maybeNumber}`);
2101
853
  return false;
2102
854
  }
2103
855
  if (event === 'Single') {
2104
- await endpoint.setAttribute(cluster.id, 'currentPosition', 1, log);
2105
- endpoint.triggerEvent(cluster.id, 'initialPress', { newPosition: 1 }, log);
2106
- await endpoint.setAttribute(cluster.id, 'currentPosition', 0, log);
2107
- endpoint.triggerEvent(cluster.id, 'shortRelease', { previousPosition: 1 }, log);
2108
- await endpoint.setAttribute(cluster.id, 'currentPosition', 0, log);
2109
- endpoint.triggerEvent(cluster.id, 'multiPressComplete', { previousPosition: 1, totalNumberOfPressesCounted: 1 }, log);
2110
- log?.info(`${db}Trigger endpoint ${or}${endpoint.id}:${endpoint.number}${db} event ${hk}${cluster.name}.SinglePress${db}`);
856
+ await this.setAttribute(Switch.Cluster.id, 'currentPosition', 1, log);
857
+ this.triggerEvent(Switch.Cluster.id, 'initialPress', { newPosition: 1 }, log);
858
+ await this.setAttribute(Switch.Cluster.id, 'currentPosition', 0, log);
859
+ this.triggerEvent(Switch.Cluster.id, 'shortRelease', { previousPosition: 1 }, log);
860
+ await this.setAttribute(Switch.Cluster.id, 'currentPosition', 0, log);
861
+ this.triggerEvent(Switch.Cluster.id, 'multiPressComplete', { previousPosition: 1, totalNumberOfPressesCounted: 1 }, log);
862
+ log?.info(`${db}Trigger endpoint ${or}${this.id}:${this.number}${db} event ${hk}Switch.SinglePress${db}`);
2111
863
  }
2112
864
  if (event === 'Double') {
2113
- await endpoint.setAttribute(cluster.id, 'currentPosition', 1, log);
2114
- endpoint.triggerEvent(cluster.id, 'initialPress', { newPosition: 1 }, log);
2115
- await endpoint.setAttribute(cluster.id, 'currentPosition', 0, log);
2116
- endpoint.triggerEvent(cluster.id, 'shortRelease', { previousPosition: 1 }, log);
2117
- await endpoint.setAttribute(cluster.id, 'currentPosition', 1, log);
2118
- endpoint.triggerEvent(cluster.id, 'initialPress', { newPosition: 1 }, log);
2119
- endpoint.triggerEvent(cluster.id, 'multiPressOngoing', { newPosition: 1, currentNumberOfPressesCounted: 2 }, log);
2120
- await endpoint.setAttribute(cluster.id, 'currentPosition', 0, log);
2121
- endpoint.triggerEvent(cluster.id, 'shortRelease', { previousPosition: 1 }, log);
2122
- endpoint.triggerEvent(cluster.id, 'multiPressComplete', { previousPosition: 1, totalNumberOfPressesCounted: 2 }, log);
2123
- log?.info(`${db}Trigger endpoint ${or}${endpoint.id}:${endpoint.number}${db} event ${hk}${cluster.name}.DoublePress${db}`);
865
+ await this.setAttribute(Switch.Cluster.id, 'currentPosition', 1, log);
866
+ this.triggerEvent(Switch.Cluster.id, 'initialPress', { newPosition: 1 }, log);
867
+ await this.setAttribute(Switch.Cluster.id, 'currentPosition', 0, log);
868
+ this.triggerEvent(Switch.Cluster.id, 'shortRelease', { previousPosition: 1 }, log);
869
+ await this.setAttribute(Switch.Cluster.id, 'currentPosition', 1, log);
870
+ this.triggerEvent(Switch.Cluster.id, 'initialPress', { newPosition: 1 }, log);
871
+ this.triggerEvent(Switch.Cluster.id, 'multiPressOngoing', { newPosition: 1, currentNumberOfPressesCounted: 2 }, log);
872
+ await this.setAttribute(Switch.Cluster.id, 'currentPosition', 0, log);
873
+ this.triggerEvent(Switch.Cluster.id, 'shortRelease', { previousPosition: 1 }, log);
874
+ this.triggerEvent(Switch.Cluster.id, 'multiPressComplete', { previousPosition: 1, totalNumberOfPressesCounted: 2 }, log);
875
+ log?.info(`${db}Trigger endpoint ${or}${this.id}:${this.number}${db} event ${hk}Switch.DoublePress${db}`);
2124
876
  }
2125
877
  if (event === 'Long') {
2126
- await endpoint.setAttribute(cluster.id, 'currentPosition', 1, log);
2127
- endpoint.triggerEvent(cluster.id, 'initialPress', { newPosition: 1 }, log);
2128
- endpoint.triggerEvent(cluster.id, 'longPress', { newPosition: 1 }, log);
2129
- await endpoint.setAttribute(cluster.id, 'currentPosition', 0, log);
2130
- endpoint.triggerEvent(cluster.id, 'longRelease', { previousPosition: 1 }, log);
2131
- log?.info(`${db}Trigger endpoint ${or}${endpoint.id}:${endpoint.number}${db} event ${hk}${cluster.name}.LongPress${db}`);
878
+ await this.setAttribute(Switch.Cluster.id, 'currentPosition', 1, log);
879
+ this.triggerEvent(Switch.Cluster.id, 'initialPress', { newPosition: 1 }, log);
880
+ this.triggerEvent(Switch.Cluster.id, 'longPress', { newPosition: 1 }, log);
881
+ await this.setAttribute(Switch.Cluster.id, 'currentPosition', 0, log);
882
+ this.triggerEvent(Switch.Cluster.id, 'longRelease', { previousPosition: 1 }, log);
883
+ log?.info(`${db}Trigger endpoint ${or}${this.id}:${this.number}${db} event ${hk}Switch.LongPress${db}`);
2132
884
  }
2133
885
  }
2134
886
  if (['Press', 'Release'].includes(event)) {
2135
- const cluster = endpoint.getClusterServer(SwitchCluster.with(Switch.Feature.LatchingSwitch));
2136
- if (!cluster || !cluster.getFeatureMapAttribute().latchingSwitch) {
2137
- log?.error(`triggerSwitchEvent ${event} error: Switch cluster with LatchingSwitch not found on endpoint ${endpoint.id}:${endpoint.number}`);
2138
- return false;
2139
- }
2140
- if (endpoint.number === undefined) {
2141
- log?.error(`triggerSwitchEvent ${event} error: Endpoint number not assigned on endpoint ${endpoint.id}:${endpoint.number}`);
887
+ if (!this.hasClusterServer(Switch.Cluster.id) || this.getAttribute(Switch.Cluster.id, 'featureMap').latchingSwitch === false) {
888
+ this.log.error(`triggerSwitchEvent ${event} error: Switch cluster with LatchingSwitch not found on endpoint ${this.maybeId}:${this.maybeNumber}`);
2142
889
  return false;
2143
890
  }
2144
891
  if (event === 'Press') {
2145
- await endpoint.setAttribute(cluster.id, 'currentPosition', 1, log);
2146
- endpoint.triggerEvent(cluster.id, 'switchLatched', { newPosition: 1 }, log);
2147
- log?.info(`${db}Trigger endpoint ${or}${endpoint.id}:${endpoint.number}${db} event ${hk}${cluster.name}.Press${db}`);
892
+ await this.setAttribute(Switch.Cluster.id, 'currentPosition', 1, log);
893
+ this.triggerEvent(Switch.Cluster.id, 'switchLatched', { newPosition: 1 }, log);
894
+ log?.info(`${db}Trigger endpoint ${or}${this.id}:${this.number}${db} event ${hk}Switch.Press${db}`);
2148
895
  }
2149
896
  if (event === 'Release') {
2150
- await endpoint.setAttribute(cluster.id, 'currentPosition', 0, log);
2151
- endpoint.triggerEvent(cluster.id, 'switchLatched', { newPosition: 0 }, log);
2152
- log?.info(`${db}Trigger endpoint ${or}${endpoint.id}:${endpoint.number}${db} event ${hk}${cluster.name}.Release${db}`);
897
+ await this.setAttribute(Switch.Cluster.id, 'currentPosition', 0, log);
898
+ this.triggerEvent(Switch.Cluster.id, 'switchLatched', { newPosition: 0 }, log);
899
+ log?.info(`${db}Trigger endpoint ${or}${this.id}:${this.number}${db} event ${hk}Switch.Release${db}`);
2153
900
  }
2154
901
  }
2155
902
  return true;
2156
903
  }
2157
- /**
2158
- * Retrieves the default mode select cluster server.
2159
- *
2160
- * @param description - The description of the cluster server.
2161
- * @param supportedModes - The supported modes for the cluster server.
2162
- * @param currentMode - The current mode of the cluster server. Defaults to 0.
2163
- * @param startUpMode - The startup mode of the cluster server. Defaults to 0.
2164
- * @returns The default mode select cluster server.
2165
- */
2166
- getDefaultModeSelectClusterServer(description, supportedModes, currentMode = 0, startUpMode = 0) {
2167
- return ClusterServer(ModeSelectCluster, {
2168
- description: description,
2169
- standardNamespace: null,
2170
- supportedModes: supportedModes,
2171
- currentMode: currentMode,
2172
- startUpMode: startUpMode,
2173
- }, {
2174
- changeToMode: async (data) => {
2175
- // Never called in edge
2176
- },
2177
- });
2178
- }
2179
- /**
2180
- * Creates a default mode select cluster server.
2181
- *
2182
- * @param description - The description of the cluster server.
2183
- * @param supportedModes - The supported modes for the cluster server.
2184
- * @param currentMode - The current mode of the cluster server. Defaults to 0.
2185
- * @param startUpMode - The startup mode of the cluster server. Defaults to 0.
2186
- * @param endpoint - The endpoint to add the cluster server to. Defaults to `this` if not provided.
2187
- *
2188
- */
2189
- createDefaultModeSelectClusterServer(description, supportedModes, currentMode = 0, startUpMode = 0, endpoint) {
2190
- if (!endpoint)
2191
- endpoint = this;
2192
- endpoint.addClusterServer(this.getDefaultModeSelectClusterServer(description, supportedModes, currentMode, startUpMode));
2193
- }
2194
- /**
2195
- * Get a default occupancy sensing cluster server.
2196
- *
2197
- * @param occupied - A boolean indicating whether the occupancy is occupied or not. Default is false.
2198
- */
2199
- getDefaultOccupancySensingClusterServer(occupied = false) {
2200
- return ClusterServer(OccupancySensingCluster, {
2201
- occupancy: { occupied },
2202
- occupancySensorType: OccupancySensing.OccupancySensorType.Pir,
2203
- occupancySensorTypeBitmap: { pir: true, ultrasonic: false, physicalContact: false },
2204
- pirOccupiedToUnoccupiedDelay: 30,
2205
- }, {});
2206
- }
2207
- /**
2208
- * Creates a default occupancy sensing cluster server.
2209
- *
2210
- * @param occupied - A boolean indicating whether the occupancy is occupied or not. Default is false.
2211
- */
2212
- createDefaultOccupancySensingClusterServer(occupied = false) {
2213
- this.addClusterServer(this.getDefaultOccupancySensingClusterServer(occupied));
2214
- }
2215
- /**
2216
- * Get a default Illuminance Measurement Cluster Server.
2217
- *
2218
- * @param measuredValue - The measured value of illuminance.
2219
- */
2220
- getDefaultIlluminanceMeasurementClusterServer(measuredValue = 0) {
2221
- return ClusterServer(IlluminanceMeasurementCluster, {
2222
- measuredValue,
2223
- minMeasuredValue: null,
2224
- maxMeasuredValue: null,
2225
- tolerance: 0,
2226
- }, {}, {});
2227
- }
2228
- /**
2229
- * Creates a default Illuminance Measurement Cluster Server.
2230
- *
2231
- * @param measuredValue - The measured value of illuminance.
2232
- */
2233
- createDefaultIlluminanceMeasurementClusterServer(measuredValue = 0) {
2234
- this.addClusterServer(this.getDefaultIlluminanceMeasurementClusterServer(measuredValue));
2235
- }
2236
- /**
2237
- * Get a default flow measurement cluster server.
2238
- *
2239
- * @param measuredValue - The measured value of the flow in 10 x m/h.
2240
- */
2241
- getDefaultFlowMeasurementClusterServer(measuredValue = 0) {
2242
- return ClusterServer(FlowMeasurementCluster, {
2243
- measuredValue,
2244
- minMeasuredValue: null,
2245
- maxMeasuredValue: null,
2246
- tolerance: 0,
2247
- }, {}, {});
2248
- }
2249
- /**
2250
- * Creates a default flow measurement cluster server.
2251
- *
2252
- * @param measuredValue - The measured value of the flow in 10 x m/h.
2253
- */
2254
- createDefaultFlowMeasurementClusterServer(measuredValue = 0) {
2255
- this.addClusterServer(this.getDefaultFlowMeasurementClusterServer(measuredValue));
2256
- }
2257
- /**
2258
- * Get a default temperature measurement cluster server.
2259
- *
2260
- * @param measuredValue - The measured value of the temperature x 100.
2261
- */
2262
- getDefaultTemperatureMeasurementClusterServer(measuredValue = 0) {
2263
- return ClusterServer(TemperatureMeasurementCluster, {
2264
- measuredValue,
2265
- minMeasuredValue: null,
2266
- maxMeasuredValue: null,
2267
- tolerance: 0,
2268
- }, {}, {});
2269
- }
2270
- /**
2271
- * Creates a default temperature measurement cluster server.
2272
- *
2273
- * @param measuredValue - The measured value of the temperature x 100.
2274
- */
2275
- createDefaultTemperatureMeasurementClusterServer(measuredValue = 0) {
2276
- this.addClusterServer(this.getDefaultTemperatureMeasurementClusterServer(measuredValue));
2277
- }
2278
- /**
2279
- * Get a default RelativeHumidityMeasurementCluster server.
2280
- *
2281
- * @param measuredValue - The measured value of the relative humidity x 100.
2282
- */
2283
- getDefaultRelativeHumidityMeasurementClusterServer(measuredValue = 0) {
2284
- return ClusterServer(RelativeHumidityMeasurementCluster, {
2285
- measuredValue,
2286
- minMeasuredValue: null,
2287
- maxMeasuredValue: null,
2288
- tolerance: 0,
2289
- }, {}, {});
2290
- }
2291
- /**
2292
- * Creates a default RelativeHumidityMeasurementCluster server.
2293
- *
2294
- * @param measuredValue - The measured value of the relative humidity x 100.
2295
- */
2296
- createDefaultRelativeHumidityMeasurementClusterServer(measuredValue = 0) {
2297
- this.addClusterServer(this.getDefaultRelativeHumidityMeasurementClusterServer(measuredValue));
2298
- }
2299
- /**
2300
- * Get a default Pressure Measurement Cluster Server.
2301
- *
2302
- * @param measuredValue - The measured value for the pressure.
2303
- */
2304
- getDefaultPressureMeasurementClusterServer(measuredValue = 1000) {
2305
- return ClusterServer(PressureMeasurementCluster, {
2306
- measuredValue,
2307
- minMeasuredValue: null,
2308
- maxMeasuredValue: null,
2309
- tolerance: 0,
2310
- }, {}, {});
2311
- }
2312
- /**
2313
- * Creates a default Pressure Measurement Cluster Server.
2314
- *
2315
- * @param measuredValue - The measured value for the pressure.
2316
- */
2317
- createDefaultPressureMeasurementClusterServer(measuredValue = 1000) {
2318
- this.addClusterServer(this.getDefaultPressureMeasurementClusterServer(measuredValue));
2319
- }
2320
- /**
2321
- * Get a default boolean state cluster server.
2322
- *
2323
- * @param contact - Optional boolean value indicating the contact state. Defaults to `true` if not provided.
2324
- */
2325
- getDefaultBooleanStateClusterServer(contact) {
2326
- return ClusterServer(BooleanStateCluster, {
2327
- stateValue: contact ?? true, // true=contact false=no_contact
2328
- }, {}, {
2329
- stateChange: true,
904
+ createDefaultBooleanStateClusterServer(contact) {
905
+ this.behaviors.require(BooleanStateServer.enable({
906
+ events: { stateChange: true },
907
+ }), {
908
+ stateValue: contact ?? true,
2330
909
  });
910
+ return this;
2331
911
  }
2332
- /**
2333
- * Creates a default boolean state configuration cluster server.
2334
- *
2335
- * @param contact - Optional boolean value indicating the contact state. Defaults to `true` if not provided.
2336
- */
2337
- createDefaultBooleanStateClusterServer(contact) {
2338
- this.addClusterServer(this.getDefaultBooleanStateClusterServer(contact));
2339
- }
2340
- /**
2341
- * Get a default boolean state configuration cluster server.
2342
- *
2343
- * @param contact - Optional boolean value indicating the sensor fault state. Defaults to `false` if not provided.
2344
- */
2345
- getDefaultBooleanStateConfigurationClusterServer(sensorFault = false) {
2346
- return ClusterServer(BooleanStateConfigurationCluster.with(BooleanStateConfiguration.Feature.Visual, BooleanStateConfiguration.Feature.Audible, BooleanStateConfiguration.Feature.SensitivityLevel), {
2347
- currentSensitivityLevel: 0,
2348
- supportedSensitivityLevels: 2,
2349
- defaultSensitivityLevel: 0,
912
+ createDefaultBooleanStateConfigurationClusterServer(sensorFault = false, currentSensitivityLevel = 0, supportedSensitivityLevels = 2, defaultSensitivityLevel = 0) {
913
+ this.behaviors.require(MatterbridgeBooleanStateConfigurationServer.with(BooleanStateConfiguration.Feature.Visual, BooleanStateConfiguration.Feature.Audible, BooleanStateConfiguration.Feature.SensitivityLevel).enable({
914
+ events: { alarmsStateChanged: true, sensorFault: true },
915
+ }), {
916
+ currentSensitivityLevel,
917
+ supportedSensitivityLevels,
918
+ defaultSensitivityLevel,
2350
919
  alarmsActive: { visual: false, audible: false },
2351
- alarmsEnabled: { visual: false, audible: false },
920
+ alarmsEnabled: { visual: true, audible: true },
2352
921
  alarmsSupported: { visual: true, audible: true },
2353
- // alarmsSuppressed: { visual: false, audible: false },
2354
922
  sensorFault: { generalFault: sensorFault },
2355
- }, {
2356
- enableDisableAlarm: async (data) => {
2357
- // Never called in edge
923
+ });
924
+ return this;
925
+ }
926
+ createDefaultPowerTopologyClusterServer() {
927
+ this.behaviors.require(PowerTopologyServer.with(PowerTopology.Feature.TreeTopology));
928
+ return this;
929
+ }
930
+ createDefaultElectricalEnergyMeasurementClusterServer(energy = null) {
931
+ this.behaviors.require(ElectricalEnergyMeasurementServer.with(ElectricalEnergyMeasurement.Feature.ImportedEnergy, ElectricalEnergyMeasurement.Feature.ExportedEnergy, ElectricalEnergyMeasurement.Feature.CumulativeEnergy), {
932
+ accuracy: {
933
+ measurementType: MeasurementType.ElectricalEnergy,
934
+ measured: true,
935
+ minMeasuredValue: Number.MIN_SAFE_INTEGER,
936
+ maxMeasuredValue: Number.MAX_SAFE_INTEGER,
937
+ accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
2358
938
  },
2359
- }, {
2360
- alarmsStateChanged: true,
2361
- sensorFault: true,
939
+ cumulativeEnergyReset: null,
940
+ cumulativeEnergyImported: energy ? { energy } : null,
941
+ cumulativeEnergyExported: null,
2362
942
  });
943
+ return this;
2363
944
  }
2364
- /**
2365
- * Creates a default boolean state configuration cluster server.
2366
- *
2367
- * @param contact - Optional boolean value indicating the sensor fault state. Defaults to `false` if not provided.
2368
- */
2369
- createDefaultBooleanStateConfigurationClusterServer(sensorFault = false) {
2370
- this.addClusterServer(this.getDefaultBooleanStateConfigurationClusterServer(sensorFault));
2371
- }
2372
- /**
2373
- * Get a default power source replaceable battery cluster server.
2374
- *
2375
- * @param batPercentRemaining - The remaining battery percentage (default: 100).
2376
- * @param batChargeLevel - The battery charge level (default: PowerSource.BatChargeLevel.Ok).
2377
- * @param batVoltage - The battery voltage (default: 1500).
2378
- * @param batReplacementDescription - The battery replacement description (default: 'Battery type').
2379
- * @param batQuantity - The battery quantity (default: 1).
2380
- */
2381
- getDefaultPowerSourceReplaceableBatteryClusterServer(batPercentRemaining = 100, batChargeLevel = PowerSource.BatChargeLevel.Ok, batVoltage = 1500, batReplacementDescription = 'Battery type', batQuantity = 1) {
2382
- return ClusterServer(PowerSourceCluster.with(PowerSource.Feature.Battery, PowerSource.Feature.Replaceable), {
2383
- status: PowerSource.PowerSourceStatus.Active,
2384
- order: 0,
2385
- description: 'Primary battery',
2386
- batVoltage,
2387
- batPercentRemaining: Math.min(Math.max(batPercentRemaining * 2, 0), 200),
2388
- batChargeLevel,
2389
- batReplacementNeeded: false,
2390
- batReplaceability: PowerSource.BatReplaceability.UserReplaceable,
2391
- activeBatFaults: undefined,
2392
- batReplacementDescription,
2393
- batQuantity,
2394
- endpointList: [],
2395
- }, {}, {});
2396
- }
2397
- /**
2398
- * Creates a default power source replaceable battery cluster server.
2399
- *
2400
- * @param batPercentRemaining - The remaining battery percentage (default: 100).
2401
- * @param batChargeLevel - The battery charge level (default: PowerSource.BatChargeLevel.Ok).
2402
- * @param batVoltage - The battery voltage (default: 1500).
2403
- * @param batReplacementDescription - The battery replacement description (default: 'Battery type').
2404
- * @param batQuantity - The battery quantity (default: 1).
2405
- */
2406
- createDefaultPowerSourceReplaceableBatteryClusterServer(batPercentRemaining = 100, batChargeLevel = PowerSource.BatChargeLevel.Ok, batVoltage = 1500, batReplacementDescription = 'Battery type', batQuantity = 1) {
2407
- this.addClusterServer(this.getDefaultPowerSourceReplaceableBatteryClusterServer(batPercentRemaining, batChargeLevel, batVoltage, batReplacementDescription, batQuantity));
2408
- }
2409
- /**
2410
- * Get a default power source rechargeable battery cluster server.
2411
- *
2412
- * @param batPercentRemaining - The remaining battery percentage (default: 100).
2413
- * @param batChargeLevel - The battery charge level (default: PowerSource.BatChargeLevel.Ok).
2414
- * @param batVoltage - The battery voltage (default: 1500).
2415
- */
2416
- getDefaultPowerSourceRechargeableBatteryClusterServer(batPercentRemaining = 100, batChargeLevel = PowerSource.BatChargeLevel.Ok, batVoltage = 1500) {
2417
- return ClusterServer(PowerSourceCluster.with(PowerSource.Feature.Battery, PowerSource.Feature.Rechargeable), {
2418
- status: PowerSource.PowerSourceStatus.Active,
2419
- order: 0,
2420
- description: 'Primary battery',
2421
- batVoltage,
2422
- batPercentRemaining: Math.min(Math.max(batPercentRemaining * 2, 0), 200),
2423
- batTimeRemaining: 1,
2424
- batChargeLevel,
2425
- batReplacementNeeded: false,
2426
- batReplaceability: PowerSource.BatReplaceability.Unspecified,
2427
- activeBatFaults: undefined,
2428
- batChargeState: PowerSource.BatChargeState.IsNotCharging,
2429
- batFunctionalWhileCharging: true,
2430
- endpointList: [],
2431
- }, {}, {});
2432
- }
2433
- /**
2434
- * Creates a default power source rechargeable battery cluster server.
2435
- *
2436
- * @param batPercentRemaining - The remaining battery percentage (default: 100).
2437
- * @param batChargeLevel - The battery charge level (default: PowerSource.BatChargeLevel.Ok).
2438
- * @param batVoltage - The battery voltage (default: 1500).
2439
- */
2440
- createDefaultPowerSourceRechargeableBatteryClusterServer(batPercentRemaining = 100, batChargeLevel = PowerSource.BatChargeLevel.Ok, batVoltage = 1500) {
2441
- this.addClusterServer(this.getDefaultPowerSourceRechargeableBatteryClusterServer(batPercentRemaining, batChargeLevel, batVoltage));
2442
- }
2443
- /**
2444
- * Get a default power source wired cluster server.
2445
- *
2446
- * @param wiredCurrentType - The type of wired current (default: PowerSource.WiredCurrentType.Ac)
2447
- */
2448
- getDefaultPowerSourceWiredClusterServer(wiredCurrentType = PowerSource.WiredCurrentType.Ac) {
2449
- return ClusterServer(PowerSourceCluster.with(PowerSource.Feature.Wired), {
2450
- wiredCurrentType,
2451
- description: wiredCurrentType === PowerSource.WiredCurrentType.Ac ? 'AC Power' : 'DC Power',
2452
- status: PowerSource.PowerSourceStatus.Active,
2453
- order: 0,
2454
- endpointList: [],
2455
- }, {}, {});
945
+ createDefaultElectricalPowerMeasurementClusterServer(voltage = null, current = null, power = null, frequency = null) {
946
+ this.behaviors.require(ElectricalPowerMeasurementServer.with(ElectricalPowerMeasurement.Feature.AlternatingCurrent), {
947
+ powerMode: ElectricalPowerMeasurement.PowerMode.Ac,
948
+ numberOfMeasurementTypes: 4,
949
+ accuracy: [
950
+ {
951
+ measurementType: MeasurementType.Voltage,
952
+ measured: true,
953
+ minMeasuredValue: Number.MIN_SAFE_INTEGER,
954
+ maxMeasuredValue: Number.MAX_SAFE_INTEGER,
955
+ accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
956
+ },
957
+ {
958
+ measurementType: MeasurementType.ActiveCurrent,
959
+ measured: true,
960
+ minMeasuredValue: Number.MIN_SAFE_INTEGER,
961
+ maxMeasuredValue: Number.MAX_SAFE_INTEGER,
962
+ accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
963
+ },
964
+ {
965
+ measurementType: MeasurementType.ActivePower,
966
+ measured: true,
967
+ minMeasuredValue: Number.MIN_SAFE_INTEGER,
968
+ maxMeasuredValue: Number.MAX_SAFE_INTEGER,
969
+ accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
970
+ },
971
+ {
972
+ measurementType: MeasurementType.Frequency,
973
+ measured: true,
974
+ minMeasuredValue: Number.MIN_SAFE_INTEGER,
975
+ maxMeasuredValue: Number.MAX_SAFE_INTEGER,
976
+ accuracyRanges: [{ rangeMin: Number.MIN_SAFE_INTEGER, rangeMax: Number.MAX_SAFE_INTEGER, fixedMax: 1 }],
977
+ },
978
+ ],
979
+ voltage: voltage,
980
+ activeCurrent: current,
981
+ activePower: power,
982
+ frequency: frequency,
983
+ });
984
+ return this;
2456
985
  }
2457
- /**
2458
- * Creates a default power source wired cluster server.
2459
- *
2460
- * @param wiredCurrentType - The type of wired current (default: PowerSource.WiredCurrentType.Ac)
2461
- */
2462
- createDefaultPowerSourceWiredClusterServer(wiredCurrentType = PowerSource.WiredCurrentType.Ac) {
2463
- this.addClusterServer(this.getDefaultPowerSourceWiredClusterServer(wiredCurrentType));
2464
- }
2465
- /**
2466
- * Get a default air quality cluster server.
2467
- *
2468
- * @param airQuality The air quality type. Defaults to `AirQuality.AirQualityType.Unknown`.
2469
- */
2470
- getDefaultAirQualityClusterServer(airQuality = AirQuality.AirQualityEnum.Unknown) {
2471
- return ClusterServer(AirQualityCluster.with(AirQuality.Feature.Fair, AirQuality.Feature.Moderate, AirQuality.Feature.VeryPoor, AirQuality.Feature.ExtremelyPoor), {
2472
- airQuality,
2473
- }, {}, {});
986
+ createDefaultTemperatureMeasurementClusterServer(measuredValue = 0) {
987
+ this.behaviors.require(TemperatureMeasurementServer, getDefaultTemperatureMeasurementClusterServer(measuredValue));
988
+ return this;
2474
989
  }
2475
- /**
2476
- * Creates a default air quality cluster server.
2477
- *
2478
- * @param airQuality The air quality type. Defaults to `AirQuality.AirQualityType.Unknown`.
2479
- */
2480
- createDefaultAirQualityClusterServer(airQuality = AirQuality.AirQualityEnum.Unknown) {
2481
- this.addClusterServer(this.getDefaultAirQualityClusterServer(airQuality));
2482
- }
2483
- /**
2484
- * Get a default TVOC measurement cluster server.
2485
- *
2486
- * @param measuredValue - The measured value for TVOC.
2487
- */
2488
- getDefaultTvocMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2489
- return ClusterServer(TotalVolatileOrganicCompoundsConcentrationMeasurementCluster.with('NumericMeasurement'), {
2490
- measuredValue,
2491
- minMeasuredValue: null,
2492
- maxMeasuredValue: null,
2493
- uncertainty: 0,
2494
- measurementUnit,
2495
- measurementMedium,
2496
- }, {}, {});
990
+ createDefaultRelativeHumidityMeasurementClusterServer(measuredValue = 0) {
991
+ this.behaviors.require(RelativeHumidityMeasurementServer, getDefaultRelativeHumidityMeasurementClusterServer(measuredValue));
992
+ return this;
2497
993
  }
2498
- /**
2499
- * Creates a default TVOC measurement cluster server.
2500
- *
2501
- * @param measuredValue - The measured value for TVOC.
2502
- */
2503
- createDefaultTvocMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2504
- this.addClusterServer(this.getDefaultTvocMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
2505
- }
2506
- /**
2507
- * Get a default heating thermostat cluster server with the specified parameters.
2508
- * @param {number} [localTemperature] - The local temperature value in degrees Celsius. Defaults to 23°.
2509
- * @param {number} [occupiedHeatingSetpoint] - The occupied heating setpoint value in degrees Celsius. Defaults to 21°.
2510
- * @param {number} [minHeatSetpointLimit] - The minimum heat setpoint limit value. Defaults to 0°.
2511
- * @param {number} [maxHeatSetpointLimit] - The maximum heat setpoint limit value. Defaults to 50°.
2512
- * @returns {ThermostatClusterServer} A default thermostat cluster server configured with the specified parameters.
2513
- */
2514
- getDefaultHeatingThermostatClusterServer(localTemperature = 23, occupiedHeatingSetpoint = 21, minHeatSetpointLimit = 0, maxHeatSetpointLimit = 50) {
2515
- return ClusterServer(ThermostatCluster.with(Thermostat.Feature.Heating), {
2516
- localTemperature: localTemperature * 100,
2517
- systemMode: Thermostat.SystemMode.Heat,
2518
- controlSequenceOfOperation: Thermostat.ControlSequenceOfOperation.HeatingOnly,
2519
- // Thermostat.Feature.Heating
2520
- occupiedHeatingSetpoint: occupiedHeatingSetpoint * 100,
2521
- minHeatSetpointLimit: minHeatSetpointLimit * 100,
2522
- maxHeatSetpointLimit: maxHeatSetpointLimit * 100,
2523
- absMinHeatSetpointLimit: minHeatSetpointLimit * 100,
2524
- absMaxHeatSetpointLimit: maxHeatSetpointLimit * 100,
2525
- }, {
2526
- setpointRaiseLower: async (data) => {
2527
- // Never called in edge
2528
- },
2529
- }, {});
2530
- }
2531
- /**
2532
- * Creates and adds a default heating thermostat cluster server to the device.
2533
- *
2534
- * @param {number} [localTemperature] - The local temperature value in degrees Celsius. Defaults to 23°.
2535
- * @param {number} [occupiedHeatingSetpoint] - The occupied heating setpoint value in degrees Celsius. Defaults to 21°.
2536
- * @param {number} [minHeatSetpointLimit] - The minimum heat setpoint limit value. Defaults to 0°.
2537
- * @param {number} [maxHeatSetpointLimit] - The maximum heat setpoint limit value. Defaults to 50°.
2538
- */
2539
- createDefaultHeatingThermostatClusterServer(localTemperature = 23, occupiedHeatingSetpoint = 25, minHeatSetpointLimit = 0, maxHeatSetpointLimit = 50) {
2540
- this.addClusterServer(this.getDefaultHeatingThermostatClusterServer(localTemperature, occupiedHeatingSetpoint, minHeatSetpointLimit, maxHeatSetpointLimit));
2541
- }
2542
- /**
2543
- * Get a default cooling thermostat cluster server with the specified parameters.
2544
- * @param {number} [localTemperature] - The local temperature value in degrees Celsius. Defaults to 23°.
2545
- * @param {number} [occupiedCoolingSetpoint] - The occupied cooling setpoint value in degrees Celsius. Defaults to 25°.
2546
- * @param {number} [minCoolSetpointLimit] - The minimum cool setpoint limit value. Defaults to 0°.
2547
- * @param {number} [maxCoolSetpointLimit] - The maximum cool setpoint limit value. Defaults to 50°.
2548
- * @returns {ThermostatClusterServer} A default thermostat cluster server configured with the specified parameters.
2549
- */
2550
- getDefaultCoolingThermostatClusterServer(localTemperature = 23, occupiedCoolingSetpoint = 25, minCoolSetpointLimit = 0, maxCoolSetpointLimit = 50) {
2551
- return ClusterServer(ThermostatCluster.with(Thermostat.Feature.Cooling), {
2552
- localTemperature: localTemperature * 100,
2553
- systemMode: Thermostat.SystemMode.Cool,
2554
- controlSequenceOfOperation: Thermostat.ControlSequenceOfOperation.CoolingOnly,
2555
- // Thermostat.Feature.Cooling
2556
- occupiedCoolingSetpoint: occupiedCoolingSetpoint * 100,
2557
- minCoolSetpointLimit: minCoolSetpointLimit * 100,
2558
- maxCoolSetpointLimit: maxCoolSetpointLimit * 100,
2559
- absMinCoolSetpointLimit: minCoolSetpointLimit * 100,
2560
- absMaxCoolSetpointLimit: maxCoolSetpointLimit * 100,
2561
- }, {
2562
- setpointRaiseLower: async (data) => {
2563
- // Never called in edge
2564
- },
2565
- }, {});
2566
- }
2567
- /**
2568
- * Creates and adds a default cooling thermostat cluster server to the device.
2569
- *
2570
- * @param {number} [localTemperature] - The local temperature value in degrees Celsius. Defaults to 23°.
2571
- * @param {number} [occupiedCoolingSetpoint] - The occupied cooling setpoint value in degrees Celsius. Defaults to 25°.
2572
- * @param {number} [minCoolSetpointLimit] - The minimum cool setpoint limit value. Defaults to 0°.
2573
- * @param {number} [maxCoolSetpointLimit] - The maximum cool setpoint limit value. Defaults to 50°.
2574
- */
2575
- createDefaultCoolingThermostatClusterServer(localTemperature = 23, occupiedCoolingSetpoint = 25, minCoolSetpointLimit = 0, maxCoolSetpointLimit = 50) {
2576
- this.addClusterServer(this.getDefaultCoolingThermostatClusterServer(localTemperature, occupiedCoolingSetpoint, minCoolSetpointLimit, maxCoolSetpointLimit));
2577
- }
2578
- /**
2579
- * Get a default thermostat cluster server with the specified parameters.
2580
- *
2581
- * @param {number} [localTemperature=23] - The local temperature value in degrees Celsius. Defaults to 23°.
2582
- * @param {number} [occupiedHeatingSetpoint=21] - The occupied heating setpoint value in degrees Celsius. Defaults to 21°.
2583
- * @param {number} [occupiedCoolingSetpoint=25] - The occupied cooling setpoint value in degrees Celsius. Defaults to 25°.
2584
- * @param {number} [minSetpointDeadBand=1] - The minimum setpoint dead band value. Defaults to 1°.
2585
- * @param {number} [minHeatSetpointLimit=0] - The minimum heat setpoint limit value. Defaults to 0°.
2586
- * @param {number} [maxHeatSetpointLimit=50] - The maximum heat setpoint limit value. Defaults to 50°.
2587
- * @param {number} [minCoolSetpointLimit=0] - The minimum cool setpoint limit value. Defaults to 0°.
2588
- * @param {number} [maxCoolSetpointLimit=50] - The maximum cool setpoint limit value. Defaults to 50°.
2589
- * @returns {ThermostatClusterServer} A default thermostat cluster server configured with the specified parameters.
2590
- */
2591
- getDefaultThermostatClusterServer(localTemperature = 23, occupiedHeatingSetpoint = 21, occupiedCoolingSetpoint = 25, minSetpointDeadBand = 1, minHeatSetpointLimit = 0, maxHeatSetpointLimit = 50, minCoolSetpointLimit = 0, maxCoolSetpointLimit = 50) {
2592
- return ClusterServer(ThermostatCluster.with(Thermostat.Feature.Heating, Thermostat.Feature.Cooling, Thermostat.Feature.AutoMode), {
2593
- localTemperature: localTemperature * 100,
2594
- systemMode: Thermostat.SystemMode.Auto,
2595
- controlSequenceOfOperation: Thermostat.ControlSequenceOfOperation.CoolingAndHeating,
2596
- // Thermostat.Feature.Heating
2597
- occupiedHeatingSetpoint: occupiedHeatingSetpoint * 100,
2598
- minHeatSetpointLimit: minHeatSetpointLimit * 100,
2599
- maxHeatSetpointLimit: maxHeatSetpointLimit * 100,
2600
- absMinHeatSetpointLimit: minHeatSetpointLimit * 100,
2601
- absMaxHeatSetpointLimit: maxHeatSetpointLimit * 100,
2602
- // Thermostat.Feature.Cooling
2603
- occupiedCoolingSetpoint: occupiedCoolingSetpoint * 100,
2604
- minCoolSetpointLimit: minCoolSetpointLimit * 100,
2605
- maxCoolSetpointLimit: maxCoolSetpointLimit * 100,
2606
- absMinCoolSetpointLimit: minCoolSetpointLimit * 100,
2607
- absMaxCoolSetpointLimit: maxCoolSetpointLimit * 100,
2608
- // Thermostat.Feature.AutoMode
2609
- minSetpointDeadBand: minSetpointDeadBand * 100,
2610
- thermostatRunningMode: Thermostat.ThermostatRunningMode.Off,
2611
- }, {
2612
- setpointRaiseLower: async (data) => {
2613
- // Never called in edge
2614
- },
2615
- }, {});
2616
- }
2617
- /**
2618
- * Creates and adds a default thermostat cluster server to the device.
2619
- *
2620
- * @param {number} [localTemperature=23] - The local temperature value in degrees Celsius. Defaults to 23°.
2621
- * @param {number} [occupiedHeatingSetpoint=21] - The occupied heating setpoint value in degrees Celsius. Defaults to 21°.
2622
- * @param {number} [occupiedCoolingSetpoint=25] - The occupied cooling setpoint value in degrees Celsius. Defaults to 25°.
2623
- * @param {number} [minSetpointDeadBand=1] - The minimum setpoint dead band value. Defaults to 1°.
2624
- * @param {number} [minHeatSetpointLimit=0] - The minimum heat setpoint limit value. Defaults to 0°.
2625
- * @param {number} [maxHeatSetpointLimit=50] - The maximum heat setpoint limit value. Defaults to 50°.
2626
- * @param {number} [minCoolSetpointLimit=0] - The minimum cool setpoint limit value. Defaults to 0°.
2627
- * @param {number} [maxCoolSetpointLimit=50] - The maximum cool setpoint limit value. Defaults to 50°.
2628
- */
2629
- createDefaultThermostatClusterServer(localTemperature = 23, occupiedHeatingSetpoint = 21, occupiedCoolingSetpoint = 25, minSetpointDeadBand = 1, minHeatSetpointLimit = 0, maxHeatSetpointLimit = 50, minCoolSetpointLimit = 0, maxCoolSetpointLimit = 50) {
2630
- this.addClusterServer(this.getDefaultThermostatClusterServer(localTemperature, occupiedHeatingSetpoint, occupiedCoolingSetpoint, minSetpointDeadBand, minHeatSetpointLimit, maxHeatSetpointLimit, minCoolSetpointLimit, maxCoolSetpointLimit));
2631
- }
2632
- /**
2633
- * Returns the default SmokeCOAlarm Cluster Server.
2634
- *
2635
- * @param smokeState - The state of the smoke alarm. Defaults to SmokeCoAlarm.AlarmState.Normal.
2636
- * @param coState - The state of the CO alarm. Defaults to SmokeCoAlarm.AlarmState.Normal.
2637
- * @returns The default SmokeCOAlarmClusterServer.
2638
- */
2639
- getDefaultSmokeCOAlarmClusterServer(smokeState = SmokeCoAlarm.AlarmState.Normal, coState = SmokeCoAlarm.AlarmState.Normal) {
2640
- return ClusterServer(SmokeCoAlarmCluster.with(SmokeCoAlarm.Feature.SmokeAlarm, SmokeCoAlarm.Feature.CoAlarm), {
2641
- smokeState,
2642
- coState,
2643
- expressedState: SmokeCoAlarm.ExpressedState.Normal,
2644
- batteryAlert: SmokeCoAlarm.AlarmState.Normal,
2645
- deviceMuted: SmokeCoAlarm.MuteState.NotMuted,
2646
- testInProgress: false,
2647
- hardwareFaultAlert: false,
2648
- endOfServiceAlert: SmokeCoAlarm.EndOfService.Normal,
2649
- interconnectSmokeAlarm: SmokeCoAlarm.AlarmState.Normal,
2650
- interconnectCoAlarm: SmokeCoAlarm.AlarmState.Normal,
2651
- }, {
2652
- selfTestRequest: async (data) => {
2653
- // Never called in edge
2654
- },
2655
- }, {
2656
- smokeAlarm: true,
2657
- interconnectSmokeAlarm: true,
2658
- coAlarm: true,
2659
- interconnectCoAlarm: true,
2660
- lowBattery: true,
2661
- hardwareFault: true,
2662
- endOfService: true,
2663
- selfTestComplete: true,
2664
- alarmMuted: true,
2665
- muteEnded: true,
2666
- allClear: true,
994
+ createDefaultPressureMeasurementClusterServer(measuredValue = 1000) {
995
+ this.behaviors.require(PressureMeasurementServer, getDefaultPressureMeasurementClusterServer(measuredValue));
996
+ return this;
997
+ }
998
+ createDefaultIlluminanceMeasurementClusterServer(measuredValue = 0) {
999
+ this.behaviors.require(IlluminanceMeasurementServer, getDefaultIlluminanceMeasurementClusterServer(measuredValue));
1000
+ return this;
1001
+ }
1002
+ createDefaultFlowMeasurementClusterServer(measuredValue = 0) {
1003
+ this.behaviors.require(FlowMeasurementServer, getDefaultFlowMeasurementClusterServer(measuredValue));
1004
+ return this;
1005
+ }
1006
+ createDefaultOccupancySensingClusterServer(occupied = false) {
1007
+ this.behaviors.require(OccupancySensingServer, getDefaultOccupancySensingClusterServer(occupied));
1008
+ return this;
1009
+ }
1010
+ createDefaultAirQualityClusterServer(airQuality = AirQuality.AirQualityEnum.Unknown) {
1011
+ this.behaviors.require(AirQualityServer.with(AirQuality.Feature.Fair, AirQuality.Feature.Moderate, AirQuality.Feature.VeryPoor, AirQuality.Feature.ExtremelyPoor), {
1012
+ airQuality,
2667
1013
  });
1014
+ return this;
2668
1015
  }
2669
- /**
2670
- * Create the default SmokeCOAlarm Cluster Server.
2671
- *
2672
- * @param smokeState - The state of the smoke alarm. Defaults to SmokeCoAlarm.AlarmState.Normal.
2673
- * @param coState - The state of the CO alarm. Defaults to SmokeCoAlarm.AlarmState.Normal.
2674
- * @returns The default SmokeCOAlarmClusterServer.
2675
- */
2676
- createDefaultSmokeCOAlarmClusterServer(smokeState = SmokeCoAlarm.AlarmState.Normal, coState = SmokeCoAlarm.AlarmState.Normal) {
2677
- this.addClusterServer(this.getDefaultSmokeCOAlarmClusterServer(smokeState, coState));
2678
- }
2679
- /**
2680
- * Returns the default Carbon Monoxide Concentration Measurement Cluster Server.
2681
- *
2682
- * @param {number} measuredValue - The measured value of the concentration.
2683
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2684
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2685
- * @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
2686
- */
2687
- getDefaultCarbonMonoxideConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2688
- return ClusterServer(CarbonMonoxideConcentrationMeasurementCluster.with('NumericMeasurement'), {
1016
+ createDefaultTvocMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
1017
+ this.behaviors.require(TotalVolatileOrganicCompoundsConcentrationMeasurementServer.with(ConcentrationMeasurement.Feature.NumericMeasurement), {
2689
1018
  measuredValue,
2690
1019
  minMeasuredValue: null,
2691
1020
  maxMeasuredValue: null,
2692
1021
  uncertainty: 0,
2693
1022
  measurementUnit,
2694
1023
  measurementMedium,
2695
- }, {}, {});
2696
- }
2697
- /**
2698
- * Create the default Carbon Monoxide Concentration Measurement Cluster Server.
2699
- *
2700
- * @param {number} measuredValue - The measured value of the concentration.
2701
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2702
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2703
- */
1024
+ });
1025
+ return this;
1026
+ }
2704
1027
  createDefaultCarbonMonoxideConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2705
- this.addClusterServer(this.getDefaultCarbonMonoxideConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
2706
- }
2707
- /**
2708
- * Returns the default Carbon Dioxide Concentration Measurement Cluster Server.
2709
- *
2710
- * @param {number} measuredValue - The measured value of the concentration.
2711
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2712
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2713
- * @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
2714
- */
2715
- getDefaultCarbonDioxideConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2716
- return ClusterServer(CarbonDioxideConcentrationMeasurementCluster.with('NumericMeasurement'), {
1028
+ this.behaviors.require(CarbonMonoxideConcentrationMeasurementServer.with(ConcentrationMeasurement.Feature.NumericMeasurement), {
2717
1029
  measuredValue,
2718
1030
  minMeasuredValue: null,
2719
1031
  maxMeasuredValue: null,
2720
1032
  uncertainty: 0,
2721
1033
  measurementUnit,
2722
1034
  measurementMedium,
2723
- }, {}, {});
2724
- }
2725
- /**
2726
- * Create the default Carbon Dioxide Concentration Measurement Cluster Server.
2727
- *
2728
- * @param {number} measuredValue - The measured value of the concentration.
2729
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2730
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2731
- */
1035
+ });
1036
+ return this;
1037
+ }
2732
1038
  createDefaultCarbonDioxideConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2733
- this.addClusterServer(this.getDefaultCarbonDioxideConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
2734
- }
2735
- /**
2736
- * Returns the default Formaldehyde Concentration Measurement Cluster Server.
2737
- *
2738
- * @param {number} measuredValue - The measured value of the concentration.
2739
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2740
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2741
- * @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
2742
- */
2743
- getDefaultFormaldehydeConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2744
- return ClusterServer(FormaldehydeConcentrationMeasurementCluster.with('NumericMeasurement'), {
1039
+ this.behaviors.require(CarbonDioxideConcentrationMeasurementServer.with(ConcentrationMeasurement.Feature.NumericMeasurement), {
2745
1040
  measuredValue,
2746
1041
  minMeasuredValue: null,
2747
1042
  maxMeasuredValue: null,
2748
1043
  uncertainty: 0,
2749
1044
  measurementUnit,
2750
1045
  measurementMedium,
2751
- }, {}, {});
2752
- }
2753
- /**
2754
- * Create the default Formaldehyde Concentration Measurement Cluster Server.
2755
- *
2756
- * @param {number} measuredValue - The measured value of the concentration.
2757
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2758
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2759
- */
1046
+ });
1047
+ return this;
1048
+ }
2760
1049
  createDefaultFormaldehydeConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2761
- this.addClusterServer(this.getDefaultFormaldehydeConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
2762
- }
2763
- /**
2764
- * Returns the default Pm1 Concentration Measurement Cluster Server.
2765
- *
2766
- * @param {number} measuredValue - The measured value of the concentration.
2767
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2768
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2769
- * @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
2770
- */
2771
- getDefaultPm1ConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2772
- return ClusterServer(Pm1ConcentrationMeasurementCluster.with('NumericMeasurement'), {
1050
+ this.behaviors.require(FormaldehydeConcentrationMeasurementServer.with(ConcentrationMeasurement.Feature.NumericMeasurement), {
2773
1051
  measuredValue,
2774
1052
  minMeasuredValue: null,
2775
1053
  maxMeasuredValue: null,
2776
1054
  uncertainty: 0,
2777
1055
  measurementUnit,
2778
1056
  measurementMedium,
2779
- }, {}, {});
2780
- }
2781
- /**
2782
- * Create the default Pm1 Concentration Measurement Cluster Server.
2783
- *
2784
- * @param {number} measuredValue - The measured value of the concentration.
2785
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2786
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2787
- */
1057
+ });
1058
+ return this;
1059
+ }
2788
1060
  createDefaultPm1ConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2789
- this.addClusterServer(this.getDefaultPm1ConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
2790
- }
2791
- /**
2792
- * Returns the default Pm25 Concentration Measurement Cluster Server.
2793
- *
2794
- * @param {number} measuredValue - The measured value of the concentration.
2795
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2796
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2797
- * @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
2798
- */
2799
- getDefaultPm25ConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2800
- return ClusterServer(Pm25ConcentrationMeasurementCluster.with('NumericMeasurement'), {
1061
+ this.behaviors.require(Pm1ConcentrationMeasurementServer.with(ConcentrationMeasurement.Feature.NumericMeasurement), {
2801
1062
  measuredValue,
2802
1063
  minMeasuredValue: null,
2803
1064
  maxMeasuredValue: null,
2804
1065
  uncertainty: 0,
2805
1066
  measurementUnit,
2806
1067
  measurementMedium,
2807
- }, {}, {});
2808
- }
2809
- /**
2810
- * Create the default Pm25 Concentration Measurement Cluster Server.
2811
- *
2812
- * @param {number} measuredValue - The measured value of the concentration.
2813
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2814
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2815
- */
1068
+ });
1069
+ return this;
1070
+ }
2816
1071
  createDefaultPm25ConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2817
- this.addClusterServer(this.getDefaultPm25ConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
2818
- }
2819
- /**
2820
- * Returns the default Pm10 Concentration Measurement Cluster Server.
2821
- *
2822
- * @param {number} measuredValue - The measured value of the concentration.
2823
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2824
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2825
- * @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
2826
- */
2827
- getDefaultPm10ConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2828
- return ClusterServer(Pm10ConcentrationMeasurementCluster.with('NumericMeasurement'), {
1072
+ this.behaviors.require(Pm25ConcentrationMeasurementServer.with(ConcentrationMeasurement.Feature.NumericMeasurement), {
2829
1073
  measuredValue,
2830
1074
  minMeasuredValue: null,
2831
1075
  maxMeasuredValue: null,
2832
1076
  uncertainty: 0,
2833
1077
  measurementUnit,
2834
1078
  measurementMedium,
2835
- }, {}, {});
2836
- }
2837
- /**
2838
- * Create the default Pm10 Concentration Measurement Cluster Server.
2839
- *
2840
- * @param {number} measuredValue - The measured value of the concentration.
2841
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2842
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2843
- */
1079
+ });
1080
+ return this;
1081
+ }
2844
1082
  createDefaultPm10ConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2845
- this.addClusterServer(this.getDefaultPm10ConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
2846
- }
2847
- /**
2848
- * Returns the default Ozone Concentration Measurement Cluster Server.
2849
- *
2850
- * @param {number} measuredValue - The measured value of the concentration.
2851
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2852
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2853
- * @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
2854
- */
2855
- getDefaultOzoneConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ugm3, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2856
- return ClusterServer(OzoneConcentrationMeasurementCluster.with('NumericMeasurement'), {
1083
+ this.behaviors.require(Pm10ConcentrationMeasurementServer.with(ConcentrationMeasurement.Feature.NumericMeasurement), {
2857
1084
  measuredValue,
2858
1085
  minMeasuredValue: null,
2859
1086
  maxMeasuredValue: null,
2860
1087
  uncertainty: 0,
2861
1088
  measurementUnit,
2862
1089
  measurementMedium,
2863
- }, {}, {});
2864
- }
2865
- /**
2866
- * Create the default Ozone Concentration Measurement Cluster Server.
2867
- *
2868
- * @param {number} measuredValue - The measured value of the concentration.
2869
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2870
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2871
- */
1090
+ });
1091
+ return this;
1092
+ }
2872
1093
  createDefaultOzoneConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ugm3, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2873
- this.addClusterServer(this.getDefaultOzoneConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
2874
- }
2875
- /**
2876
- * Returns the default Radon Concentration Measurement Cluster Server.
2877
- *
2878
- * @param {number} measuredValue - The measured value of the concentration.
2879
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2880
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2881
- * @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
2882
- */
2883
- getDefaultRadonConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2884
- return ClusterServer(RadonConcentrationMeasurementCluster.with('NumericMeasurement'), {
1094
+ this.behaviors.require(OzoneConcentrationMeasurementServer.with(ConcentrationMeasurement.Feature.NumericMeasurement), {
2885
1095
  measuredValue,
2886
1096
  minMeasuredValue: null,
2887
1097
  maxMeasuredValue: null,
2888
1098
  uncertainty: 0,
2889
1099
  measurementUnit,
2890
1100
  measurementMedium,
2891
- }, {}, {});
2892
- }
2893
- /**
2894
- * Create the default Radon Concentration Measurement Cluster Server.
2895
- *
2896
- * @param {number} measuredValue - The measured value of the concentration.
2897
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2898
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2899
- */
1101
+ });
1102
+ return this;
1103
+ }
2900
1104
  createDefaultRadonConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ppm, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2901
- this.addClusterServer(this.getDefaultRadonConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
2902
- }
2903
- /**
2904
- * Returns the default Nitrogen Dioxide Concentration Measurement Cluster Server.
2905
- *
2906
- * @param {number} measuredValue - The measured value of the concentration.
2907
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2908
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2909
- * @returns {ClusterServer} - The default Carbon Monoxide Concentration Measurement Cluster Server.
2910
- */
2911
- getDefaultNitrogenDioxideConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ugm3, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2912
- return ClusterServer(NitrogenDioxideConcentrationMeasurementCluster.with('NumericMeasurement'), {
1105
+ this.behaviors.require(RadonConcentrationMeasurementServer.with(ConcentrationMeasurement.Feature.NumericMeasurement), {
2913
1106
  measuredValue,
2914
1107
  minMeasuredValue: null,
2915
1108
  maxMeasuredValue: null,
2916
1109
  uncertainty: 0,
2917
1110
  measurementUnit,
2918
1111
  measurementMedium,
2919
- }, {}, {});
2920
- }
2921
- /**
2922
- * Create the default Nitrogen Dioxide Concentration Measurement Cluster Server.
2923
- *
2924
- * @param {number} measuredValue - The measured value of the concentration.
2925
- * @param {ConcentrationMeasurement.MeasurementUnit} measurementUnit - The unit of measurement.
2926
- * @param {ConcentrationMeasurement.MeasurementMedium} measurementMedium - The medium of measurement.
2927
- */
1112
+ });
1113
+ return this;
1114
+ }
2928
1115
  createDefaultNitrogenDioxideConcentrationMeasurementClusterServer(measuredValue = 0, measurementUnit = ConcentrationMeasurement.MeasurementUnit.Ugm3, measurementMedium = ConcentrationMeasurement.MeasurementMedium.Air) {
2929
- this.addClusterServer(this.getDefaultNitrogenDioxideConcentrationMeasurementClusterServer(measuredValue, measurementUnit, measurementMedium));
2930
- }
2931
- /**
2932
- * Returns the default fan control cluster server rev 2.
2933
- *
2934
- * @param fanMode The fan mode to set. Defaults to `FanControl.FanMode.Off`.
2935
- * @returns The default fan control cluster server.
2936
- */
2937
- getDefaultFanControlClusterServer(fanMode = FanControl.FanMode.Off) {
2938
- return ClusterServer(FanControlCluster.with(FanControl.Feature.MultiSpeed, FanControl.Feature.Auto, FanControl.Feature.Step), {
2939
- fanMode,
2940
- fanModeSequence: FanControl.FanModeSequence.OffLowMedHighAuto,
2941
- percentSetting: 0,
2942
- percentCurrent: 0,
2943
- speedMax: 100,
2944
- speedSetting: 0,
2945
- speedCurrent: 0,
2946
- }, {
2947
- step: async (data) => {
2948
- // Never called in edge
2949
- },
2950
- }, {});
2951
- }
2952
- /**
2953
- * Create the default fan control cluster server rev 2.
2954
- *
2955
- * @param fanMode The fan mode to set. Defaults to `FanControl.FanMode.Off`.
2956
- * @returns The default fan control cluster server.
2957
- */
2958
- createDefaultFanControlClusterServer(fanMode = FanControl.FanMode.Off) {
2959
- this.addClusterServer(this.getDefaultFanControlClusterServer(fanMode));
2960
- }
2961
- /**
2962
- * Returns the default Pump Configuration And Control cluster server.
2963
- *
2964
- * @param {PumpConfigurationAndControl.OperationMode} [pumpMode=PumpConfigurationAndControl.OperationMode.Normal] - The pump mode to set. Defaults to `PumpConfigurationAndControl.OperationMode.Normal`.
2965
- * @returns {ClusterServer} - The default Pump Configuration And Control cluster server.
2966
- */
2967
- getDefaultPumpConfigurationAndControlClusterServer(pumpMode = PumpConfigurationAndControl.OperationMode.Normal) {
2968
- return ClusterServer(PumpConfigurationAndControlCluster.with(PumpConfigurationAndControl.Feature.ConstantSpeed), {
2969
- minConstSpeed: null,
2970
- maxConstSpeed: null,
2971
- maxPressure: null,
2972
- maxSpeed: null,
2973
- maxFlow: null,
2974
- effectiveOperationMode: pumpMode,
2975
- effectiveControlMode: PumpConfigurationAndControl.ControlMode.ConstantSpeed,
2976
- capacity: null,
2977
- operationMode: pumpMode,
2978
- }, {}, {});
2979
- }
2980
- /**
2981
- * Creates the default Pump Configuration And Control cluster server.
2982
- *
2983
- * @param {PumpConfigurationAndControl.OperationMode} [pumpMode=PumpConfigurationAndControl.OperationMode.Normal] - The pump mode to set. Defaults to `PumpConfigurationAndControl.OperationMode.Normal`.
2984
- * @returns {void}
2985
- */
2986
- createDefaultPumpConfigurationAndControlClusterServer(pumpMode = PumpConfigurationAndControl.OperationMode.Normal) {
2987
- this.addClusterServer(this.getDefaultPumpConfigurationAndControlClusterServer(pumpMode));
2988
- }
2989
- /**
2990
- * Returns the default Valve Configuration And Control cluster server rev 2.
2991
- *
2992
- * @param {ValveConfigurationAndControl.ValveState} [valveState=ValveConfigurationAndControl.ValveState.Closed] - The valve state to set. Defaults to `ValveConfigurationAndControl.ValveState.Closed`.
2993
- * @param {number} [valveLevel=0] - The valve level to set. Defaults to 0.
2994
- * @returns {ClusterServer} - The default Valve Configuration And Control cluster server.
2995
- */
2996
- getDefaultValveConfigurationAndControlClusterServer(valveState = ValveConfigurationAndControl.ValveState.Closed, valveLevel = 0) {
2997
- return ClusterServer(ValveConfigurationAndControlCluster.with(ValveConfigurationAndControl.Feature.Level), {
2998
- currentState: valveState,
2999
- targetState: valveState,
3000
- currentLevel: valveLevel,
3001
- targetLevel: valveLevel,
3002
- openDuration: null,
3003
- defaultOpenDuration: null,
3004
- remainingDuration: null,
3005
- }, {
3006
- open: async (data) => {
3007
- // Never called in edge
3008
- },
3009
- close: async (data) => {
3010
- // Never called in edge
3011
- },
3012
- }, {});
3013
- }
3014
- /**
3015
- * Create the default Valve Configuration And Control cluster server rev 2.
3016
- *
3017
- * @param {ValveConfigurationAndControl.ValveState} [valveState=ValveConfigurationAndControl.ValveState.Closed] - The valve state to set. Defaults to `ValveConfigurationAndControl.ValveState.Closed`.
3018
- * @param {number} [valveLevel=0] - The valve level to set. Defaults to 0.
3019
- * @returns {void}
3020
- */
3021
- createDefaultValveConfigurationAndControlClusterServer(valveState = ValveConfigurationAndControl.ValveState.Closed, valveLevel = 0) {
3022
- this.addClusterServer(this.getDefaultValveConfigurationAndControlClusterServer(valveState, valveLevel));
1116
+ this.behaviors.require(NitrogenDioxideConcentrationMeasurementServer.with(ConcentrationMeasurement.Feature.NumericMeasurement), {
1117
+ measuredValue,
1118
+ minMeasuredValue: null,
1119
+ maxMeasuredValue: null,
1120
+ uncertainty: 0,
1121
+ measurementUnit,
1122
+ measurementMedium,
1123
+ });
1124
+ return this;
3023
1125
  }
3024
1126
  }
3025
- //# sourceMappingURL=matterbridgeEndpoint.js.map