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,146 +1,147 @@
|
|
|
1
|
-
import { async, VEvent } from 'node-ical';
|
|
2
|
-
import { ServerLogService } from '../log-service';
|
|
3
|
-
import { TimeCallbackService } from '../time-callback-service';
|
|
4
|
-
import { LogLevel } from '../../../models/logLevel';
|
|
5
|
-
import { TimeCallback, TimeCallbackType } from '../../../models/timeCallback';
|
|
6
|
-
import { iMuellSettings } from '../../config/iConfig';
|
|
7
|
-
import { Utils } from '../utils/utils';
|
|
8
|
-
import { MuellTonne } from './muell-tonne';
|
|
9
|
-
import { OwnSonosDevice } from '../Sonos/sonos-service';
|
|
10
|
-
|
|
11
|
-
export class MuellService {
|
|
12
|
-
public static alleTonnen: Array<{ name: string; date: Date }> = [];
|
|
13
|
-
public static blaueTonne: MuellTonne;
|
|
14
|
-
public static graueTonne: MuellTonne;
|
|
15
|
-
public static gelbeTonne: MuellTonne;
|
|
16
|
-
public static brauneTonne: MuellTonne;
|
|
17
|
-
public static updateTimeCallback: TimeCallback;
|
|
18
|
-
public static checkTimeCallback: TimeCallback;
|
|
19
|
-
private static lastCheck: Date = new Date(0);
|
|
20
|
-
private static _calendarURL: string;
|
|
21
|
-
private static _active: boolean = false;
|
|
22
|
-
private static defaultSonosDevice: OwnSonosDevice | undefined = undefined;
|
|
23
|
-
|
|
24
|
-
public static months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
25
|
-
|
|
26
|
-
public static intialize(config: iMuellSettings, defaultSonosDevice: OwnSonosDevice | undefined): void {
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
63
|
-
this.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this.
|
|
107
|
-
this.
|
|
108
|
-
this.
|
|
109
|
-
this.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.
|
|
142
|
-
this.
|
|
143
|
-
this.
|
|
144
|
-
this.
|
|
145
|
-
|
|
146
|
-
}
|
|
1
|
+
import { async, VEvent } from 'node-ical';
|
|
2
|
+
import { ServerLogService } from '../log-service';
|
|
3
|
+
import { TimeCallbackService } from '../time-callback-service';
|
|
4
|
+
import { LogLevel } from '../../../models/logLevel';
|
|
5
|
+
import { TimeCallback, TimeCallbackType } from '../../../models/timeCallback';
|
|
6
|
+
import { iMuellSettings } from '../../config/iConfig';
|
|
7
|
+
import { Utils } from '../utils/utils';
|
|
8
|
+
import { MuellTonne } from './muell-tonne';
|
|
9
|
+
import { OwnSonosDevice } from '../Sonos/sonos-service';
|
|
10
|
+
|
|
11
|
+
export class MuellService {
|
|
12
|
+
public static alleTonnen: Array<{ name: string; date: Date }> = [];
|
|
13
|
+
public static blaueTonne: MuellTonne;
|
|
14
|
+
public static graueTonne: MuellTonne;
|
|
15
|
+
public static gelbeTonne: MuellTonne;
|
|
16
|
+
public static brauneTonne: MuellTonne;
|
|
17
|
+
public static updateTimeCallback: TimeCallback;
|
|
18
|
+
public static checkTimeCallback: TimeCallback;
|
|
19
|
+
private static lastCheck: Date = new Date(0);
|
|
20
|
+
private static _calendarURL: string;
|
|
21
|
+
private static _active: boolean = false;
|
|
22
|
+
private static defaultSonosDevice: OwnSonosDevice | undefined = undefined;
|
|
23
|
+
|
|
24
|
+
public static months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
25
|
+
|
|
26
|
+
public static intialize(config: iMuellSettings, defaultSonosDevice: OwnSonosDevice | undefined): void {
|
|
27
|
+
this.defaultSonosDevice = defaultSonosDevice;
|
|
28
|
+
this._active = true;
|
|
29
|
+
this._calendarURL = config.calendarURL;
|
|
30
|
+
this.updateTimeCallback = new TimeCallback(
|
|
31
|
+
'MuelltonnenServiceUpdater',
|
|
32
|
+
TimeCallbackType.TimeOfDay,
|
|
33
|
+
() => {
|
|
34
|
+
this.updateCalendar(false);
|
|
35
|
+
},
|
|
36
|
+
0,
|
|
37
|
+
2,
|
|
38
|
+
0,
|
|
39
|
+
);
|
|
40
|
+
TimeCallbackService.addCallback(this.updateTimeCallback);
|
|
41
|
+
|
|
42
|
+
this.checkTimeCallback = new TimeCallback(
|
|
43
|
+
'MuelltonnenServiceChecker',
|
|
44
|
+
TimeCallbackType.TimeOfDay,
|
|
45
|
+
() => {
|
|
46
|
+
this.checkAll();
|
|
47
|
+
},
|
|
48
|
+
0,
|
|
49
|
+
18,
|
|
50
|
+
0,
|
|
51
|
+
);
|
|
52
|
+
TimeCallbackService.addCallback(this.checkTimeCallback);
|
|
53
|
+
|
|
54
|
+
this.updateCalendar();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public static updateCalendar(checkAfterwards: boolean = true): void {
|
|
58
|
+
ServerLogService.writeLog(LogLevel.Debug, `Muell Service wird nun initialisiert`);
|
|
59
|
+
async.fromURL(this._calendarURL).then((data) => {
|
|
60
|
+
this.gelbeTonne = new MuellTonne('Gelbe Tonne', this.defaultSonosDevice);
|
|
61
|
+
this.graueTonne = new MuellTonne('Graue Tonne', this.defaultSonosDevice);
|
|
62
|
+
this.blaueTonne = new MuellTonne('Blaue Tonne', this.defaultSonosDevice);
|
|
63
|
+
this.brauneTonne = new MuellTonne('Braune Tonne', this.defaultSonosDevice);
|
|
64
|
+
this.alleTonnen = [];
|
|
65
|
+
const todayMidnight: number = new Date().setHours(0, 0, 0, 0);
|
|
66
|
+
for (const k in data) {
|
|
67
|
+
if (!data.hasOwnProperty(k)) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (data[k].type !== 'VEVENT') {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const ev = data[k] as VEvent;
|
|
76
|
+
ServerLogService.writeLog(
|
|
77
|
+
LogLevel.DeepTrace,
|
|
78
|
+
`${ev.summary} is in ${ev.location} on the ${ev.start.getDate()} of ${
|
|
79
|
+
this.months[ev.start.getMonth()]
|
|
80
|
+
} at ${ev.start.toLocaleTimeString('en-GB')}`,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
if (ev.start.getTime() < todayMidnight) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this.alleTonnen.push({ name: ev.summary, date: ev.start });
|
|
88
|
+
switch (ev.summary) {
|
|
89
|
+
case this.gelbeTonne.name:
|
|
90
|
+
this.gelbeTonne.dates.push(ev.start);
|
|
91
|
+
break;
|
|
92
|
+
case this.graueTonne.name:
|
|
93
|
+
this.graueTonne.dates.push(ev.start);
|
|
94
|
+
break;
|
|
95
|
+
case this.blaueTonne.name:
|
|
96
|
+
this.blaueTonne.dates.push(ev.start);
|
|
97
|
+
break;
|
|
98
|
+
case this.brauneTonne.name:
|
|
99
|
+
this.brauneTonne.dates.push(ev.start);
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
ServerLogService.writeLog(LogLevel.Warn, `Unbekannte Mülltonne (${ev.summary})`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.gelbeTonne.sortDates();
|
|
107
|
+
this.graueTonne.sortDates();
|
|
108
|
+
this.blaueTonne.sortDates();
|
|
109
|
+
this.brauneTonne.sortDates();
|
|
110
|
+
this.alleTonnen = this.alleTonnen.sort((a, b) => a.date.getTime() - b.date.getTime());
|
|
111
|
+
if (checkAfterwards) {
|
|
112
|
+
this.checkAll();
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public static checkAll(pRetries: number = 10): void {
|
|
118
|
+
if (!this._active) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const now: Date = new Date();
|
|
123
|
+
if (now.getTime() - this.lastCheck.getTime() < 60000 && now.getDate() === this.lastCheck.getDate()) {
|
|
124
|
+
ServerLogService.writeLog(LogLevel.Trace, `MüllService.checkAll: Skipped weil wir gerade erst geprüft hatten.`);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (this.gelbeTonne === undefined) {
|
|
129
|
+
if (pRetries > 0) {
|
|
130
|
+
ServerLogService.writeLog(LogLevel.Warn, `Der Müllservice ist noch nicht bereit --> warten`);
|
|
131
|
+
Utils.guardedTimeout(() => {
|
|
132
|
+
MuellService.checkAll(pRetries - 1);
|
|
133
|
+
}, 1000);
|
|
134
|
+
} else {
|
|
135
|
+
ServerLogService.writeLog(LogLevel.Error, `Der Müllservice ist trotz Warten nicht bereit --> Abbruch`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
this.lastCheck = now;
|
|
142
|
+
this.gelbeTonne.check();
|
|
143
|
+
this.graueTonne.check();
|
|
144
|
+
this.blaueTonne.check();
|
|
145
|
+
this.brauneTonne.check();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
import { Mongo } from 'meteor/mongo';
|
|
2
|
-
import { ServerLogService } from '../log-service';
|
|
3
|
-
import { LogLevel } from '../../../models/logLevel';
|
|
4
|
-
import { TemperaturDataPoint } from '../../../models/persistence/temperaturDataPoint';
|
|
5
|
-
import { CountToday } from '../../../models/persistence/todaysCount';
|
|
6
|
-
import { HmIpHeizgruppe } from '../../devices/hmIPDevices/hmIpHeizgruppe';
|
|
7
|
-
import { HmIPDevice } from '../../devices/hmIPDevices/hmIpDevice';
|
|
8
|
-
import { RoomBase } from '../../../models/rooms/RoomBase';
|
|
9
|
-
import { BasicRoomInfo } from '../../../models/persistence/BasicRoomInfo';
|
|
10
|
-
import { RoomDetailInfo } from '../../../models/persistence/RoomDetailInfo';
|
|
11
|
-
import { DailyMovementCount } from '../../../models/persistence/DailyMovementCount';
|
|
12
|
-
import { iTemperaturDataPoint } from
|
|
13
|
-
|
|
14
|
-
export const TemperatureHistoryCollection = new Mongo.Collection<TemperaturDataPoint>('TemperaturData');
|
|
15
|
-
export const HeatGroupCollection = new Mongo.Collection<TemperaturDataPoint>('HeatGroupCollection');
|
|
16
|
-
export const BasicRoomCollection = new Mongo.Collection<BasicRoomInfo>('BasicRooms');
|
|
17
|
-
export const RoomDetailsCollection = new Mongo.Collection<RoomDetailInfo>('RoomDetailsCollection');
|
|
18
|
-
export const CountTodayCollection = new Mongo.Collection<CountToday>('PresenceToday');
|
|
19
|
-
export const DailyMovementCountTodayCollection = new Mongo.Collection<DailyMovementCount>('DailyMovementCount');
|
|
20
|
-
export class Persist {
|
|
21
|
-
public static MeteorBound: (callback: any) => void;
|
|
22
|
-
public static addTemperaturDataPoint(hzGrp: HmIpHeizgruppe): void {
|
|
23
|
-
const dataPoint: iTemperaturDataPoint = new TemperaturDataPoint(
|
|
24
|
-
hzGrp.info.customName,
|
|
25
|
-
hzGrp.iTemperatur,
|
|
26
|
-
hzGrp.desiredTemperatur,
|
|
27
|
-
hzGrp.iLevel,
|
|
28
|
-
hzGrp.humidity,
|
|
29
|
-
new Date(),
|
|
30
|
-
);
|
|
31
|
-
ServerLogService.writeLog(LogLevel.Trace, `Persisting Temperatur Data for ${hzGrp.info.customName}`);
|
|
32
|
-
this.MeteorBound(() => {
|
|
33
|
-
TemperatureHistoryCollection.insert(dataPoint);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
this.MeteorBound(() => {
|
|
37
|
-
HeatGroupCollection.update({ name: dataPoint.name }, dataPoint, { upsert: true });
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public static addRoom(room: RoomBase): void {
|
|
42
|
-
ServerLogService.writeLog(LogLevel.Trace, `Persisting Room for ${room.roomName}`);
|
|
43
|
-
this.MeteorBound(() => {
|
|
44
|
-
BasicRoomCollection.update({ roomName: room.roomName }, new BasicRoomInfo(room.roomName, room.Settings.etage), {
|
|
45
|
-
upsert: true,
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
const detailed = new RoomDetailInfo(room.roomName, room.Settings.etage);
|
|
49
|
-
for (const h of room.HeatGroup.heaters) {
|
|
50
|
-
detailed.heaters.push(h.info.customName);
|
|
51
|
-
}
|
|
52
|
-
this.MeteorBound(() => {
|
|
53
|
-
RoomDetailsCollection.update({ roomName: room.roomName }, detailed, { upsert: true });
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public static async getCount(device: HmIPDevice): Promise<CountToday> {
|
|
58
|
-
const result = new Promise<CountToday>((resolve) => {
|
|
59
|
-
this.MeteorBound(() => {
|
|
60
|
-
const options = {
|
|
61
|
-
limit: 1,
|
|
62
|
-
};
|
|
63
|
-
const databaseValue: CountToday[] = CountTodayCollection.find(
|
|
64
|
-
{ deviceID: device.info.fullID },
|
|
65
|
-
options,
|
|
66
|
-
).fetch();
|
|
67
|
-
if (databaseValue.length === 0) {
|
|
68
|
-
ServerLogService.writeLog(
|
|
69
|
-
LogLevel.Debug,
|
|
70
|
-
`Es gibt noch keinen persistierten Counter für ${device.info.fullName}`,
|
|
71
|
-
);
|
|
72
|
-
resolve(new CountToday(device.info.fullID, 0));
|
|
73
|
-
} else {
|
|
74
|
-
resolve(databaseValue[0]);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public static persistTodayCount(device: HmIPDevice, count: number, oldCount: number): void {
|
|
83
|
-
this.MeteorBound(() => {
|
|
84
|
-
const result = CountTodayCollection.update(
|
|
85
|
-
{ deviceID: device.info.fullID },
|
|
86
|
-
new CountToday(device.info.fullID, count),
|
|
87
|
-
{ upsert: true },
|
|
88
|
-
);
|
|
89
|
-
if (count === 0) {
|
|
90
|
-
const date = new Date();
|
|
91
|
-
date.setHours(-24, 0, 0, 0);
|
|
92
|
-
const result2 = DailyMovementCountTodayCollection.update(
|
|
93
|
-
{ deviceID: device.info.fullID, date: date },
|
|
94
|
-
new DailyMovementCount(device.info.fullID, oldCount, device.info.room, date),
|
|
95
|
-
{ upsert: true },
|
|
96
|
-
);
|
|
97
|
-
ServerLogService.writeLog(
|
|
98
|
-
LogLevel.Trace,
|
|
99
|
-
`Persisting Daily Movement Count for ${device.info.customName} to ${oldCount} resolved with "${result2}"`,
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
ServerLogService.writeLog(
|
|
103
|
-
LogLevel.Trace,
|
|
104
|
-
`Persisting PresenceToday Data for ${device.info.customName} to ${count} resolved with "${result}"`,
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
public static async readTemperaturDataPoint(
|
|
110
|
-
hzGrp: HmIpHeizgruppe,
|
|
111
|
-
limit: number = -1,
|
|
112
|
-
): Promise<TemperaturDataPoint[]> {
|
|
113
|
-
const result = new Promise<TemperaturDataPoint[]>((resolve) => {
|
|
114
|
-
this.MeteorBound(() => {
|
|
115
|
-
const options = {
|
|
116
|
-
limit: limit > 0 ? limit : undefined,
|
|
117
|
-
sort: { date: -1 },
|
|
118
|
-
};
|
|
119
|
-
resolve(TemperatureHistoryCollection.find({ name: hzGrp.info.customName }, options).fetch());
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
return result;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
1
|
+
import { Mongo } from 'meteor/mongo';
|
|
2
|
+
import { ServerLogService } from '../log-service';
|
|
3
|
+
import { LogLevel } from '../../../models/logLevel';
|
|
4
|
+
import { TemperaturDataPoint } from '../../../models/persistence/temperaturDataPoint';
|
|
5
|
+
import { CountToday } from '../../../models/persistence/todaysCount';
|
|
6
|
+
import { HmIpHeizgruppe } from '../../devices/hmIPDevices/hmIpHeizgruppe';
|
|
7
|
+
import { HmIPDevice } from '../../devices/hmIPDevices/hmIpDevice';
|
|
8
|
+
import { RoomBase } from '../../../models/rooms/RoomBase';
|
|
9
|
+
import { BasicRoomInfo } from '../../../models/persistence/BasicRoomInfo';
|
|
10
|
+
import { RoomDetailInfo } from '../../../models/persistence/RoomDetailInfo';
|
|
11
|
+
import { DailyMovementCount } from '../../../models/persistence/DailyMovementCount';
|
|
12
|
+
import { iTemperaturDataPoint } from '../../../models/iTemperaturDataPoint';
|
|
13
|
+
|
|
14
|
+
export const TemperatureHistoryCollection = new Mongo.Collection<TemperaturDataPoint>('TemperaturData');
|
|
15
|
+
export const HeatGroupCollection = new Mongo.Collection<TemperaturDataPoint>('HeatGroupCollection');
|
|
16
|
+
export const BasicRoomCollection = new Mongo.Collection<BasicRoomInfo>('BasicRooms');
|
|
17
|
+
export const RoomDetailsCollection = new Mongo.Collection<RoomDetailInfo>('RoomDetailsCollection');
|
|
18
|
+
export const CountTodayCollection = new Mongo.Collection<CountToday>('PresenceToday');
|
|
19
|
+
export const DailyMovementCountTodayCollection = new Mongo.Collection<DailyMovementCount>('DailyMovementCount');
|
|
20
|
+
export class Persist {
|
|
21
|
+
public static MeteorBound: (callback: any) => void;
|
|
22
|
+
public static addTemperaturDataPoint(hzGrp: HmIpHeizgruppe): void {
|
|
23
|
+
const dataPoint: iTemperaturDataPoint = new TemperaturDataPoint(
|
|
24
|
+
hzGrp.info.customName,
|
|
25
|
+
hzGrp.iTemperatur,
|
|
26
|
+
hzGrp.desiredTemperatur,
|
|
27
|
+
hzGrp.iLevel,
|
|
28
|
+
hzGrp.humidity,
|
|
29
|
+
new Date(),
|
|
30
|
+
);
|
|
31
|
+
ServerLogService.writeLog(LogLevel.Trace, `Persisting Temperatur Data for ${hzGrp.info.customName}`);
|
|
32
|
+
this.MeteorBound(() => {
|
|
33
|
+
TemperatureHistoryCollection.insert(dataPoint);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
this.MeteorBound(() => {
|
|
37
|
+
HeatGroupCollection.update({ name: dataPoint.name }, dataPoint, { upsert: true });
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public static addRoom(room: RoomBase): void {
|
|
42
|
+
ServerLogService.writeLog(LogLevel.Trace, `Persisting Room for ${room.roomName}`);
|
|
43
|
+
this.MeteorBound(() => {
|
|
44
|
+
BasicRoomCollection.update({ roomName: room.roomName }, new BasicRoomInfo(room.roomName, room.Settings.etage), {
|
|
45
|
+
upsert: true,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
const detailed = new RoomDetailInfo(room.roomName, room.Settings.etage);
|
|
49
|
+
for (const h of room.HeatGroup.heaters) {
|
|
50
|
+
detailed.heaters.push(h.info.customName);
|
|
51
|
+
}
|
|
52
|
+
this.MeteorBound(() => {
|
|
53
|
+
RoomDetailsCollection.update({ roomName: room.roomName }, detailed, { upsert: true });
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public static async getCount(device: HmIPDevice): Promise<CountToday> {
|
|
58
|
+
const result = new Promise<CountToday>((resolve) => {
|
|
59
|
+
this.MeteorBound(() => {
|
|
60
|
+
const options = {
|
|
61
|
+
limit: 1,
|
|
62
|
+
};
|
|
63
|
+
const databaseValue: CountToday[] = CountTodayCollection.find(
|
|
64
|
+
{ deviceID: device.info.fullID },
|
|
65
|
+
options,
|
|
66
|
+
).fetch();
|
|
67
|
+
if (databaseValue.length === 0) {
|
|
68
|
+
ServerLogService.writeLog(
|
|
69
|
+
LogLevel.Debug,
|
|
70
|
+
`Es gibt noch keinen persistierten Counter für ${device.info.fullName}`,
|
|
71
|
+
);
|
|
72
|
+
resolve(new CountToday(device.info.fullID, 0));
|
|
73
|
+
} else {
|
|
74
|
+
resolve(databaseValue[0]);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public static persistTodayCount(device: HmIPDevice, count: number, oldCount: number): void {
|
|
83
|
+
this.MeteorBound(() => {
|
|
84
|
+
const result = CountTodayCollection.update(
|
|
85
|
+
{ deviceID: device.info.fullID },
|
|
86
|
+
new CountToday(device.info.fullID, count),
|
|
87
|
+
{ upsert: true },
|
|
88
|
+
);
|
|
89
|
+
if (count === 0) {
|
|
90
|
+
const date = new Date();
|
|
91
|
+
date.setHours(-24, 0, 0, 0);
|
|
92
|
+
const result2 = DailyMovementCountTodayCollection.update(
|
|
93
|
+
{ deviceID: device.info.fullID, date: date },
|
|
94
|
+
new DailyMovementCount(device.info.fullID, oldCount, device.info.room, date),
|
|
95
|
+
{ upsert: true },
|
|
96
|
+
);
|
|
97
|
+
ServerLogService.writeLog(
|
|
98
|
+
LogLevel.Trace,
|
|
99
|
+
`Persisting Daily Movement Count for ${device.info.customName} to ${oldCount} resolved with "${result2}"`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
ServerLogService.writeLog(
|
|
103
|
+
LogLevel.Trace,
|
|
104
|
+
`Persisting PresenceToday Data for ${device.info.customName} to ${count} resolved with "${result}"`,
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public static async readTemperaturDataPoint(
|
|
110
|
+
hzGrp: HmIpHeizgruppe,
|
|
111
|
+
limit: number = -1,
|
|
112
|
+
): Promise<TemperaturDataPoint[]> {
|
|
113
|
+
const result = new Promise<TemperaturDataPoint[]>((resolve) => {
|
|
114
|
+
this.MeteorBound(() => {
|
|
115
|
+
const options = {
|
|
116
|
+
limit: limit > 0 ? limit : undefined,
|
|
117
|
+
sort: { date: -1 },
|
|
118
|
+
};
|
|
119
|
+
resolve(TemperatureHistoryCollection.find({ name: hzGrp.info.customName }, options).fetch());
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
}
|