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.
Files changed (113) hide show
  1. package/.eslintrc.js +27 -27
  2. package/.github/workflows/npm-publish.yml +50 -0
  3. package/.prettierrc.js +9 -9
  4. package/LICENSE +21 -21
  5. package/index.js +1 -1
  6. package/models/connectionCallbacks.ts +13 -13
  7. package/models/daytime.ts +3 -3
  8. package/models/deviceConfig.ts +8 -8
  9. package/models/dimmerSettings.ts +5 -5
  10. package/models/iTemperaturDataPoint.ts +9 -9
  11. package/models/lampSettings.ts +5 -5
  12. package/models/ledSettings.ts +19 -19
  13. package/models/logLevel.ts +9 -9
  14. package/models/persistence/BasicRoomInfo.ts +3 -3
  15. package/models/persistence/DailyMovementCount.ts +3 -3
  16. package/models/persistence/RoomDetailInfo.ts +4 -4
  17. package/models/persistence/temperaturDataPoint.ts +12 -12
  18. package/models/persistence/todaysCount.ts +3 -3
  19. package/models/rooms/RoomBase.ts +357 -357
  20. package/models/rooms/RoomSettings/RoomSettings.ts +159 -159
  21. package/models/rooms/RoomSettings/hmIPRoomSettings.ts +53 -53
  22. package/models/rooms/RoomSettings/iRoomDefaultSettings.ts +17 -17
  23. package/models/rooms/RoomSettings/readme.md +17 -17
  24. package/models/rooms/RoomSettings/zigbeeRoomSettings.ts +51 -51
  25. package/models/rooms/iRoomImportEnforcer.ts +3 -3
  26. package/models/rooms/readme.md +11 -11
  27. package/models/temperaturSettings.ts +22 -22
  28. package/models/timeCallback.ts +90 -90
  29. package/package.json +1 -1
  30. package/server/config/config-readme.md +19 -19
  31. package/server/config/iConfig.ts +53 -53
  32. package/server/config/private/mainConfig.json +64 -64
  33. package/server/devices/DeviceInfo.ts +66 -66
  34. package/server/devices/Griffe.ts +31 -31
  35. package/server/devices/Heizgruppen.ts +91 -91
  36. package/server/devices/Rollos.ts +48 -48
  37. package/server/devices/deviceUpdater.ts +72 -72
  38. package/server/devices/devices.ts +189 -189
  39. package/server/devices/groups/fensterGroup.ts +175 -175
  40. package/server/devices/groups/heatGroup.ts +32 -32
  41. package/server/devices/groups/lampenGroup.ts +88 -88
  42. package/server/devices/groups/praesenzGroup.ts +182 -182
  43. package/server/devices/groups/smokeGroup.ts +16 -16
  44. package/server/devices/groups/sonosGroup.ts +33 -33
  45. package/server/devices/groups/tasterGroup.ts +48 -48
  46. package/server/devices/groups/waterGroup.ts +16 -16
  47. package/server/devices/hmIPDevices/Fenster.ts +114 -114
  48. package/server/devices/hmIPDevices/FensterPosition.ts +5 -5
  49. package/server/devices/hmIPDevices/TuerPosition.ts +4 -4
  50. package/server/devices/hmIPDevices/hmIpBewegung.ts +126 -126
  51. package/server/devices/hmIPDevices/hmIpDevice.ts +90 -90
  52. package/server/devices/hmIPDevices/hmIpDeviceType.ts +14 -14
  53. package/server/devices/hmIPDevices/hmIpGriff.ts +143 -143
  54. package/server/devices/hmIPDevices/hmIpHeizgruppe.ts +172 -172
  55. package/server/devices/hmIPDevices/hmIpHeizung.ts +69 -69
  56. package/server/devices/hmIPDevices/hmIpLampe.ts +119 -119
  57. package/server/devices/hmIPDevices/hmIpPraezenz.ts +99 -99
  58. package/server/devices/hmIPDevices/hmIpRoll.ts +133 -133
  59. package/server/devices/hmIPDevices/hmIpTaster.ts +82 -73
  60. package/server/devices/hmIPDevices/hmIpTherm.ts +19 -19
  61. package/server/devices/hmIPDevices/hmIpTuer.ts +115 -115
  62. package/server/devices/hmIPDevices/hmIpWippe.ts +55 -55
  63. package/server/devices/iDeviceUpdater.ts +4 -4
  64. package/server/devices/iIoBrokerDevice.ts +44 -44
  65. package/server/devices/iTaster.ts +6 -0
  66. package/server/devices/{hmIPDevices/hmIpTaste.ts → taste.ts} +84 -72
  67. package/server/devices/wledDevice.ts +124 -124
  68. package/server/devices/zigbee/ZigbeeActuator.ts +113 -113
  69. package/server/devices/zigbee/zigbeeAquaraVibra.ts +171 -171
  70. package/server/devices/zigbee/zigbeeAquaraWater.ts +94 -94
  71. package/server/devices/zigbee/zigbeeBlitzShp.ts +77 -77
  72. package/server/devices/zigbee/zigbeeDevice.ts +115 -115
  73. package/server/devices/zigbee/zigbeeDeviceType.ts +13 -13
  74. package/server/devices/zigbee/zigbeeHeimanSmoke.ts +99 -99
  75. package/server/devices/zigbee/zigbeeIkeaSteckdose.ts +31 -31
  76. package/server/devices/zigbee/zigbeeIlluActuator.ts +37 -37
  77. package/server/devices/zigbee/zigbeeIlluDimmer.ts +165 -165
  78. package/server/devices/zigbee/zigbeeIlluLampe.ts +33 -33
  79. package/server/devices/zigbee/zigbeeIlluLedRGBCCT.ts +137 -137
  80. package/server/ioBroker/connection.ts +1655 -1655
  81. package/server/ioBroker/ioBroker.main.ts +99 -99
  82. package/server/ioBroker/socketIOAuthInfo.ts +5 -5
  83. package/server/ioBroker/socketIOConnectOptions.ts +6 -6
  84. package/server/ioBroker/socketIOLogging.ts +29 -29
  85. package/server/ioBroker/socketIOVisCommand.ts +11 -11
  86. package/server/services/HTTPSOptions.ts +14 -14
  87. package/server/services/Sonos/OwnSonosDevices.ts +9 -0
  88. package/server/services/Sonos/mp3-server.ts +75 -75
  89. package/server/services/Sonos/polly-service.ts +100 -100
  90. package/server/services/Sonos/sonos-service.ts +194 -199
  91. package/server/services/Telegram/telegram-Commands.ts +237 -215
  92. package/server/services/Telegram/telegram-service.ts +171 -171
  93. package/server/services/Telegram/telegramMessageCalback.ts +11 -11
  94. package/server/services/calendar/muell-tonne.ts +82 -83
  95. package/server/services/calendar/m/303/274ll-service.ts +147 -146
  96. package/server/services/dbo/persist.ts +125 -125
  97. package/server/services/https-service.ts +71 -71
  98. package/server/services/log-service.ts +69 -69
  99. package/server/services/news-service.ts +81 -81
  100. package/server/services/settings-service.ts +15 -15
  101. package/server/services/time-callback-service.ts +223 -223
  102. package/server/services/utils/ringstorage.ts +24 -24
  103. package/server/services/utils/utils.ts +52 -52
  104. package/server/services/weather/weather-alert.ts +7 -7
  105. package/server/services/weather/weather-current.ts +26 -26
  106. package/server/services/weather/weather-daily.ts +22 -22
  107. package/server/services/weather/weather-feelsLike.ts +6 -6
  108. package/server/services/weather/weather-hourly.ts +17 -17
  109. package/server/services/weather/weather-item.ts +6 -6
  110. package/server/services/weather/weather-minutes.ts +4 -4
  111. package/server/services/weather/weather-service.ts +277 -277
  112. package/server/services/weather/weather-temp.ts +8 -8
  113. 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._active = true;
28
- this._calendarURL = config.calendarURL;
29
- this.updateTimeCallback = new TimeCallback(
30
- 'MuelltonnenServiceUpdater',
31
- TimeCallbackType.TimeOfDay,
32
- () => {
33
- this.updateCalendar(false);
34
- },
35
- 0,
36
- 2,
37
- 0,
38
- );
39
- TimeCallbackService.addCallback(this.updateTimeCallback);
40
-
41
- this.checkTimeCallback = new TimeCallback(
42
- 'MuelltonnenServiceChecker',
43
- TimeCallbackType.TimeOfDay,
44
- () => {
45
- this.checkAll();
46
- },
47
- 0,
48
- 18,
49
- 0,
50
- );
51
- TimeCallbackService.addCallback(this.checkTimeCallback);
52
-
53
- this.updateCalendar();
54
- }
55
-
56
- public static updateCalendar(checkAfterwards: boolean = true): void {
57
- ServerLogService.writeLog(LogLevel.Debug, `Muell Service wird nun initialisiert`);
58
- async.fromURL(this._calendarURL).then((data) => {
59
- this.gelbeTonne = new MuellTonne('Gelbe Tonne', this.defaultSonosDevice);
60
- this.graueTonne = new MuellTonne('Graue Tonne', this.defaultSonosDevice);
61
- this.blaueTonne = new MuellTonne('Blaue Tonne', this.defaultSonosDevice);
62
- this.brauneTonne = new MuellTonne('Braune Tonne', this.defaultSonosDevice);
63
- this.alleTonnen = [];
64
- const todayMidnight: number = new Date().setHours(0, 0, 0, 0);
65
- for (const k in data) {
66
- if (!data.hasOwnProperty(k)) {
67
- continue;
68
- }
69
-
70
- if (data[k].type !== 'VEVENT') {
71
- continue;
72
- }
73
-
74
- const ev = data[k] as VEvent;
75
- ServerLogService.writeLog(
76
- LogLevel.DeepTrace,
77
- `${ev.summary} is in ${ev.location} on the ${ev.start.getDate()} of ${
78
- this.months[ev.start.getMonth()]
79
- } at ${ev.start.toLocaleTimeString('en-GB')}`,
80
- );
81
-
82
- if (ev.start.getTime() < todayMidnight) {
83
- continue;
84
- }
85
-
86
- this.alleTonnen.push({name: ev.summary, date: ev.start});
87
- switch (ev.summary) {
88
- case this.gelbeTonne.name:
89
- this.gelbeTonne.dates.push(ev.start);
90
- break;
91
- case this.graueTonne.name:
92
- this.graueTonne.dates.push(ev.start);
93
- break;
94
- case this.blaueTonne.name:
95
- this.blaueTonne.dates.push(ev.start);
96
- break;
97
- case this.brauneTonne.name:
98
- this.brauneTonne.dates.push(ev.start);
99
- break;
100
- default:
101
- ServerLogService.writeLog(LogLevel.Warn, `Unbekannte Mülltonne (${ev.summary})`);
102
- }
103
- }
104
-
105
- this.gelbeTonne.sortDates();
106
- this.graueTonne.sortDates();
107
- this.blaueTonne.sortDates();
108
- this.brauneTonne.sortDates();
109
- this.alleTonnen = this.alleTonnen.sort((a, b) => a.date.getTime() - b.date.getTime());
110
- if (checkAfterwards) {
111
- this.checkAll();
112
- }
113
- });
114
- }
115
-
116
- public static checkAll(pRetries: number = 10): void {
117
- if (!this._active) {
118
- return;
119
- }
120
-
121
- const now: Date = new Date();
122
- if (now.getTime() - this.lastCheck.getTime() < 60000 && now.getDate() === this.lastCheck.getDate()) {
123
- ServerLogService.writeLog(LogLevel.Trace, `MüllService.checkAll: Skipped weil wir gerade erst geprüft hatten.`);
124
- return;
125
- }
126
-
127
- if (this.gelbeTonne === undefined) {
128
- if (pRetries > 0) {
129
- ServerLogService.writeLog(LogLevel.Warn, `Der Müllservice ist noch nicht bereit --> warten`);
130
- Utils.guardedTimeout(() => {
131
- MuellService.checkAll(pRetries - 1);
132
- }, 1000);
133
- } else {
134
- ServerLogService.writeLog(LogLevel.Error, `Der Müllservice ist trotz Warten nicht bereit --> Abbruch`);
135
- }
136
-
137
- return;
138
- }
139
-
140
- this.lastCheck = now;
141
- this.gelbeTonne.check();
142
- this.graueTonne.check();
143
- this.blaueTonne.check();
144
- this.brauneTonne.check();
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 "../../../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
- }
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
+ }