hoffmation-base 1.0.63 → 1.0.66

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 (38) hide show
  1. package/lib/index.js +1 -4
  2. package/lib/models/persistence/index.d.ts +0 -1
  3. package/lib/models/persistence/index.js +0 -1
  4. package/lib/models/persistence/todaysCount.d.ts +2 -3
  5. package/lib/models/persistence/todaysCount.js +2 -3
  6. package/lib/server/config/iConfig.d.ts +0 -5
  7. package/lib/server/devices/baseDeviceInterfaces/iLamp.d.ts +1 -0
  8. package/lib/server/devices/device-cluster-type.d.ts +0 -1
  9. package/lib/server/devices/device-cluster-type.js +0 -1
  10. package/lib/server/devices/device-cluster.js +1 -3
  11. package/lib/server/devices/devices.d.ts +1 -1
  12. package/lib/server/devices/devices.js +4 -7
  13. package/lib/server/devices/groups/praesenzGroup.d.ts +1 -3
  14. package/lib/server/devices/groups/praesenzGroup.js +2 -37
  15. package/lib/server/devices/hmIPDevices/hmIpBewegung.js +2 -5
  16. package/lib/server/devices/hmIPDevices/hmIpLampe.d.ts +1 -0
  17. package/lib/server/devices/hmIPDevices/hmIpLampe.js +5 -0
  18. package/lib/server/devices/hmIPDevices/hmIpPraezenz.d.ts +10 -5
  19. package/lib/server/devices/hmIPDevices/hmIpPraezenz.js +21 -12
  20. package/lib/server/devices/zigbee/BaseDevices/ZigbeeActuator.js +3 -1
  21. package/lib/server/devices/zigbee/BaseDevices/zigbeeMotionSensor.js +3 -6
  22. package/lib/server/devices/zigbee/zigbeeIlluDimmer.d.ts +1 -0
  23. package/lib/server/devices/zigbee/zigbeeIlluDimmer.js +6 -0
  24. package/lib/server/devices/zigbee/zigbeeIlluLampe.d.ts +1 -0
  25. package/lib/server/devices/zigbee/zigbeeIlluLampe.js +6 -1
  26. package/lib/server/services/dbo/iPersist.d.ts +3 -3
  27. package/lib/server/services/dbo/index.d.ts +0 -1
  28. package/lib/server/services/dbo/index.js +0 -1
  29. package/lib/server/services/dbo/postgreSqlPersist.d.ts +3 -3
  30. package/lib/server/services/dbo/postgreSqlPersist.js +27 -60
  31. package/lib/server/services/time-callback-service.js +1 -1
  32. package/lib/server/services/utils/utils.js +2 -3
  33. package/lib/tsconfig.tsbuildinfo +1 -1
  34. package/package.json +2 -2
  35. package/lib/models/persistence/DailyMovementCount.d.ts +0 -7
  36. package/lib/models/persistence/DailyMovementCount.js +0 -12
  37. package/lib/server/services/dbo/mongoPersistance.d.ts +0 -33
  38. package/lib/server/services/dbo/mongoPersistance.js +0 -174
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hoffmation-base",
3
3
  "description": "Base Libraries and functions for own Hoffmation projects",
4
- "version": "1.0.63",
4
+ "version": "1.0.66",
5
5
  "files": [
6
6
  "lib/**/*"
7
7
  ],
@@ -47,11 +47,11 @@
47
47
  "@types/socket.io-client": "^1.4.36",
48
48
  "@types/xml2js": "^0.4.11",
49
49
  "aws-sdk": "2.1211.0",
50
+ "bson": "^4.7.0",
50
51
  "daikin-controller": "^2.1.0",
51
52
  "get-mp3-duration": "^1.0.0",
52
53
  "https": "^1.0.0",
53
54
  "lodash": "^4.17.21",
54
- "mongodb": "^4.9.1",
55
55
  "node-fetch": "3.2.10",
56
56
  "node-ical": "^0.15.1",
57
57
  "node-merlin-wrt-api": "^0.0.2-alpha.5",
@@ -1,7 +0,0 @@
1
- export declare class DailyMovementCount {
2
- deviceID: string;
3
- counter: number;
4
- roomName: string;
5
- date: Date;
6
- constructor(deviceID: string, counter: number, roomName: string, date: Date);
7
- }
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DailyMovementCount = void 0;
4
- class DailyMovementCount {
5
- constructor(deviceID, counter, roomName, date) {
6
- this.deviceID = deviceID;
7
- this.counter = counter;
8
- this.roomName = roomName;
9
- this.date = date;
10
- }
11
- }
12
- exports.DailyMovementCount = DailyMovementCount;
@@ -1,33 +0,0 @@
1
- import { iPersistenceSettings } from '../../config';
2
- import { CountToday, CurrentIlluminationDataPoint, EnergyCalculation, RoomBase, ShutterCalibration, TemperaturDataPoint } from '../../../models';
3
- import { iPersist } from './iPersist';
4
- import { iAcDevice, iHeater, iMotionSensor, IoBrokerBaseDevice } from '../../devices';
5
- export declare class MongoPersistance implements iPersist {
6
- initialized: boolean;
7
- private BasicRoomCollection?;
8
- private CountTodayCollection?;
9
- private CurrentIlluminationCollection?;
10
- private DailyMovementCountTodayCollection?;
11
- private HeatGroupCollection?;
12
- private RoomDetailsCollection?;
13
- private ShutterCalibrationCollection?;
14
- private TemperatureHistoryCollection?;
15
- private Mongo?;
16
- private MongoClient;
17
- private mongoConf;
18
- constructor(config: iPersistenceSettings);
19
- persistAC(_device: iAcDevice): void;
20
- persistMotionSensor(_device: iMotionSensor): void;
21
- private static handleReject;
22
- addTemperaturDataPoint(heater: iHeater): void;
23
- addRoom(room: RoomBase): void;
24
- getCount(device: IoBrokerBaseDevice): Promise<CountToday>;
25
- getShutterCalibration(device: IoBrokerBaseDevice): Promise<ShutterCalibration>;
26
- initialize(): Promise<void>;
27
- persistTodayCount(device: IoBrokerBaseDevice, count: number, oldCount: number): void;
28
- persistShutterCalibration(data: ShutterCalibration): void;
29
- persistCurrentIllumination(data: CurrentIlluminationDataPoint): void;
30
- readTemperaturDataPoint(heater: iHeater, limit?: number): Promise<TemperaturDataPoint[]>;
31
- persistEnergyManager(_energyData: EnergyCalculation): void;
32
- private isMongoAllowedAndReady;
33
- }
@@ -1,174 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongoPersistance = void 0;
4
- const mongodb_1 = require("mongodb");
5
- const log_service_1 = require("../log-service");
6
- const models_1 = require("../../../models");
7
- class MongoPersistance {
8
- constructor(config) {
9
- this.initialized = false;
10
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
11
- this.mongoConf = config.mongo;
12
- this.MongoClient = new mongodb_1.MongoClient(this.mongoConf.mongoConnection);
13
- }
14
- persistAC(_device) {
15
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Mongo doesn't support AC Persistence yet.`);
16
- }
17
- persistMotionSensor(_device) {
18
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Mongo doesn't support MotionSensor Persistence yet.`);
19
- }
20
- static handleReject(reason, func) {
21
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Error persisting data for "${func}"`);
22
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Persisting Error reason: "${reason}"`);
23
- }
24
- addTemperaturDataPoint(heater) {
25
- var _a, _b;
26
- if (!this.isMongoAllowedAndReady()) {
27
- return;
28
- }
29
- const dataPoint = new models_1.TemperaturDataPoint(heater.info.customName, heater.iTemperature, heater.desiredTemperature, heater.iLevel, heater.humidity, new Date());
30
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Trace, `Persisting Temperatur Data for ${heater.info.customName}`);
31
- (_a = this.TemperatureHistoryCollection) === null || _a === void 0 ? void 0 : _a.insertOne(dataPoint).catch((r) => {
32
- MongoPersistance.handleReject(r, 'TemperatureHistoryCollection.insertOne');
33
- });
34
- // Needs to be duplicated as the object "dataPoint" is an document now
35
- const heatGroupDataPoint = new models_1.TemperaturDataPoint(heater.info.customName, heater.iTemperature, heater.desiredTemperature, heater.iLevel, heater.humidity, new Date());
36
- (_b = this.HeatGroupCollection) === null || _b === void 0 ? void 0 : _b.updateOne({ name: dataPoint.name }, { $set: heatGroupDataPoint }, { upsert: true }).catch((r) => {
37
- MongoPersistance.handleReject(r, 'HeatGroupCollection.updateOne');
38
- });
39
- }
40
- addRoom(room) {
41
- var _a, _b;
42
- if (!this.isMongoAllowedAndReady()) {
43
- return;
44
- }
45
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Trace, `Persisting Room for ${room.roomName}`);
46
- (_a = this.BasicRoomCollection) === null || _a === void 0 ? void 0 : _a.updateOne({ roomName: room.roomName }, { $set: new models_1.BasicRoomInfo(room.roomName, room.settings.etage) }, { upsert: true }).catch((r) => {
47
- MongoPersistance.handleReject(r, 'BasicRoomCollection.updateOne');
48
- });
49
- const detailed = new models_1.RoomDetailInfo(room.roomName, room.settings.etage);
50
- if (room.HeatGroup) {
51
- for (const h of (_b = room.HeatGroup) === null || _b === void 0 ? void 0 : _b.getHeater()) {
52
- detailed.heaters.push(h.info.customName);
53
- }
54
- }
55
- if (this.RoomDetailsCollection) {
56
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
57
- // @ts-ignore
58
- this.RoomDetailsCollection.updateOne({ roomName: room.roomName }, { $set: detailed }, { upsert: true }).catch((r) => {
59
- MongoPersistance.handleReject(r, 'RoomDetailsCollection.updateOne');
60
- });
61
- }
62
- }
63
- async getCount(device) {
64
- var _a;
65
- if (!this.isMongoAllowedAndReady()) {
66
- return new models_1.CountToday(device.info.fullID, 0);
67
- }
68
- const options = {
69
- limit: 1,
70
- };
71
- const databaseValue = (await ((_a = this.CountTodayCollection) === null || _a === void 0 ? void 0 : _a.find({ deviceID: device.info.fullID }, options).toArray()));
72
- if (databaseValue.length !== 0) {
73
- return databaseValue[0];
74
- }
75
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Es gibt noch keinen persistierten Counter für ${device.info.fullName}`);
76
- return new models_1.CountToday(device.info.fullID, 0);
77
- }
78
- async getShutterCalibration(device) {
79
- var _a;
80
- if (!this.isMongoAllowedAndReady()) {
81
- return new models_1.ShutterCalibration(device.info.fullID, 0, 0, 0, 0);
82
- }
83
- const options = {
84
- limit: 1,
85
- };
86
- const databaseValue = (await ((_a = this.ShutterCalibrationCollection) === null || _a === void 0 ? void 0 : _a.find({ deviceID: device.info.fullID }, options).toArray()));
87
- if (databaseValue.length !== 0) {
88
- return databaseValue[0];
89
- }
90
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `There is no persisted calibration data for ${device.info.fullName}`);
91
- return new models_1.ShutterCalibration(device.info.fullID, 0, 0, 0, 0);
92
- }
93
- async initialize() {
94
- await this.MongoClient.connect();
95
- this.Mongo = this.MongoClient.db(this.mongoConf.mongoDbName);
96
- this.TemperatureHistoryCollection = this.Mongo.collection('TemperaturData');
97
- this.HeatGroupCollection = this.Mongo.collection('HeatGroupCollection');
98
- this.BasicRoomCollection = this.Mongo.collection('BasicRooms');
99
- this.RoomDetailsCollection = this.Mongo.collection('RoomDetailsCollection');
100
- this.CountTodayCollection = this.Mongo.collection('PresenceToday');
101
- this.CurrentIlluminationCollection = this.Mongo.collection('CurrentIllumination');
102
- this.DailyMovementCountTodayCollection = this.Mongo.collection('DailyMovementCount');
103
- this.ShutterCalibrationCollection = this.Mongo.collection('ShutterCalibration');
104
- this.initialized = true;
105
- }
106
- persistTodayCount(device, count, oldCount) {
107
- var _a, _b;
108
- if (!this.isMongoAllowedAndReady()) {
109
- return;
110
- }
111
- const result = (_a = this.CountTodayCollection) === null || _a === void 0 ? void 0 : _a.updateOne({ deviceID: device.info.fullID }, { $set: new models_1.CountToday(device.info.fullID, count) }, { upsert: true });
112
- if (count === 0) {
113
- const date = new Date();
114
- date.setHours(-24, 0, 0, 0);
115
- const result2 = (_b = this.DailyMovementCountTodayCollection) === null || _b === void 0 ? void 0 : _b.updateOne({ deviceID: device.info.fullID, date: date }, { $set: new models_1.DailyMovementCount(device.info.fullID, oldCount, device.info.room, date) }, { upsert: true }).catch((r) => {
116
- MongoPersistance.handleReject(r, 'DailyMovementCountTodayCollection.updateOne');
117
- });
118
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Trace, `Persisting Daily Movement Count for ${device.info.customName} to ${oldCount} resolved with "${result2}"`);
119
- }
120
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Trace, `Persisting PresenceToday Data for ${device.info.customName} to ${count} resolved with "${result}"`);
121
- }
122
- persistShutterCalibration(data) {
123
- var _a;
124
- if (!this.isMongoAllowedAndReady()) {
125
- return;
126
- }
127
- const result = (_a = this.CountTodayCollection) === null || _a === void 0 ? void 0 : _a.updateOne({ deviceID: data.deviceID }, { $set: data }, { upsert: true });
128
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Trace, `Persisting ShutterCalibration for ${data.deviceID} resolved with "${result}"`);
129
- }
130
- persistCurrentIllumination(data) {
131
- var _a;
132
- if (!this.isMongoAllowedAndReady()) {
133
- return;
134
- }
135
- const result = (_a = this.CurrentIlluminationCollection) === null || _a === void 0 ? void 0 : _a.updateOne({ deviceID: data.deviceID, date: data.date }, { $set: data }, { upsert: true }).catch((r) => {
136
- MongoPersistance.handleReject(r, 'persistCurrentIllumination');
137
- });
138
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Trace, `Persisting Illumination Data for ${data.deviceID} to ${data.currentIllumination} resolved with "${result}"`);
139
- }
140
- async readTemperaturDataPoint(heater, limit = -1) {
141
- return new Promise(async (resolve) => {
142
- var _a;
143
- if (!this.isMongoAllowedAndReady()) {
144
- resolve([]);
145
- return;
146
- }
147
- const options = {
148
- limit: limit > 0 ? limit : undefined,
149
- sort: { date: -1 },
150
- };
151
- const data = (await ((_a = this.TemperatureHistoryCollection) === null || _a === void 0 ? void 0 : _a.find({ name: heater.info.customName }, options).toArray()));
152
- resolve(data);
153
- });
154
- }
155
- persistEnergyManager(_energyData) {
156
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `MongoDb doesn't support EnergyCalculation yet.`);
157
- }
158
- isMongoAllowedAndReady() {
159
- if (!this.initialized) {
160
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Db is not yet initialized`);
161
- return false;
162
- }
163
- if (!this.MongoClient) {
164
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Error, `Mongo client missing`);
165
- return false;
166
- }
167
- if (!this.Mongo) {
168
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Error, `MongoDb connection is missing`);
169
- return false;
170
- }
171
- return true;
172
- }
173
- }
174
- exports.MongoPersistance = MongoPersistance;