@uncaught/gpio-shutter-bridge 1.2.0 → 1.2.1

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.
@@ -34,7 +34,7 @@ export declare class VeluxShutter implements ShutterInterfaceWithState, ShutterI
34
34
  private notifyPositionChange;
35
35
  private storeDuration;
36
36
  private getAverageDuration;
37
- private getAverageActionDuration;
37
+ private getEstimatedActionDuration;
38
38
  private getPositionDelta;
39
39
  private setState;
40
40
  private clearPositioningTimeout;
@@ -88,18 +88,20 @@ export class VeluxShutter {
88
88
  }
89
89
  return 0;
90
90
  }
91
- getAverageActionDuration(action) {
91
+ getEstimatedActionDuration(action) {
92
+ const signalDuration = this.getAverageDuration('topSignalDurations');
93
+ let avg = 0;
92
94
  if (action === 'opening') {
93
- return this.getAverageDuration('topFullOpenDurations');
95
+ avg = this.getAverageDuration('topFullOpenDurations');
94
96
  }
95
97
  if (action === 'closing') {
96
- return this.getAverageDuration('topFullCloseDurations');
98
+ avg = this.getAverageDuration('topFullCloseDurations');
97
99
  }
98
- return 0;
100
+ return avg > 0 ? Math.max(0, avg - signalDuration) : 0;
99
101
  }
100
102
  getPositionDelta(prevState, duration) {
101
103
  if (isShutterAction(prevState) && duration > 0) {
102
- const avg = this.getAverageActionDuration(prevState);
104
+ const avg = this.getEstimatedActionDuration(prevState);
103
105
  if (avg > 0) {
104
106
  return minMaxPercentage(Math.round((duration / avg) * 100));
105
107
  }
@@ -205,11 +207,11 @@ export class VeluxShutter {
205
207
  else if (position > 0 && position < 100) {
206
208
  let timeout = 0;
207
209
  if (position > this.position) {
208
- timeout = (this.getAverageActionDuration('opening') * (position - this.position)) / 100;
210
+ timeout = (this.getEstimatedActionDuration('opening') * (position - this.position)) / 100;
209
211
  this.open();
210
212
  }
211
213
  else {
212
- timeout = (this.getAverageActionDuration('closing') * (this.position - position)) / 100;
214
+ timeout = (this.getEstimatedActionDuration('closing') * (this.position - position)) / 100;
213
215
  this.close();
214
216
  }
215
217
  if (timeout) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@uncaught/gpio-shutter-bridge",
3
3
  "author": "uncaught <uncaught42@gmail.com>",
4
4
  "license": "MIT",
5
- "version": "1.2.0",
5
+ "version": "1.2.1",
6
6
  "description": "MQTT shutter bridge for home assistant with Velux KLF 150 support",
7
7
  "repository": {
8
8
  "type": "git",