@matterbridge/core 3.7.2-dev-20260328-c77b608 → 3.7.2-dev-20260330-bb55c39

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 (76) hide show
  1. package/dist/behaviors/activatedCarbonFilterMonitoringServer.d.ts +8 -0
  2. package/dist/behaviors/activatedCarbonFilterMonitoringServer.js +20 -0
  3. package/dist/{matterbridgeBehaviorsClient.js → behaviors/bindingServer.js} +1 -1
  4. package/dist/behaviors/booleanStateConfigurationServer.d.ts +7 -0
  5. package/dist/behaviors/booleanStateConfigurationServer.js +18 -0
  6. package/dist/behaviors/colorControlServer.d.ts +788 -0
  7. package/dist/behaviors/colorControlServer.js +105 -0
  8. package/dist/behaviors/deviceEnergyManagementModeServer.d.ts +5 -0
  9. package/dist/behaviors/deviceEnergyManagementModeServer.js +42 -0
  10. package/dist/behaviors/deviceEnergyManagementServer.d.ts +306 -0
  11. package/dist/behaviors/deviceEnergyManagementServer.js +31 -0
  12. package/dist/behaviors/doorLockServer.d.ts +28 -0
  13. package/dist/behaviors/doorLockServer.js +97 -0
  14. package/dist/behaviors/export.d.ts +24 -1
  15. package/dist/behaviors/export.js +24 -1
  16. package/dist/behaviors/fanControlServer.d.ts +7 -0
  17. package/dist/behaviors/fanControlServer.js +35 -0
  18. package/dist/behaviors/hepaFilterMonitoringServer.d.ts +8 -0
  19. package/dist/behaviors/hepaFilterMonitoringServer.js +20 -0
  20. package/dist/behaviors/identifyServer.d.ts +6 -0
  21. package/dist/behaviors/identifyServer.js +32 -0
  22. package/dist/behaviors/levelControlServer.d.ts +6 -0
  23. package/dist/behaviors/levelControlServer.js +32 -0
  24. package/dist/behaviors/matterbridgeServer.d.ts +14 -0
  25. package/dist/behaviors/matterbridgeServer.js +15 -0
  26. package/dist/behaviors/modeSelectServer.d.ts +5 -0
  27. package/dist/behaviors/modeSelectServer.js +18 -0
  28. package/dist/behaviors/onOffServer.d.ts +6 -0
  29. package/dist/behaviors/onOffServer.js +46 -0
  30. package/dist/behaviors/operationalStateServer.d.ts +10 -0
  31. package/dist/behaviors/operationalStateServer.js +84 -0
  32. package/dist/behaviors/pinDoorLockServer.d.ts +32 -0
  33. package/dist/behaviors/pinDoorLockServer.js +168 -0
  34. package/dist/behaviors/powerSourceServer.d.ts +4 -0
  35. package/dist/behaviors/powerSourceServer.js +21 -0
  36. package/dist/behaviors/serviceAreaServer.d.ts +5 -0
  37. package/dist/behaviors/serviceAreaServer.js +18 -0
  38. package/dist/behaviors/smokeCoAlarmServer.d.ts +83 -0
  39. package/dist/behaviors/smokeCoAlarmServer.js +18 -0
  40. package/dist/behaviors/switchServer.d.ts +4 -0
  41. package/dist/behaviors/switchServer.js +8 -0
  42. package/dist/behaviors/thermostatServer.d.ts +732 -0
  43. package/dist/behaviors/thermostatServer.js +50 -0
  44. package/dist/behaviors/userPinDoorLockServer.d.ts +57 -0
  45. package/dist/behaviors/userPinDoorLockServer.js +348 -0
  46. package/dist/behaviors/valveConfigurationAndControlServer.d.ts +8 -0
  47. package/dist/behaviors/valveConfigurationAndControlServer.js +44 -0
  48. package/dist/behaviors/windowCoveringServer.d.ts +583 -0
  49. package/dist/behaviors/windowCoveringServer.js +96 -0
  50. package/dist/devices/basicVideoPlayer.js +2 -1
  51. package/dist/devices/castingVideoPlayer.js +1 -1
  52. package/dist/devices/closure.js +1 -1
  53. package/dist/devices/closurePanel.js +1 -1
  54. package/dist/devices/dishwasher.js +2 -1
  55. package/dist/devices/evse.js +1 -1
  56. package/dist/devices/laundryWasher.js +2 -1
  57. package/dist/devices/microwaveOven.js +2 -1
  58. package/dist/devices/oven.js +1 -1
  59. package/dist/devices/refrigerator.js +1 -1
  60. package/dist/devices/roboticVacuumCleaner.js +2 -1
  61. package/dist/devices/temperatureControl.js +1 -1
  62. package/dist/devices/waterHeater.js +1 -1
  63. package/dist/export.d.ts +24 -1
  64. package/dist/export.js +24 -1
  65. package/dist/frontend.js +2 -0
  66. package/dist/matterbridge.d.ts +1 -0
  67. package/dist/matterbridge.js +11 -0
  68. package/dist/matterbridgeEndpoint.d.ts +12 -1
  69. package/dist/matterbridgeEndpoint.js +22 -1
  70. package/dist/matterbridgeEndpointCommandHandler.d.ts +5 -1
  71. package/dist/matterbridgeEndpointHelpers.d.ts +5 -1
  72. package/dist/matterbridgeEndpointHelpers.js +24 -1
  73. package/package.json +9 -5
  74. package/dist/matterbridgeBehaviorsServer.d.ts +0 -2687
  75. package/dist/matterbridgeBehaviorsServer.js +0 -1222
  76. /package/dist/{matterbridgeBehaviorsClient.d.ts → behaviors/bindingServer.d.ts} +0 -0
@@ -1,1222 +0,0 @@
1
- import { Behavior } from '@matter/node';
2
- import { ActivatedCarbonFilterMonitoringServer } from '@matter/node/behaviors/activated-carbon-filter-monitoring';
3
- import { BooleanStateConfigurationServer } from '@matter/node/behaviors/boolean-state-configuration';
4
- import { ColorControlServer } from '@matter/node/behaviors/color-control';
5
- import { DeviceEnergyManagementServer } from '@matter/node/behaviors/device-energy-management';
6
- import { DeviceEnergyManagementModeServer } from '@matter/node/behaviors/device-energy-management-mode';
7
- import { DoorLockServer } from '@matter/node/behaviors/door-lock';
8
- import { FanControlServer } from '@matter/node/behaviors/fan-control';
9
- import { HepaFilterMonitoringServer } from '@matter/node/behaviors/hepa-filter-monitoring';
10
- import { IdentifyServer } from '@matter/node/behaviors/identify';
11
- import { LevelControlServer } from '@matter/node/behaviors/level-control';
12
- import { ModeSelectServer } from '@matter/node/behaviors/mode-select';
13
- import { OnOffServer } from '@matter/node/behaviors/on-off';
14
- import { OperationalStateServer } from '@matter/node/behaviors/operational-state';
15
- import { PowerSourceServer } from '@matter/node/behaviors/power-source';
16
- import { ServiceAreaServer } from '@matter/node/behaviors/service-area';
17
- import { SmokeCoAlarmServer } from '@matter/node/behaviors/smoke-co-alarm';
18
- import { SwitchServer } from '@matter/node/behaviors/switch';
19
- import { ThermostatServer } from '@matter/node/behaviors/thermostat';
20
- import { ValveConfigurationAndControlServer } from '@matter/node/behaviors/valve-configuration-and-control';
21
- import { WindowCoveringServer } from '@matter/node/behaviors/window-covering';
22
- import { BooleanStateConfiguration } from '@matter/types/clusters/boolean-state-configuration';
23
- import { ColorControl } from '@matter/types/clusters/color-control';
24
- import { DeviceEnergyManagement } from '@matter/types/clusters/device-energy-management';
25
- import { DeviceEnergyManagementMode } from '@matter/types/clusters/device-energy-management-mode';
26
- import { DoorLock } from '@matter/types/clusters/door-lock';
27
- import { FanControl } from '@matter/types/clusters/fan-control';
28
- import { ModeBase } from '@matter/types/clusters/mode-base';
29
- import { OperationalState } from '@matter/types/clusters/operational-state';
30
- import { ResourceMonitoring } from '@matter/types/clusters/resource-monitoring';
31
- import { SmokeCoAlarm } from '@matter/types/clusters/smoke-co-alarm';
32
- import { Thermostat } from '@matter/types/clusters/thermostat';
33
- import { ValveConfigurationAndControl } from '@matter/types/clusters/valve-configuration-and-control';
34
- import { WindowCovering } from '@matter/types/clusters/window-covering';
35
- import { StatusResponse } from '@matter/types/common';
36
- import { FabricIndex } from '@matter/types/datatype';
37
- import { Status } from '@matter/types/globals';
38
- import { getEnumDescription } from '@matterbridge/utils';
39
- import { debugStringify } from 'node-ansi-logger';
40
- export class MatterbridgeServer extends Behavior {
41
- static id = 'matterbridge';
42
- initialize() {
43
- this.state.log.debug(`MatterbridgeServer initialized (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
44
- super.initialize();
45
- }
46
- }
47
- (function (MatterbridgeServer) {
48
- class State {
49
- log;
50
- commandHandler;
51
- }
52
- MatterbridgeServer.State = State;
53
- })(MatterbridgeServer || (MatterbridgeServer = {}));
54
- export class MatterbridgePowerSourceServer extends PowerSourceServer {
55
- async initialize() {
56
- await super.initialize();
57
- const device = this.endpoint.stateOf(MatterbridgeServer);
58
- device.log.info(`Initializing MatterbridgePowerSourceServer (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
59
- this.state.endpointList = [this.endpoint.number];
60
- this.endpoint.construction.onSuccess(async () => {
61
- device.log.debug(`MatterbridgePowerSourceServer: endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber} construction completed`);
62
- const endpointList = [this.endpoint.number];
63
- for (const endpoint of this.endpoint.parts) {
64
- if (endpoint.lifecycle.isReady) {
65
- endpointList.push(endpoint.number);
66
- }
67
- }
68
- await this.endpoint.setStateOf(PowerSourceServer, { endpointList });
69
- device.log.debug(`MatterbridgePowerSourceServer: endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber} construction completed with endpointList: ${endpointList.join(', ')}`);
70
- });
71
- }
72
- }
73
- export class MatterbridgeIdentifyServer extends IdentifyServer {
74
- async identify(request) {
75
- const device = this.endpoint.stateOf(MatterbridgeServer);
76
- device.log.info(`Identifying device for ${request.identifyTime} seconds (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
77
- await device.commandHandler.executeHandler('Identify.identify', {
78
- command: 'identify',
79
- request,
80
- cluster: IdentifyServer.id,
81
- attributes: this.state,
82
- endpoint: this.endpoint,
83
- });
84
- device.log.debug(`MatterbridgeIdentifyServer: identify called`);
85
- await super.identify(request);
86
- }
87
- async triggerEffect(request) {
88
- const device = this.endpoint.stateOf(MatterbridgeServer);
89
- device.log.info(`Triggering effect ${request.effectIdentifier} variant ${request.effectVariant} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
90
- await device.commandHandler.executeHandler('Identify.triggerEffect', {
91
- command: 'triggerEffect',
92
- request,
93
- cluster: IdentifyServer.id,
94
- attributes: this.state,
95
- endpoint: this.endpoint,
96
- });
97
- device.log.debug(`MatterbridgeIdentifyServer: triggerEffect called`);
98
- await super.triggerEffect(request);
99
- }
100
- }
101
- export class MatterbridgeOnOffServer extends OnOffServer {
102
- async on() {
103
- const device = this.endpoint.stateOf(MatterbridgeServer);
104
- device.log.info(`Switching device on (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
105
- await device.commandHandler.executeHandler('OnOff.on', {
106
- command: 'on',
107
- request: {},
108
- cluster: OnOffServer.id,
109
- attributes: this.state,
110
- endpoint: this.endpoint,
111
- });
112
- device.log.debug(`MatterbridgeOnOffServer: on called`);
113
- await super.on();
114
- }
115
- async off() {
116
- const device = this.endpoint.stateOf(MatterbridgeServer);
117
- device.log.info(`Switching device off (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
118
- await device.commandHandler.executeHandler('OnOff.off', {
119
- command: 'off',
120
- request: {},
121
- cluster: OnOffServer.id,
122
- attributes: this.state,
123
- endpoint: this.endpoint,
124
- });
125
- device.log.debug(`MatterbridgeOnOffServer: off called`);
126
- await super.off();
127
- }
128
- async toggle() {
129
- const device = this.endpoint.stateOf(MatterbridgeServer);
130
- device.log.info(`Toggle device on/off (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
131
- await device.commandHandler.executeHandler('OnOff.toggle', {
132
- command: 'toggle',
133
- request: {},
134
- cluster: OnOffServer.id,
135
- attributes: this.state,
136
- endpoint: this.endpoint,
137
- });
138
- device.log.debug(`MatterbridgeOnOffServer: toggle called`);
139
- await super.toggle();
140
- }
141
- }
142
- export class MatterbridgeLevelControlServer extends LevelControlServer {
143
- async moveToLevel(request) {
144
- const device = this.endpoint.stateOf(MatterbridgeServer);
145
- device.log.info(`Setting level to ${request.level} with transitionTime ${request.transitionTime} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
146
- await device.commandHandler.executeHandler('LevelControl.moveToLevel', {
147
- command: 'moveToLevel',
148
- request,
149
- cluster: LevelControlServer.id,
150
- attributes: this.state,
151
- endpoint: this.endpoint,
152
- });
153
- device.log.debug(`MatterbridgeLevelControlServer: moveToLevel called`);
154
- await super.moveToLevel(request);
155
- }
156
- async moveToLevelWithOnOff(request) {
157
- const device = this.endpoint.stateOf(MatterbridgeServer);
158
- device.log.info(`Setting level to ${request.level} with transitionTime ${request.transitionTime} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
159
- await device.commandHandler.executeHandler('LevelControl.moveToLevelWithOnOff', {
160
- command: 'moveToLevelWithOnOff',
161
- request,
162
- cluster: LevelControlServer.id,
163
- attributes: this.state,
164
- endpoint: this.endpoint,
165
- });
166
- device.log.debug(`MatterbridgeLevelControlServer: moveToLevelWithOnOff called`);
167
- await super.moveToLevelWithOnOff(request);
168
- }
169
- }
170
- export class MatterbridgeColorControlServer extends ColorControlServer.with(ColorControl.Feature.HueSaturation, ColorControl.Feature.Xy, ColorControl.Feature.ColorTemperature, ColorControl.Feature.EnhancedHue) {
171
- async moveToHue(request) {
172
- const device = this.endpoint.stateOf(MatterbridgeServer);
173
- device.log.info(`Setting hue to ${request.hue} with transitionTime ${request.transitionTime} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
174
- await device.commandHandler.executeHandler('ColorControl.moveToHue', {
175
- command: 'moveToHue',
176
- request,
177
- cluster: ColorControlServer.id,
178
- attributes: this.state,
179
- endpoint: this.endpoint,
180
- });
181
- device.log.debug(`MatterbridgeColorControlServer: moveToHue called`);
182
- await super.moveToHue(request);
183
- }
184
- async enhancedMoveToHue(request) {
185
- const device = this.endpoint.stateOf(MatterbridgeServer);
186
- device.log.info(`Setting enhanced hue to ${request.enhancedHue} with transitionTime ${request.transitionTime} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
187
- await device.commandHandler.executeHandler('ColorControl.enhancedMoveToHue', {
188
- command: 'enhancedMoveToHue',
189
- request,
190
- cluster: ColorControlServer.id,
191
- attributes: this.state,
192
- endpoint: this.endpoint,
193
- });
194
- device.log.debug(`MatterbridgeColorControlServer: enhancedMoveToHue called`);
195
- await super.enhancedMoveToHue(request);
196
- }
197
- async moveToSaturation(request) {
198
- const device = this.endpoint.stateOf(MatterbridgeServer);
199
- device.log.info(`Setting saturation to ${request.saturation} with transitionTime ${request.transitionTime} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
200
- await device.commandHandler.executeHandler('ColorControl.moveToSaturation', {
201
- command: 'moveToSaturation',
202
- request,
203
- cluster: ColorControlServer.id,
204
- attributes: this.state,
205
- endpoint: this.endpoint,
206
- });
207
- device.log.debug(`MatterbridgeColorControlServer: moveToSaturation called`);
208
- await super.moveToSaturation(request);
209
- }
210
- async moveToHueAndSaturation(request) {
211
- const device = this.endpoint.stateOf(MatterbridgeServer);
212
- device.log.info(`Setting hue to ${request.hue} and saturation to ${request.saturation} with transitionTime ${request.transitionTime} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
213
- await device.commandHandler.executeHandler('ColorControl.moveToHueAndSaturation', {
214
- command: 'moveToHueAndSaturation',
215
- request,
216
- cluster: ColorControlServer.id,
217
- attributes: this.state,
218
- endpoint: this.endpoint,
219
- });
220
- device.log.debug(`MatterbridgeColorControlServer: moveToHueAndSaturation called`);
221
- await super.moveToHueAndSaturation(request);
222
- }
223
- async enhancedMoveToHueAndSaturation(request) {
224
- const device = this.endpoint.stateOf(MatterbridgeServer);
225
- device.log.info(`Setting enhanced hue to ${request.enhancedHue} and saturation to ${request.saturation} with transitionTime ${request.transitionTime} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
226
- await device.commandHandler.executeHandler('ColorControl.enhancedMoveToHueAndSaturation', {
227
- command: 'enhancedMoveToHueAndSaturation',
228
- request,
229
- cluster: ColorControlServer.id,
230
- attributes: this.state,
231
- endpoint: this.endpoint,
232
- });
233
- device.log.debug(`MatterbridgeColorControlServer: enhancedMoveToHueAndSaturation called`);
234
- await super.enhancedMoveToHueAndSaturation(request);
235
- }
236
- async moveToColor(request) {
237
- const device = this.endpoint.stateOf(MatterbridgeServer);
238
- device.log.info(`Setting color to ${request.colorX}, ${request.colorY} with transitionTime ${request.transitionTime} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
239
- await device.commandHandler.executeHandler('ColorControl.moveToColor', {
240
- command: 'moveToColor',
241
- request,
242
- cluster: ColorControlServer.id,
243
- attributes: this.state,
244
- endpoint: this.endpoint,
245
- });
246
- device.log.debug(`MatterbridgeColorControlServer: moveToColor called`);
247
- await super.moveToColor(request);
248
- }
249
- async moveToColorTemperature(request) {
250
- const device = this.endpoint.stateOf(MatterbridgeServer);
251
- device.log.info(`Setting color temperature to ${request.colorTemperatureMireds} with transitionTime ${request.transitionTime} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
252
- await device.commandHandler.executeHandler('ColorControl.moveToColorTemperature', {
253
- command: 'moveToColorTemperature',
254
- request,
255
- cluster: ColorControlServer.id,
256
- attributes: this.state,
257
- endpoint: this.endpoint,
258
- });
259
- device.log.debug(`MatterbridgeColorControlServer: moveToColorTemperature called`);
260
- await super.moveToColorTemperature(request);
261
- }
262
- }
263
- export class MatterbridgeEnhancedColorControlServer extends MatterbridgeColorControlServer.with(ColorControl.Feature.HueSaturation, ColorControl.Feature.EnhancedHue, ColorControl.Feature.Xy, ColorControl.Feature.ColorTemperature) {
264
- }
265
- export class MatterbridgeWindowCoveringServer extends WindowCoveringServer.with(WindowCovering.Feature.Lift, WindowCovering.Feature.PositionAwareLift, WindowCovering.Feature.Tilt, WindowCovering.Feature.PositionAwareTilt) {
266
- lookupMovementStatus = ['Stopped', 'Opening', 'Closing', 'Unknown'];
267
- async initialize() {
268
- const device = this.endpoint.stateOf(MatterbridgeServer);
269
- device.log.info(`Initializing MatterbridgeWindowCoveringServer (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
270
- this.internal.disableOperationalModeHandling = true;
271
- await super.initialize();
272
- }
273
- async upOrOpen() {
274
- const device = this.endpoint.stateOf(MatterbridgeServer);
275
- device.log.info(`Opening cover (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
276
- await device.commandHandler.executeHandler('WindowCovering.upOrOpen', {
277
- command: 'upOrOpen',
278
- request: {},
279
- cluster: WindowCoveringServer.id,
280
- attributes: this.state,
281
- endpoint: this.endpoint,
282
- });
283
- device.log.debug(`MatterbridgeWindowCoveringServer: upOrOpen called`);
284
- await super.upOrOpen();
285
- device.log.debug(`MatterbridgeWindowCoveringServer: upOrOpen result target ${this.state.targetPositionLiftPercent100ths} current ${this.state.currentPositionLiftPercent100ths} status global ${this.lookupMovementStatus[this.state.operationalStatus.global ?? 3]} lift ${this.lookupMovementStatus[this.state.operationalStatus.lift ?? 3]} tilt ${this.lookupMovementStatus[this.state.operationalStatus.tilt ?? 3]}`);
286
- }
287
- async downOrClose() {
288
- const device = this.endpoint.stateOf(MatterbridgeServer);
289
- device.log.info(`Closing cover (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
290
- await device.commandHandler.executeHandler('WindowCovering.downOrClose', {
291
- command: 'downOrClose',
292
- request: {},
293
- cluster: WindowCoveringServer.id,
294
- attributes: this.state,
295
- endpoint: this.endpoint,
296
- });
297
- device.log.debug(`MatterbridgeWindowCoveringServer: downOrClose called`);
298
- await super.downOrClose();
299
- device.log.debug(`MatterbridgeWindowCoveringServer: downOrClose result target ${this.state.targetPositionLiftPercent100ths} current ${this.state.currentPositionLiftPercent100ths} status global ${this.lookupMovementStatus[this.state.operationalStatus.global ?? 3]} lift ${this.lookupMovementStatus[this.state.operationalStatus.lift ?? 3]} tilt ${this.lookupMovementStatus[this.state.operationalStatus.tilt ?? 3]}`);
300
- }
301
- async stopMotion() {
302
- const device = this.endpoint.stateOf(MatterbridgeServer);
303
- device.log.info(`Stopping cover (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
304
- await device.commandHandler.executeHandler('WindowCovering.stopMotion', {
305
- command: 'stopMotion',
306
- request: {},
307
- cluster: WindowCoveringServer.id,
308
- attributes: this.state,
309
- endpoint: this.endpoint,
310
- });
311
- device.log.debug(`MatterbridgeWindowCoveringServer: stopMotion called`);
312
- await super.stopMotion();
313
- device.log.debug(`MatterbridgeWindowCoveringServer: stopMotion result target ${this.state.targetPositionLiftPercent100ths} current ${this.state.currentPositionLiftPercent100ths} status global ${this.lookupMovementStatus[this.state.operationalStatus.global ?? 3]} lift ${this.lookupMovementStatus[this.state.operationalStatus.lift ?? 3]} tilt ${this.lookupMovementStatus[this.state.operationalStatus.tilt ?? 3]}`);
314
- }
315
- async goToLiftPercentage(request) {
316
- const device = this.endpoint.stateOf(MatterbridgeServer);
317
- device.log.info(`Setting cover lift percentage to ${request.liftPercent100thsValue} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
318
- await device.commandHandler.executeHandler('WindowCovering.goToLiftPercentage', {
319
- command: 'goToLiftPercentage',
320
- request,
321
- cluster: WindowCoveringServer.id,
322
- attributes: this.state,
323
- endpoint: this.endpoint,
324
- });
325
- device.log.debug(`MatterbridgeWindowCoveringServer: goToLiftPercentage with ${request.liftPercent100thsValue}`);
326
- await super.goToLiftPercentage(request);
327
- device.log.debug(`MatterbridgeWindowCoveringServer: goToLiftPercentage result target ${this.state.targetPositionLiftPercent100ths} current ${this.state.currentPositionLiftPercent100ths} status global ${this.lookupMovementStatus[this.state.operationalStatus.global ?? 3]} lift ${this.lookupMovementStatus[this.state.operationalStatus.lift ?? 3]} tilt ${this.lookupMovementStatus[this.state.operationalStatus.tilt ?? 3]}`);
328
- }
329
- async goToTiltPercentage(request) {
330
- const device = this.endpoint.stateOf(MatterbridgeServer);
331
- device.log.info(`Setting cover tilt percentage to ${request.tiltPercent100thsValue} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
332
- await device.commandHandler.executeHandler('WindowCovering.goToTiltPercentage', {
333
- command: 'goToTiltPercentage',
334
- request,
335
- cluster: WindowCoveringServer.id,
336
- attributes: this.state,
337
- endpoint: this.endpoint,
338
- });
339
- device.log.debug(`MatterbridgeWindowCoveringServer: goToTiltPercentage with ${request.tiltPercent100thsValue}`);
340
- await super.goToTiltPercentage(request);
341
- device.log.debug(`MatterbridgeWindowCoveringServer: goToTiltPercentage result target ${this.state.targetPositionTiltPercent100ths} current ${this.state.currentPositionTiltPercent100ths} status global ${this.lookupMovementStatus[this.state.operationalStatus.global ?? 3]} lift ${this.lookupMovementStatus[this.state.operationalStatus.lift ?? 3]} tilt ${this.lookupMovementStatus[this.state.operationalStatus.tilt ?? 3]}`);
342
- }
343
- async handleMovement(type, reversed, direction, targetPercent100ths) {
344
- }
345
- }
346
- export class MatterbridgeLiftWindowCoveringServer extends MatterbridgeWindowCoveringServer.with(WindowCovering.Feature.Lift, WindowCovering.Feature.PositionAwareLift) {
347
- }
348
- export class MatterbridgeLiftTiltWindowCoveringServer extends MatterbridgeWindowCoveringServer.with(WindowCovering.Feature.Lift, WindowCovering.Feature.PositionAwareLift, WindowCovering.Feature.Tilt, WindowCovering.Feature.PositionAwareTilt) {
349
- }
350
- export class MatterbridgeDoorLockServer extends DoorLockServer.enable({
351
- events: { doorLockAlarm: true, lockOperation: true, lockOperationError: true },
352
- commands: { lockDoor: true, unlockDoor: true, unlockWithTimeout: true },
353
- }) {
354
- async lockDoor(request) {
355
- const device = this.endpoint.stateOf(MatterbridgeServer);
356
- device.log.info(`Locking door (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
357
- await device.commandHandler.executeHandler('DoorLock.lockDoor', {
358
- command: 'lockDoor',
359
- request,
360
- cluster: DoorLockServer.id,
361
- attributes: this.state,
362
- endpoint: this.endpoint,
363
- });
364
- device.log.debug(`MatterbridgeDoorLockServer: lockDoor called`);
365
- await super.lockDoor(request);
366
- }
367
- async unlockDoor(request) {
368
- const device = this.endpoint.stateOf(MatterbridgeServer);
369
- device.log.info(`Unlocking door (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
370
- await device.commandHandler.executeHandler('DoorLock.unlockDoor', {
371
- command: 'unlockDoor',
372
- request,
373
- cluster: DoorLockServer.id,
374
- attributes: this.state,
375
- endpoint: this.endpoint,
376
- });
377
- device.log.debug(`MatterbridgeDoorLockServer: unlockDoor called`);
378
- await super.unlockDoor(request);
379
- }
380
- async unlockWithTimeout(request) {
381
- const device = this.endpoint.stateOf(MatterbridgeServer);
382
- device.log.info(`Unlocking door with timeout ${request.timeout} seconds (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
383
- await device.commandHandler.executeHandler('DoorLock.unlockWithTimeout', {
384
- command: 'unlockWithTimeout',
385
- request,
386
- cluster: DoorLockServer.id,
387
- attributes: this.state,
388
- endpoint: this.endpoint,
389
- });
390
- device.log.debug(`MatterbridgeDoorLockServer: unlockWithTimeout called`);
391
- this.state.lockState = DoorLock.LockState.Unlocked;
392
- }
393
- }
394
- export class MatterbridgePinDoorLockServer extends DoorLockServer.with(DoorLock.Feature.PinCredential, DoorLock.Feature.CredentialOverTheAirAccess).enable({
395
- events: { doorLockAlarm: true, lockOperation: true, lockOperationError: true },
396
- commands: { lockDoor: true, unlockDoor: true, unlockWithTimeout: true, setUserStatus: true, getUserStatus: true, setUserType: true, getUserType: true },
397
- }) {
398
- async lockDoor(request) {
399
- const device = this.endpoint.stateOf(MatterbridgeServer);
400
- device.log.info(`Locking door with pincode ${request.pinCode ? '0x' + Buffer.from(request.pinCode).toString('hex') : 'N/A'} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
401
- await device.commandHandler.executeHandler('DoorLock.lockDoor', {
402
- command: 'lockDoor',
403
- request,
404
- cluster: DoorLockServer.id,
405
- attributes: this.state,
406
- endpoint: this.endpoint,
407
- });
408
- device.log.debug(`MatterbridgeDoorLockServer: lockDoor called`);
409
- await super.lockDoor(request);
410
- }
411
- async unlockDoor(request) {
412
- const device = this.endpoint.stateOf(MatterbridgeServer);
413
- device.log.info(`Unlocking door with pincode ${request.pinCode ? '0x' + Buffer.from(request.pinCode).toString('hex') : 'N/A'} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
414
- await device.commandHandler.executeHandler('DoorLock.unlockDoor', {
415
- command: 'unlockDoor',
416
- request,
417
- cluster: DoorLockServer.id,
418
- attributes: this.state,
419
- endpoint: this.endpoint,
420
- });
421
- device.log.debug(`MatterbridgeDoorLockServer: unlockDoor called`);
422
- await super.unlockDoor(request);
423
- }
424
- async unlockWithTimeout(request) {
425
- const device = this.endpoint.stateOf(MatterbridgeServer);
426
- device.log.info(`Unlocking door with pincode ${request.pinCode ? '0x' + Buffer.from(request.pinCode).toString('hex') : 'N/A'} timeout ${request.timeout} seconds (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
427
- await device.commandHandler.executeHandler('DoorLock.unlockWithTimeout', {
428
- command: 'unlockWithTimeout',
429
- request,
430
- cluster: DoorLockServer.id,
431
- attributes: this.state,
432
- endpoint: this.endpoint,
433
- });
434
- device.log.debug(`MatterbridgeDoorLockServer: unlockWithTimeout called`);
435
- this.state.lockState = DoorLock.LockState.Unlocked;
436
- }
437
- async setPinCode(request) {
438
- const device = this.endpoint.stateOf(MatterbridgeServer);
439
- device.log.info(`Setting pin code ${request.pin ? '0x' + Buffer.from(request.pin).toString('hex') : 'N/A'} for user ${request.userId} type ${getEnumDescription(DoorLock.UserType, request.userType)} status ${getEnumDescription(DoorLock.UserStatus, request.userStatus)} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
440
- await device.commandHandler.executeHandler('DoorLock.setPinCode', {
441
- command: 'setPinCode',
442
- request,
443
- cluster: DoorLockServer.id,
444
- attributes: this.state,
445
- endpoint: this.endpoint,
446
- });
447
- device.log.debug(`MatterbridgeDoorLockServer: setPinCode called for user ${request.userId}`);
448
- }
449
- async getPinCode(request) {
450
- const device = this.endpoint.stateOf(MatterbridgeServer);
451
- device.log.info(`Getting pin code for user ${request.userId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
452
- await device.commandHandler.executeHandler('DoorLock.getPinCode', {
453
- command: 'getPinCode',
454
- request,
455
- cluster: DoorLockServer.id,
456
- attributes: this.state,
457
- endpoint: this.endpoint,
458
- });
459
- return {
460
- userId: request.userId,
461
- userStatus: DoorLock.UserStatus.Available,
462
- userType: DoorLock.UserType.UnrestrictedUser,
463
- pinCode: Buffer.from('1234'),
464
- };
465
- }
466
- async clearPinCode(request) {
467
- const device = this.endpoint.stateOf(MatterbridgeServer);
468
- device.log.info(`Clearing pin code for ${request.pinSlotIndex === 0xfffe ? 'all slots' : 'slot ' + request.pinSlotIndex} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
469
- await device.commandHandler.executeHandler('DoorLock.clearPinCode', {
470
- command: 'clearPinCode',
471
- request,
472
- cluster: DoorLockServer.id,
473
- attributes: this.state,
474
- endpoint: this.endpoint,
475
- });
476
- device.log.debug(`MatterbridgeDoorLockServer: clearPinCode called for ${request.pinSlotIndex === 0xfffe ? 'all PIN slots' : 'PIN slot ' + request.pinSlotIndex}`);
477
- }
478
- async clearAllPinCodes() {
479
- const device = this.endpoint.stateOf(MatterbridgeServer);
480
- device.log.info(`Clearing all pin codes (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
481
- await device.commandHandler.executeHandler('DoorLock.clearAllPinCodes', {
482
- command: 'clearAllPinCodes',
483
- request: {},
484
- cluster: DoorLockServer.id,
485
- attributes: this.state,
486
- endpoint: this.endpoint,
487
- });
488
- device.log.debug('MatterbridgeDoorLockServer: clearAllPinCodes called');
489
- }
490
- async setUserStatus(request) {
491
- const device = this.endpoint.stateOf(MatterbridgeServer);
492
- device.log.info(`Setting user status for user ${request.userId} to ${getEnumDescription(DoorLock.UserStatus, request.userStatus)} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
493
- await device.commandHandler.executeHandler('DoorLock.setUserStatus', {
494
- command: 'setUserStatus',
495
- request,
496
- cluster: DoorLockServer.id,
497
- attributes: this.state,
498
- endpoint: this.endpoint,
499
- });
500
- device.log.debug(`MatterbridgeDoorLockServer: setUserStatus called for user ${request.userId}`);
501
- }
502
- async getUserStatus(request) {
503
- const device = this.endpoint.stateOf(MatterbridgeServer);
504
- device.log.info(`Getting user status for user ${request.userId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
505
- await device.commandHandler.executeHandler('DoorLock.getUserStatus', {
506
- command: 'getUserStatus',
507
- request,
508
- cluster: DoorLockServer.id,
509
- attributes: this.state,
510
- endpoint: this.endpoint,
511
- });
512
- device.log.debug(`MatterbridgeDoorLockServer: getUserStatus called for user ${request.userId}`);
513
- return {
514
- userId: request.userId,
515
- userStatus: DoorLock.UserStatus.Available,
516
- };
517
- }
518
- async setUserType(request) {
519
- const device = this.endpoint.stateOf(MatterbridgeServer);
520
- device.log.info(`Setting user type for user ${request.userId} to ${getEnumDescription(DoorLock.UserType, request.userType)} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
521
- await device.commandHandler.executeHandler('DoorLock.setUserType', {
522
- command: 'setUserType',
523
- request,
524
- cluster: DoorLockServer.id,
525
- attributes: this.state,
526
- endpoint: this.endpoint,
527
- });
528
- device.log.debug(`MatterbridgeDoorLockServer: setUserType called for user ${request.userId}`);
529
- }
530
- async getUserType(request) {
531
- const device = this.endpoint.stateOf(MatterbridgeServer);
532
- device.log.info(`Getting user type for user ${request.userId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
533
- await device.commandHandler.executeHandler('DoorLock.getUserType', {
534
- command: 'getUserType',
535
- request,
536
- cluster: DoorLockServer.id,
537
- attributes: this.state,
538
- endpoint: this.endpoint,
539
- });
540
- device.log.debug(`MatterbridgeDoorLockServer: getUserType called for user ${request.userId}`);
541
- return {
542
- userId: request.userId,
543
- userType: DoorLock.UserType.UnrestrictedUser,
544
- };
545
- }
546
- }
547
- export class MatterbridgeUserPinDoorLockServer extends DoorLockServer.with(DoorLock.Feature.User, DoorLock.Feature.PinCredential, DoorLock.Feature.CredentialOverTheAirAccess).enable({
548
- events: { doorLockAlarm: true, lockOperation: true, lockOperationError: true },
549
- commands: { lockDoor: true, unlockDoor: true, unlockWithTimeout: true },
550
- }) {
551
- getAccessingFabricIndex() {
552
- let fabricIndex;
553
- try {
554
- fabricIndex = this.context.fabric;
555
- }
556
- catch {
557
- return null;
558
- }
559
- if (fabricIndex === undefined || fabricIndex === FabricIndex.NO_FABRIC) {
560
- return null;
561
- }
562
- return fabricIndex;
563
- }
564
- findStoredCredential(credential) {
565
- for (const user of this.internal.users) {
566
- for (const storedCredential of user.credentials ?? []) {
567
- if (storedCredential.credentialType === credential.credentialType && storedCredential.credentialIndex === credential.credentialIndex) {
568
- return { user, storedCredential };
569
- }
570
- }
571
- }
572
- return null;
573
- }
574
- getStoredCredentialStateDebug() {
575
- if (this.internal.users.length === 0) {
576
- return 'no users';
577
- }
578
- return this.internal.users
579
- .map((user) => {
580
- const credentials = user.credentials
581
- ?.map((credential) => `${getEnumDescription(DoorLock.CredentialType, credential.credentialType)}:${credential.credentialIndex}=0x${Buffer.from(credential.credentialData).toString('hex')}`)
582
- .join(', ') ?? 'none';
583
- return `user ${user.userIndex} [${credentials}]`;
584
- })
585
- .join('; ');
586
- }
587
- logStoredCredentialState(reason) {
588
- const device = this.endpoint.stateOf(MatterbridgeServer);
589
- device.log.debug(`MatterbridgeDoorLockServer: ${reason}; stored credentials: ${this.getStoredCredentialStateDebug()}`);
590
- }
591
- hasMatchingPinCredential(pinCode) {
592
- const device = this.endpoint.stateOf(MatterbridgeServer);
593
- device.log.debug(`MatterbridgeDoorLockServer: checking remote PIN 0x${Buffer.from(pinCode).toString('hex')} against ${this.internal.users.length} user(s)`);
594
- for (const user of this.internal.users) {
595
- for (const storedCredential of user.credentials ?? []) {
596
- if (storedCredential.credentialType !== DoorLock.CredentialType.Pin) {
597
- continue;
598
- }
599
- if (Buffer.from(storedCredential.credentialData).equals(Buffer.from(pinCode))) {
600
- device.log.debug(`MatterbridgeDoorLockServer: remote PIN matched userIndex ${user.userIndex} credentialIndex ${storedCredential.credentialIndex}`);
601
- return true;
602
- }
603
- }
604
- }
605
- device.log.debug(`MatterbridgeDoorLockServer: remote PIN 0x${Buffer.from(pinCode).toString('hex')} did not match any stored PIN credential`);
606
- return false;
607
- }
608
- validateRemotePinCode(pinCode) {
609
- const device = this.endpoint.stateOf(MatterbridgeServer);
610
- if (!this.state.requirePinForRemoteOperation) {
611
- device.log.debug('MatterbridgeDoorLockServer: skipping remote PIN validation because requirePinForRemoteOperation is false');
612
- return;
613
- }
614
- if (pinCode === undefined) {
615
- device.log.debug('MatterbridgeDoorLockServer: rejecting remote operation because the request did not include a PIN');
616
- this.logStoredCredentialState('remote PIN validation failed');
617
- throw new StatusResponse.FailureError('Missing or invalid PIN code for remote operation');
618
- }
619
- device.log.debug(`MatterbridgeDoorLockServer: validating remote PIN 0x${Buffer.from(pinCode).toString('hex')}`);
620
- if (pinCode === undefined || !this.hasMatchingPinCredential(pinCode)) {
621
- this.logStoredCredentialState('remote PIN validation failed');
622
- throw new StatusResponse.FailureError('Missing or invalid PIN code for remote operation');
623
- }
624
- device.log.debug(`MatterbridgeDoorLockServer: accepted remote PIN 0x${Buffer.from(pinCode).toString('hex')}`);
625
- }
626
- getNextOccupiedCredentialIndex(credential) {
627
- let nextCredentialIndex = null;
628
- for (const user of this.internal.users) {
629
- for (const storedCredential of user.credentials ?? []) {
630
- if (storedCredential.credentialType !== credential.credentialType || storedCredential.credentialIndex <= credential.credentialIndex) {
631
- continue;
632
- }
633
- if (nextCredentialIndex === null || storedCredential.credentialIndex < nextCredentialIndex) {
634
- nextCredentialIndex = storedCredential.credentialIndex;
635
- }
636
- }
637
- }
638
- return nextCredentialIndex;
639
- }
640
- upsertStoredCredential(userIndex, credential, credentialData) {
641
- const device = this.endpoint.stateOf(MatterbridgeServer);
642
- if (userIndex === null) {
643
- device.log.debug(`MatterbridgeDoorLockServer: not storing credentialType ${getEnumDescription(DoorLock.CredentialType, credential.credentialType)} credentialIndex ${credential.credentialIndex} because userIndex is null`);
644
- return;
645
- }
646
- const user = this.internal.users.find((storedUser) => storedUser.userIndex === userIndex);
647
- if (!user) {
648
- device.log.debug(`MatterbridgeDoorLockServer: not storing credentialType ${getEnumDescription(DoorLock.CredentialType, credential.credentialType)} credentialIndex ${credential.credentialIndex} because userIndex ${userIndex} was not found`);
649
- return;
650
- }
651
- let removedCredentials = 0;
652
- for (const storedUser of this.internal.users) {
653
- const nextCredentials = storedUser.credentials?.filter((storedCredential) => storedCredential.credentialType !== credential.credentialType || storedCredential.credentialIndex !== credential.credentialIndex) ?? null;
654
- removedCredentials += (storedUser.credentials?.length ?? 0) - (nextCredentials?.length ?? 0);
655
- storedUser.credentials = nextCredentials && nextCredentials.length > 0 ? nextCredentials : null;
656
- }
657
- if (!user.credentials) {
658
- user.credentials = [];
659
- }
660
- user.credentials.push({
661
- credentialType: credential.credentialType,
662
- credentialIndex: credential.credentialIndex,
663
- credentialData: Uint8Array.from(credentialData),
664
- });
665
- device.log.debug(`MatterbridgeDoorLockServer: stored credentialType ${getEnumDescription(DoorLock.CredentialType, credential.credentialType)} credentialIndex ${credential.credentialIndex} for userIndex ${userIndex} (removed ${removedCredentials} replaced credential(s))`);
666
- this.logStoredCredentialState('credential stored');
667
- }
668
- clearStoredCredential(credential) {
669
- const device = this.endpoint.stateOf(MatterbridgeServer);
670
- for (const user of this.internal.users) {
671
- if (credential === null) {
672
- user.credentials = null;
673
- continue;
674
- }
675
- const nextCredentials = user.credentials?.filter((storedCredential) => storedCredential.credentialType !== credential.credentialType || storedCredential.credentialIndex !== credential.credentialIndex) ?? null;
676
- user.credentials = nextCredentials && nextCredentials.length > 0 ? nextCredentials : null;
677
- }
678
- device.log.debug(`MatterbridgeDoorLockServer: cleared ${credential ? `${getEnumDescription(DoorLock.CredentialType, credential.credentialType)} credentialIndex ${credential.credentialIndex}` : 'all credentials'} from internal state`);
679
- this.logStoredCredentialState('credential cleared');
680
- }
681
- async lockDoor(request) {
682
- const device = this.endpoint.stateOf(MatterbridgeServer);
683
- device.log.info(`Locking door with pincode ${request.pinCode ? '0x' + Buffer.from(request.pinCode).toString('hex') : 'N/A'} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
684
- this.validateRemotePinCode(request.pinCode);
685
- device.log.debug(`MatterbridgeDoorLockServer: remote lockDoor PIN validation completed`);
686
- await device.commandHandler.executeHandler('DoorLock.lockDoor', {
687
- command: 'lockDoor',
688
- request,
689
- cluster: DoorLockServer.id,
690
- attributes: this.state,
691
- endpoint: this.endpoint,
692
- });
693
- device.log.debug(`MatterbridgeDoorLockServer: lockDoor called`);
694
- await super.lockDoor(request);
695
- }
696
- async unlockDoor(request) {
697
- const device = this.endpoint.stateOf(MatterbridgeServer);
698
- device.log.info(`Unlocking door with pincode ${request.pinCode ? '0x' + Buffer.from(request.pinCode).toString('hex') : 'N/A'} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
699
- this.validateRemotePinCode(request.pinCode);
700
- device.log.debug(`MatterbridgeDoorLockServer: remote unlockDoor PIN validation completed`);
701
- await device.commandHandler.executeHandler('DoorLock.unlockDoor', {
702
- command: 'unlockDoor',
703
- request,
704
- cluster: DoorLockServer.id,
705
- attributes: this.state,
706
- endpoint: this.endpoint,
707
- });
708
- device.log.debug(`MatterbridgeDoorLockServer: unlockDoor called`);
709
- await super.unlockDoor(request);
710
- }
711
- async unlockWithTimeout(request) {
712
- const device = this.endpoint.stateOf(MatterbridgeServer);
713
- device.log.info(`Unlocking door with pincode ${request.pinCode ? '0x' + Buffer.from(request.pinCode).toString('hex') : 'N/A'} timeout ${request.timeout} seconds (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
714
- this.validateRemotePinCode(request.pinCode);
715
- device.log.debug(`MatterbridgeDoorLockServer: remote unlockWithTimeout PIN validation completed`);
716
- await device.commandHandler.executeHandler('DoorLock.unlockWithTimeout', {
717
- command: 'unlockWithTimeout',
718
- request,
719
- cluster: DoorLockServer.id,
720
- attributes: this.state,
721
- endpoint: this.endpoint,
722
- });
723
- device.log.debug(`MatterbridgeDoorLockServer: unlockWithTimeout called`);
724
- this.state.lockState = DoorLock.LockState.Unlocked;
725
- }
726
- async setUser(request) {
727
- const device = this.endpoint.stateOf(MatterbridgeServer);
728
- const accessingFabricIndex = this.getAccessingFabricIndex();
729
- device.log.info(`Setting user operationType ${getEnumDescription(DoorLock.DataOperationType, request.operationType)} userIndex ${request.userIndex} userName ${request.userName ?? 'null'} userUniqueId ${request.userUniqueId ?? 'null'} userStatus ${getEnumDescription(DoorLock.UserStatus, request.userStatus, { fallback: 'null' })} userType ${getEnumDescription(DoorLock.UserType, request.userType, { fallback: 'null' })} credentialRule ${getEnumDescription(DoorLock.CredentialRule, request.credentialRule, { fallback: 'null' })} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
730
- device.log.debug(`MatterbridgeDoorLockServer: setUser accessingFabricIndex ${accessingFabricIndex ?? 'null'}`);
731
- await device.commandHandler.executeHandler('DoorLock.setUser', {
732
- command: 'setUser',
733
- request,
734
- cluster: DoorLockServer.id,
735
- attributes: this.state,
736
- endpoint: this.endpoint,
737
- });
738
- const user = this.internal.users.find((user) => user.userIndex === request.userIndex);
739
- device.log.debug(`MatterbridgeDoorLockServer: setUser called for userIndex ${request.userIndex} (${user ? 'existing user ' + debugStringify(user) : 'new user'})`);
740
- if (!user && request.operationType === DoorLock.DataOperationType.Add) {
741
- this.internal.users.push({
742
- userIndex: request.userIndex,
743
- userName: request.userName,
744
- userUniqueId: request.userUniqueId,
745
- userStatus: request.userStatus,
746
- userType: request.userType,
747
- credentialRule: request.credentialRule,
748
- credentials: null,
749
- creatorFabricIndex: accessingFabricIndex,
750
- lastModifiedFabricIndex: accessingFabricIndex,
751
- nextUserIndex: null,
752
- });
753
- device.log.debug(`MatterbridgeDoorLockServer: added userIndex ${request.userIndex} (total users: ${this.internal.users.length}) to internal state: ${debugStringify(this.internal.users.find((user) => user.userIndex === request.userIndex))}`);
754
- this.logStoredCredentialState('user added');
755
- return;
756
- }
757
- this.logStoredCredentialState(`setUser completed for userIndex ${request.userIndex} without adding a new internal user`);
758
- }
759
- async getUser(request) {
760
- const device = this.endpoint.stateOf(MatterbridgeServer);
761
- device.log.info(`Getting userIndex ${request.userIndex} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
762
- await device.commandHandler.executeHandler('DoorLock.getUser', {
763
- command: 'getUser',
764
- request,
765
- cluster: DoorLockServer.id,
766
- attributes: this.state,
767
- endpoint: this.endpoint,
768
- });
769
- const user = this.internal.users.find((user) => user.userIndex === request.userIndex);
770
- device.log.debug(`MatterbridgeDoorLockServer: getUser called for userIndex ${request.userIndex} (total users: ${this.internal.users.length}) (${user ? 'existing user: ' + debugStringify(user) : 'new user'})`);
771
- this.logStoredCredentialState(`getUser returning state for userIndex ${request.userIndex}`);
772
- if (user) {
773
- return {
774
- ...user,
775
- credentials: user.credentials?.map(({ credentialType, credentialIndex }) => ({ credentialType, credentialIndex })) ?? null,
776
- };
777
- }
778
- return {
779
- userIndex: request.userIndex,
780
- userName: null,
781
- userUniqueId: null,
782
- userStatus: null,
783
- userType: null,
784
- credentialRule: null,
785
- credentials: null,
786
- creatorFabricIndex: null,
787
- lastModifiedFabricIndex: null,
788
- nextUserIndex: null,
789
- };
790
- }
791
- async clearUser(request) {
792
- const device = this.endpoint.stateOf(MatterbridgeServer);
793
- device.log.info(`Clearing userIndex ${request.userIndex} ${request.userIndex === 0xfffe ? '(all users)' : ''} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
794
- await device.commandHandler.executeHandler('DoorLock.clearUser', {
795
- command: 'clearUser',
796
- request,
797
- cluster: DoorLockServer.id,
798
- attributes: this.state,
799
- endpoint: this.endpoint,
800
- });
801
- device.log.debug(`MatterbridgeDoorLockServer: clearUser called for userIndex ${request.userIndex}`);
802
- this.logStoredCredentialState(`clearUser completed for userIndex ${request.userIndex}`);
803
- }
804
- async setCredential(request) {
805
- const device = this.endpoint.stateOf(MatterbridgeServer);
806
- const accessingFabricIndex = this.getAccessingFabricIndex();
807
- device.log.info(`Setting credential operationType ${getEnumDescription(DoorLock.DataOperationType, request.operationType)} credentialType ${getEnumDescription(DoorLock.CredentialType, request.credential.credentialType)} credentialIndex ${request.credential.credentialIndex} credentialData ${Buffer.from(request.credentialData).toString('hex') ? '0x' + Buffer.from(request.credentialData).toString('hex') : '0x'} userIndex ${request.userIndex ?? 'null'} userStatus ${getEnumDescription(DoorLock.UserStatus, request.userStatus, { fallback: 'null' })} userType ${getEnumDescription(DoorLock.UserType, request.userType, { fallback: 'null' })} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
808
- await device.commandHandler.executeHandler('DoorLock.setCredential', {
809
- command: 'setCredential',
810
- request,
811
- cluster: DoorLockServer.id,
812
- attributes: this.state,
813
- endpoint: this.endpoint,
814
- });
815
- const user = this.internal.users.find((user) => user.userIndex === request.userIndex);
816
- const existingCredential = this.findStoredCredential(request.credential);
817
- device.log.debug(`MatterbridgeDoorLockServer: setCredential pre-update lookup for credentialIndex ${request.credential.credentialIndex} (${existingCredential ? 'existing credential found' : 'no existing credential'})`);
818
- device.log.debug(`MatterbridgeDoorLockServer: setCredential called for credentialIndex ${request.credential.credentialIndex}`);
819
- if (user && (request.operationType === DoorLock.DataOperationType.Add || request.operationType === DoorLock.DataOperationType.Modify)) {
820
- this.upsertStoredCredential(request.userIndex, request.credential, request.credentialData);
821
- user.lastModifiedFabricIndex = accessingFabricIndex;
822
- device.log.debug(`MatterbridgeDoorLockServer: setCredential updated lastModifiedFabricIndex for userIndex ${user.userIndex} to ${accessingFabricIndex ?? 'null'}`);
823
- }
824
- else {
825
- device.log.debug(`MatterbridgeDoorLockServer: setCredential did not update internal state for credentialIndex ${request.credential.credentialIndex} (user ${request.userIndex ?? 'null'} not found or operation not handled)`);
826
- }
827
- return {
828
- status: Status.Success,
829
- userIndex: request.userIndex,
830
- };
831
- }
832
- async getCredentialStatus(request) {
833
- const device = this.endpoint.stateOf(MatterbridgeServer);
834
- device.log.info(`Getting credential status for credentialType ${getEnumDescription(DoorLock.CredentialType, request.credential.credentialType)} credentialIndex ${request.credential.credentialIndex} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
835
- await device.commandHandler.executeHandler('DoorLock.getCredentialStatus', {
836
- command: 'getCredentialStatus',
837
- request,
838
- cluster: DoorLockServer.id,
839
- attributes: this.state,
840
- endpoint: this.endpoint,
841
- });
842
- const credentialRecord = this.findStoredCredential(request.credential);
843
- const nextCredentialIndex = this.getNextOccupiedCredentialIndex(request.credential);
844
- device.log.debug(`MatterbridgeDoorLockServer: getCredentialStatus called`);
845
- device.log.debug(`MatterbridgeDoorLockServer: getCredentialStatus result for credentialIndex ${request.credential.credentialIndex} (${credentialRecord ? `userIndex ${credentialRecord.user.userIndex} credentialData 0x${Buffer.from(credentialRecord.storedCredential.credentialData).toString('hex')}` : 'credential missing'}, nextCredentialIndex ${nextCredentialIndex ?? 'null'})`);
846
- return {
847
- credentialExists: credentialRecord !== null,
848
- userIndex: credentialRecord?.user.userIndex ?? null,
849
- creatorFabricIndex: credentialRecord?.user.creatorFabricIndex ?? null,
850
- lastModifiedFabricIndex: credentialRecord?.user.lastModifiedFabricIndex ?? null,
851
- nextCredentialIndex,
852
- credentialData: credentialRecord?.storedCredential.credentialData ?? null,
853
- };
854
- }
855
- async clearCredential(request) {
856
- const device = this.endpoint.stateOf(MatterbridgeServer);
857
- device.log.info(`Clearing credentialType ${request.credential ? getEnumDescription(DoorLock.CredentialType, request.credential.credentialType) : 'null'} credentialIndex ${request.credential ? request.credential.credentialIndex : 'null'} ${request.credential === null ? '(all credentials)' : ''} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
858
- await device.commandHandler.executeHandler('DoorLock.clearCredential', {
859
- command: 'clearCredential',
860
- request,
861
- cluster: DoorLockServer.id,
862
- attributes: this.state,
863
- endpoint: this.endpoint,
864
- });
865
- this.clearStoredCredential(request.credential);
866
- device.log.debug('MatterbridgeDoorLockServer: clearCredential called');
867
- this.logStoredCredentialState(`clearCredential completed for ${request.credential
868
- ? `${getEnumDescription(DoorLock.CredentialType, request.credential.credentialType)} credentialIndex ${request.credential.credentialIndex}`
869
- : 'all credentials'}`);
870
- }
871
- }
872
- (function (MatterbridgeUserPinDoorLockServer) {
873
- class Internal {
874
- users = [];
875
- }
876
- MatterbridgeUserPinDoorLockServer.Internal = Internal;
877
- })(MatterbridgeUserPinDoorLockServer || (MatterbridgeUserPinDoorLockServer = {}));
878
- export class MatterbridgeFanControlServer extends FanControlServer.with(FanControl.Feature.Auto, FanControl.Feature.Step) {
879
- async step(request) {
880
- const device = this.endpoint.stateOf(MatterbridgeServer);
881
- device.log.info(`Stepping fan with direction ${request.direction} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
882
- await device.commandHandler.executeHandler('FanControl.step', {
883
- command: 'step',
884
- request,
885
- cluster: FanControlServer.id,
886
- attributes: this.state,
887
- endpoint: this.endpoint,
888
- });
889
- const lookupStepDirection = ['Increase', 'Decrease'];
890
- device.log.debug(`MatterbridgeFanControlServer: step called with direction: ${lookupStepDirection[request.direction]} wrap: ${request.wrap} lowestOff: ${request.lowestOff}`);
891
- device.log.debug(`- current percentCurrent: ${this.state.percentCurrent}`);
892
- if (request.direction === FanControl.StepDirection.Increase) {
893
- if (request.wrap && this.state.percentCurrent === 100) {
894
- this.state.percentCurrent = request.lowestOff ? 0 : 10;
895
- }
896
- else
897
- this.state.percentCurrent = Math.min(this.state.percentCurrent + 10, 100);
898
- }
899
- else if (request.direction === FanControl.StepDirection.Decrease) {
900
- if (request.wrap && this.state.percentCurrent === (request.lowestOff ? 0 : 10)) {
901
- this.state.percentCurrent = 100;
902
- }
903
- else
904
- this.state.percentCurrent = Math.max(this.state.percentCurrent - 10, request.lowestOff ? 0 : 10);
905
- }
906
- device.log.debug('Set percentCurrent to:', this.state.percentCurrent);
907
- }
908
- }
909
- export class MatterbridgeThermostatServer extends ThermostatServer.with(Thermostat.Feature.Cooling, Thermostat.Feature.Heating, Thermostat.Feature.AutoMode, Thermostat.Feature.Presets) {
910
- async initialize() {
911
- await super.initialize();
912
- this.endpoint.construction.onSuccess(async () => {
913
- const device = this.endpoint.stateOf(MatterbridgeServer);
914
- device.log.debug(`Removing atomic commands (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
915
- await this.endpoint.setStateOf(ThermostatServer, {
916
- acceptedCommandList: [0],
917
- generatedCommandList: [],
918
- });
919
- });
920
- }
921
- async setpointRaiseLower(request) {
922
- const device = this.endpoint.stateOf(MatterbridgeServer);
923
- device.log.info(`Setting setpoint by ${request.amount} in mode ${request.mode} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
924
- await device.commandHandler.executeHandler('Thermostat.setpointRaiseLower', {
925
- command: 'setpointRaiseLower',
926
- request,
927
- cluster: ThermostatServer.id,
928
- attributes: this.state,
929
- endpoint: this.endpoint,
930
- });
931
- const lookupSetpointAdjustMode = ['Heat', 'Cool', 'Both'];
932
- device.log.debug(`MatterbridgeThermostatServer: setpointRaiseLower called with mode: ${lookupSetpointAdjustMode[request.mode]} amount: ${request.amount / 10}`);
933
- await super.setpointRaiseLower(request);
934
- }
935
- async setActivePresetRequest(request) {
936
- const device = this.endpoint.stateOf(MatterbridgeServer);
937
- const presetHandle = request.presetHandle ? `0x${Buffer.from(request.presetHandle).toString('hex')}` : 'null';
938
- device.log.info(`Setting preset to ${presetHandle} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
939
- await device.commandHandler.executeHandler('Thermostat.setActivePresetRequest', {
940
- command: 'setActivePresetRequest',
941
- request,
942
- cluster: ThermostatServer.id,
943
- attributes: this.state,
944
- endpoint: this.endpoint,
945
- });
946
- device.log.debug(`MatterbridgeThermostatServer: setActivePresetRequest called with presetHandle: ${presetHandle}`);
947
- await super.setActivePresetRequest(request);
948
- const activePresetHandle = this.state.activePresetHandle ? `0x${Buffer.from(this.state.activePresetHandle).toString('hex')}` : 'null';
949
- device.log.debug(`MatterbridgeThermostatServer: setActivePresetRequest completed with activePresetHandle: ${activePresetHandle} occupiedHeatingSetpoint: ${this.state.occupiedHeatingSetpoint} occupiedCoolingSetpoint: ${this.state.occupiedCoolingSetpoint}`);
950
- }
951
- }
952
- export class MatterbridgePresetThermostatServer extends ThermostatServer.with(Thermostat.Feature.Presets, Thermostat.Feature.Cooling, Thermostat.Feature.Heating, Thermostat.Feature.AutoMode) {
953
- }
954
- export class MatterbridgeValveConfigurationAndControlServer extends ValveConfigurationAndControlServer.with(ValveConfigurationAndControl.Feature.Level) {
955
- async open(request) {
956
- const device = this.endpoint.stateOf(MatterbridgeServer);
957
- device.log.info(`Opening valve to ${request.targetLevel ? request.targetLevel + '%' : 'fully opened'} ${request.openDuration ? 'for ' + request.openDuration + 's' : 'until closed'} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
958
- await device.commandHandler.executeHandler('ValveConfigurationAndControl.open', {
959
- command: 'open',
960
- request,
961
- cluster: ValveConfigurationAndControlServer.id,
962
- attributes: this.state,
963
- endpoint: this.endpoint,
964
- });
965
- device.log.debug(`MatterbridgeValveConfigurationAndControlServer: open called with openDuration: ${request.openDuration} targetLevel: ${request.targetLevel}`);
966
- this.state.targetState = ValveConfigurationAndControl.ValveState.Open;
967
- this.state.currentState = ValveConfigurationAndControl.ValveState.Open;
968
- this.state.targetLevel = request.targetLevel ?? 100;
969
- this.state.currentLevel = request.targetLevel ?? 100;
970
- this.state.openDuration = request.openDuration ?? this.state.defaultOpenDuration;
971
- if (this.state.openDuration === null)
972
- this.state.remainingDuration = null;
973
- }
974
- async close() {
975
- const device = this.endpoint.stateOf(MatterbridgeServer);
976
- device.log.info(`Closing valve (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
977
- await device.commandHandler.executeHandler('ValveConfigurationAndControl.close', {
978
- command: 'close',
979
- request: {},
980
- cluster: ValveConfigurationAndControlServer.id,
981
- attributes: this.state,
982
- endpoint: this.endpoint,
983
- });
984
- device.log.debug(`MatterbridgeValveConfigurationAndControlServer: close called`);
985
- this.state.targetState = ValveConfigurationAndControl.ValveState.Closed;
986
- this.state.currentState = ValveConfigurationAndControl.ValveState.Closed;
987
- this.state.targetLevel = 0;
988
- this.state.currentLevel = 0;
989
- this.state.openDuration = null;
990
- this.state.remainingDuration = null;
991
- }
992
- }
993
- export class MatterbridgeSmokeCoAlarmServer extends SmokeCoAlarmServer.with(SmokeCoAlarm.Feature.SmokeAlarm, SmokeCoAlarm.Feature.CoAlarm) {
994
- async selfTestRequest() {
995
- const device = this.endpoint.stateOf(MatterbridgeServer);
996
- device.log.info(`Testing SmokeCOAlarm (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
997
- await device.commandHandler.executeHandler('SmokeCoAlarm.selfTestRequest', {
998
- command: 'selfTestRequest',
999
- request: {},
1000
- cluster: SmokeCoAlarmServer.id,
1001
- attributes: this.state,
1002
- endpoint: this.endpoint,
1003
- });
1004
- device.log.debug(`MatterbridgeSmokeCoAlarmServer: selfTestRequest called`);
1005
- }
1006
- }
1007
- export class MatterbridgeBooleanStateConfigurationServer extends BooleanStateConfigurationServer.with(BooleanStateConfiguration.Feature.Visual, BooleanStateConfiguration.Feature.Audible, BooleanStateConfiguration.Feature.SensitivityLevel) {
1008
- async enableDisableAlarm(request) {
1009
- const device = this.endpoint.stateOf(MatterbridgeServer);
1010
- device.log.info(`Enabling/disabling alarm ${request.alarmsToEnableDisable} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
1011
- await device.commandHandler.executeHandler('BooleanStateConfiguration.enableDisableAlarm', {
1012
- command: 'enableDisableAlarm',
1013
- request,
1014
- cluster: BooleanStateConfigurationServer.id,
1015
- attributes: this.state,
1016
- endpoint: this.endpoint,
1017
- });
1018
- device.log.debug(`MatterbridgeBooleanStateConfigurationServer: enableDisableAlarm called`);
1019
- }
1020
- }
1021
- export class MatterbridgeSwitchServer extends SwitchServer {
1022
- initialize() {
1023
- }
1024
- }
1025
- export class MatterbridgeOperationalStateServer extends OperationalStateServer {
1026
- initialize() {
1027
- const device = this.endpoint.stateOf(MatterbridgeServer);
1028
- device.log.debug('MatterbridgeOperationalStateServer initialized: setting operational state to Stopped');
1029
- this.state.operationalState = OperationalState.OperationalStateEnum.Stopped;
1030
- this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' };
1031
- super.initialize();
1032
- }
1033
- async pause() {
1034
- const device = this.endpoint.stateOf(MatterbridgeServer);
1035
- device.log.info(`Pause (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
1036
- await device.commandHandler.executeHandler('OperationalState.pause', {
1037
- command: 'pause',
1038
- request: {},
1039
- cluster: OperationalStateServer.id,
1040
- attributes: this.state,
1041
- endpoint: this.endpoint,
1042
- });
1043
- device.log.debug('MatterbridgeOperationalStateServer: pause called setting operational state to Paused');
1044
- this.state.operationalState = OperationalState.OperationalStateEnum.Paused;
1045
- this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' };
1046
- return {
1047
- commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' },
1048
- };
1049
- }
1050
- async stop() {
1051
- const device = this.endpoint.stateOf(MatterbridgeServer);
1052
- device.log.info(`Stop (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
1053
- await device.commandHandler.executeHandler('OperationalState.stop', {
1054
- command: 'stop',
1055
- request: {},
1056
- cluster: OperationalStateServer.id,
1057
- attributes: this.state,
1058
- endpoint: this.endpoint,
1059
- });
1060
- device.log.debug('MatterbridgeOperationalStateServer: stop called setting operational state to Stopped');
1061
- this.state.operationalState = OperationalState.OperationalStateEnum.Stopped;
1062
- this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' };
1063
- return {
1064
- commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' },
1065
- };
1066
- }
1067
- async start() {
1068
- const device = this.endpoint.stateOf(MatterbridgeServer);
1069
- device.log.info(`Start (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
1070
- await device.commandHandler.executeHandler('OperationalState.start', {
1071
- command: 'start',
1072
- request: {},
1073
- cluster: OperationalStateServer.id,
1074
- attributes: this.state,
1075
- endpoint: this.endpoint,
1076
- });
1077
- device.log.debug('MatterbridgeOperationalStateServer: start called setting operational state to Running');
1078
- this.state.operationalState = OperationalState.OperationalStateEnum.Running;
1079
- this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' };
1080
- return {
1081
- commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' },
1082
- };
1083
- }
1084
- async resume() {
1085
- const device = this.endpoint.stateOf(MatterbridgeServer);
1086
- device.log.info(`Resume (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
1087
- await device.commandHandler.executeHandler('OperationalState.resume', {
1088
- command: 'resume',
1089
- request: {},
1090
- cluster: OperationalStateServer.id,
1091
- attributes: this.state,
1092
- endpoint: this.endpoint,
1093
- });
1094
- device.log.debug('MatterbridgeOperationalStateServer: resume called setting operational state to Running');
1095
- this.state.operationalState = OperationalState.OperationalStateEnum.Running;
1096
- this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' };
1097
- return {
1098
- commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' },
1099
- };
1100
- }
1101
- }
1102
- export class MatterbridgeServiceAreaServer extends ServiceAreaServer {
1103
- async selectAreas(request) {
1104
- const device = this.endpoint.stateOf(MatterbridgeServer);
1105
- device.log.info(`Selecting areas [${request.newAreas.join(', ')}] (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
1106
- await device.commandHandler.executeHandler('ServiceArea.selectAreas', {
1107
- command: 'selectAreas',
1108
- request,
1109
- cluster: ServiceAreaServer.id,
1110
- attributes: this.state,
1111
- endpoint: this.endpoint,
1112
- });
1113
- device.log.debug(`MatterbridgeServiceAreaServer selectAreas called with: [${request.newAreas.join(', ')}]`);
1114
- return await super.selectAreas(request);
1115
- }
1116
- }
1117
- export class MatterbridgeModeSelectServer extends ModeSelectServer {
1118
- async changeToMode(request) {
1119
- const device = this.endpoint.stateOf(MatterbridgeServer);
1120
- device.log.info(`Changing mode to ${request.newMode} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
1121
- await device.commandHandler.executeHandler('ModeSelect.changeToMode', {
1122
- command: 'changeToMode',
1123
- request,
1124
- cluster: ModeSelectServer.id,
1125
- attributes: this.state,
1126
- endpoint: this.endpoint,
1127
- });
1128
- device.log.debug(`MatterbridgeModeSelectServer: changeToMode called with mode: ${request.newMode}`);
1129
- await super.changeToMode(request);
1130
- }
1131
- }
1132
- export class MatterbridgeHepaFilterMonitoringServer extends HepaFilterMonitoringServer.with(ResourceMonitoring.Feature.Condition) {
1133
- async resetCondition() {
1134
- const device = this.endpoint.stateOf(MatterbridgeServer);
1135
- device.log.info(`Resetting condition (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
1136
- await device.commandHandler.executeHandler('HepaFilterMonitoring.resetCondition', {
1137
- command: 'resetCondition',
1138
- request: {},
1139
- cluster: MatterbridgeHepaFilterMonitoringServer.id,
1140
- attributes: this.state,
1141
- endpoint: this.endpoint,
1142
- });
1143
- this.state.condition = 100;
1144
- this.state.lastChangedTime = Math.floor(new Date().getTime() / 1000);
1145
- device.log.debug(`MatterbridgeHepaFilterMonitoringServer: resetCondition called`);
1146
- }
1147
- }
1148
- export class MatterbridgeActivatedCarbonFilterMonitoringServer extends ActivatedCarbonFilterMonitoringServer.with(ResourceMonitoring.Feature.Condition) {
1149
- async resetCondition() {
1150
- const device = this.endpoint.stateOf(MatterbridgeServer);
1151
- device.log.info(`Resetting condition (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
1152
- await device.commandHandler.executeHandler('ActivatedCarbonFilterMonitoring.resetCondition', {
1153
- command: 'resetCondition',
1154
- request: {},
1155
- cluster: MatterbridgeActivatedCarbonFilterMonitoringServer.id,
1156
- attributes: this.state,
1157
- endpoint: this.endpoint,
1158
- });
1159
- this.state.condition = 100;
1160
- this.state.lastChangedTime = Math.floor(new Date().getTime() / 1000);
1161
- device.log.debug(`MatterbridgeActivatedCarbonFilterMonitoringServer: resetCondition called`);
1162
- }
1163
- }
1164
- export class MatterbridgeDeviceEnergyManagementServer extends DeviceEnergyManagementServer.with(DeviceEnergyManagement.Feature.PowerForecastReporting, DeviceEnergyManagement.Feature.PowerAdjustment) {
1165
- async powerAdjustRequest(request) {
1166
- const device = this.endpoint.stateOf(MatterbridgeServer);
1167
- device.log.info(`Adjusting power to ${request.power} duration ${request.duration} cause ${request.cause} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
1168
- await device.commandHandler.executeHandler('DeviceEnergyManagement.powerAdjustRequest', {
1169
- command: 'powerAdjustRequest',
1170
- request,
1171
- cluster: DeviceEnergyManagementServer.id,
1172
- attributes: this.state,
1173
- endpoint: this.endpoint,
1174
- });
1175
- device.log.debug(`MatterbridgeDeviceEnergyManagementServer powerAdjustRequest called with power ${request.power} duration ${request.duration} cause ${request.cause}`);
1176
- }
1177
- async cancelPowerAdjustRequest() {
1178
- const device = this.endpoint.stateOf(MatterbridgeServer);
1179
- device.log.info(`Cancelling power adjustment (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
1180
- await device.commandHandler.executeHandler('DeviceEnergyManagement.cancelPowerAdjustRequest', {
1181
- command: 'cancelPowerAdjustRequest',
1182
- request: {},
1183
- cluster: DeviceEnergyManagementServer.id,
1184
- attributes: this.state,
1185
- endpoint: this.endpoint,
1186
- });
1187
- device.log.debug(`MatterbridgeDeviceEnergyManagementServer cancelPowerAdjustRequest called`);
1188
- }
1189
- }
1190
- export class MatterbridgeDeviceEnergyManagementModeServer extends DeviceEnergyManagementModeServer {
1191
- async changeToMode(request) {
1192
- const device = this.endpoint.stateOf(MatterbridgeServer);
1193
- device.log.info(`Changing mode to ${request.newMode} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
1194
- await device.commandHandler.executeHandler('DeviceEnergyManagementMode.changeToMode', {
1195
- command: 'changeToMode',
1196
- request,
1197
- cluster: DeviceEnergyManagementModeServer.id,
1198
- attributes: this.state,
1199
- endpoint: this.endpoint,
1200
- });
1201
- const supported = this.state.supportedModes.find((mode) => mode.mode === request.newMode);
1202
- if (!supported) {
1203
- device.log.error(`MatterbridgeDeviceEnergyManagementModeServer changeToMode called with unsupported newMode: ${request.newMode}`);
1204
- return { status: ModeBase.ModeChangeStatus.UnsupportedMode, statusText: 'Unsupported mode' };
1205
- }
1206
- this.state.currentMode = request.newMode;
1207
- if (supported.modeTags.find((tag) => tag.value === DeviceEnergyManagementMode.ModeTag.NoOptimization)) {
1208
- if (this.endpoint.behaviors.has(DeviceEnergyManagementServer))
1209
- await this.endpoint.setStateOf(DeviceEnergyManagementServer.with(DeviceEnergyManagement.Feature.PowerForecastReporting, DeviceEnergyManagement.Feature.PowerAdjustment), {
1210
- optOutState: DeviceEnergyManagement.OptOutState.OptOut,
1211
- });
1212
- }
1213
- else {
1214
- if (this.endpoint.behaviors.has(DeviceEnergyManagementServer))
1215
- await this.endpoint.setStateOf(DeviceEnergyManagementServer.with(DeviceEnergyManagement.Feature.PowerForecastReporting, DeviceEnergyManagement.Feature.PowerAdjustment), {
1216
- optOutState: DeviceEnergyManagement.OptOutState.NoOptOut,
1217
- });
1218
- }
1219
- device.log.debug(`MatterbridgeDeviceEnergyManagementModeServer changeToMode called with newMode ${request.newMode} => ${supported.label}`);
1220
- return await super.changeToMode(request);
1221
- }
1222
- }