hoffmation-base 3.0.0-alpha.38 → 3.0.0-alpha.39
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.
|
@@ -9,16 +9,22 @@ export declare class PresenceGroup extends BaseGroup {
|
|
|
9
9
|
constructor(roomName: string, motionSensorIds: string[]);
|
|
10
10
|
getMotionDetector(): Array<iMotionSensor>;
|
|
11
11
|
initCallbacks(): void;
|
|
12
|
-
addLastLeftCallback(cb: (action: PresenceGroupLastLeftAction) => void): void;
|
|
13
12
|
presentAmount(): number;
|
|
13
|
+
addLastLeftCallback(cb: (action: PresenceGroupLastLeftAction) => void): void;
|
|
14
14
|
anyPresent(): boolean;
|
|
15
|
+
private fireFistEnterCBs;
|
|
15
16
|
addFirstEnterCallback(cb: (action: PresenceGroupFirstEnterAction) => void): void;
|
|
16
|
-
private
|
|
17
|
+
private motionSensorOnAnyMovement;
|
|
17
18
|
private motionSensorOnLastLeft;
|
|
19
|
+
/**
|
|
20
|
+
* Calculates whether we are after (negative if before) the time the movement
|
|
21
|
+
* reset timer should have reset the movement.
|
|
22
|
+
* @returns The time in milliseconds after the reset time.
|
|
23
|
+
*/
|
|
24
|
+
private getTimeAfterReset;
|
|
18
25
|
/**
|
|
19
26
|
* In case of an existing delayed last left callback timeout, this removes it.
|
|
20
27
|
*/
|
|
21
28
|
private resetLastLeftTimeout;
|
|
22
|
-
private motionSensorOnFirstEnter;
|
|
23
29
|
private executeLastLeftCbs;
|
|
24
30
|
}
|
|
@@ -22,9 +22,21 @@ class PresenceGroup extends base_group_1.BaseGroup {
|
|
|
22
22
|
initCallbacks() {
|
|
23
23
|
this.getMotionDetector().forEach((b) => {
|
|
24
24
|
b.addMovementCallback((action) => {
|
|
25
|
-
|
|
25
|
+
if (action.motionDetected) {
|
|
26
|
+
this.motionSensorOnAnyMovement(action);
|
|
27
|
+
}
|
|
28
|
+
if (action.motionDetected || this.anyPresent()) {
|
|
29
|
+
// TODO: Possible Edge Case, if the other motion sensor doesn't fire motion end event this will never be called
|
|
30
|
+
this.resetLastLeftTimeout();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
else if (!action.motionDetected && !this.anyPresent()) {
|
|
34
|
+
this.motionSensorOnLastLeft(action);
|
|
35
|
+
}
|
|
36
|
+
if (action.motionDetected && this.presentAmount() === 1 && this._lastLeftTimeout === null) {
|
|
37
|
+
this.fireFistEnterCBs(action);
|
|
38
|
+
}
|
|
26
39
|
this.motionSensorOnLastLeft(action);
|
|
27
|
-
this.motionSensorAnyMovement(action);
|
|
28
40
|
});
|
|
29
41
|
});
|
|
30
42
|
this.addLastLeftCallback((action) => {
|
|
@@ -40,34 +52,26 @@ class PresenceGroup extends base_group_1.BaseGroup {
|
|
|
40
52
|
this.getRoom().setLightTimeBased(new models_1.RoomSetLightTimeBasedCommand(action, true));
|
|
41
53
|
});
|
|
42
54
|
}
|
|
55
|
+
presentAmount() {
|
|
56
|
+
return this.getMotionDetector().filter((b) => b.movementDetected).length;
|
|
57
|
+
}
|
|
43
58
|
addLastLeftCallback(cb) {
|
|
44
59
|
this._lastLeftCbs.push(cb);
|
|
45
60
|
}
|
|
46
|
-
presentAmount() {
|
|
47
|
-
let count = 0;
|
|
48
|
-
for (let i = 0; i < this.getMotionDetector().length; i++) {
|
|
49
|
-
if (this.getMotionDetector()[i].movementDetected) {
|
|
50
|
-
count++;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return count;
|
|
54
|
-
}
|
|
55
61
|
anyPresent() {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
return this.getMotionDetector().find((b) => b.movementDetected) !== undefined;
|
|
63
|
+
}
|
|
64
|
+
fireFistEnterCBs(action) {
|
|
65
|
+
for (const cb of this._firstEnterCbs) {
|
|
66
|
+
cb(new models_1.PresenceGroupFirstEnterAction(action));
|
|
60
67
|
}
|
|
61
|
-
return false;
|
|
62
68
|
}
|
|
63
69
|
addFirstEnterCallback(cb) {
|
|
64
70
|
this._firstEnterCbs.push(cb);
|
|
65
71
|
}
|
|
66
|
-
|
|
72
|
+
motionSensorOnAnyMovement(action) {
|
|
67
73
|
var _a;
|
|
68
|
-
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
74
|
+
this._lastMovement = new Date();
|
|
71
75
|
if (services_1.RoomService.awayModeActive || (services_1.RoomService.nightAlarmActive && !action.sensor.settings.excludeFromNightAlarm)) {
|
|
72
76
|
services_1.RoomService.startIntrusionAlarm(this.getRoom(), action.sensor);
|
|
73
77
|
}
|
|
@@ -77,11 +81,7 @@ class PresenceGroup extends base_group_1.BaseGroup {
|
|
|
77
81
|
services_1.RoomService.movementHistory.add(`${services_1.Utils.nowString()}: Raum "${this.roomName}" Gerät "${action.sensor.info.fullName}"`);
|
|
78
82
|
}
|
|
79
83
|
motionSensorOnLastLeft(action) {
|
|
80
|
-
|
|
81
|
-
this.resetLastLeftTimeout();
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
let timeAfterReset = services_1.Utils.nowMS() - this._lastMovement.getTime() - this.getRoom().settings.movementResetTimer * 1000;
|
|
84
|
+
let timeAfterReset = this.getTimeAfterReset();
|
|
85
85
|
if (timeAfterReset > 0) {
|
|
86
86
|
this.log(models_1.LogLevel.Debug, `Movement reset. Active Motions: ${this.presentAmount()}\tTime after Last Movement including Reset: ${timeAfterReset}`);
|
|
87
87
|
this.executeLastLeftCbs(new models_1.PresenceGroupLastLeftAction(action));
|
|
@@ -90,15 +90,23 @@ class PresenceGroup extends base_group_1.BaseGroup {
|
|
|
90
90
|
this.log(models_1.LogLevel.Debug, `Movement reset in ${this.roomName} delayed.`);
|
|
91
91
|
this.resetLastLeftTimeout();
|
|
92
92
|
this._lastLeftTimeout = services_1.Utils.guardedTimeout(() => {
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
this._lastLeftTimeout = null;
|
|
94
|
+
timeAfterReset = this.getTimeAfterReset();
|
|
95
95
|
const presentAmount = this.presentAmount();
|
|
96
|
-
this.log(models_1.LogLevel.Debug, `Delayed Movement reset. Active Motions: ${
|
|
96
|
+
this.log(models_1.LogLevel.Debug, `Delayed Movement reset. Active Motions: ${presentAmount}\tTime after Last Movement including Reset: ${timeAfterReset}, action: ${action.reasonTrace}`);
|
|
97
97
|
if (presentAmount <= 0 && timeAfterReset > 0) {
|
|
98
98
|
this.executeLastLeftCbs(new models_1.PresenceGroupLastLeftAction(action));
|
|
99
99
|
}
|
|
100
100
|
}, Math.abs(timeAfterReset) + 500, this);
|
|
101
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Calculates whether we are after (negative if before) the time the movement
|
|
104
|
+
* reset timer should have reset the movement.
|
|
105
|
+
* @returns The time in milliseconds after the reset time.
|
|
106
|
+
*/
|
|
107
|
+
getTimeAfterReset() {
|
|
108
|
+
return services_1.Utils.nowMS() - this._lastMovement.getTime() - this.getRoom().settings.movementResetTimer * 1000;
|
|
109
|
+
}
|
|
102
110
|
/**
|
|
103
111
|
* In case of an existing delayed last left callback timeout, this removes it.
|
|
104
112
|
*/
|
|
@@ -107,18 +115,6 @@ class PresenceGroup extends base_group_1.BaseGroup {
|
|
|
107
115
|
clearTimeout(this._lastLeftTimeout);
|
|
108
116
|
}
|
|
109
117
|
}
|
|
110
|
-
motionSensorOnFirstEnter(action) {
|
|
111
|
-
if (!action.motionDetected) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
this._lastMovement = new Date();
|
|
115
|
-
if (this.presentAmount() > 1) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
for (const cb of this._firstEnterCbs) {
|
|
119
|
-
cb(new models_1.PresenceGroupFirstEnterAction(action));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
118
|
executeLastLeftCbs(action) {
|
|
123
119
|
for (const cb of this._lastLeftCbs) {
|
|
124
120
|
cb(action);
|