hoffmation-base 0.1.29-5 → 0.1.29-9

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 (44) hide show
  1. package/README.md +32 -0
  2. package/lib/index.js +6 -1
  3. package/lib/models/persistence/ShutterCalibration.d.ts +8 -0
  4. package/lib/models/persistence/ShutterCalibration.js +13 -0
  5. package/lib/models/persistence/index.d.ts +4 -3
  6. package/lib/models/persistence/index.js +4 -3
  7. package/lib/server/config/iConfig.d.ts +1 -1
  8. package/lib/server/devices/Fenster.d.ts +1 -1
  9. package/lib/server/devices/Fenster.js +1 -1
  10. package/lib/server/devices/Griffe.js +1 -1
  11. package/lib/server/devices/deviceType.d.ts +1 -0
  12. package/lib/server/devices/deviceType.js +1 -0
  13. package/lib/server/devices/devices.js +4 -0
  14. package/lib/server/devices/groups/fensterGroup.js +2 -1
  15. package/lib/server/devices/hmIPDevices/hmIpGriff.d.ts +1 -1
  16. package/lib/server/devices/hmIPDevices/hmIpGriff.js +1 -1
  17. package/lib/server/devices/hmIPDevices/hmIpRoll.js +1 -1
  18. package/lib/server/devices/hmIPDevices/hmIpTuer.d.ts +5 -5
  19. package/lib/server/devices/hmIPDevices/hmIpTuer.js +13 -13
  20. package/lib/server/devices/hmIPDevices/index.d.ts +2 -2
  21. package/lib/server/devices/hmIPDevices/index.js +2 -2
  22. package/lib/server/devices/index.d.ts +1 -0
  23. package/lib/server/devices/index.js +1 -0
  24. package/lib/server/devices/{FensterPosition.d.ts → models/FensterPosition.d.ts} +0 -0
  25. package/lib/server/devices/{FensterPosition.js → models/FensterPosition.js} +0 -0
  26. package/lib/server/devices/models/MagnetPosition.d.ts +4 -0
  27. package/lib/server/devices/models/MagnetPosition.js +8 -0
  28. package/lib/server/devices/models/index.d.ts +2 -0
  29. package/lib/server/devices/models/index.js +14 -0
  30. package/lib/server/devices/zigbee/index.d.ts +2 -0
  31. package/lib/server/devices/zigbee/index.js +2 -0
  32. package/lib/server/devices/zigbee/zigbeeIlluShutter.d.ts +2 -0
  33. package/lib/server/devices/zigbee/zigbeeIlluShutter.js +24 -1
  34. package/lib/server/devices/zigbee/zigbeeMagnetContact.d.ts +17 -0
  35. package/lib/server/devices/zigbee/zigbeeMagnetContact.js +81 -0
  36. package/lib/server/devices/zigbee/zigbeeSMaBiTMagnetContact.d.ts +7 -0
  37. package/lib/server/devices/zigbee/zigbeeSMaBiTMagnetContact.js +23 -0
  38. package/lib/server/devices/zigbee/zigbeeShutter.js +1 -1
  39. package/lib/server/services/dbo/persist.d.ts +11 -3
  40. package/lib/server/services/dbo/persist.js +75 -14
  41. package/lib/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +2 -2
  43. package/lib/server/devices/hmIPDevices/TuerPosition.d.ts +0 -4
  44. package/lib/server/devices/hmIPDevices/TuerPosition.js +0 -8
@@ -5,7 +5,7 @@ const utils_1 = require("../../services/utils/utils");
5
5
  const log_service_1 = require("../../services/log-service");
6
6
  const logLevel_1 = require("../../../models/logLevel");
7
7
  const zigbeeDevice_1 = require("./zigbeeDevice");
8
- const FensterPosition_1 = require("../FensterPosition");
8
+ const FensterPosition_1 = require("../models/FensterPosition");
9
9
  class ZigbeeShutter extends zigbeeDevice_1.ZigbeeDevice {
10
10
  constructor(pInfo, pType) {
11
11
  super(pInfo, pType);
@@ -5,22 +5,30 @@ import { TemperaturDataPoint } from '../../../models/persistence/temperaturDataP
5
5
  import { HmIpHeizgruppe } from '../../devices/hmIPDevices/hmIpHeizgruppe';
6
6
  import { CurrentIlluminationDataPoint } from '../../../models/persistence/CurrentIlluminationDataPoint';
7
7
  import { iPersistenceSettings } from '../../config/iConfig';
8
+ import { ShutterCalibration } from '../../../models/persistence/ShutterCalibration';
8
9
  export declare class Persist {
9
- private static TemperatureHistoryCollection;
10
- private static HeatGroupCollection;
11
10
  private static BasicRoomCollection;
12
- private static RoomDetailsCollection;
13
11
  private static CountTodayCollection;
14
12
  private static CurrentIlluminationCollection;
15
13
  private static DailyMovementCountTodayCollection;
14
+ private static HeatGroupCollection;
15
+ private static RoomDetailsCollection;
16
+ private static ShutterCalibrationCollection;
17
+ private static TemperatureHistoryCollection;
18
+ private static initialized;
16
19
  private static Mongo;
17
20
  private static MongoClient;
21
+ private static turnedOff;
18
22
  static addTemperaturDataPoint(hzGrp: HmIpHeizgruppe): void;
19
23
  static addRoom(room: RoomBase): void;
20
24
  static getCount(device: IoBrokerBaseDevice): Promise<CountToday>;
25
+ static getShutterCalibration(device: IoBrokerBaseDevice): Promise<ShutterCalibration>;
21
26
  static initialize(config: iPersistenceSettings): Promise<void>;
22
27
  static persistTodayCount(device: IoBrokerBaseDevice, count: number, oldCount: number): void;
28
+ static persistShutterCalibration(data: ShutterCalibration): void;
23
29
  static persistCurrentIllumination(data: CurrentIlluminationDataPoint): void;
24
30
  static readTemperaturDataPoint(hzGrp: HmIpHeizgruppe, limit?: number): Promise<TemperaturDataPoint[]>;
31
+ static turnOff(): void;
25
32
  private static handleReject;
33
+ private static isMongoAllowedAndReady;
26
34
  }
@@ -9,8 +9,12 @@ const temperaturDataPoint_1 = require("../../../models/persistence/temperaturDat
9
9
  const log_service_1 = require("../log-service");
10
10
  const BasicRoomInfo_1 = require("../../../models/persistence/BasicRoomInfo");
11
11
  const logLevel_1 = require("../../../models/logLevel");
12
+ const ShutterCalibration_1 = require("../../../models/persistence/ShutterCalibration");
12
13
  class Persist {
13
14
  static addTemperaturDataPoint(hzGrp) {
15
+ if (!this.isMongoAllowedAndReady()) {
16
+ return;
17
+ }
14
18
  const dataPoint = new temperaturDataPoint_1.TemperaturDataPoint(hzGrp.info.customName, hzGrp.iTemperatur, hzGrp.desiredTemperatur, hzGrp.iLevel, hzGrp.humidity, new Date());
15
19
  log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Trace, `Persisting Temperatur Data for ${hzGrp.info.customName}`);
16
20
  this.TemperatureHistoryCollection.insertOne(dataPoint).catch((r) => {
@@ -23,6 +27,9 @@ class Persist {
23
27
  });
24
28
  }
25
29
  static addRoom(room) {
30
+ if (!this.isMongoAllowedAndReady()) {
31
+ return;
32
+ }
26
33
  log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Trace, `Persisting Room for ${room.roomName}`);
27
34
  this.BasicRoomCollection.updateOne({ roomName: room.roomName }, { $set: new BasicRoomInfo_1.BasicRoomInfo(room.roomName, room.Settings.etage) }, { upsert: true }).catch((r) => {
28
35
  this.handleReject(r, 'BasicRoomCollection.updateOne');
@@ -36,20 +43,32 @@ class Persist {
36
43
  });
37
44
  }
38
45
  static async getCount(device) {
39
- const result = new Promise(async (resolve) => {
40
- const options = {
41
- limit: 1,
42
- };
43
- const databaseValue = (await this.CountTodayCollection.find({ deviceID: device.info.fullID }, options).toArray());
44
- if (databaseValue.length === 0) {
45
- log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Debug, `Es gibt noch keinen persistierten Counter für ${device.info.fullName}`);
46
- resolve(new todaysCount_1.CountToday(device.info.fullID, 0));
47
- }
48
- else {
49
- resolve(databaseValue[0]);
50
- }
51
- });
52
- return result;
46
+ if (!this.isMongoAllowedAndReady()) {
47
+ return new todaysCount_1.CountToday(device.info.fullID, 0);
48
+ }
49
+ const options = {
50
+ limit: 1,
51
+ };
52
+ const databaseValue = (await this.CountTodayCollection.find({ deviceID: device.info.fullID }, options).toArray());
53
+ if (databaseValue.length !== 0) {
54
+ return databaseValue[0];
55
+ }
56
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Debug, `Es gibt noch keinen persistierten Counter für ${device.info.fullName}`);
57
+ return new todaysCount_1.CountToday(device.info.fullID, 0);
58
+ }
59
+ static async getShutterCalibration(device) {
60
+ if (!this.isMongoAllowedAndReady()) {
61
+ return new ShutterCalibration_1.ShutterCalibration(device.info.fullID, 0, 0, 0, 0);
62
+ }
63
+ const options = {
64
+ limit: 1,
65
+ };
66
+ const databaseValue = (await this.ShutterCalibrationCollection.find({ deviceID: device.info.fullID }, options).toArray());
67
+ if (databaseValue.length !== 0) {
68
+ return databaseValue[0];
69
+ }
70
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Debug, `There is no persisted calibration data for ${device.info.fullName}`);
71
+ return new ShutterCalibration_1.ShutterCalibration(device.info.fullID, 0, 0, 0, 0);
53
72
  }
54
73
  static async initialize(config) {
55
74
  this.MongoClient = new mongodb_1.MongoClient(config.mongoConnection);
@@ -62,8 +81,13 @@ class Persist {
62
81
  this.CountTodayCollection = this.Mongo.collection('PresenceToday');
63
82
  this.CurrentIlluminationCollection = this.Mongo.collection('CurrentIllumination');
64
83
  this.DailyMovementCountTodayCollection = this.Mongo.collection('DailyMovementCount');
84
+ this.ShutterCalibrationCollection = this.Mongo.collection('ShutterCalibration');
85
+ this.initialized = true;
65
86
  }
66
87
  static persistTodayCount(device, count, oldCount) {
88
+ if (!this.isMongoAllowedAndReady()) {
89
+ return;
90
+ }
67
91
  const result = this.CountTodayCollection.updateOne({ deviceID: device.info.fullID }, { $set: new todaysCount_1.CountToday(device.info.fullID, count) }, { upsert: true });
68
92
  if (count === 0) {
69
93
  const date = new Date();
@@ -75,7 +99,17 @@ class Persist {
75
99
  }
76
100
  log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Trace, `Persisting PresenceToday Data for ${device.info.customName} to ${count} resolved with "${result}"`);
77
101
  }
102
+ static persistShutterCalibration(data) {
103
+ if (!this.isMongoAllowedAndReady()) {
104
+ return;
105
+ }
106
+ const result = this.CountTodayCollection.updateOne({ deviceID: data.deviceID }, { $set: data }, { upsert: true });
107
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Trace, `Persisting ShutterCalibration for ${data.deviceID} resolved with "${result}"`);
108
+ }
78
109
  static persistCurrentIllumination(data) {
110
+ if (!this.isMongoAllowedAndReady()) {
111
+ return;
112
+ }
79
113
  const result = this.CurrentIlluminationCollection.updateOne({ deviceID: data.deviceID, date: data.date }, { $set: data }, { upsert: true }).catch((r) => {
80
114
  this.handleReject(r, 'persistCurrentIllumination');
81
115
  });
@@ -83,6 +117,10 @@ class Persist {
83
117
  }
84
118
  static async readTemperaturDataPoint(hzGrp, limit = -1) {
85
119
  const result = new Promise(async (resolve) => {
120
+ if (!this.isMongoAllowedAndReady()) {
121
+ resolve([]);
122
+ return;
123
+ }
86
124
  const options = {
87
125
  limit: limit > 0 ? limit : undefined,
88
126
  sort: { date: -1 },
@@ -92,9 +130,32 @@ class Persist {
92
130
  });
93
131
  return result;
94
132
  }
133
+ static turnOff() {
134
+ this.turnedOff = true;
135
+ }
95
136
  static handleReject(reason, func) {
96
137
  log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Warn, `Error persisting data for "${func}"`);
97
138
  log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Debug, `Persisting Error reason: "${reason}"`);
98
139
  }
140
+ static isMongoAllowedAndReady() {
141
+ if (this.turnedOff) {
142
+ return false;
143
+ }
144
+ if (!this.initialized) {
145
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Warn, `Db is not yet initialized`);
146
+ return false;
147
+ }
148
+ if (!this.MongoClient) {
149
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Error, `Mongo client missing`);
150
+ return false;
151
+ }
152
+ if (!this.Mongo) {
153
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Error, `MongoDb connection is missing`);
154
+ return false;
155
+ }
156
+ return true;
157
+ }
99
158
  }
100
159
  exports.Persist = Persist;
160
+ Persist.initialized = false;
161
+ Persist.turnedOff = false;