@matterbridge/core 3.10.7-dev-20260823-f911eb8 → 3.10.7-dev-20260825-7ebac36

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 (38) hide show
  1. package/dist/behaviors/export.d.ts +1 -0
  2. package/dist/behaviors/export.js +1 -0
  3. package/dist/behaviors/operationalStateServer.d.ts +12 -1
  4. package/dist/behaviors/operationalStateServer.js +77 -2
  5. package/dist/behaviors/pumpConfigurationAndControlServer.d.ts +23 -0
  6. package/dist/behaviors/pumpConfigurationAndControlServer.js +100 -0
  7. package/dist/behaviors/valveConfigurationAndControlServer.d.ts +20 -2
  8. package/dist/behaviors/valveConfigurationAndControlServer.js +98 -11
  9. package/dist/chipTests.js +31 -1
  10. package/dist/demoDevices.js +137 -5
  11. package/dist/devices/airConditioner.d.ts +6 -0
  12. package/dist/devices/airConditioner.js +6 -1
  13. package/dist/devices/cooktop.d.ts +16 -2
  14. package/dist/devices/cooktop.js +11 -5
  15. package/dist/devices/dishwasher.d.ts +18 -0
  16. package/dist/devices/dishwasher.js +25 -7
  17. package/dist/devices/extractorHood.d.ts +20 -1
  18. package/dist/devices/extractorHood.js +23 -4
  19. package/dist/devices/irrigationSystem.d.ts +5 -1
  20. package/dist/devices/irrigationSystem.js +35 -3
  21. package/dist/devices/laundryDryer.d.ts +18 -0
  22. package/dist/devices/laundryDryer.js +25 -7
  23. package/dist/devices/laundryWasher.d.ts +22 -0
  24. package/dist/devices/laundryWasher.js +30 -8
  25. package/dist/devices/microwaveOven.d.ts +17 -0
  26. package/dist/devices/microwaveOven.js +21 -12
  27. package/dist/devices/oven.d.ts +24 -2
  28. package/dist/devices/oven.js +40 -19
  29. package/dist/devices/refrigerator.d.ts +21 -1
  30. package/dist/devices/refrigerator.js +21 -11
  31. package/dist/devices/roboticVacuumCleaner.d.ts +21 -0
  32. package/dist/devices/roboticVacuumCleaner.js +28 -6
  33. package/dist/matterbridge.js +3 -2
  34. package/dist/matterbridgeEndpoint.d.ts +3 -3
  35. package/dist/matterbridgeEndpoint.js +21 -11
  36. package/dist/matterbridgeEndpointHelpers.d.ts +1 -1
  37. package/dist/matterbridgeEndpointHelpers.js +13 -12
  38. package/package.json +5 -5
@@ -15,6 +15,7 @@ export * from './onOffServer.js';
15
15
  export * from './occupancySensingServer.js';
16
16
  export * from './operationalStateServer.js';
17
17
  export * from './powerSourceServer.js';
18
+ export * from './pumpConfigurationAndControlServer.js';
18
19
  export * from './serviceAreaServer.js';
19
20
  export * from './smokeCoAlarmServer.js';
20
21
  export * from './switchServer.js';
@@ -15,6 +15,7 @@ export * from './onOffServer.js';
15
15
  export * from './occupancySensingServer.js';
16
16
  export * from './operationalStateServer.js';
17
17
  export * from './powerSourceServer.js';
18
+ export * from './pumpConfigurationAndControlServer.js';
18
19
  export * from './serviceAreaServer.js';
19
20
  export * from './smokeCoAlarmServer.js';
20
21
  export * from './switchServer.js';
@@ -1,10 +1,21 @@
1
1
  import type { MaybePromise } from '@matter/general';
2
2
  import { OperationalStateServer } from '@matter/node/behaviors/operational-state';
3
3
  import { OperationalState } from '@matter/types/clusters/operational-state';
4
- export declare class MatterbridgeOperationalStateServer extends OperationalStateServer {
4
+ declare const MatterbridgeOperationalStateServerBase: import("@matter/node").ClusterBehavior.Type<typeof OperationalStateServer, import("@matter/types").ClusterType.WithEnabledAttributes<import("@matter/types").ClusterType.WithEnabledEvents<OperationalState, "operationCompletion">, never>, import("@matter/types").ClusterType.Concrete, new () => {}, "operationalState">;
5
+ export declare class MatterbridgeOperationalStateServer extends MatterbridgeOperationalStateServerBase {
6
+ protected internal: MatterbridgeOperationalStateServer.Internal;
5
7
  initialize(): MaybePromise;
6
8
  pause(): Promise<OperationalState.OperationalCommandResponse>;
7
9
  stop(): Promise<OperationalState.OperationalCommandResponse>;
8
10
  start(): Promise<OperationalState.OperationalCommandResponse>;
9
11
  resume(): Promise<OperationalState.OperationalCommandResponse>;
10
12
  }
13
+ export declare namespace MatterbridgeOperationalStateServer {
14
+ class Internal extends MatterbridgeOperationalStateServerBase.Internal {
15
+ operationalStateBeforePause: OperationalState.OperationalStateEnum;
16
+ operationStartedAt: number | undefined;
17
+ pausedAccumulatedMs: number;
18
+ pausedSinceMs: number | undefined;
19
+ }
20
+ }
21
+ export {};
@@ -1,7 +1,8 @@
1
1
  import { OperationalStateServer } from '@matter/node/behaviors/operational-state';
2
2
  import { OperationalState } from '@matter/types/clusters/operational-state';
3
3
  import { MatterbridgeServer } from './matterbridgeServer.js';
4
- export class MatterbridgeOperationalStateServer extends OperationalStateServer {
4
+ const MatterbridgeOperationalStateServerBase = OperationalStateServer.enable({ events: { operationCompletion: true } });
5
+ export class MatterbridgeOperationalStateServer extends MatterbridgeOperationalStateServerBase {
5
6
  initialize() {
6
7
  const device = this.endpoint.stateOf(MatterbridgeServer);
7
8
  device.log.debug('MatterbridgeOperationalStateServer initialized: setting operational state to Stopped');
@@ -20,7 +21,21 @@ export class MatterbridgeOperationalStateServer extends OperationalStateServer {
20
21
  endpoint: this.endpoint,
21
22
  context: this.context,
22
23
  });
24
+ if (this.state.operationalState === OperationalState.OperationalStateEnum.Paused) {
25
+ device.log.debug('MatterbridgeOperationalStateServer: pause received while already Paused, taking no further action');
26
+ return {
27
+ commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Already paused' },
28
+ };
29
+ }
30
+ if (this.state.operationalState !== OperationalState.OperationalStateEnum.Running) {
31
+ device.log.debug(`MatterbridgeOperationalStateServer: pause received in state ${this.state.operationalState} which is not Pause-compatible`);
32
+ return {
33
+ commandResponseState: { errorStateId: OperationalState.ErrorState.CommandInvalidInState, errorStateDetails: 'Not Pause-compatible in the current operational state' },
34
+ };
35
+ }
23
36
  device.log.debug('MatterbridgeOperationalStateServer: pause called setting operational state to Paused');
37
+ this.internal.operationalStateBeforePause = this.state.operationalState;
38
+ this.internal.pausedSinceMs = Date.now();
24
39
  this.state.operationalState = OperationalState.OperationalStateEnum.Paused;
25
40
  this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' };
26
41
  return {
@@ -38,7 +53,22 @@ export class MatterbridgeOperationalStateServer extends OperationalStateServer {
38
53
  endpoint: this.endpoint,
39
54
  context: this.context,
40
55
  });
56
+ if (this.state.operationalState === OperationalState.OperationalStateEnum.Stopped) {
57
+ device.log.debug('MatterbridgeOperationalStateServer: stop received while already Stopped, taking no further action');
58
+ return {
59
+ commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Already stopped' },
60
+ };
61
+ }
41
62
  device.log.debug('MatterbridgeOperationalStateServer: stop called setting operational state to Stopped');
63
+ if (this.internal.pausedSinceMs !== undefined) {
64
+ this.internal.pausedAccumulatedMs += Date.now() - this.internal.pausedSinceMs;
65
+ this.internal.pausedSinceMs = undefined;
66
+ }
67
+ const totalOperationalTime = this.internal.operationStartedAt === undefined ? null : Math.round((Date.now() - this.internal.operationStartedAt) / 1000);
68
+ const pausedTime = this.internal.operationStartedAt === undefined ? null : Math.round(this.internal.pausedAccumulatedMs / 1000);
69
+ this.internal.operationStartedAt = undefined;
70
+ this.internal.pausedAccumulatedMs = 0;
71
+ this.events.operationCompletion.emit({ completionErrorCode: OperationalState.ErrorState.NoError, totalOperationalTime, pausedTime }, this.context);
42
72
  this.state.operationalState = OperationalState.OperationalStateEnum.Stopped;
43
73
  this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' };
44
74
  return {
@@ -56,7 +86,27 @@ export class MatterbridgeOperationalStateServer extends OperationalStateServer {
56
86
  endpoint: this.endpoint,
57
87
  context: this.context,
58
88
  });
89
+ if (this.state.operationalState === OperationalState.OperationalStateEnum.Running) {
90
+ device.log.debug('MatterbridgeOperationalStateServer: start received while already Running, taking no further action');
91
+ return {
92
+ commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Already running' },
93
+ };
94
+ }
95
+ if (this.state.operationalState === OperationalState.OperationalStateEnum.Error) {
96
+ device.log.debug('MatterbridgeOperationalStateServer: start received while in the Error state, unable to honor');
97
+ return {
98
+ commandResponseState: { errorStateId: OperationalState.ErrorState.UnableToStartOrResume, errorStateDetails: 'Unable to start while in the Error state' },
99
+ };
100
+ }
59
101
  device.log.debug('MatterbridgeOperationalStateServer: start called setting operational state to Running');
102
+ if (this.state.operationalState === OperationalState.OperationalStateEnum.Paused && this.internal.pausedSinceMs !== undefined) {
103
+ this.internal.pausedAccumulatedMs += Date.now() - this.internal.pausedSinceMs;
104
+ this.internal.pausedSinceMs = undefined;
105
+ }
106
+ else {
107
+ this.internal.operationStartedAt = Date.now();
108
+ this.internal.pausedAccumulatedMs = 0;
109
+ }
60
110
  this.state.operationalState = OperationalState.OperationalStateEnum.Running;
61
111
  this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' };
62
112
  return {
@@ -74,11 +124,36 @@ export class MatterbridgeOperationalStateServer extends OperationalStateServer {
74
124
  endpoint: this.endpoint,
75
125
  context: this.context,
76
126
  });
127
+ if (this.state.operationalState === OperationalState.OperationalStateEnum.Running) {
128
+ device.log.debug('MatterbridgeOperationalStateServer: resume received while already Running, taking no further action');
129
+ return {
130
+ commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Already running' },
131
+ };
132
+ }
133
+ if (this.state.operationalState !== OperationalState.OperationalStateEnum.Paused) {
134
+ device.log.debug(`MatterbridgeOperationalStateServer: resume received in state ${this.state.operationalState} which is not Resume-compatible`);
135
+ return {
136
+ commandResponseState: { errorStateId: OperationalState.ErrorState.CommandInvalidInState, errorStateDetails: 'Not Resume-compatible in the current operational state' },
137
+ };
138
+ }
77
139
  device.log.debug('MatterbridgeOperationalStateServer: resume called setting operational state to Running');
78
- this.state.operationalState = OperationalState.OperationalStateEnum.Running;
140
+ if (this.internal.pausedSinceMs !== undefined) {
141
+ this.internal.pausedAccumulatedMs += Date.now() - this.internal.pausedSinceMs;
142
+ this.internal.pausedSinceMs = undefined;
143
+ }
144
+ this.state.operationalState = this.internal.operationalStateBeforePause;
79
145
  this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' };
80
146
  return {
81
147
  commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateDetails: 'Fully operational' },
82
148
  };
83
149
  }
84
150
  }
151
+ (function (MatterbridgeOperationalStateServer) {
152
+ class Internal extends MatterbridgeOperationalStateServerBase.Internal {
153
+ operationalStateBeforePause = OperationalState.OperationalStateEnum.Running;
154
+ operationStartedAt;
155
+ pausedAccumulatedMs = 0;
156
+ pausedSinceMs;
157
+ }
158
+ MatterbridgeOperationalStateServer.Internal = Internal;
159
+ })(MatterbridgeOperationalStateServer || (MatterbridgeOperationalStateServer = {}));
@@ -0,0 +1,23 @@
1
+ import type { MaybePromise } from '@matter/general';
2
+ import { PumpConfigurationAndControlServer } from '@matter/node/behaviors/pump-configuration-and-control';
3
+ import { PumpConfigurationAndControl } from '@matter/types/clusters/pump-configuration-and-control';
4
+ declare const MatterbridgePumpConfigurationAndControlServer_base: import("@matter/node").ClusterBehavior.Type<typeof PumpConfigurationAndControlServer, import("@matter/types").ClusterType.WithSupportedFeatures<PumpConfigurationAndControl, {
5
+ automatic: false;
6
+ compensatedPressure: false;
7
+ constantFlow: false;
8
+ constantPressure: false;
9
+ constantSpeed: true;
10
+ constantTemperature: false;
11
+ localOperation: false;
12
+ }>, import("@matter/types").ClusterType.Concrete, new () => {}, "pumpConfigurationAndControl">;
13
+ export declare class MatterbridgePumpConfigurationAndControlServer extends MatterbridgePumpConfigurationAndControlServer_base {
14
+ #private;
15
+ protected internal: MatterbridgePumpConfigurationAndControlServer.Internal;
16
+ initialize(): MaybePromise;
17
+ }
18
+ export declare namespace MatterbridgePumpConfigurationAndControlServer {
19
+ class Internal {
20
+ lastLevel?: number;
21
+ }
22
+ }
23
+ export {};
@@ -0,0 +1,100 @@
1
+ import { LevelControlServer } from '@matter/node/behaviors/level-control';
2
+ import { OnOffServer } from '@matter/node/behaviors/on-off';
3
+ import { PumpConfigurationAndControlServer } from '@matter/node/behaviors/pump-configuration-and-control';
4
+ import { Status, StatusResponseError } from '@matter/types';
5
+ import { PumpConfigurationAndControl } from '@matter/types/clusters/pump-configuration-and-control';
6
+ import { MatterbridgeServer } from './matterbridgeServer.js';
7
+ export class MatterbridgePumpConfigurationAndControlServer extends PumpConfigurationAndControlServer.with(PumpConfigurationAndControl.Feature.ConstantSpeed) {
8
+ initialize() {
9
+ this.state.minConstSpeed ??= 600;
10
+ this.state.maxConstSpeed ??= 3000;
11
+ this.state.maxPressure ??= 6000;
12
+ this.state.maxSpeed ??= 3000;
13
+ this.state.maxFlow ??= 100;
14
+ const device = this.endpoint.stateOf(MatterbridgeServer);
15
+ device.log.info(`MatterbridgePumpConfigurationAndControlServer: initialized with minConstSpeed=${this.state.minConstSpeed}, maxConstSpeed=${this.state.maxConstSpeed}, maxPressure=${this.state.maxPressure}, maxSpeed=${this.state.maxSpeed}, maxFlow=${this.state.maxFlow} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
16
+ if (this.endpoint.behaviors.has(OnOffServer.id)) {
17
+ this.reactTo(this.agent.get(OnOffServer).events.onOff$Changed, this.#handleOnOffChanged);
18
+ }
19
+ if (this.endpoint.behaviors.has(LevelControlServer.id)) {
20
+ const levelControlState = this.agent.get(LevelControlServer).state;
21
+ this.internal.lastLevel = levelControlState.currentLevel ?? levelControlState.maxLevel;
22
+ this.reactTo(this.agent.get(LevelControlServer).events.currentLevel$Changed, this.#handleCurrentLevelChanged);
23
+ }
24
+ this.reactTo(this.events.operationMode$Changing, this.#handleOperationModeChanging);
25
+ this.reactTo(this.events.operationMode$Changed, this.#handleOperationModeChanged);
26
+ }
27
+ #percentFromLevel(currentLevel) {
28
+ if (currentLevel <= 0)
29
+ return 0;
30
+ return currentLevel <= 200 ? currentLevel / 2 : 100;
31
+ }
32
+ #speedFromPercent(percent) {
33
+ const maxConstSpeed = this.state.maxConstSpeed ?? this.state.maxSpeed ?? 0;
34
+ return Math.round((percent / 100) * maxConstSpeed);
35
+ }
36
+ #capacityFromPercent(percent) {
37
+ return Math.round(percent * 200);
38
+ }
39
+ #currentSetpoint(normalLevel) {
40
+ const maxConstSpeed = this.state.maxConstSpeed ?? this.state.maxSpeed ?? 0;
41
+ if (this.state.operationMode === PumpConfigurationAndControl.OperationMode.Minimum) {
42
+ const speed = this.state.minConstSpeed ?? 0;
43
+ return { speed, percent: maxConstSpeed > 0 ? (speed / maxConstSpeed) * 100 : 0 };
44
+ }
45
+ if (this.state.operationMode === PumpConfigurationAndControl.OperationMode.Maximum) {
46
+ return { speed: maxConstSpeed, percent: 100 };
47
+ }
48
+ const percent = this.#percentFromLevel(normalLevel);
49
+ return { speed: this.#speedFromPercent(percent), percent };
50
+ }
51
+ #applySetpoint(normalLevel) {
52
+ const { speed, percent } = this.#currentSetpoint(normalLevel);
53
+ const capacity = this.#capacityFromPercent(percent);
54
+ this.agent.asLocalActor(() => {
55
+ this.state.speed = speed;
56
+ this.state.capacity = capacity;
57
+ });
58
+ return { speed, capacity };
59
+ }
60
+ #stopPump() {
61
+ this.agent.asLocalActor(() => {
62
+ this.state.speed = 0;
63
+ this.state.capacity = 0;
64
+ });
65
+ return { speed: 0, capacity: 0 };
66
+ }
67
+ #handleOperationModeChanging() {
68
+ if (this.state.pumpStatus?.localOverride) {
69
+ throw new StatusResponseError('OperationMode cannot be changed while PumpStatus.LocalOverride is set', Status.Failure);
70
+ }
71
+ }
72
+ #handleOperationModeChanged(operationMode, oldOperationMode) {
73
+ const device = this.endpoint.stateOf(MatterbridgeServer);
74
+ device.log.info(`MatterbridgePumpConfigurationAndControlServer: operationMode changed to ${operationMode} from ${oldOperationMode} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
75
+ this.agent.asLocalActor(() => {
76
+ this.state.effectiveOperationMode = operationMode;
77
+ });
78
+ const { speed, capacity } = this.#applySetpoint(this.internal.lastLevel ?? 254);
79
+ device.log.info(`MatterbridgePumpConfigurationAndControlServer: pump speed changed to ${speed}, capacity changed to ${capacity} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
80
+ }
81
+ #handleOnOffChanged(onOff, oldOnOff) {
82
+ const device = this.endpoint.stateOf(MatterbridgeServer);
83
+ device.log.info(`MatterbridgePumpConfigurationAndControlServer: onOff changed to ${onOff} from ${oldOnOff} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
84
+ const { speed, capacity } = onOff ? this.#applySetpoint(this.internal.lastLevel ?? 254) : this.#stopPump();
85
+ device.log.info(`MatterbridgePumpConfigurationAndControlServer: pump speed changed to ${speed}, capacity changed to ${capacity} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
86
+ }
87
+ #handleCurrentLevelChanged(currentLevel, oldCurrentLevel) {
88
+ const device = this.endpoint.stateOf(MatterbridgeServer);
89
+ device.log.info(`MatterbridgePumpConfigurationAndControlServer: currentLevel changed to ${currentLevel} from ${oldCurrentLevel} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
90
+ this.internal.lastLevel = currentLevel ?? this.internal.lastLevel;
91
+ const { speed, capacity } = this.#applySetpoint(currentLevel ?? 0);
92
+ device.log.info(`MatterbridgePumpConfigurationAndControlServer: pump speed changed to ${speed}, capacity changed to ${capacity} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
93
+ }
94
+ }
95
+ (function (MatterbridgePumpConfigurationAndControlServer) {
96
+ class Internal {
97
+ lastLevel;
98
+ }
99
+ MatterbridgePumpConfigurationAndControlServer.Internal = Internal;
100
+ })(MatterbridgePumpConfigurationAndControlServer || (MatterbridgePumpConfigurationAndControlServer = {}));
@@ -1,11 +1,29 @@
1
+ import { type MaybePromise, type Timer } from '@matter/general';
1
2
  import { ValveConfigurationAndControlServer } from '@matter/node/behaviors/valve-configuration-and-control';
2
3
  import { ValveConfigurationAndControl } from '@matter/types/clusters/valve-configuration-and-control';
3
- declare const MatterbridgeValveConfigurationAndControlServer_base: import("@matter/node").ClusterBehavior.Type<typeof ValveConfigurationAndControlServer, import("@matter/types").ClusterType.WithSupportedFeatures<ValveConfigurationAndControl, {
4
+ declare const MatterbridgeValveConfigurationAndControlServerBase: import("@matter/node").ClusterBehavior.Type<typeof ValveConfigurationAndControlServer, import("@matter/types").ClusterType.WithSupportedFeatures<ValveConfigurationAndControl, {
4
5
  level: true;
5
6
  timeSync: false;
6
7
  }>, import("@matter/types").ClusterType.Concrete, new () => {}, "valveConfigurationAndControl">;
7
- export declare class MatterbridgeValveConfigurationAndControlServer extends MatterbridgeValveConfigurationAndControlServer_base {
8
+ export declare class MatterbridgeValveConfigurationAndControlServer extends MatterbridgeValveConfigurationAndControlServerBase {
9
+ #private;
10
+ readonly state: MatterbridgeValveConfigurationAndControlServer.State;
11
+ protected internal: MatterbridgeValveConfigurationAndControlServer.Internal;
12
+ initialize(): MaybePromise;
8
13
  open(request: ValveConfigurationAndControl.OpenRequest): Promise<void>;
9
14
  close(): Promise<void>;
15
+ [Symbol.asyncDispose](): Promise<void>;
16
+ }
17
+ export declare namespace MatterbridgeValveConfigurationAndControlServer {
18
+ class Internal extends MatterbridgeValveConfigurationAndControlServerBase.Internal {
19
+ movementTimer?: Timer;
20
+ movementFinalState: ValveConfigurationAndControl.ValveState;
21
+ movementFinalLevel: number;
22
+ autoCloseTimer?: Timer;
23
+ }
24
+ class State extends MatterbridgeValveConfigurationAndControlServerBase.State {
25
+ movementDuration: number;
26
+ autoClose: boolean;
27
+ }
10
28
  }
11
29
  export {};
@@ -1,7 +1,17 @@
1
+ import { Millis, Seconds, Time } from '@matter/general';
1
2
  import { ValveConfigurationAndControlServer } from '@matter/node/behaviors/valve-configuration-and-control';
3
+ import { Status, StatusResponseError } from '@matter/types';
2
4
  import { ValveConfigurationAndControl } from '@matter/types/clusters/valve-configuration-and-control';
3
5
  import { MatterbridgeServer } from './matterbridgeServer.js';
4
- export class MatterbridgeValveConfigurationAndControlServer extends ValveConfigurationAndControlServer.with(ValveConfigurationAndControl.Feature.Level) {
6
+ const MatterbridgeValveConfigurationAndControlServerBase = ValveConfigurationAndControlServer.with(ValveConfigurationAndControl.Feature.Level);
7
+ export class MatterbridgeValveConfigurationAndControlServer extends MatterbridgeValveConfigurationAndControlServerBase {
8
+ initialize() {
9
+ if (process.env.MATTERBRIDGE_CHIP_TEST) {
10
+ this.state.movementDuration = 2000;
11
+ this.state.autoClose = true;
12
+ }
13
+ return super.initialize();
14
+ }
5
15
  async open(request) {
6
16
  const device = this.endpoint.stateOf(MatterbridgeServer);
7
17
  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})`);
@@ -14,13 +24,25 @@ export class MatterbridgeValveConfigurationAndControlServer extends ValveConfigu
14
24
  context: this.context,
15
25
  });
16
26
  device.log.debug(`MatterbridgeValveConfigurationAndControlServer: open called with openDuration: ${request.openDuration} targetLevel: ${request.targetLevel}`);
27
+ if (this.#hasFault()) {
28
+ throw new ValveConfigurationAndControl.FailureDueToFaultError('Open ignored: the valve has a registered fault');
29
+ }
30
+ this.#stopMovementTimer();
31
+ this.#stopAutoCloseTimer();
17
32
  this.state.targetState = ValveConfigurationAndControl.ValveState.Open;
18
- this.state.currentState = ValveConfigurationAndControl.ValveState.Open;
19
- this.state.targetLevel = request.targetLevel ?? 100;
20
- this.state.currentLevel = request.targetLevel ?? 100;
21
- this.state.openDuration = request.openDuration ?? this.state.defaultOpenDuration;
22
- if (this.state.openDuration === null)
23
- this.state.remainingDuration = null;
33
+ this.state.currentState = ValveConfigurationAndControl.ValveState.Transitioning;
34
+ this.state.openDuration = request.openDuration === undefined ? this.state.defaultOpenDuration : request.openDuration;
35
+ this.state.remainingDuration = this.state.openDuration;
36
+ if (this.features.level) {
37
+ if (request.targetLevel !== undefined && request.targetLevel !== 100 && this.state.levelStep !== undefined && request.targetLevel % this.state.levelStep !== 0) {
38
+ throw new StatusResponseError(`Open TargetLevel ${request.targetLevel} is not a multiple of LevelStep ${this.state.levelStep}`, Status.ConstraintError);
39
+ }
40
+ this.state.targetLevel = request.targetLevel ?? this.state.defaultOpenLevel ?? 100;
41
+ }
42
+ if (this.state.movementDuration > 0)
43
+ this.#scheduleMovementComplete(ValveConfigurationAndControl.ValveState.Open, this.state.targetLevel ?? 100);
44
+ if (this.state.autoClose && this.state.remainingDuration !== null)
45
+ this.#scheduleAutoClose();
24
46
  }
25
47
  async close() {
26
48
  const device = this.endpoint.stateOf(MatterbridgeServer);
@@ -34,11 +56,76 @@ export class MatterbridgeValveConfigurationAndControlServer extends ValveConfigu
34
56
  context: this.context,
35
57
  });
36
58
  device.log.debug(`MatterbridgeValveConfigurationAndControlServer: close called`);
37
- this.state.targetState = ValveConfigurationAndControl.ValveState.Closed;
38
- this.state.currentState = ValveConfigurationAndControl.ValveState.Closed;
39
- this.state.targetLevel = 0;
40
- this.state.currentLevel = 0;
59
+ if (this.#hasFault()) {
60
+ throw new ValveConfigurationAndControl.FailureDueToFaultError('Close ignored: the valve has a registered fault');
61
+ }
62
+ this.#stopMovementTimer();
63
+ this.#stopAutoCloseTimer();
41
64
  this.state.openDuration = null;
42
65
  this.state.remainingDuration = null;
66
+ this.state.targetState = ValveConfigurationAndControl.ValveState.Closed;
67
+ this.state.currentState = ValveConfigurationAndControl.ValveState.Transitioning;
68
+ if (this.features.level)
69
+ this.state.targetLevel = 0;
70
+ if (this.state.movementDuration > 0)
71
+ this.#scheduleMovementComplete(ValveConfigurationAndControl.ValveState.Closed, 0);
72
+ }
73
+ #hasFault() {
74
+ const fault = this.state.valveFault;
75
+ return fault !== undefined && Object.values(fault).some((bit) => bit === true);
76
+ }
77
+ #stopMovementTimer() {
78
+ this.internal.movementTimer?.stop();
79
+ this.internal.movementTimer = undefined;
80
+ }
81
+ #stopAutoCloseTimer() {
82
+ this.internal.autoCloseTimer?.stop();
83
+ this.internal.autoCloseTimer = undefined;
84
+ }
85
+ #scheduleMovementComplete(finalState, finalLevel) {
86
+ this.internal.movementFinalState = finalState;
87
+ this.internal.movementFinalLevel = finalLevel;
88
+ this.internal.movementTimer = Time.getTimer('ValveConfigurationAndControl movement complete', Millis(this.state.movementDuration), this.callback(this.#completeMovement, { lock: true })).start();
89
+ }
90
+ #completeMovement() {
91
+ this.internal.movementTimer = undefined;
92
+ this.state.currentState = this.internal.movementFinalState;
93
+ if (this.features.level)
94
+ this.state.currentLevel = this.internal.movementFinalLevel;
95
+ this.state.targetState = null;
96
+ if (this.features.level)
97
+ this.state.targetLevel = null;
98
+ }
99
+ #scheduleAutoClose() {
100
+ this.internal.autoCloseTimer = Time.getPeriodicTimer('ValveConfigurationAndControl auto close', Seconds(1), this.callback(this.#tickAutoClose, { lock: true })).start();
101
+ }
102
+ #tickAutoClose() {
103
+ if (this.state.remainingDuration === null)
104
+ return;
105
+ const remaining = Math.max(0, this.state.remainingDuration - 1);
106
+ this.state.remainingDuration = remaining;
107
+ if (remaining === 0) {
108
+ this.#stopAutoCloseTimer();
109
+ void this.close();
110
+ }
111
+ }
112
+ async [Symbol.asyncDispose]() {
113
+ this.#stopMovementTimer();
114
+ this.#stopAutoCloseTimer();
115
+ await super[Symbol.asyncDispose]?.();
43
116
  }
44
117
  }
118
+ (function (MatterbridgeValveConfigurationAndControlServer) {
119
+ class Internal extends MatterbridgeValveConfigurationAndControlServerBase.Internal {
120
+ movementTimer;
121
+ movementFinalState = ValveConfigurationAndControl.ValveState.Closed;
122
+ movementFinalLevel = 0;
123
+ autoCloseTimer;
124
+ }
125
+ MatterbridgeValveConfigurationAndControlServer.Internal = Internal;
126
+ class State extends MatterbridgeValveConfigurationAndControlServerBase.State {
127
+ movementDuration = 0;
128
+ autoClose = false;
129
+ }
130
+ MatterbridgeValveConfigurationAndControlServer.State = State;
131
+ })(MatterbridgeValveConfigurationAndControlServer || (MatterbridgeValveConfigurationAndControlServer = {}));
package/dist/chipTests.js CHANGED
@@ -10,6 +10,7 @@ import { ClosureControl } from '@matter/types/clusters/closure-control';
10
10
  import { DeviceEnergyManagement } from '@matter/types/clusters/device-energy-management';
11
11
  import { ElectricalEnergyMeasurement } from '@matter/types/clusters/electrical-energy-measurement';
12
12
  import { ElectricalPowerMeasurement } from '@matter/types/clusters/electrical-power-measurement';
13
+ import { OperationalState } from '@matter/types/clusters/operational-state';
13
14
  import { SmokeCoAlarm } from '@matter/types/clusters/smoke-co-alarm';
14
15
  import { MatterbridgeOccupancySensingServer } from './behaviors/occupancySensingServer.js';
15
16
  import { cliEmitter } from './cliEmitter.js';
@@ -579,6 +580,32 @@ async function handleChipTestAppPipeCommand(matterbridge, command) {
579
580
  await endpoint.setStateOf(endpoint.behaviors.supported.soilMeasurement, { soilMoistureMeasuredValue: command.SoilMoistureValue ?? null });
580
581
  matterbridge.log.info(`CHIP test app pipe set SoilMeasurement.SoilMoistureMeasuredValue to ${command.SoilMoistureValue ?? null} on endpoint ${endpointId}`);
581
582
  return;
583
+ case 'OperationalStateChange':
584
+ switch (command.Operation) {
585
+ case 'Stop':
586
+ await endpoint.setStateOf(endpoint.behaviors.supported.operationalState, { operationalState: OperationalState.OperationalStateEnum.Stopped });
587
+ break;
588
+ case 'Start':
589
+ await endpoint.setStateOf(endpoint.behaviors.supported.operationalState, { operationalState: OperationalState.OperationalStateEnum.Running });
590
+ break;
591
+ case 'Pause':
592
+ await endpoint.setStateOf(endpoint.behaviors.supported.operationalState, { operationalState: OperationalState.OperationalStateEnum.Paused });
593
+ break;
594
+ case 'OnFault': {
595
+ const errorStateId = command.Param ?? OperationalState.ErrorState.NoError;
596
+ const isNoError = errorStateId === OperationalState.ErrorState.NoError;
597
+ await endpoint.setStateOf(endpoint.behaviors.supported.operationalState, {
598
+ operationalError: { errorStateId, errorStateDetails: isNoError ? 'Fully operational' : 'Simulated CHIP test fault' },
599
+ ...(isNoError ? {} : { operationalState: OperationalState.OperationalStateEnum.Error }),
600
+ });
601
+ break;
602
+ }
603
+ default:
604
+ matterbridge.log.warn(`Ignoring unsupported CHIP test app pipe OperationalStateChange operation: ${JSON.stringify(command)}`);
605
+ return;
606
+ }
607
+ matterbridge.log.info(`CHIP test app pipe OperationalStateChange(${command.Operation}${command.Param === undefined ? '' : `, ${command.Param}`}) applied on endpoint ${endpointId}`);
608
+ return;
582
609
  default:
583
610
  matterbridge.log.warn(`Ignoring unsupported CHIP test app pipe command: ${JSON.stringify(command)}`);
584
611
  }
@@ -606,5 +633,8 @@ function isChipTestAppPipeCommand(value) {
606
633
  (!('NewState' in value) || typeof value.NewState === 'boolean') &&
607
634
  (!('Occupancy' in value) || typeof value.Occupancy === 'number') &&
608
635
  (!('SensorFault' in value) || typeof value.SensorFault === 'number') &&
609
- (!('SoilMoistureValue' in value) || typeof value.SoilMoistureValue === 'number'));
636
+ (!('SoilMoistureValue' in value) || typeof value.SoilMoistureValue === 'number') &&
637
+ (!('Device' in value) || typeof value.Device === 'string') &&
638
+ (!('Operation' in value) || typeof value.Operation === 'string') &&
639
+ (!('Param' in value) || typeof value.Param === 'number'));
610
640
  }