@matterbridge/core 3.10.8-dev-20260901-971f7bf → 3.10.8-dev-20260902-361500d

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.
@@ -1,4 +1,4 @@
1
- import type { MaybePromise } from '@matter/general';
1
+ import { type MaybePromise, type Timer } from '@matter/general';
2
2
  import { ClosureControlServer } from '@matter/node/behaviors/closure-control';
3
3
  import { type EndpointNumber } from '@matter/types';
4
4
  import { ClosureControl } from '@matter/types/clusters/closure-control';
@@ -18,19 +18,21 @@ declare const MatterbridgeClosureControlServerBase: import("@matter/node").Clust
18
18
  ventilation: false;
19
19
  }>, import("@matter/types").ClusterType.Concrete, new () => {}, "closureControl">;
20
20
  export declare class MatterbridgeClosureControlServer extends MatterbridgeClosureControlServerBase {
21
+ #private;
21
22
  readonly state: MatterbridgeClosureControlServer.State;
22
23
  protected internal: MatterbridgeClosureControlServer.Internal;
23
24
  initialize(): MaybePromise;
24
25
  moveTo: (request: ClosureControl.MoveToRequest) => Promise<void>;
25
- private completeMoveTo;
26
26
  stop: () => Promise<void>;
27
27
  calibrate: () => Promise<void>;
28
- private completeCalibrate;
28
+ [Symbol.asyncDispose](): Promise<void>;
29
29
  }
30
30
  export declare namespace MatterbridgeClosureControlServer {
31
31
  class Internal extends MatterbridgeClosureControlServerBase.Internal {
32
- movementTimer?: NodeJS.Timeout;
33
- calibrateTimer?: NodeJS.Timeout;
32
+ movementTimer?: Timer;
33
+ movementTargetState: ClosureControl.OverallTargetState;
34
+ movementPreviousState: ClosureControl.OverallCurrentState;
35
+ calibrateTimer?: Timer;
34
36
  }
35
37
  class State extends MatterbridgeClosureControlServerBase.State {
36
38
  movementDuration: number;
@@ -1,3 +1,4 @@
1
+ import { Millis, Time } from '@matter/general';
1
2
  import { ClosureTag } from '@matter/node';
2
3
  import { ClosureControlServer } from '@matter/node/behaviors/closure-control';
3
4
  import { StatusResponse } from '@matter/types';
@@ -73,25 +74,24 @@ export class MatterbridgeClosureControlServer extends MatterbridgeClosureControl
73
74
  (!this.features.motionLatching || nextTarget.latch === undefined || nextTarget.latch === currentState.latch) &&
74
75
  (!this.features.speed || nextTarget.speed === currentState.speed);
75
76
  this.state.mainState = isAtTarget ? ClosureControl.MainState.Stopped : ClosureControl.MainState.Moving;
76
- clearTimeout(this.internal.movementTimer);
77
+ this.internal.movementTimer?.stop();
78
+ this.internal.movementTimer = undefined;
77
79
  if (isAtTarget) {
78
- this.internal.movementTimer = undefined;
79
80
  this.state.countdownTime = 0;
80
81
  }
81
82
  else if (currentState === null || this.state.movementDuration <= 0) {
82
- this.internal.movementTimer = undefined;
83
83
  }
84
84
  else {
85
85
  this.state.countdownTime = this.state.movementDuration / 1000;
86
- const previousState = currentState;
87
- this.internal.movementTimer = setTimeout(() => {
88
- this.internal.movementTimer = undefined;
89
- void this.completeMoveTo(nextTarget, previousState);
90
- }, this.state.movementDuration);
86
+ this.internal.movementTargetState = nextTarget;
87
+ this.internal.movementPreviousState = currentState;
88
+ this.internal.movementTimer = Time.getTimer('ClosureControl movement complete', Millis(this.state.movementDuration), this.callback(this.#completeMoveTo, { lock: true })).start();
91
89
  }
92
90
  };
93
- completeMoveTo = async (targetState, previousState) => {
94
- const closure = this.endpoint;
91
+ #completeMoveTo() {
92
+ this.internal.movementTimer = undefined;
93
+ const targetState = this.internal.movementTargetState;
94
+ const previousState = this.internal.movementPreviousState;
95
95
  let position = previousState.position;
96
96
  if (targetState.position !== undefined && targetState.position !== null) {
97
97
  const mappedPosition = targetToCurrentPosition[targetState.position];
@@ -100,17 +100,25 @@ export class MatterbridgeClosureControlServer extends MatterbridgeClosureControl
100
100
  }
101
101
  const latch = targetState.latch ?? previousState.latch;
102
102
  const secureState = this.features.motionLatching ? latch === true : position === ClosureControl.CurrentPosition.FullyClosed;
103
- await closure.setState({
103
+ this.state.countdownTime = 0;
104
+ this.state.mainState = ClosureControl.MainState.Stopped;
105
+ this.state.currentErrorList = [];
106
+ this.state.overallCurrentState = {
104
107
  position,
105
108
  ...(this.features.motionLatching ? { latch } : null),
106
109
  ...(this.features.speed ? { speed: targetState.speed } : null),
107
110
  secureState,
108
- }, targetState, ClosureControl.MainState.Stopped, 0);
111
+ };
112
+ this.state.overallTargetState = {
113
+ position: targetState.position,
114
+ ...(this.features.motionLatching ? { latch: targetState.latch } : null),
115
+ ...(this.features.speed ? { speed: targetState.speed } : null),
116
+ };
109
117
  if (secureState !== previousState.secureState) {
110
- await closure.triggerSecureStateChanged(secureState);
118
+ this.events.secureStateChanged.emit({ secureValue: secureState }, this.context);
111
119
  }
112
- await closure.triggerMovementCompleted();
113
- };
120
+ this.events.movementCompleted.emit(undefined, this.context);
121
+ }
114
122
  stop = async () => {
115
123
  const device = this.endpoint.stateOf(MatterbridgeServer);
116
124
  device.log.info(`Stop (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
@@ -121,9 +129,9 @@ export class MatterbridgeClosureControlServer extends MatterbridgeClosureControl
121
129
  attributes: this.state,
122
130
  endpoint: this.endpoint,
123
131
  });
124
- clearTimeout(this.internal.movementTimer);
132
+ this.internal.movementTimer?.stop();
125
133
  this.internal.movementTimer = undefined;
126
- clearTimeout(this.internal.calibrateTimer);
134
+ this.internal.calibrateTimer?.stop();
127
135
  this.internal.calibrateTimer = undefined;
128
136
  if ([ClosureControl.MainState.Moving, ClosureControl.MainState.WaitingForMotion, ClosureControl.MainState.Calibrating].includes(this.state.mainState)) {
129
137
  this.state.mainState = ClosureControl.MainState.Stopped;
@@ -147,27 +155,33 @@ export class MatterbridgeClosureControlServer extends MatterbridgeClosureControl
147
155
  throw new StatusResponse.InvalidInStateError('ClosureControl.calibrate is only allowed while Stopped or SetupRequired');
148
156
  }
149
157
  this.state.mainState = ClosureControl.MainState.Calibrating;
150
- clearTimeout(this.internal.calibrateTimer);
158
+ this.internal.calibrateTimer?.stop();
151
159
  if (this.state.calibrationDuration <= 0) {
152
160
  this.internal.calibrateTimer = undefined;
153
161
  }
154
162
  else {
155
163
  this.state.countdownTime = this.state.calibrationDuration / 1000;
156
- this.internal.calibrateTimer = setTimeout(() => {
157
- this.internal.calibrateTimer = undefined;
158
- void this.completeCalibrate();
159
- }, this.state.calibrationDuration);
164
+ this.internal.calibrateTimer = Time.getTimer('ClosureControl calibrate complete', Millis(this.state.calibrationDuration), this.callback(this.#completeCalibrate, { lock: true })).start();
160
165
  }
161
166
  };
162
- completeCalibrate = async () => {
163
- const closure = this.endpoint;
164
- await closure.setAttribute(ClosureControl, 'countdownTime', 0);
165
- await closure.setAttribute(ClosureControl, 'mainState', ClosureControl.MainState.Stopped);
166
- };
167
+ #completeCalibrate() {
168
+ this.internal.calibrateTimer = undefined;
169
+ this.state.countdownTime = 0;
170
+ this.state.mainState = ClosureControl.MainState.Stopped;
171
+ }
172
+ async [Symbol.asyncDispose]() {
173
+ this.internal.movementTimer?.stop();
174
+ this.internal.movementTimer = undefined;
175
+ this.internal.calibrateTimer?.stop();
176
+ this.internal.calibrateTimer = undefined;
177
+ await super[Symbol.asyncDispose]?.();
178
+ }
167
179
  }
168
180
  (function (MatterbridgeClosureControlServer) {
169
181
  class Internal extends MatterbridgeClosureControlServerBase.Internal {
170
182
  movementTimer;
183
+ movementTargetState = {};
184
+ movementPreviousState = { position: ClosureControl.CurrentPosition.FullyClosed, secureState: true };
171
185
  calibrateTimer;
172
186
  }
173
187
  MatterbridgeClosureControlServer.Internal = Internal;
@@ -1,4 +1,4 @@
1
- import type { MaybePromise } from '@matter/general';
1
+ import { type MaybePromise, type Timer } from '@matter/general';
2
2
  import { ClosureDimensionServer } from '@matter/node/behaviors/closure-dimension';
3
3
  import { ClosureDimension } from '@matter/types/clusters/closure-dimension';
4
4
  import type { EndpointNumber } from '@matter/types/datatype';
@@ -15,17 +15,19 @@ declare const MatterbridgeClosureDimensionServerBase: import("@matter/node").Clu
15
15
  unit: false;
16
16
  }>, import("@matter/types").ClusterType.Concrete, new () => {}, "closureDimension">;
17
17
  export declare class MatterbridgeClosureDimensionServer extends MatterbridgeClosureDimensionServerBase {
18
+ #private;
18
19
  readonly state: MatterbridgeClosureDimensionServer.State;
19
20
  protected internal: MatterbridgeClosureDimensionServer.Internal;
20
21
  initialize(): MaybePromise;
21
22
  setTarget: (request: ClosureDimension.SetTargetRequest) => Promise<void>;
22
23
  step: (request: ClosureDimension.StepRequest) => Promise<void>;
23
- private scheduleMovement;
24
- private completeMovement;
24
+ [Symbol.asyncDispose](): Promise<void>;
25
25
  }
26
26
  export declare namespace MatterbridgeClosureDimensionServer {
27
27
  class Internal extends MatterbridgeClosureDimensionServerBase.Internal {
28
- movementTimer?: NodeJS.Timeout;
28
+ movementTimer?: Timer;
29
+ movementTargetState: ClosureDimension.DimensionState;
30
+ movementPreviousState: ClosureDimension.DimensionState;
29
31
  }
30
32
  class State extends MatterbridgeClosureDimensionServerBase.State {
31
33
  movementDuration: number;
@@ -1,3 +1,4 @@
1
+ import { Millis, Time } from '@matter/general';
1
2
  import { ClosureControlServer } from '@matter/node/behaviors/closure-control';
2
3
  import { ClosureDimensionServer } from '@matter/node/behaviors/closure-dimension';
3
4
  import { StatusResponse } from '@matter/types';
@@ -71,7 +72,7 @@ export class MatterbridgeClosureDimensionServer extends MatterbridgeClosureDimen
71
72
  if (matchesCurrentState)
72
73
  return;
73
74
  this.state.targetState = nextTarget;
74
- this.scheduleMovement(nextTarget, currentState);
75
+ this.#scheduleMovement(nextTarget, currentState);
75
76
  };
76
77
  step = async (request) => {
77
78
  const device = this.endpoint.stateOf(MatterbridgeServer);
@@ -121,35 +122,41 @@ export class MatterbridgeClosureDimensionServer extends MatterbridgeClosureDimen
121
122
  ...(this.features.speed && request.speed !== undefined ? { speed: request.speed } : null),
122
123
  };
123
124
  this.state.targetState = nextTarget;
124
- this.scheduleMovement(nextTarget, currentState);
125
+ this.#scheduleMovement(nextTarget, currentState);
125
126
  };
126
- scheduleMovement(targetState, currentState) {
127
- clearTimeout(this.internal.movementTimer);
128
- if (currentState === null || this.state.movementDuration <= 0) {
129
- this.internal.movementTimer = undefined;
127
+ #scheduleMovement(targetState, currentState) {
128
+ this.internal.movementTimer?.stop();
129
+ this.internal.movementTimer = undefined;
130
+ if (currentState === null || this.state.movementDuration <= 0)
130
131
  return;
131
- }
132
- const previousState = currentState;
133
- this.internal.movementTimer = setTimeout(() => {
134
- this.internal.movementTimer = undefined;
135
- void this.completeMovement(targetState, previousState);
136
- }, this.state.movementDuration);
132
+ this.internal.movementTargetState = targetState;
133
+ this.internal.movementPreviousState = currentState;
134
+ this.internal.movementTimer = Time.getTimer('ClosureDimension movement complete', Millis(this.state.movementDuration), this.callback(this.#completeMovement, { lock: true })).start();
137
135
  }
138
- completeMovement = async (targetState, previousState) => {
139
- const endpoint = this.endpoint;
136
+ #completeMovement() {
137
+ this.internal.movementTimer = undefined;
138
+ const targetState = this.internal.movementTargetState;
139
+ const previousState = this.internal.movementPreviousState;
140
140
  const position = targetState.position ?? previousState.position;
141
141
  const latch = targetState.latch ?? previousState.latch;
142
142
  const speed = targetState.speed ?? previousState.speed;
143
- await endpoint.setAttribute(ClosureDimensionServer, 'currentState', {
143
+ this.state.currentState = {
144
144
  position,
145
145
  ...(this.features.motionLatching ? { latch } : null),
146
146
  ...(this.features.speed ? { speed } : null),
147
- });
148
- };
147
+ };
148
+ }
149
+ async [Symbol.asyncDispose]() {
150
+ this.internal.movementTimer?.stop();
151
+ this.internal.movementTimer = undefined;
152
+ await super[Symbol.asyncDispose]?.();
153
+ }
149
154
  }
150
155
  (function (MatterbridgeClosureDimensionServer) {
151
156
  class Internal extends MatterbridgeClosureDimensionServerBase.Internal {
152
157
  movementTimer;
158
+ movementTargetState = {};
159
+ movementPreviousState = {};
153
160
  }
154
161
  MatterbridgeClosureDimensionServer.Internal = Internal;
155
162
  class State extends MatterbridgeClosureDimensionServerBase.State {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matterbridge/core",
3
- "version": "3.10.8-dev-20260901-971f7bf",
3
+ "version": "3.10.8-dev-20260902-361500d",
4
4
  "description": "Matterbridge core library",
5
5
  "author": "https://github.com/Luligu",
6
6
  "homepage": "https://matterbridge.io/",
@@ -132,10 +132,10 @@
132
132
  },
133
133
  "dependencies": {
134
134
  "@matter/main": "0.17.9",
135
- "@matterbridge/dgram": "3.10.8-dev-20260901-971f7bf",
136
- "@matterbridge/thread": "3.10.8-dev-20260901-971f7bf",
137
- "@matterbridge/types": "3.10.8-dev-20260901-971f7bf",
138
- "@matterbridge/utils": "3.10.8-dev-20260901-971f7bf",
135
+ "@matterbridge/dgram": "3.10.8-dev-20260902-361500d",
136
+ "@matterbridge/thread": "3.10.8-dev-20260902-361500d",
137
+ "@matterbridge/types": "3.10.8-dev-20260902-361500d",
138
+ "@matterbridge/utils": "3.10.8-dev-20260902-361500d",
139
139
  "escape-html": "1.0.3",
140
140
  "express": "5.2.1",
141
141
  "express-rate-limit": "8.7.0",