hoffmation-base 1.0.63 → 1.0.64
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.
- package/lib/index.js +1 -4
- package/lib/models/persistence/todaysCount.d.ts +2 -3
- package/lib/models/persistence/todaysCount.js +2 -3
- package/lib/server/config/iConfig.d.ts +0 -5
- package/lib/server/devices/device-cluster-type.d.ts +0 -1
- package/lib/server/devices/device-cluster-type.js +0 -1
- package/lib/server/devices/device-cluster.js +1 -3
- package/lib/server/devices/devices.d.ts +1 -1
- package/lib/server/devices/devices.js +4 -7
- package/lib/server/devices/groups/praesenzGroup.d.ts +1 -3
- package/lib/server/devices/groups/praesenzGroup.js +2 -37
- package/lib/server/devices/hmIPDevices/hmIpBewegung.js +2 -5
- package/lib/server/devices/hmIPDevices/hmIpPraezenz.d.ts +10 -5
- package/lib/server/devices/hmIPDevices/hmIpPraezenz.js +21 -12
- package/lib/server/devices/zigbee/BaseDevices/zigbeeMotionSensor.js +3 -6
- package/lib/server/services/dbo/iPersist.d.ts +1 -2
- package/lib/server/services/dbo/index.d.ts +0 -1
- package/lib/server/services/dbo/index.js +0 -1
- package/lib/server/services/dbo/postgreSqlPersist.d.ts +1 -2
- package/lib/server/services/dbo/postgreSqlPersist.js +6 -41
- package/lib/server/services/time-callback-service.js +1 -1
- package/lib/server/services/utils/utils.js +2 -3
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/lib/server/services/dbo/mongoPersistance.d.ts +0 -33
- package/lib/server/services/dbo/mongoPersistance.js +0 -174
package/lib/index.js
CHANGED
|
@@ -36,10 +36,7 @@ class HoffmationBase {
|
|
|
36
36
|
}
|
|
37
37
|
server_1.ServerLogService.writeLog(models_1.LogLevel.Info, `Hoffmation-Base Startup`);
|
|
38
38
|
if (initObject.config.persistence) {
|
|
39
|
-
if (initObject.config.persistence.
|
|
40
|
-
server_1.Utils.dbo = new server_1.MongoPersistance(initObject.config.persistence);
|
|
41
|
-
}
|
|
42
|
-
else if (initObject.config.persistence.postgreSql) {
|
|
39
|
+
if (initObject.config.persistence.postgreSql) {
|
|
43
40
|
server_1.Utils.dbo = new server_1.PostgreSqlPersist(initObject.config.persistence);
|
|
44
41
|
}
|
|
45
42
|
await ((_a = server_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.initialize());
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CountToday = void 0;
|
|
4
4
|
class CountToday {
|
|
5
|
-
constructor(
|
|
6
|
-
this.
|
|
7
|
-
this.counter = counter;
|
|
5
|
+
constructor(count) {
|
|
6
|
+
this.count = count;
|
|
8
7
|
}
|
|
9
8
|
}
|
|
10
9
|
exports.CountToday = CountToday;
|
|
@@ -76,13 +76,8 @@ export interface iTelegramSettings {
|
|
|
76
76
|
subscribedIDs: number[];
|
|
77
77
|
}
|
|
78
78
|
export interface iPersistenceSettings {
|
|
79
|
-
mongo?: iMongoSettings;
|
|
80
79
|
postgreSql?: PoolConfig;
|
|
81
80
|
}
|
|
82
|
-
export interface iMongoSettings {
|
|
83
|
-
mongoConnection: string;
|
|
84
|
-
mongoDbName: string;
|
|
85
|
-
}
|
|
86
81
|
export interface iPollySettings {
|
|
87
82
|
mp3Path: string;
|
|
88
83
|
region: string;
|
|
@@ -10,7 +10,6 @@ var DeviceClusterType;
|
|
|
10
10
|
DeviceClusterType[DeviceClusterType["Lamps"] = 4] = "Lamps";
|
|
11
11
|
DeviceClusterType[DeviceClusterType["MotionDetection"] = 5] = "MotionDetection";
|
|
12
12
|
DeviceClusterType[DeviceClusterType["Outlets"] = 6] = "Outlets";
|
|
13
|
-
DeviceClusterType[DeviceClusterType["PresenceDetection"] = 7] = "PresenceDetection";
|
|
14
13
|
DeviceClusterType[DeviceClusterType["Speaker"] = 8] = "Speaker";
|
|
15
14
|
DeviceClusterType[DeviceClusterType["SmokeDetector"] = 9] = "SmokeDetector";
|
|
16
15
|
DeviceClusterType[DeviceClusterType["WaterDetectors"] = 10] = "WaterDetectors";
|
|
@@ -48,9 +48,6 @@ class DeviceCluster {
|
|
|
48
48
|
clusterTypes.push(device_cluster_type_1.DeviceClusterType.TemperaturSensor);
|
|
49
49
|
clusterTypes.push(device_cluster_type_1.DeviceClusterType.HumiditySensor);
|
|
50
50
|
break;
|
|
51
|
-
case deviceType_1.DeviceType.HmIpPraezenz:
|
|
52
|
-
clusterTypes.push(device_cluster_type_1.DeviceClusterType.PresenceDetection);
|
|
53
|
-
break;
|
|
54
51
|
case deviceType_1.DeviceType.HmIpGriff:
|
|
55
52
|
clusterTypes.push(device_cluster_type_1.DeviceClusterType.Handle);
|
|
56
53
|
break;
|
|
@@ -67,6 +64,7 @@ class DeviceCluster {
|
|
|
67
64
|
case deviceType_1.DeviceType.HmIpBewegung:
|
|
68
65
|
case deviceType_1.DeviceType.ZigbeeAquaraMotion:
|
|
69
66
|
case deviceType_1.DeviceType.ZigbeeSonoffMotion:
|
|
67
|
+
case deviceType_1.DeviceType.HmIpPraezenz:
|
|
70
68
|
clusterTypes.push(device_cluster_type_1.DeviceClusterType.MotionDetection);
|
|
71
69
|
break;
|
|
72
70
|
case deviceType_1.DeviceType.ZigbeeIkeaSteckdose:
|
|
@@ -13,7 +13,7 @@ export declare class Devices {
|
|
|
13
13
|
[id: string]: deviceConfig;
|
|
14
14
|
}, pRoomImportEnforcer?: iRoomImportEnforcer);
|
|
15
15
|
static midnightReset(): void;
|
|
16
|
-
static
|
|
16
|
+
static resetDetectionsToday(): void;
|
|
17
17
|
static getBatteryInfo(): string;
|
|
18
18
|
private static processZigbeeDevice;
|
|
19
19
|
private static processWledDevice;
|
|
@@ -45,15 +45,12 @@ class Devices {
|
|
|
45
45
|
static midnightReset() {
|
|
46
46
|
// Nothing yet
|
|
47
47
|
}
|
|
48
|
-
static
|
|
49
|
-
services_1.ServerLogService.writeLog(models_1.LogLevel.Info, `3
|
|
48
|
+
static resetDetectionsToday() {
|
|
49
|
+
services_1.ServerLogService.writeLog(models_1.LogLevel.Info, `3 o'clock reset of motion sensors`);
|
|
50
50
|
for (const dID in Devices.alLDevices) {
|
|
51
51
|
const d = Devices.alLDevices[dID];
|
|
52
|
-
if (d.
|
|
53
|
-
d.
|
|
54
|
-
d.deviceType === deviceType_1.DeviceType.ZigbeeSonoffMotion ||
|
|
55
|
-
d.deviceType === deviceType_1.DeviceType.ZigbeeAquaraMotion) {
|
|
56
|
-
services_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `2 Uhr Reset der Tages Detektionen von ${d.info.customName}`);
|
|
52
|
+
if (d.deviceCapabilities.includes(DeviceCapability_1.DeviceCapability.motionSensor)) {
|
|
53
|
+
d.log(models_1.LogLevel.Debug, `3 o'clock reset of detections`);
|
|
57
54
|
d.detectionsToday = 0;
|
|
58
55
|
}
|
|
59
56
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { HmIpPraezenz } from '../hmIPDevices';
|
|
2
1
|
import { BaseGroup } from './base-group';
|
|
3
2
|
import { iMotionSensor } from '../baseDeviceInterfaces';
|
|
4
3
|
export declare class PraesenzGroup extends BaseGroup {
|
|
5
4
|
private _lastMovement;
|
|
6
5
|
private _lastLeftTimeout;
|
|
7
|
-
constructor(roomName: string,
|
|
6
|
+
constructor(roomName: string, motionSensorIds: string[]);
|
|
8
7
|
getMotionDetector(): Array<iMotionSensor>;
|
|
9
|
-
getPresenceSensors(): HmIpPraezenz[];
|
|
10
8
|
initCallbacks(): void;
|
|
11
9
|
presentAmount(): number;
|
|
12
10
|
anyPresent(): boolean;
|
|
@@ -8,31 +8,16 @@ const device_cluster_type_1 = require("../device-cluster-type");
|
|
|
8
8
|
const group_type_1 = require("./group-type");
|
|
9
9
|
const device_list_1 = require("../device-list");
|
|
10
10
|
class PraesenzGroup extends base_group_1.BaseGroup {
|
|
11
|
-
constructor(roomName,
|
|
11
|
+
constructor(roomName, motionSensorIds) {
|
|
12
12
|
super(roomName, group_type_1.GroupType.Presence);
|
|
13
13
|
this._lastMovement = new Date(0);
|
|
14
14
|
this._lastLeftTimeout = null;
|
|
15
|
-
this.deviceCluster.deviceMap.set(device_cluster_type_1.DeviceClusterType.PresenceDetection, new device_list_1.DeviceList(presenceDetectorIds));
|
|
16
15
|
this.deviceCluster.deviceMap.set(device_cluster_type_1.DeviceClusterType.MotionDetection, new device_list_1.DeviceList(motionSensorIds));
|
|
17
16
|
}
|
|
18
17
|
getMotionDetector() {
|
|
19
|
-
return this.deviceCluster.
|
|
20
|
-
}
|
|
21
|
-
getPresenceSensors() {
|
|
22
|
-
return this.deviceCluster.getIoBrokerDevicesByType(device_cluster_type_1.DeviceClusterType.PresenceDetection);
|
|
18
|
+
return this.deviceCluster.getDevicesByType(device_cluster_type_1.DeviceClusterType.MotionDetection);
|
|
23
19
|
}
|
|
24
20
|
initCallbacks() {
|
|
25
|
-
this.getPresenceSensors().forEach((p) => {
|
|
26
|
-
p.addPresenceCallback((val) => {
|
|
27
|
-
if (!val) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (services_1.RoomService.awayModeActive || (services_1.RoomService.nightAlarmActive && !p.excludeFromNightAlarm)) {
|
|
31
|
-
services_1.RoomService.startIntrusionAlarm(this.getRoom(), p);
|
|
32
|
-
}
|
|
33
|
-
services_1.RoomService.movementHistory.add(`${services_1.Utils.nowString()}: Raum "${this.roomName}" Gerät "${p.info.fullName}"`);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
21
|
this.getMotionDetector().forEach((b) => {
|
|
37
22
|
b.addMovementCallback((val) => {
|
|
38
23
|
var _a;
|
|
@@ -69,11 +54,6 @@ class PraesenzGroup extends base_group_1.BaseGroup {
|
|
|
69
54
|
}
|
|
70
55
|
presentAmount() {
|
|
71
56
|
let count = 0;
|
|
72
|
-
for (let i = 0; i < this.getPresenceSensors().length; i++) {
|
|
73
|
-
if (this.getPresenceSensors()[i].presenceDetected) {
|
|
74
|
-
count++;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
57
|
for (let i = 0; i < this.getMotionDetector().length; i++) {
|
|
78
58
|
if (this.getMotionDetector()[i].movementDetected) {
|
|
79
59
|
count++;
|
|
@@ -82,11 +62,6 @@ class PraesenzGroup extends base_group_1.BaseGroup {
|
|
|
82
62
|
return count;
|
|
83
63
|
}
|
|
84
64
|
anyPresent() {
|
|
85
|
-
for (let i = 0; i < this.getPresenceSensors().length; i++) {
|
|
86
|
-
if (this.getPresenceSensors()[i].presenceDetected) {
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
65
|
for (let i = 0; i < this.getMotionDetector().length; i++) {
|
|
91
66
|
if (this.getMotionDetector()[i].movementDetected) {
|
|
92
67
|
return true;
|
|
@@ -121,11 +96,6 @@ class PraesenzGroup extends base_group_1.BaseGroup {
|
|
|
121
96
|
}, Math.abs(timeAfterReset) + 500, this);
|
|
122
97
|
}
|
|
123
98
|
addLastLeftCallback(cb) {
|
|
124
|
-
this.getPresenceSensors().forEach((p) => {
|
|
125
|
-
p.addPresenceCallback((val) => {
|
|
126
|
-
this.lastLeftCB(val, cb);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
99
|
this.getMotionDetector().forEach((b) => {
|
|
130
100
|
b.addMovementCallback((val) => {
|
|
131
101
|
this.lastLeftCB(val, cb);
|
|
@@ -133,11 +103,6 @@ class PraesenzGroup extends base_group_1.BaseGroup {
|
|
|
133
103
|
});
|
|
134
104
|
}
|
|
135
105
|
addFirstEnterCallback(cb) {
|
|
136
|
-
this.getPresenceSensors().forEach((p) => {
|
|
137
|
-
p.addPresenceCallback((val) => {
|
|
138
|
-
this.firstEnterCallback(val, cb);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
106
|
this.getMotionDetector().forEach((b) => {
|
|
142
107
|
b.addMovementCallback((val) => {
|
|
143
108
|
this.firstEnterCallback(val, cb);
|
|
@@ -23,8 +23,8 @@ class HmIpBewegung extends hmIpDevice_1.HmIPDevice {
|
|
|
23
23
|
this.initialized = true;
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
(_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.
|
|
27
|
-
this.detectionsToday = todayCount.
|
|
26
|
+
(_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.motionSensorTodayCount(this).then((todayCount) => {
|
|
27
|
+
this.detectionsToday = todayCount.count;
|
|
28
28
|
this.log(models_1.LogLevel.Debug, `Bewegungscounter vorinitialisiert mit ${this.detectionsToday}`);
|
|
29
29
|
this.initialized = true;
|
|
30
30
|
}).catch((err) => {
|
|
@@ -40,10 +40,7 @@ class HmIpBewegung extends hmIpDevice_1.HmIPDevice {
|
|
|
40
40
|
return this._detectionsToday;
|
|
41
41
|
}
|
|
42
42
|
set detectionsToday(pVal) {
|
|
43
|
-
var _a;
|
|
44
|
-
const oldVal = this._detectionsToday;
|
|
45
43
|
this._detectionsToday = pVal;
|
|
46
|
-
(_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistTodayCount(this, pVal, oldVal);
|
|
47
44
|
}
|
|
48
45
|
get currentIllumination() {
|
|
49
46
|
return this._currentIllumination;
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
/// <reference types="iobroker" />
|
|
2
2
|
import { HmIPDevice } from './hmIpDevice';
|
|
3
|
-
import {
|
|
3
|
+
import { MotionSensorSettings } from '../../../models';
|
|
4
|
+
import { iBatteryDevice, iIlluminationSensor, iMotionSensor } from '../baseDeviceInterfaces';
|
|
4
5
|
import { IoBrokerDeviceInfo } from '../IoBrokerDeviceInfo';
|
|
5
|
-
export declare class HmIpPraezenz extends HmIPDevice implements iIlluminationSensor, iBatteryDevice {
|
|
6
|
+
export declare class HmIpPraezenz extends HmIPDevice implements iIlluminationSensor, iBatteryDevice, iMotionSensor {
|
|
6
7
|
private static PRESENCE_DETECTION;
|
|
7
8
|
private static CURRENT_ILLUMINATION;
|
|
8
9
|
excludeFromNightAlarm: boolean;
|
|
9
|
-
|
|
10
|
+
movementDetected: boolean;
|
|
10
11
|
battery: number;
|
|
11
|
-
|
|
12
|
+
settings: MotionSensorSettings;
|
|
13
|
+
private _movementDetectedCallback;
|
|
12
14
|
private initialized;
|
|
15
|
+
private _lastMotionTime;
|
|
13
16
|
constructor(pInfo: IoBrokerDeviceInfo);
|
|
17
|
+
get timeSinceLastMotion(): number;
|
|
14
18
|
private _detectionsToday;
|
|
15
19
|
get detectionsToday(): number;
|
|
16
20
|
set detectionsToday(pVal: number);
|
|
17
21
|
private _currentIllumination;
|
|
18
22
|
get currentIllumination(): number;
|
|
19
23
|
private set currentIllumination(value);
|
|
20
|
-
|
|
24
|
+
addMovementCallback(pCallback: (pValue: boolean) => void): void;
|
|
21
25
|
update(idSplit: string[], state: ioBroker.State, initial?: boolean): void;
|
|
22
26
|
updatePresence(pVal: boolean): void;
|
|
27
|
+
persist(): void;
|
|
23
28
|
}
|
|
@@ -11,22 +11,25 @@ class HmIpPraezenz extends hmIpDevice_1.HmIPDevice {
|
|
|
11
11
|
var _a;
|
|
12
12
|
super(pInfo, deviceType_1.DeviceType.HmIpPraezenz);
|
|
13
13
|
this.excludeFromNightAlarm = false;
|
|
14
|
-
this.
|
|
14
|
+
this.movementDetected = false;
|
|
15
15
|
this.battery = -99;
|
|
16
|
-
this.
|
|
16
|
+
this.settings = new models_1.MotionSensorSettings();
|
|
17
|
+
this._movementDetectedCallback = [];
|
|
17
18
|
// private presenceStateID: string;
|
|
18
19
|
this.initialized = false;
|
|
20
|
+
this._lastMotionTime = 0;
|
|
19
21
|
this._detectionsToday = 0;
|
|
20
22
|
this._currentIllumination = -1;
|
|
21
23
|
this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.illuminationSensor);
|
|
22
24
|
this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.batteryDriven);
|
|
25
|
+
this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.motionSensor);
|
|
23
26
|
// this.presenceStateID = `${this.info.fullID}.1.${HmIpPraezenz.PRESENCE_DETECTION}`;
|
|
24
27
|
if (!services_1.Utils.anyDboActive) {
|
|
25
28
|
this.initialized = true;
|
|
26
29
|
}
|
|
27
30
|
else {
|
|
28
|
-
(_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.
|
|
29
|
-
this.detectionsToday = todayCount.
|
|
31
|
+
(_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.motionSensorTodayCount(this).then((todayCount) => {
|
|
32
|
+
this.detectionsToday = todayCount.count;
|
|
30
33
|
this.log(models_1.LogLevel.Debug, `Präsenzcounter vorinitialisiert mit ${this.detectionsToday}`);
|
|
31
34
|
this.initialized = true;
|
|
32
35
|
}).catch((err) => {
|
|
@@ -35,14 +38,14 @@ class HmIpPraezenz extends hmIpDevice_1.HmIPDevice {
|
|
|
35
38
|
});
|
|
36
39
|
}
|
|
37
40
|
}
|
|
41
|
+
get timeSinceLastMotion() {
|
|
42
|
+
return Math.floor((services_1.Utils.nowMS() - this._lastMotionTime) / 1000);
|
|
43
|
+
}
|
|
38
44
|
get detectionsToday() {
|
|
39
45
|
return this._detectionsToday;
|
|
40
46
|
}
|
|
41
47
|
set detectionsToday(pVal) {
|
|
42
|
-
var _a;
|
|
43
|
-
const oldVal = this._detectionsToday;
|
|
44
48
|
this._detectionsToday = pVal;
|
|
45
|
-
(_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistTodayCount(this, pVal, oldVal);
|
|
46
49
|
}
|
|
47
50
|
get currentIllumination() {
|
|
48
51
|
return this._currentIllumination;
|
|
@@ -52,8 +55,8 @@ class HmIpPraezenz extends hmIpDevice_1.HmIPDevice {
|
|
|
52
55
|
this._currentIllumination = value;
|
|
53
56
|
(_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistCurrentIllumination(new models_1.CurrentIlluminationDataPoint(this.info.room, this.info.devID, value, new Date(), (_d = (_c = (_b = this.room) === null || _b === void 0 ? void 0 : _b.LampenGroup) === null || _c === void 0 ? void 0 : _c.anyLightsOn()) !== null && _d !== void 0 ? _d : false));
|
|
54
57
|
}
|
|
55
|
-
|
|
56
|
-
this.
|
|
58
|
+
addMovementCallback(pCallback) {
|
|
59
|
+
this._movementDetectedCallback.push(pCallback);
|
|
57
60
|
}
|
|
58
61
|
update(idSplit, state, initial = false) {
|
|
59
62
|
this.log(models_1.LogLevel.DeepTrace, `Präzens Update: JSON: ${JSON.stringify(state)}ID: ${idSplit.join('.')}`);
|
|
@@ -86,20 +89,26 @@ class HmIpPraezenz extends hmIpDevice_1.HmIPDevice {
|
|
|
86
89
|
}, 1000, this);
|
|
87
90
|
return;
|
|
88
91
|
}
|
|
89
|
-
if (pVal === this.
|
|
92
|
+
if (pVal === this.movementDetected) {
|
|
90
93
|
this.log(models_1.LogLevel.Debug, `Überspringe Präsenz da bereits der Wert ${pVal} vorliegt`);
|
|
91
94
|
return;
|
|
92
95
|
}
|
|
93
|
-
this.
|
|
96
|
+
this.movementDetected = pVal;
|
|
97
|
+
this.persist();
|
|
94
98
|
this.log(models_1.LogLevel.Debug, `Neuer Präsenzstatus Wert : ${pVal}`);
|
|
95
99
|
if (pVal) {
|
|
96
100
|
this.detectionsToday++;
|
|
101
|
+
this._lastMotionTime = services_1.Utils.nowMS();
|
|
97
102
|
this.log(models_1.LogLevel.Trace, `Dies ist die ${this.detectionsToday} Bewegung `);
|
|
98
103
|
}
|
|
99
|
-
for (const c of this.
|
|
104
|
+
for (const c of this._movementDetectedCallback) {
|
|
100
105
|
c(pVal);
|
|
101
106
|
}
|
|
102
107
|
}
|
|
108
|
+
persist() {
|
|
109
|
+
var _a;
|
|
110
|
+
(_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistMotionSensor(this);
|
|
111
|
+
}
|
|
103
112
|
}
|
|
104
113
|
exports.HmIpPraezenz = HmIpPraezenz;
|
|
105
114
|
// TODO: Add iPresenceSensor
|
|
@@ -23,9 +23,9 @@ class ZigbeeMotionSensor extends index_1.ZigbeeDevice {
|
|
|
23
23
|
this._initialized = true;
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
(_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.
|
|
27
|
-
this.detectionsToday = todayCount.
|
|
28
|
-
this.log(models_1.LogLevel.Debug, `
|
|
26
|
+
(_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.motionSensorTodayCount(this).then((todayCount) => {
|
|
27
|
+
this.detectionsToday = todayCount.count;
|
|
28
|
+
this.log(models_1.LogLevel.Debug, `Reinitialized movement counter with ${this.detectionsToday}`);
|
|
29
29
|
this._initialized = true;
|
|
30
30
|
}).catch((err) => {
|
|
31
31
|
var _a;
|
|
@@ -41,10 +41,7 @@ class ZigbeeMotionSensor extends index_1.ZigbeeDevice {
|
|
|
41
41
|
return this._detectionsToday;
|
|
42
42
|
}
|
|
43
43
|
set detectionsToday(pVal) {
|
|
44
|
-
var _a;
|
|
45
|
-
const oldVal = this._detectionsToday;
|
|
46
44
|
this._detectionsToday = pVal;
|
|
47
|
-
(_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistTodayCount(this, pVal, oldVal);
|
|
48
45
|
}
|
|
49
46
|
/**
|
|
50
47
|
* Adds a callback for when a motion state has changed.
|
|
@@ -4,10 +4,9 @@ export interface iPersist {
|
|
|
4
4
|
initialized: boolean;
|
|
5
5
|
addTemperaturDataPoint(heater: iHeater): void;
|
|
6
6
|
addRoom(room: RoomBase): void;
|
|
7
|
-
|
|
7
|
+
motionSensorTodayCount(device: iMotionSensor): Promise<CountToday>;
|
|
8
8
|
getShutterCalibration(device: IoBrokerBaseDevice): Promise<ShutterCalibration>;
|
|
9
9
|
initialize(): Promise<void>;
|
|
10
|
-
persistTodayCount(device: IoBrokerBaseDevice, count: number, oldCount: number): void;
|
|
11
10
|
persistShutterCalibration(data: ShutterCalibration): void;
|
|
12
11
|
persistCurrentIllumination(data: CurrentIlluminationDataPoint): void;
|
|
13
12
|
persistEnergyManager(energyData: EnergyCalculation): void;
|
|
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./mongoPersistance"), exports);
|
|
18
17
|
__exportStar(require("./postgreSqlPersist"), exports);
|
|
19
18
|
__exportStar(require("./iPersist"), exports);
|
|
@@ -8,14 +8,13 @@ export declare class PostgreSqlPersist implements iPersist {
|
|
|
8
8
|
constructor(config: iPersistenceSettings);
|
|
9
9
|
addRoom(room: RoomBase): void;
|
|
10
10
|
addTemperaturDataPoint(heater: iHeater): void;
|
|
11
|
-
|
|
11
|
+
motionSensorTodayCount(device: iMotionSensor): Promise<CountToday>;
|
|
12
12
|
getShutterCalibration(_device: IoBrokerBaseDevice): Promise<ShutterCalibration>;
|
|
13
13
|
initialize(): Promise<void>;
|
|
14
14
|
persistAC(device: iAcDevice): void;
|
|
15
15
|
persistMotionSensor(device: iMotionSensor): void;
|
|
16
16
|
persistCurrentIllumination(data: CurrentIlluminationDataPoint): void;
|
|
17
17
|
persistShutterCalibration(_data: ShutterCalibration): void;
|
|
18
|
-
persistTodayCount(device: IoBrokerBaseDevice, count: number, oldCount: number): void;
|
|
19
18
|
readTemperaturDataPoint(heater: iHeater, limit: number): Promise<TemperaturDataPoint[]>;
|
|
20
19
|
persistEnergyManager(calc: EnergyCalculation): void;
|
|
21
20
|
private query;
|
|
@@ -38,13 +38,15 @@ values ('${new Date().toISOString()}',${heater.humidity},${heater.iTemperature},
|
|
|
38
38
|
;
|
|
39
39
|
`);
|
|
40
40
|
}
|
|
41
|
-
async
|
|
42
|
-
const dbResult = await this.query(`SELECT *
|
|
41
|
+
async motionSensorTodayCount(device) {
|
|
42
|
+
const dbResult = await this.query(`SELECT Count(*)
|
|
43
|
+
from hoffmation_schema."MotionSensorDeviceData"
|
|
44
|
+
WHERE "deviceID" = '${device.id}' and "movementDetected" and date >= CURRENT_DATE AND date < CURRENT_DATE + INTERVAL '1 DAY'`);
|
|
43
45
|
if (dbResult !== null && dbResult.length > 0) {
|
|
44
46
|
return dbResult[0];
|
|
45
47
|
}
|
|
46
|
-
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Es gibt noch
|
|
47
|
-
return new models_1.CountToday(
|
|
48
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Es gibt noch keine persistierten Bewegungen für ${device.info.fullName}`);
|
|
49
|
+
return new models_1.CountToday(0);
|
|
48
50
|
}
|
|
49
51
|
getShutterCalibration(_device) {
|
|
50
52
|
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Postgres doesn't support Shutter Calibration yet.`);
|
|
@@ -147,21 +149,6 @@ create unique index heatgroupcollection_name_uindex
|
|
|
147
149
|
on "HeatGroupCollection" (name);
|
|
148
150
|
|
|
149
151
|
END IF;
|
|
150
|
-
IF (SELECT to_regclass('hoffmation_schema."PresenceToday"') IS NULL) Then
|
|
151
|
-
create table "PresenceToday"
|
|
152
|
-
(
|
|
153
|
-
counter integer,
|
|
154
|
-
"deviceID" varchar(60) not null
|
|
155
|
-
constraint presencetoday_pk
|
|
156
|
-
primary key
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
alter table "PresenceToday"
|
|
160
|
-
owner to postgres;
|
|
161
|
-
|
|
162
|
-
create unique index presencetoday_deviceid_uindex
|
|
163
|
-
on "PresenceToday" ("deviceID");
|
|
164
|
-
END IF;
|
|
165
152
|
|
|
166
153
|
IF (SELECT to_regclass('hoffmation_schema."AcDeviceData"') IS NULL) Then
|
|
167
154
|
create table hoffmation_schema."AcDeviceData"
|
|
@@ -234,28 +221,6 @@ values ('${data.roomName}','${data.deviceID}',${data.currentIllumination},'${dat
|
|
|
234
221
|
persistShutterCalibration(_data) {
|
|
235
222
|
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Postgres doesn't support Shutter Calibration yet.`);
|
|
236
223
|
}
|
|
237
|
-
persistTodayCount(device, count, oldCount) {
|
|
238
|
-
this.query(`
|
|
239
|
-
insert into hoffmation_schema."PresenceToday" (counter, "deviceID")
|
|
240
|
-
values (${count}, '${device.id}')
|
|
241
|
-
ON CONFLICT ("deviceID")
|
|
242
|
-
DO UPDATE SET
|
|
243
|
-
counter = ${count}
|
|
244
|
-
;
|
|
245
|
-
`);
|
|
246
|
-
if (count === 0) {
|
|
247
|
-
const date = new Date();
|
|
248
|
-
date.setHours(-24, 0, 0, 0);
|
|
249
|
-
this.query(`
|
|
250
|
-
insert into hoffmation_schema."DailyMovementCount" (counter, "date", "deviceID", "roomName")
|
|
251
|
-
values (${oldCount}, '${date.toISOString()}', '${device.id}', '${device.info.room}')
|
|
252
|
-
ON CONFLICT ("deviceID", "date")
|
|
253
|
-
DO UPDATE SET
|
|
254
|
-
counter = ${oldCount}
|
|
255
|
-
;
|
|
256
|
-
`);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
224
|
async readTemperaturDataPoint(heater, limit) {
|
|
260
225
|
const dbResult = await this.query(`
|
|
261
226
|
SELECT * FROM hoffmation_schema."TemperaturData"
|
|
@@ -110,7 +110,7 @@ class TimeCallbackService {
|
|
|
110
110
|
devices_1.Devices.midnightReset();
|
|
111
111
|
}, 0, 0, 0);
|
|
112
112
|
const daily3oClockRecalc = new models_1.TimeCallback('Daily3oClockRecalc', models_1.TimeCallbackType.TimeOfDay, () => {
|
|
113
|
-
devices_1.Devices.
|
|
113
|
+
devices_1.Devices.resetDetectionsToday();
|
|
114
114
|
}, 0, 3, 0);
|
|
115
115
|
TimeCallbackService.recalcSunTimes();
|
|
116
116
|
TimeCallbackService.addCallback(dailyRecalc);
|
|
@@ -12,9 +12,8 @@ const settings_service_1 = require("../settings-service");
|
|
|
12
12
|
exports.DAYMS = 24 * 60 * 60 * 1000;
|
|
13
13
|
class Utils {
|
|
14
14
|
static get anyDboActive() {
|
|
15
|
-
var _a
|
|
16
|
-
return ((
|
|
17
|
-
((_b = settings_service_1.SettingsService.settings.persistence) === null || _b === void 0 ? void 0 : _b.postgreSql) !== undefined);
|
|
15
|
+
var _a;
|
|
16
|
+
return ((_a = settings_service_1.SettingsService.settings.persistence) === null || _a === void 0 ? void 0 : _a.postgreSql) !== undefined;
|
|
18
17
|
}
|
|
19
18
|
static get timeTilMidnight() {
|
|
20
19
|
return new Date(Utils.nowMS() + exports.DAYMS).setHours(0, 0, 0, 0) - Utils.nowMS();
|