hoffmation-base 0.1.1 → 0.1.5
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/.eslintrc.js +27 -27
- package/.github/workflows/npm-publish.yml +50 -0
- package/.prettierrc.js +9 -9
- package/LICENSE +21 -21
- package/index.js +1 -1
- package/models/connectionCallbacks.ts +13 -13
- package/models/daytime.ts +3 -3
- package/models/deviceConfig.ts +8 -8
- package/models/dimmerSettings.ts +5 -5
- package/models/iTemperaturDataPoint.ts +9 -9
- package/models/lampSettings.ts +5 -5
- package/models/ledSettings.ts +19 -19
- package/models/logLevel.ts +9 -9
- package/models/persistence/BasicRoomInfo.ts +3 -3
- package/models/persistence/DailyMovementCount.ts +3 -3
- package/models/persistence/RoomDetailInfo.ts +4 -4
- package/models/persistence/temperaturDataPoint.ts +12 -12
- package/models/persistence/todaysCount.ts +3 -3
- package/models/rooms/RoomBase.ts +357 -357
- package/models/rooms/RoomSettings/RoomSettings.ts +159 -159
- package/models/rooms/RoomSettings/hmIPRoomSettings.ts +53 -53
- package/models/rooms/RoomSettings/iRoomDefaultSettings.ts +17 -17
- package/models/rooms/RoomSettings/readme.md +17 -17
- package/models/rooms/RoomSettings/zigbeeRoomSettings.ts +51 -51
- package/models/rooms/iRoomImportEnforcer.ts +3 -3
- package/models/rooms/readme.md +11 -11
- package/models/temperaturSettings.ts +22 -22
- package/models/timeCallback.ts +90 -90
- package/package.json +1 -1
- package/server/config/config-readme.md +19 -19
- package/server/config/iConfig.ts +53 -53
- package/server/config/private/mainConfig.json +64 -64
- package/server/devices/DeviceInfo.ts +66 -66
- package/server/devices/Griffe.ts +31 -31
- package/server/devices/Heizgruppen.ts +91 -91
- package/server/devices/Rollos.ts +48 -48
- package/server/devices/deviceUpdater.ts +72 -72
- package/server/devices/devices.ts +189 -189
- package/server/devices/groups/fensterGroup.ts +175 -175
- package/server/devices/groups/heatGroup.ts +32 -32
- package/server/devices/groups/lampenGroup.ts +88 -88
- package/server/devices/groups/praesenzGroup.ts +182 -182
- package/server/devices/groups/smokeGroup.ts +16 -16
- package/server/devices/groups/sonosGroup.ts +33 -33
- package/server/devices/groups/tasterGroup.ts +48 -48
- package/server/devices/groups/waterGroup.ts +16 -16
- package/server/devices/hmIPDevices/Fenster.ts +114 -114
- package/server/devices/hmIPDevices/FensterPosition.ts +5 -5
- package/server/devices/hmIPDevices/TuerPosition.ts +4 -4
- package/server/devices/hmIPDevices/hmIpBewegung.ts +126 -126
- package/server/devices/hmIPDevices/hmIpDevice.ts +90 -90
- package/server/devices/hmIPDevices/hmIpDeviceType.ts +14 -14
- package/server/devices/hmIPDevices/hmIpGriff.ts +143 -143
- package/server/devices/hmIPDevices/hmIpHeizgruppe.ts +172 -172
- package/server/devices/hmIPDevices/hmIpHeizung.ts +69 -69
- package/server/devices/hmIPDevices/hmIpLampe.ts +119 -119
- package/server/devices/hmIPDevices/hmIpPraezenz.ts +99 -99
- package/server/devices/hmIPDevices/hmIpRoll.ts +133 -133
- package/server/devices/hmIPDevices/hmIpTaster.ts +82 -73
- package/server/devices/hmIPDevices/hmIpTherm.ts +19 -19
- package/server/devices/hmIPDevices/hmIpTuer.ts +115 -115
- package/server/devices/hmIPDevices/hmIpWippe.ts +55 -55
- package/server/devices/iDeviceUpdater.ts +4 -4
- package/server/devices/iIoBrokerDevice.ts +44 -44
- package/server/devices/iTaster.ts +6 -0
- package/server/devices/{hmIPDevices/hmIpTaste.ts → taste.ts} +84 -72
- package/server/devices/wledDevice.ts +124 -124
- package/server/devices/zigbee/ZigbeeActuator.ts +113 -113
- package/server/devices/zigbee/zigbeeAquaraVibra.ts +171 -171
- package/server/devices/zigbee/zigbeeAquaraWater.ts +94 -94
- package/server/devices/zigbee/zigbeeBlitzShp.ts +77 -77
- package/server/devices/zigbee/zigbeeDevice.ts +115 -115
- package/server/devices/zigbee/zigbeeDeviceType.ts +13 -13
- package/server/devices/zigbee/zigbeeHeimanSmoke.ts +99 -99
- package/server/devices/zigbee/zigbeeIkeaSteckdose.ts +31 -31
- package/server/devices/zigbee/zigbeeIlluActuator.ts +37 -37
- package/server/devices/zigbee/zigbeeIlluDimmer.ts +165 -165
- package/server/devices/zigbee/zigbeeIlluLampe.ts +33 -33
- package/server/devices/zigbee/zigbeeIlluLedRGBCCT.ts +137 -137
- package/server/ioBroker/connection.ts +1655 -1655
- package/server/ioBroker/ioBroker.main.ts +99 -99
- package/server/ioBroker/socketIOAuthInfo.ts +5 -5
- package/server/ioBroker/socketIOConnectOptions.ts +6 -6
- package/server/ioBroker/socketIOLogging.ts +29 -29
- package/server/ioBroker/socketIOVisCommand.ts +11 -11
- package/server/services/HTTPSOptions.ts +14 -14
- package/server/services/Sonos/OwnSonosDevices.ts +9 -0
- package/server/services/Sonos/mp3-server.ts +75 -75
- package/server/services/Sonos/polly-service.ts +100 -100
- package/server/services/Sonos/sonos-service.ts +194 -199
- package/server/services/Telegram/telegram-Commands.ts +237 -215
- package/server/services/Telegram/telegram-service.ts +171 -171
- package/server/services/Telegram/telegramMessageCalback.ts +11 -11
- package/server/services/calendar/muell-tonne.ts +82 -83
- package/server/services/calendar/m/303/274ll-service.ts +147 -146
- package/server/services/dbo/persist.ts +125 -125
- package/server/services/https-service.ts +71 -71
- package/server/services/log-service.ts +69 -69
- package/server/services/news-service.ts +81 -81
- package/server/services/settings-service.ts +15 -15
- package/server/services/time-callback-service.ts +223 -223
- package/server/services/utils/ringstorage.ts +24 -24
- package/server/services/utils/utils.ts +52 -52
- package/server/services/weather/weather-alert.ts +7 -7
- package/server/services/weather/weather-current.ts +26 -26
- package/server/services/weather/weather-daily.ts +22 -22
- package/server/services/weather/weather-feelsLike.ts +6 -6
- package/server/services/weather/weather-hourly.ts +17 -17
- package/server/services/weather/weather-item.ts +6 -6
- package/server/services/weather/weather-minutes.ts +4 -4
- package/server/services/weather/weather-service.ts +277 -277
- package/server/services/weather/weather-temp.ts +8 -8
- package/tsconfig.json +58 -58
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
import { LogLevel } from '../../../models/logLevel';
|
|
2
|
-
import { ZigbeeAquaraVibra } from '../zigbee/zigbeeAquaraVibra';
|
|
3
|
-
import { FensterPosition } from './FensterPosition';
|
|
4
|
-
import { HmIpGriff } from './hmIpGriff';
|
|
5
|
-
import { HmIpRoll } from './hmIpRoll';
|
|
6
|
-
import { ServerLogService } from '../../services/log-service';
|
|
7
|
-
import { TimeCallbackService, TimeOfDay } from '../../services/time-callback-service';
|
|
8
|
-
import { Utils } from '../../services/utils/utils';
|
|
9
|
-
import { RoomBase } from '../../../models/rooms/RoomBase';
|
|
10
|
-
|
|
11
|
-
export class Fenster {
|
|
12
|
-
public desiredPosition: number = 0;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* sets the desired Pos and moves rollo to this level
|
|
16
|
-
* @param {number} value
|
|
17
|
-
*/
|
|
18
|
-
public setDesiredPosition(value: number) {
|
|
19
|
-
this.desiredPosition = value;
|
|
20
|
-
this.restoreDesiredPosition();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public constructor(
|
|
24
|
-
public room: RoomBase,
|
|
25
|
-
public griffe: HmIpGriff[],
|
|
26
|
-
public vibration: ZigbeeAquaraVibra[],
|
|
27
|
-
public rollo: HmIpRoll | undefined = undefined,
|
|
28
|
-
public noRolloOnSunrise: boolean = false,
|
|
29
|
-
) {
|
|
30
|
-
for (const griff of griffe) {
|
|
31
|
-
griff.addKippCallback((kipp: boolean) => {
|
|
32
|
-
if (kipp && this.griffeInPosition(FensterPosition.offen) === 0) {
|
|
33
|
-
this.vibration.forEach((element) => {
|
|
34
|
-
element.vibrationBlocked = true;
|
|
35
|
-
});
|
|
36
|
-
const timeOfDay: TimeOfDay = TimeCallbackService.dayType(this.room.Einstellungen.rolloOffset);
|
|
37
|
-
if (TimeCallbackService.darkOutsideOrNight(timeOfDay)) {
|
|
38
|
-
this.rollo?.setLevel(50);
|
|
39
|
-
} else {
|
|
40
|
-
this.rollo?.up();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
griff.addOffenCallback((offen: boolean) => {
|
|
46
|
-
if (offen) {
|
|
47
|
-
this.vibration.forEach((element) => {
|
|
48
|
-
element.vibrationBlocked = true;
|
|
49
|
-
});
|
|
50
|
-
this.rollo?.up();
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
griff.addClosedCallback((geschlossen: boolean) => {
|
|
56
|
-
if (
|
|
57
|
-
geschlossen &&
|
|
58
|
-
this.griffeInPosition(FensterPosition.offen) === 0 &&
|
|
59
|
-
this.griffeInPosition(FensterPosition.kipp) === 0
|
|
60
|
-
) {
|
|
61
|
-
const now = new Date().getTime();
|
|
62
|
-
this.vibration.forEach((element) => {
|
|
63
|
-
ServerLogService.writeLog(
|
|
64
|
-
LogLevel.Debug,
|
|
65
|
-
`Starte Timeout für Vibrationsdeaktivierung für ${element.info.customName}`,
|
|
66
|
-
);
|
|
67
|
-
Utils.guardedTimeout(() => {
|
|
68
|
-
if (element.vibrationBlockedTimeStamp < now) {
|
|
69
|
-
element.vibrationBlocked = false;
|
|
70
|
-
}
|
|
71
|
-
}, 12000);
|
|
72
|
-
});
|
|
73
|
-
this.restoreDesiredPosition();
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
Utils.guardedTimeout(
|
|
78
|
-
() => {
|
|
79
|
-
if (this.rollo) this.rollo.Fenster = this;
|
|
80
|
-
for (const g of this.griffe) {
|
|
81
|
-
g.Fenster = this;
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
5,
|
|
85
|
-
this,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public griffeInPosition(pPosition: FensterPosition): number {
|
|
90
|
-
let count = 0;
|
|
91
|
-
for (const griff of this.griffe) {
|
|
92
|
-
if (griff.position === pPosition) {
|
|
93
|
-
count++;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return count;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
public rolloPositionChange(pValue: number): void {
|
|
100
|
-
if (!this.room) {
|
|
101
|
-
ServerLogService.writeLog(LogLevel.Error, `Fenster Rollo Update, but this one is not connected to any room!`);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
ServerLogService.writeLog(LogLevel.Debug, `Rollo Position Change in ${this.room.roomName} to ${pValue}`);
|
|
105
|
-
|
|
106
|
-
if (pValue === 0 || pValue === 100) {
|
|
107
|
-
this.room.setLightTimeBased(true);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public restoreDesiredPosition() {
|
|
112
|
-
this.rollo?.setLevel(this.desiredPosition);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
1
|
+
import { LogLevel } from '../../../models/logLevel';
|
|
2
|
+
import { ZigbeeAquaraVibra } from '../zigbee/zigbeeAquaraVibra';
|
|
3
|
+
import { FensterPosition } from './FensterPosition';
|
|
4
|
+
import { HmIpGriff } from './hmIpGriff';
|
|
5
|
+
import { HmIpRoll } from './hmIpRoll';
|
|
6
|
+
import { ServerLogService } from '../../services/log-service';
|
|
7
|
+
import { TimeCallbackService, TimeOfDay } from '../../services/time-callback-service';
|
|
8
|
+
import { Utils } from '../../services/utils/utils';
|
|
9
|
+
import { RoomBase } from '../../../models/rooms/RoomBase';
|
|
10
|
+
|
|
11
|
+
export class Fenster {
|
|
12
|
+
public desiredPosition: number = 0;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* sets the desired Pos and moves rollo to this level
|
|
16
|
+
* @param {number} value
|
|
17
|
+
*/
|
|
18
|
+
public setDesiredPosition(value: number) {
|
|
19
|
+
this.desiredPosition = value;
|
|
20
|
+
this.restoreDesiredPosition();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public constructor(
|
|
24
|
+
public room: RoomBase,
|
|
25
|
+
public griffe: HmIpGriff[],
|
|
26
|
+
public vibration: ZigbeeAquaraVibra[],
|
|
27
|
+
public rollo: HmIpRoll | undefined = undefined,
|
|
28
|
+
public noRolloOnSunrise: boolean = false,
|
|
29
|
+
) {
|
|
30
|
+
for (const griff of griffe) {
|
|
31
|
+
griff.addKippCallback((kipp: boolean) => {
|
|
32
|
+
if (kipp && this.griffeInPosition(FensterPosition.offen) === 0) {
|
|
33
|
+
this.vibration.forEach((element) => {
|
|
34
|
+
element.vibrationBlocked = true;
|
|
35
|
+
});
|
|
36
|
+
const timeOfDay: TimeOfDay = TimeCallbackService.dayType(this.room.Einstellungen.rolloOffset);
|
|
37
|
+
if (TimeCallbackService.darkOutsideOrNight(timeOfDay)) {
|
|
38
|
+
this.rollo?.setLevel(50);
|
|
39
|
+
} else {
|
|
40
|
+
this.rollo?.up();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
griff.addOffenCallback((offen: boolean) => {
|
|
46
|
+
if (offen) {
|
|
47
|
+
this.vibration.forEach((element) => {
|
|
48
|
+
element.vibrationBlocked = true;
|
|
49
|
+
});
|
|
50
|
+
this.rollo?.up();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
griff.addClosedCallback((geschlossen: boolean) => {
|
|
56
|
+
if (
|
|
57
|
+
geschlossen &&
|
|
58
|
+
this.griffeInPosition(FensterPosition.offen) === 0 &&
|
|
59
|
+
this.griffeInPosition(FensterPosition.kipp) === 0
|
|
60
|
+
) {
|
|
61
|
+
const now = new Date().getTime();
|
|
62
|
+
this.vibration.forEach((element) => {
|
|
63
|
+
ServerLogService.writeLog(
|
|
64
|
+
LogLevel.Debug,
|
|
65
|
+
`Starte Timeout für Vibrationsdeaktivierung für ${element.info.customName}`,
|
|
66
|
+
);
|
|
67
|
+
Utils.guardedTimeout(() => {
|
|
68
|
+
if (element.vibrationBlockedTimeStamp < now) {
|
|
69
|
+
element.vibrationBlocked = false;
|
|
70
|
+
}
|
|
71
|
+
}, 12000);
|
|
72
|
+
});
|
|
73
|
+
this.restoreDesiredPosition();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
Utils.guardedTimeout(
|
|
78
|
+
() => {
|
|
79
|
+
if (this.rollo) this.rollo.Fenster = this;
|
|
80
|
+
for (const g of this.griffe) {
|
|
81
|
+
g.Fenster = this;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
5,
|
|
85
|
+
this,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public griffeInPosition(pPosition: FensterPosition): number {
|
|
90
|
+
let count = 0;
|
|
91
|
+
for (const griff of this.griffe) {
|
|
92
|
+
if (griff.position === pPosition) {
|
|
93
|
+
count++;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return count;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public rolloPositionChange(pValue: number): void {
|
|
100
|
+
if (!this.room) {
|
|
101
|
+
ServerLogService.writeLog(LogLevel.Error, `Fenster Rollo Update, but this one is not connected to any room!`);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
ServerLogService.writeLog(LogLevel.Debug, `Rollo Position Change in ${this.room.roomName} to ${pValue}`);
|
|
105
|
+
|
|
106
|
+
if (pValue === 0 || pValue === 100) {
|
|
107
|
+
this.room.setLightTimeBased(true);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public restoreDesiredPosition() {
|
|
112
|
+
this.rollo?.setLevel(this.desiredPosition);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export enum FensterPosition {
|
|
2
|
-
geschlossen = 0,
|
|
3
|
-
kipp = 1,
|
|
4
|
-
offen = 2,
|
|
5
|
-
}
|
|
1
|
+
export enum FensterPosition {
|
|
2
|
+
geschlossen = 0,
|
|
3
|
+
kipp = 1,
|
|
4
|
+
offen = 2,
|
|
5
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export enum TuerPosition {
|
|
2
|
-
geschlossen = 0,
|
|
3
|
-
offen = 1,
|
|
4
|
-
}
|
|
1
|
+
export enum TuerPosition {
|
|
2
|
+
geschlossen = 0,
|
|
3
|
+
offen = 1,
|
|
4
|
+
}
|
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
import { LogLevel } from '../../../models/logLevel';
|
|
2
|
-
import { HmIPDevice } from './hmIpDevice';
|
|
3
|
-
import { HmIpDeviceType } from './hmIpDeviceType';
|
|
4
|
-
import { DeviceInfo } from '../DeviceInfo';
|
|
5
|
-
import { ServerLogService } from '../../services/log-service';
|
|
6
|
-
import { Persist } from '../../services/dbo/persist';
|
|
7
|
-
import { CountToday } from '../../../models/persistence/todaysCount';
|
|
8
|
-
import { Utils } from '../../services/utils/utils';
|
|
9
|
-
|
|
10
|
-
export class HmIpBewegung extends HmIPDevice {
|
|
11
|
-
public excludeFromNightAlarm: boolean = false;
|
|
12
|
-
public movementDetected: boolean = false;
|
|
13
|
-
private _detectionsToday: number = 0;
|
|
14
|
-
private _movementDetectedCallback: Array<(pValue: boolean) => void> = [];
|
|
15
|
-
private static MOVEMENT_DETECTION: string = 'MOTION';
|
|
16
|
-
private initialized: boolean = false;
|
|
17
|
-
private fallBackTimeout: NodeJS.Timeout | undefined;
|
|
18
|
-
|
|
19
|
-
public get detectionsToday(): number {
|
|
20
|
-
return this._detectionsToday;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public set detectionsToday(pVal: number) {
|
|
24
|
-
const oldVal: number = this._detectionsToday;
|
|
25
|
-
this._detectionsToday = pVal;
|
|
26
|
-
Persist.persistTodayCount(this, pVal, oldVal);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public constructor(pInfo: DeviceInfo) {
|
|
30
|
-
super(pInfo, HmIpDeviceType.HmIpBewegung);
|
|
31
|
-
Persist.getCount(this).then((todayCount: CountToday) => {
|
|
32
|
-
this.detectionsToday = todayCount.counter;
|
|
33
|
-
ServerLogService.writeLog(
|
|
34
|
-
LogLevel.Debug,
|
|
35
|
-
`Bewegungscounter "${this.info.customName}" vorinitialisiert mit ${this.detectionsToday}`,
|
|
36
|
-
);
|
|
37
|
-
this.initialized = true;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public addMovementCallback(pCallback: (pValue: boolean) => void): void {
|
|
42
|
-
this._movementDetectedCallback.push(pCallback);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public update(idSplit: string[], state: ioBroker.State, initial: boolean = false): void {
|
|
46
|
-
ServerLogService.writeLog(
|
|
47
|
-
LogLevel.Trace,
|
|
48
|
-
`Bewegungs Update: JSON: ${JSON.stringify(state)}ID: ${idSplit.join('.')}`,
|
|
49
|
-
);
|
|
50
|
-
super.update(idSplit, state, initial, true);
|
|
51
|
-
|
|
52
|
-
if (idSplit[3] !== '3') {
|
|
53
|
-
// Nur die Infos in Kanal 1 sind relevant
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
switch (idSplit[4]) {
|
|
58
|
-
case HmIpBewegung.MOVEMENT_DETECTION:
|
|
59
|
-
this.updateMovement(state.val as boolean);
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public updateMovement(pVal: boolean): void {
|
|
65
|
-
if (!this.initialized && pVal) {
|
|
66
|
-
ServerLogService.writeLog(
|
|
67
|
-
LogLevel.Trace,
|
|
68
|
-
`Bewegung für "${this.info.customName}" erkannt aber die Initialisierung aus der DB ist noch nicht erfolgt --> verzögern`,
|
|
69
|
-
);
|
|
70
|
-
Utils.guardedTimeout(
|
|
71
|
-
() => {
|
|
72
|
-
this.updateMovement(pVal);
|
|
73
|
-
},
|
|
74
|
-
1000,
|
|
75
|
-
this,
|
|
76
|
-
);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (pVal === this.movementDetected) {
|
|
80
|
-
ServerLogService.writeLog(
|
|
81
|
-
LogLevel.Debug,
|
|
82
|
-
`Überspringe Bewegung für "${this.info.customName}" da bereits der Wert ${pVal} vorliegt`,
|
|
83
|
-
);
|
|
84
|
-
if (pVal) {
|
|
85
|
-
this.resetFallbackTimeout();
|
|
86
|
-
this.startFallbackTimeout();
|
|
87
|
-
}
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
this.resetFallbackTimeout();
|
|
92
|
-
this.movementDetected = pVal;
|
|
93
|
-
ServerLogService.writeLog(LogLevel.Debug, `Neuer Bewegunsstatus Wert für "${this.info.customName}": ${pVal}`);
|
|
94
|
-
if (pVal) {
|
|
95
|
-
this.startFallbackTimeout();
|
|
96
|
-
this.detectionsToday++;
|
|
97
|
-
ServerLogService.writeLog(
|
|
98
|
-
LogLevel.Trace,
|
|
99
|
-
`Dies ist die ${this.detectionsToday} Bewegung für "${this.info.customName}"`,
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
for (const c of this._movementDetectedCallback) {
|
|
104
|
-
c(pVal);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
private resetFallbackTimeout(): void {
|
|
109
|
-
if (this.fallBackTimeout) {
|
|
110
|
-
ServerLogService.writeLog(LogLevel.Trace, `Fallback Timeout für "${this.info.customName}" zurücksetzen`);
|
|
111
|
-
clearTimeout(this.fallBackTimeout);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
private startFallbackTimeout(): void {
|
|
116
|
-
this.fallBackTimeout = Utils.guardedTimeout(
|
|
117
|
-
() => {
|
|
118
|
-
ServerLogService.writeLog(LogLevel.Debug, `Benötige Fallback Bewegungs Reset für "${this.info.customName}"`);
|
|
119
|
-
this.fallBackTimeout = undefined;
|
|
120
|
-
this.updateMovement(false);
|
|
121
|
-
},
|
|
122
|
-
270000,
|
|
123
|
-
this,
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
1
|
+
import { LogLevel } from '../../../models/logLevel';
|
|
2
|
+
import { HmIPDevice } from './hmIpDevice';
|
|
3
|
+
import { HmIpDeviceType } from './hmIpDeviceType';
|
|
4
|
+
import { DeviceInfo } from '../DeviceInfo';
|
|
5
|
+
import { ServerLogService } from '../../services/log-service';
|
|
6
|
+
import { Persist } from '../../services/dbo/persist';
|
|
7
|
+
import { CountToday } from '../../../models/persistence/todaysCount';
|
|
8
|
+
import { Utils } from '../../services/utils/utils';
|
|
9
|
+
|
|
10
|
+
export class HmIpBewegung extends HmIPDevice {
|
|
11
|
+
public excludeFromNightAlarm: boolean = false;
|
|
12
|
+
public movementDetected: boolean = false;
|
|
13
|
+
private _detectionsToday: number = 0;
|
|
14
|
+
private _movementDetectedCallback: Array<(pValue: boolean) => void> = [];
|
|
15
|
+
private static MOVEMENT_DETECTION: string = 'MOTION';
|
|
16
|
+
private initialized: boolean = false;
|
|
17
|
+
private fallBackTimeout: NodeJS.Timeout | undefined;
|
|
18
|
+
|
|
19
|
+
public get detectionsToday(): number {
|
|
20
|
+
return this._detectionsToday;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public set detectionsToday(pVal: number) {
|
|
24
|
+
const oldVal: number = this._detectionsToday;
|
|
25
|
+
this._detectionsToday = pVal;
|
|
26
|
+
Persist.persistTodayCount(this, pVal, oldVal);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public constructor(pInfo: DeviceInfo) {
|
|
30
|
+
super(pInfo, HmIpDeviceType.HmIpBewegung);
|
|
31
|
+
Persist.getCount(this).then((todayCount: CountToday) => {
|
|
32
|
+
this.detectionsToday = todayCount.counter;
|
|
33
|
+
ServerLogService.writeLog(
|
|
34
|
+
LogLevel.Debug,
|
|
35
|
+
`Bewegungscounter "${this.info.customName}" vorinitialisiert mit ${this.detectionsToday}`,
|
|
36
|
+
);
|
|
37
|
+
this.initialized = true;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public addMovementCallback(pCallback: (pValue: boolean) => void): void {
|
|
42
|
+
this._movementDetectedCallback.push(pCallback);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public update(idSplit: string[], state: ioBroker.State, initial: boolean = false): void {
|
|
46
|
+
ServerLogService.writeLog(
|
|
47
|
+
LogLevel.Trace,
|
|
48
|
+
`Bewegungs Update: JSON: ${JSON.stringify(state)}ID: ${idSplit.join('.')}`,
|
|
49
|
+
);
|
|
50
|
+
super.update(idSplit, state, initial, true);
|
|
51
|
+
|
|
52
|
+
if (idSplit[3] !== '3') {
|
|
53
|
+
// Nur die Infos in Kanal 1 sind relevant
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
switch (idSplit[4]) {
|
|
58
|
+
case HmIpBewegung.MOVEMENT_DETECTION:
|
|
59
|
+
this.updateMovement(state.val as boolean);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public updateMovement(pVal: boolean): void {
|
|
65
|
+
if (!this.initialized && pVal) {
|
|
66
|
+
ServerLogService.writeLog(
|
|
67
|
+
LogLevel.Trace,
|
|
68
|
+
`Bewegung für "${this.info.customName}" erkannt aber die Initialisierung aus der DB ist noch nicht erfolgt --> verzögern`,
|
|
69
|
+
);
|
|
70
|
+
Utils.guardedTimeout(
|
|
71
|
+
() => {
|
|
72
|
+
this.updateMovement(pVal);
|
|
73
|
+
},
|
|
74
|
+
1000,
|
|
75
|
+
this,
|
|
76
|
+
);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (pVal === this.movementDetected) {
|
|
80
|
+
ServerLogService.writeLog(
|
|
81
|
+
LogLevel.Debug,
|
|
82
|
+
`Überspringe Bewegung für "${this.info.customName}" da bereits der Wert ${pVal} vorliegt`,
|
|
83
|
+
);
|
|
84
|
+
if (pVal) {
|
|
85
|
+
this.resetFallbackTimeout();
|
|
86
|
+
this.startFallbackTimeout();
|
|
87
|
+
}
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.resetFallbackTimeout();
|
|
92
|
+
this.movementDetected = pVal;
|
|
93
|
+
ServerLogService.writeLog(LogLevel.Debug, `Neuer Bewegunsstatus Wert für "${this.info.customName}": ${pVal}`);
|
|
94
|
+
if (pVal) {
|
|
95
|
+
this.startFallbackTimeout();
|
|
96
|
+
this.detectionsToday++;
|
|
97
|
+
ServerLogService.writeLog(
|
|
98
|
+
LogLevel.Trace,
|
|
99
|
+
`Dies ist die ${this.detectionsToday} Bewegung für "${this.info.customName}"`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
for (const c of this._movementDetectedCallback) {
|
|
104
|
+
c(pVal);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private resetFallbackTimeout(): void {
|
|
109
|
+
if (this.fallBackTimeout) {
|
|
110
|
+
ServerLogService.writeLog(LogLevel.Trace, `Fallback Timeout für "${this.info.customName}" zurücksetzen`);
|
|
111
|
+
clearTimeout(this.fallBackTimeout);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private startFallbackTimeout(): void {
|
|
116
|
+
this.fallBackTimeout = Utils.guardedTimeout(
|
|
117
|
+
() => {
|
|
118
|
+
ServerLogService.writeLog(LogLevel.Debug, `Benötige Fallback Bewegungs Reset für "${this.info.customName}"`);
|
|
119
|
+
this.fallBackTimeout = undefined;
|
|
120
|
+
this.updateMovement(false);
|
|
121
|
+
},
|
|
122
|
+
270000,
|
|
123
|
+
this,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|