@uncaught/gpio-shutter-bridge 1.2.1 → 1.2.2
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,9 +1,9 @@
|
|
|
1
1
|
import { Gpio } from 'onoff';
|
|
2
2
|
import { ShutterState, ShutterInterfaceWithState, ShutterInterfaceWithPosition, ShutterPosition } from './Shutter.js';
|
|
3
3
|
interface Durations {
|
|
4
|
+
bottomSignalDurations?: number[];
|
|
4
5
|
topFullCloseDurations?: number[];
|
|
5
6
|
topFullOpenDurations?: number[];
|
|
6
|
-
topSignalDurations?: number[];
|
|
7
7
|
}
|
|
8
8
|
export interface Persistence extends Durations {
|
|
9
9
|
position?: number;
|
|
@@ -2,6 +2,14 @@ import { Gpio } from 'onoff';
|
|
|
2
2
|
import { isShutterPosition, isShutterAction, } from './Shutter.js';
|
|
3
3
|
import { press } from '../Gpio.js';
|
|
4
4
|
const durationsToKeep = 20;
|
|
5
|
+
const getBottomDurations = (d) => d.sort((a, b) => a - b).slice(0, durationsToKeep);
|
|
6
|
+
const getLastDurations = (d) => d.slice(-durationsToKeep);
|
|
7
|
+
const getTopDurations = (d) => d.sort((a, b) => b - a).slice(0, durationsToKeep);
|
|
8
|
+
const durationHandlers = {
|
|
9
|
+
bottomSignalDurations: getBottomDurations,
|
|
10
|
+
topFullCloseDurations: getTopDurations,
|
|
11
|
+
topFullOpenDurations: getTopDurations,
|
|
12
|
+
};
|
|
5
13
|
function minMaxPercentage(num) {
|
|
6
14
|
return Math.min(Math.max(num, 0), 100);
|
|
7
15
|
}
|
|
@@ -74,10 +82,7 @@ export class VeluxShutter {
|
|
|
74
82
|
}
|
|
75
83
|
storeDuration(key, duration) {
|
|
76
84
|
if (duration > 0) {
|
|
77
|
-
|
|
78
|
-
this.store.set({
|
|
79
|
-
[key]: [...(this.store.get()[key] ?? []), duration].sort((a, b) => b - a).slice(0, durationsToKeep),
|
|
80
|
-
});
|
|
85
|
+
this.store.set({ [key]: durationHandlers[key]([...(this.store.get()[key] ?? []), duration]) });
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
getAverageDuration(key) {
|
|
@@ -89,7 +94,7 @@ export class VeluxShutter {
|
|
|
89
94
|
return 0;
|
|
90
95
|
}
|
|
91
96
|
getEstimatedActionDuration(action) {
|
|
92
|
-
const signalDuration = this.getAverageDuration('
|
|
97
|
+
const signalDuration = this.getAverageDuration('bottomSignalDurations');
|
|
93
98
|
let avg = 0;
|
|
94
99
|
if (action === 'opening') {
|
|
95
100
|
avg = this.getAverageDuration('topFullOpenDurations');
|
|
@@ -120,7 +125,7 @@ export class VeluxShutter {
|
|
|
120
125
|
//Measure the time it takes between a manual "stop" and the following stopped signal.
|
|
121
126
|
// This gives us an estimate on how long the KLF 150 takes to send it for any operation.
|
|
122
127
|
const stopDuration = this.lastStoppingStartTime ? Date.now() - this.lastStoppingStartTime : 0;
|
|
123
|
-
this.storeDuration('
|
|
128
|
+
this.storeDuration('bottomSignalDurations', stopDuration);
|
|
124
129
|
}
|
|
125
130
|
else {
|
|
126
131
|
this.lastStoppingStartTime = 0;
|
|
@@ -133,7 +138,7 @@ export class VeluxShutter {
|
|
|
133
138
|
}
|
|
134
139
|
}
|
|
135
140
|
if (isShutterPosition(state)) {
|
|
136
|
-
const signalDuration = this.getAverageDuration('
|
|
141
|
+
const signalDuration = this.getAverageDuration('bottomSignalDurations');
|
|
137
142
|
const measuredDuration = this.lastActionStartTime ? Date.now() - this.lastActionStartTime : 0;
|
|
138
143
|
const positionDuration = measuredDuration > 0 ? Math.max(0, measuredDuration - signalDuration) : 0;
|
|
139
144
|
if (state === 'closed') {
|
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.
|
|
5
|
+
"version": "1.2.2",
|
|
6
6
|
"description": "MQTT shutter bridge for home assistant with Velux KLF 150 support",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|