hoffmation-base 0.1.38-1 → 0.1.38-2

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 (60) hide show
  1. package/lib/index.d.ts +2 -1
  2. package/lib/index.js +8 -5
  3. package/lib/models/{actuatorSettings.d.ts → deviceSettings/actuatorSettings.d.ts} +0 -0
  4. package/lib/models/{actuatorSettings.js → deviceSettings/actuatorSettings.js} +0 -0
  5. package/lib/models/{deviceSettings.d.ts → deviceSettings/deviceSettings.d.ts} +0 -0
  6. package/lib/models/{deviceSettings.js → deviceSettings/deviceSettings.js} +0 -0
  7. package/lib/models/{dimmerSettings.d.ts → deviceSettings/dimmerSettings.d.ts} +0 -0
  8. package/lib/models/{dimmerSettings.js → deviceSettings/dimmerSettings.js} +0 -0
  9. package/lib/models/deviceSettings/index.d.ts +5 -0
  10. package/lib/models/deviceSettings/index.js +21 -0
  11. package/lib/models/{ledSettings.d.ts → deviceSettings/ledSettings.d.ts} +0 -0
  12. package/lib/models/{ledSettings.js → deviceSettings/ledSettings.js} +0 -0
  13. package/lib/models/deviceSettings/shutterSettings.d.ts +5 -0
  14. package/lib/models/deviceSettings/shutterSettings.js +12 -0
  15. package/lib/models/index.d.ts +1 -3
  16. package/lib/models/index.js +1 -3
  17. package/lib/models/persistence/EnergyCalculation.d.ts +11 -0
  18. package/lib/models/persistence/EnergyCalculation.js +16 -0
  19. package/lib/models/persistence/index.d.ts +1 -0
  20. package/lib/models/persistence/index.js +1 -0
  21. package/lib/models/rooms/RoomBase.js +2 -2
  22. package/lib/server/config/iConfig.d.ts +7 -0
  23. package/lib/server/devices/Heizgruppen.js +3 -2
  24. package/lib/server/devices/hmIPDevices/hmIpBewegung.js +5 -7
  25. package/lib/server/devices/hmIPDevices/hmIpHeizgruppe.js +3 -3
  26. package/lib/server/devices/hmIPDevices/hmIpLampe.d.ts +1 -1
  27. package/lib/server/devices/hmIPDevices/hmIpLampe.js +1 -1
  28. package/lib/server/devices/hmIPDevices/hmIpPraezenz.js +5 -7
  29. package/lib/server/devices/iEnergyManager.d.ts +1 -0
  30. package/lib/server/devices/iLamp.d.ts +1 -1
  31. package/lib/server/devices/jsObject/jsObjectEnergyManager.d.ts +14 -4
  32. package/lib/server/devices/jsObject/jsObjectEnergyManager.js +63 -6
  33. package/lib/server/devices/zigbee/ZigbeeActuator.d.ts +1 -1
  34. package/lib/server/devices/zigbee/ZigbeeActuator.js +1 -1
  35. package/lib/server/devices/zigbee/zigbeeAquaraMotion.js +2 -2
  36. package/lib/server/devices/zigbee/zigbeeBlitzShp.d.ts +1 -1
  37. package/lib/server/devices/zigbee/zigbeeBlitzShp.js +1 -1
  38. package/lib/server/devices/zigbee/zigbeeIlluDimmer.d.ts +1 -1
  39. package/lib/server/devices/zigbee/zigbeeIlluDimmer.js +1 -1
  40. package/lib/server/devices/zigbee/zigbeeIlluLedRGBCCT.d.ts +1 -1
  41. package/lib/server/devices/zigbee/zigbeeIlluLedRGBCCT.js +1 -1
  42. package/lib/server/devices/zigbee/zigbeeIlluShutter.d.ts +0 -3
  43. package/lib/server/devices/zigbee/zigbeeIlluShutter.js +0 -18
  44. package/lib/server/devices/zigbee/zigbeeMotionSensor.js +4 -6
  45. package/lib/server/devices/zigbee/zigbeeShutter.d.ts +8 -0
  46. package/lib/server/devices/zigbee/zigbeeShutter.js +36 -0
  47. package/lib/server/services/dbo/iPersist.d.ts +21 -0
  48. package/lib/server/services/dbo/iPersist.js +2 -0
  49. package/lib/server/services/dbo/index.d.ts +3 -1
  50. package/lib/server/services/dbo/index.js +3 -1
  51. package/lib/server/services/dbo/mongoPersistance.d.ts +37 -0
  52. package/lib/server/services/dbo/{persist.js → mongoPersistance.js} +45 -39
  53. package/lib/server/services/dbo/postgreSqlPersist.d.ts +27 -0
  54. package/lib/server/services/dbo/postgreSqlPersist.js +164 -0
  55. package/lib/server/services/https-service.js +5 -3
  56. package/lib/server/services/utils/utils.d.ts +2 -0
  57. package/lib/server/services/utils/utils.js +7 -0
  58. package/lib/tsconfig.tsbuildinfo +1 -1
  59. package/package.json +12 -10
  60. package/lib/server/services/dbo/persist.d.ts +0 -34
package/lib/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { Devices, iConfig, ioBrokerMain, OwnSonosDevice } from './server';
1
+ import { Devices, iConfig, ioBrokerMain, OwnSonosDevice, iPersist } from './server';
2
2
  export * from './models/index';
3
3
  export * from './server/index';
4
4
  export declare class HoffmationInitializationObject {
5
5
  config: iConfig;
6
6
  constructor(config: iConfig);
7
7
  }
8
+ export declare let dbo: iPersist | undefined;
8
9
  export declare class HoffmationBase {
9
10
  static ioMain: ioBrokerMain;
10
11
  static initializeBeforeIoBroker(initObject: HoffmationInitializationObject): Promise<void>;
package/lib/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.HoffmationBase = exports.HoffmationInitializationObject = void 0;
17
+ exports.HoffmationBase = exports.dbo = exports.HoffmationInitializationObject = void 0;
18
18
  const models_1 = require("./models");
19
19
  const server_1 = require("./server");
20
20
  __exportStar(require("./models/index"), exports);
@@ -34,10 +34,13 @@ class HoffmationBase {
34
34
  }
35
35
  server_1.ServerLogService.writeLog(models_1.LogLevel.Info, `Hoffmation-Base Startup`);
36
36
  if (initObject.config.persistence) {
37
- await server_1.Persist.initialize(initObject.config.persistence);
38
- }
39
- else {
40
- server_1.Persist.turnOff();
37
+ if (initObject.config.persistence.mongo) {
38
+ exports.dbo = new server_1.MongoPersistance(initObject.config.persistence);
39
+ }
40
+ else if (initObject.config.persistence.postgreSql) {
41
+ exports.dbo = new server_1.PostgreSqlPersist(initObject.config.persistence);
42
+ }
43
+ await (exports.dbo === null || exports.dbo === void 0 ? void 0 : exports.dbo.initialize());
41
44
  }
42
45
  if (server_1.SettingsService.settings.mp3Server) {
43
46
  server_1.ServerLogService.writeLog(models_1.LogLevel.Info, `Mp3Server settings detected --> initializing`);
@@ -0,0 +1,5 @@
1
+ export * from './actuatorSettings';
2
+ export * from './deviceSettings';
3
+ export * from './dimmerSettings';
4
+ export * from './ledSettings';
5
+ export * from './shutterSettings';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./actuatorSettings"), exports);
18
+ __exportStar(require("./deviceSettings"), exports);
19
+ __exportStar(require("./dimmerSettings"), exports);
20
+ __exportStar(require("./ledSettings"), exports);
21
+ __exportStar(require("./shutterSettings"), exports);
@@ -0,0 +1,5 @@
1
+ import { DeviceSettings } from './deviceSettings';
2
+ export declare class ShutterSettings extends DeviceSettings {
3
+ msTilTop: number;
4
+ msTilBot: number;
5
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ShutterSettings = void 0;
4
+ const deviceSettings_1 = require("./deviceSettings");
5
+ class ShutterSettings extends deviceSettings_1.DeviceSettings {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.msTilTop = -1;
9
+ this.msTilBot = -1;
10
+ }
11
+ }
12
+ exports.ShutterSettings = ShutterSettings;
@@ -1,13 +1,11 @@
1
1
  export * from './rooms/index';
2
+ export * from './deviceSettings/index';
2
3
  export * from './persistence/index';
3
- export * from './actuatorSettings';
4
4
  export * from './connectionCallbacks';
5
5
  export * from './daytime';
6
6
  export * from './deviceConfig';
7
- export * from './dimmerSettings';
8
7
  export * from './excessEnergyConsumerSettings';
9
8
  export * from './iTemperaturDataPoint';
10
- export * from './ledSettings';
11
9
  export * from './logLevel';
12
10
  export * from './temperaturSettings';
13
11
  export * from './timeCallback';
@@ -15,15 +15,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./rooms/index"), exports);
18
+ __exportStar(require("./deviceSettings/index"), exports);
18
19
  __exportStar(require("./persistence/index"), exports);
19
- __exportStar(require("./actuatorSettings"), exports);
20
20
  __exportStar(require("./connectionCallbacks"), exports);
21
21
  __exportStar(require("./daytime"), exports);
22
22
  __exportStar(require("./deviceConfig"), exports);
23
- __exportStar(require("./dimmerSettings"), exports);
24
23
  __exportStar(require("./excessEnergyConsumerSettings"), exports);
25
24
  __exportStar(require("./iTemperaturDataPoint"), exports);
26
- __exportStar(require("./ledSettings"), exports);
27
25
  __exportStar(require("./logLevel"), exports);
28
26
  __exportStar(require("./temperaturSettings"), exports);
29
27
  __exportStar(require("./timeCallback"), exports);
@@ -0,0 +1,11 @@
1
+ export declare class EnergyCalculation {
2
+ startMs: number;
3
+ drawnWattage: number;
4
+ injectedWattage: number;
5
+ selfConsumedWattage: number;
6
+ costDrawn: number;
7
+ earnedInjected: number;
8
+ savedSelfConsume: number;
9
+ endMs: number;
10
+ constructor(startMs: number);
11
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EnergyCalculation = void 0;
4
+ class EnergyCalculation {
5
+ constructor(startMs) {
6
+ this.startMs = startMs;
7
+ this.drawnWattage = 0;
8
+ this.injectedWattage = 0;
9
+ this.selfConsumedWattage = 0;
10
+ this.costDrawn = 0;
11
+ this.earnedInjected = 0;
12
+ this.savedSelfConsume = 0;
13
+ this.endMs = 0;
14
+ }
15
+ }
16
+ exports.EnergyCalculation = EnergyCalculation;
@@ -1,6 +1,7 @@
1
1
  export * from './BasicRoomInfo';
2
2
  export * from './CurrentIlluminationDataPoint';
3
3
  export * from './DailyMovementCount';
4
+ export * from './EnergyCalculation';
4
5
  export * from './RoomDetailInfo';
5
6
  export * from './ShutterCalibration';
6
7
  export * from './temperaturDataPoint';
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./BasicRoomInfo"), exports);
18
18
  __exportStar(require("./CurrentIlluminationDataPoint"), exports);
19
19
  __exportStar(require("./DailyMovementCount"), exports);
20
+ __exportStar(require("./EnergyCalculation"), exports);
20
21
  __exportStar(require("./RoomDetailInfo"), exports);
21
22
  __exportStar(require("./ShutterCalibration"), exports);
22
23
  __exportStar(require("./temperaturDataPoint"), exports);
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.RoomBase = void 0;
7
7
  const logLevel_1 = require("../logLevel");
8
8
  const log_service_1 = require("../../server/services/log-service/log-service");
9
- const persist_1 = require("../../server/services/dbo/persist");
10
9
  const time_callback_service_1 = require("../../server/services/time-callback-service");
11
10
  const room_service_1 = require("../../server/services/room-service/room-service");
12
11
  const roomInfo_1 = require("./roomInfo");
@@ -15,6 +14,7 @@ const ShutterService_1 = require("../../server/services/ShutterService");
15
14
  const utils_1 = require("../../server/services/utils/utils");
16
15
  const lodash_1 = __importDefault(require("lodash"));
17
16
  const device_cluster_1 = require("../../server/devices/device-cluster");
17
+ const index_1 = require("../../index");
18
18
  class RoomBase {
19
19
  constructor(roomName, settings, groups) {
20
20
  this.settings = settings;
@@ -68,7 +68,7 @@ class RoomBase {
68
68
  (_c = this.TasterGroup) === null || _c === void 0 ? void 0 : _c.initCallbacks();
69
69
  }
70
70
  persist() {
71
- persist_1.Persist.addRoom(this);
71
+ index_1.dbo === null || index_1.dbo === void 0 ? void 0 : index_1.dbo.addRoom(this);
72
72
  }
73
73
  recalcTimeCallbacks() {
74
74
  const now = new Date();
@@ -1,5 +1,6 @@
1
1
  import { LogLevel } from '../../models/logLevel';
2
2
  import { iRoomDefaultSettings } from '../../models/rooms/RoomSettings/iRoomDefaultSettings';
3
+ import { PoolConfig } from 'pg';
3
4
  interface iSonosSettings {
4
5
  active: boolean;
5
6
  }
@@ -8,6 +9,8 @@ export interface iRestSettings {
8
9
  port?: number;
9
10
  }
10
11
  export interface iConfig {
12
+ wattagePrice: number;
13
+ injectWattagePrice?: number;
11
14
  ioBrokerUrl: string;
12
15
  logSettings?: iLogSettings;
13
16
  translationSettings: iTranslationSettings;
@@ -42,6 +45,10 @@ export interface iTelegramSettings {
42
45
  subscribedIDs: number[];
43
46
  }
44
47
  export interface iPersistenceSettings {
48
+ mongo?: iMongoSettings;
49
+ postgreSql?: PoolConfig;
50
+ }
51
+ export interface iMongoSettings {
45
52
  mongoConnection: string;
46
53
  mongoDbName: string;
47
54
  }
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Heizgruppen = void 0;
4
4
  const deviceType_1 = require("./deviceType");
5
- const persist_1 = require("../services/dbo/persist");
6
5
  const devices_1 = require("./devices");
6
+ const index_1 = require("../../index");
7
7
  class Heizgruppen {
8
8
  static getInfo() {
9
9
  const gruppen = Heizgruppen.getAllGruppen();
@@ -18,6 +18,7 @@ class Heizgruppen {
18
18
  return response.join('\n');
19
19
  }
20
20
  static async getSpecificInfo(pText) {
21
+ var _a;
21
22
  if (pText === undefined || !pText.includes('"')) {
22
23
  return `Bitte übergeben Sie eine Heizgruppe innerhalb von "". z.B. "EG Flur HeizGr"`;
23
24
  }
@@ -26,7 +27,7 @@ class Heizgruppen {
26
27
  if (group === undefined) {
27
28
  return `"${searchText}" ist keine gültige Heizgruppe, im Folgenden ist eine Liste aller gültigen Heizgruppen:\n${this.getInfo()}`;
28
29
  }
29
- const results = await persist_1.Persist.readTemperaturDataPoint(group, 20);
30
+ const results = (_a = (await (index_1.dbo === null || index_1.dbo === void 0 ? void 0 : index_1.dbo.readTemperaturDataPoint(group, 20)))) !== null && _a !== void 0 ? _a : [];
30
31
  const response = [`Dies sind die letzten 20 Messpunkte der Heizgruppe:`];
31
32
  response.push(`Zeitpunkt\t\tIst-Temperatur\t\tSoll-Temperatur\t\tVentilstellung`);
32
33
  for (const r of results) {
@@ -4,9 +4,9 @@ exports.HmIpBewegung = void 0;
4
4
  const hmIpDevice_1 = require("./hmIpDevice");
5
5
  const deviceType_1 = require("../deviceType");
6
6
  const utils_1 = require("../../services/utils/utils");
7
- const persist_1 = require("../../services/dbo/persist");
8
7
  const CurrentIlluminationDataPoint_1 = require("../../../models/persistence/CurrentIlluminationDataPoint");
9
8
  const logLevel_1 = require("../../../models/logLevel");
9
+ const index_1 = require("../../../index");
10
10
  class HmIpBewegung extends hmIpDevice_1.HmIPDevice {
11
11
  constructor(pInfo) {
12
12
  super(pInfo, deviceType_1.DeviceType.HmIpBewegung);
@@ -16,13 +16,11 @@ class HmIpBewegung extends hmIpDevice_1.HmIPDevice {
16
16
  this._movementDetectedCallback = [];
17
17
  this.initialized = false;
18
18
  this._currentIllumination = -1;
19
- persist_1.Persist.getCount(this)
20
- .then((todayCount) => {
19
+ index_1.dbo === null || index_1.dbo === void 0 ? void 0 : index_1.dbo.getCount(this).then((todayCount) => {
21
20
  this.detectionsToday = todayCount.counter;
22
21
  this.log(logLevel_1.LogLevel.Debug, `Bewegungscounter vorinitialisiert mit ${this.detectionsToday}`);
23
22
  this.initialized = true;
24
- })
25
- .catch((err) => {
23
+ }).catch((err) => {
26
24
  this.log(logLevel_1.LogLevel.Warn, `Failed to initialize Movement Counter, err ${err.message}`);
27
25
  });
28
26
  }
@@ -32,7 +30,7 @@ class HmIpBewegung extends hmIpDevice_1.HmIPDevice {
32
30
  set currentIllumination(value) {
33
31
  var _a, _b, _c;
34
32
  this._currentIllumination = value;
35
- persist_1.Persist.persistCurrentIllumination(new CurrentIlluminationDataPoint_1.CurrentIlluminationDataPoint(this.info.room, this.info.devID, value, new Date(), (_c = (_b = (_a = this.room) === null || _a === void 0 ? void 0 : _a.LampenGroup) === null || _b === void 0 ? void 0 : _b.anyLightsOwn()) !== null && _c !== void 0 ? _c : false));
33
+ index_1.dbo === null || index_1.dbo === void 0 ? void 0 : index_1.dbo.persistCurrentIllumination(new CurrentIlluminationDataPoint_1.CurrentIlluminationDataPoint(this.info.room, this.info.devID, value, new Date(), (_c = (_b = (_a = this.room) === null || _a === void 0 ? void 0 : _a.LampenGroup) === null || _b === void 0 ? void 0 : _b.anyLightsOwn()) !== null && _c !== void 0 ? _c : false));
36
34
  }
37
35
  get detectionsToday() {
38
36
  return this._detectionsToday;
@@ -40,7 +38,7 @@ class HmIpBewegung extends hmIpDevice_1.HmIPDevice {
40
38
  set detectionsToday(pVal) {
41
39
  const oldVal = this._detectionsToday;
42
40
  this._detectionsToday = pVal;
43
- persist_1.Persist.persistTodayCount(this, pVal, oldVal);
41
+ index_1.dbo === null || index_1.dbo === void 0 ? void 0 : index_1.dbo.persistTodayCount(this, pVal, oldVal);
44
42
  }
45
43
  addMovementCallback(pCallback) {
46
44
  this._movementDetectedCallback.push(pCallback);
@@ -4,9 +4,9 @@ exports.HmIpHeizgruppe = void 0;
4
4
  const hmIpDevice_1 = require("./hmIpDevice");
5
5
  const deviceType_1 = require("../deviceType");
6
6
  const utils_1 = require("../../services/utils/utils");
7
- const persist_1 = require("../../services/dbo/persist");
8
7
  const logLevel_1 = require("../../../models/logLevel");
9
8
  const device_cluster_type_1 = require("../device-cluster-type");
9
+ const index_1 = require("../../../index");
10
10
  class HmIpHeizgruppe extends hmIpDevice_1.HmIPDevice {
11
11
  constructor(pInfo) {
12
12
  super(pInfo, deviceType_1.DeviceType.HmIpHeizgruppe);
@@ -108,7 +108,7 @@ class HmIpHeizgruppe extends hmIpDevice_1.HmIPDevice {
108
108
  checkAutomaticChange() {
109
109
  var _a;
110
110
  if (!this._automaticMode) {
111
- persist_1.Persist.addTemperaturDataPoint(this);
111
+ index_1.dbo === null || index_1.dbo === void 0 ? void 0 : index_1.dbo.addTemperaturDataPoint(this);
112
112
  return;
113
113
  }
114
114
  for (const name in this._automaticPoints) {
@@ -125,7 +125,7 @@ class HmIpHeizgruppe extends hmIpDevice_1.HmIPDevice {
125
125
  }
126
126
  break;
127
127
  }
128
- persist_1.Persist.addTemperaturDataPoint(this);
128
+ index_1.dbo === null || index_1.dbo === void 0 ? void 0 : index_1.dbo.addTemperaturDataPoint(this);
129
129
  }
130
130
  }
131
131
  exports.HmIpHeizgruppe = HmIpHeizgruppe;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="iobroker" />
2
2
  import { HmIPDevice } from './hmIpDevice';
3
- import { ActuatorSettings } from '../../../models/actuatorSettings';
3
+ import { ActuatorSettings } from '../../../models/deviceSettings/actuatorSettings';
4
4
  import { DeviceInfo } from '../DeviceInfo';
5
5
  import { iLamp } from '../iLamp';
6
6
  import { TimeOfDay } from '../../services/time-callback-service';
@@ -4,7 +4,7 @@ exports.HmIpLampe = void 0;
4
4
  const hmIpDevice_1 = require("./hmIpDevice");
5
5
  const deviceType_1 = require("../deviceType");
6
6
  const utils_1 = require("../../services/utils/utils");
7
- const actuatorSettings_1 = require("../../../models/actuatorSettings");
7
+ const actuatorSettings_1 = require("../../../models/deviceSettings/actuatorSettings");
8
8
  const logLevel_1 = require("../../../models/logLevel");
9
9
  const time_callback_service_1 = require("../../services/time-callback-service");
10
10
  class HmIpLampe extends hmIpDevice_1.HmIPDevice {
@@ -4,9 +4,9 @@ exports.HmIpPraezenz = void 0;
4
4
  const hmIpDevice_1 = require("./hmIpDevice");
5
5
  const deviceType_1 = require("../deviceType");
6
6
  const utils_1 = require("../../services/utils/utils");
7
- const persist_1 = require("../../services/dbo/persist");
8
7
  const CurrentIlluminationDataPoint_1 = require("../../../models/persistence/CurrentIlluminationDataPoint");
9
8
  const logLevel_1 = require("../../../models/logLevel");
9
+ const index_1 = require("../../../index");
10
10
  class HmIpPraezenz extends hmIpDevice_1.HmIPDevice {
11
11
  constructor(pInfo) {
12
12
  super(pInfo, deviceType_1.DeviceType.HmIpPraezenz);
@@ -18,13 +18,11 @@ class HmIpPraezenz extends hmIpDevice_1.HmIPDevice {
18
18
  this.initialized = false;
19
19
  this._currentIllumination = -1;
20
20
  // this.presenceStateID = `${this.info.fullID}.1.${HmIpPraezenz.PRESENCE_DETECTION}`;
21
- persist_1.Persist.getCount(this)
22
- .then((todayCount) => {
21
+ index_1.dbo === null || index_1.dbo === void 0 ? void 0 : index_1.dbo.getCount(this).then((todayCount) => {
23
22
  this.detectionsToday = todayCount.counter;
24
23
  this.log(logLevel_1.LogLevel.Debug, `Präsenzcounter vorinitialisiert mit ${this.detectionsToday}`);
25
24
  this.initialized = true;
26
- })
27
- .catch((err) => {
25
+ }).catch((err) => {
28
26
  this.log(logLevel_1.LogLevel.Warn, `Failed to initialize Movement Counter, err ${err.message}`);
29
27
  });
30
28
  }
@@ -34,7 +32,7 @@ class HmIpPraezenz extends hmIpDevice_1.HmIPDevice {
34
32
  set detectionsToday(pVal) {
35
33
  const oldVal = this._detectionsToday;
36
34
  this._detectionsToday = pVal;
37
- persist_1.Persist.persistTodayCount(this, pVal, oldVal);
35
+ index_1.dbo === null || index_1.dbo === void 0 ? void 0 : index_1.dbo.persistTodayCount(this, pVal, oldVal);
38
36
  }
39
37
  get currentIllumination() {
40
38
  return this._currentIllumination;
@@ -42,7 +40,7 @@ class HmIpPraezenz extends hmIpDevice_1.HmIPDevice {
42
40
  set currentIllumination(value) {
43
41
  var _a, _b, _c;
44
42
  this._currentIllumination = value;
45
- persist_1.Persist.persistCurrentIllumination(new CurrentIlluminationDataPoint_1.CurrentIlluminationDataPoint(this.info.room, this.info.devID, value, new Date(), (_c = (_b = (_a = this.room) === null || _a === void 0 ? void 0 : _a.LampenGroup) === null || _b === void 0 ? void 0 : _b.anyLightsOwn()) !== null && _c !== void 0 ? _c : false));
43
+ index_1.dbo === null || index_1.dbo === void 0 ? void 0 : index_1.dbo.persistCurrentIllumination(new CurrentIlluminationDataPoint_1.CurrentIlluminationDataPoint(this.info.room, this.info.devID, value, new Date(), (_c = (_b = (_a = this.room) === null || _a === void 0 ? void 0 : _a.LampenGroup) === null || _b === void 0 ? void 0 : _b.anyLightsOwn()) !== null && _c !== void 0 ? _c : false));
46
44
  }
47
45
  addPresenceCallback(pCallback) {
48
46
  this._presenceDetectedCallback.push(pCallback);
@@ -5,6 +5,7 @@ export interface iEnergyManager extends IoBrokerBaseDevice {
5
5
  currentProduction: number;
6
6
  excessEnergy: number;
7
7
  excessEnergyConsumerConsumption: number;
8
+ totalConsumption: number;
8
9
  addExcessConsumer(device: iExcessEnergyConsumer): void;
9
10
  recalculatePowerSharing(): void;
10
11
  }
@@ -1,4 +1,4 @@
1
- import { ActuatorSettings } from '../../models/actuatorSettings';
1
+ import { ActuatorSettings } from '../../models/deviceSettings/actuatorSettings';
2
2
  import { RoomBase } from '../../models/rooms/RoomBase';
3
3
  import { TimeOfDay } from '../services/time-callback-service';
4
4
  import { IoBrokerBaseDevice } from './IoBrokerBaseDevice';
@@ -4,14 +4,24 @@ import { iEnergyManager } from '../iEnergyManager';
4
4
  import { iExcessEnergyConsumer } from '../iExcessEnergyConsumer';
5
5
  import { DeviceInfo } from '../DeviceInfo';
6
6
  export declare class JsObjectEnergyManager extends IoBrokerBaseDevice implements iEnergyManager {
7
- baseConsumption: number;
8
- currentProduction: number;
9
- excessEnergy: number;
10
- excessEnergyConsumerConsumption: number;
7
+ get excessEnergyConsumerConsumption(): number;
8
+ get excessEnergy(): number;
9
+ get baseConsumption(): number;
10
+ get totalConsumption(): number;
11
+ get currentProduction(): number;
12
+ private _currentProduction;
13
+ private _excessEnergy;
14
+ private _excessEnergyConsumerConsumption;
11
15
  private _excessEnergyConsumer;
16
+ private _iDatabaseLoggerInterval;
17
+ private _nextPersistEntry;
18
+ private _lastPersistenceCalculation;
12
19
  constructor(info: DeviceInfo);
20
+ cleanup(): void;
13
21
  addExcessConsumer(device: iExcessEnergyConsumer): void;
14
22
  recalculatePowerSharing(): void;
15
23
  update(idSplit: string[], state: ioBroker.State, initial: boolean, pOverride?: boolean): void;
16
24
  private setExcessEnergy;
25
+ private calculatePersistenceValues;
26
+ private persist;
17
27
  }
@@ -4,14 +4,42 @@ exports.JsObjectEnergyManager = void 0;
4
4
  const IoBrokerBaseDevice_1 = require("../IoBrokerBaseDevice");
5
5
  const deviceType_1 = require("../deviceType");
6
6
  const logLevel_1 = require("../../../models/logLevel");
7
+ const utils_1 = require("../../services/utils/utils");
8
+ const index_1 = require("../../../index");
7
9
  class JsObjectEnergyManager extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
8
10
  constructor(info) {
9
11
  super(info, deviceType_1.DeviceType.JsEnergyManager);
10
- this.baseConsumption = -1;
11
- this.currentProduction = -1;
12
- this.excessEnergy = -1;
13
- this.excessEnergyConsumerConsumption = -1;
12
+ this._currentProduction = -1;
13
+ this._excessEnergy = -1;
14
+ this._excessEnergyConsumerConsumption = 0;
14
15
  this._excessEnergyConsumer = [];
16
+ this._iDatabaseLoggerInterval = null;
17
+ this._lastPersistenceCalculation = utils_1.Utils.nowMS();
18
+ this._iDatabaseLoggerInterval = utils_1.Utils.guardedInterval(() => {
19
+ this.persist();
20
+ }, 15 * 60 * 1000, this);
21
+ this._nextPersistEntry = new index_1.EnergyCalculation(utils_1.Utils.nowMS());
22
+ }
23
+ get excessEnergyConsumerConsumption() {
24
+ return this._excessEnergyConsumerConsumption;
25
+ }
26
+ get excessEnergy() {
27
+ return this._excessEnergy;
28
+ }
29
+ get baseConsumption() {
30
+ return this.totalConsumption - this._excessEnergyConsumerConsumption;
31
+ }
32
+ get totalConsumption() {
33
+ return this._currentProduction - this._excessEnergy;
34
+ }
35
+ get currentProduction() {
36
+ return this._currentProduction;
37
+ }
38
+ cleanup() {
39
+ if (this._iDatabaseLoggerInterval !== null) {
40
+ clearInterval(this._iDatabaseLoggerInterval);
41
+ this._iDatabaseLoggerInterval = null;
42
+ }
15
43
  }
16
44
  addExcessConsumer(device) {
17
45
  this._excessEnergyConsumer.push(device);
@@ -28,13 +56,42 @@ class JsObjectEnergyManager extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
28
56
  break;
29
57
  case 'CurrentProduction':
30
58
  this.log(logLevel_1.LogLevel.Trace, `Current Production Update to ${state.val}`);
31
- this.currentProduction = state.val;
59
+ this._currentProduction = state.val;
32
60
  break;
33
61
  }
34
62
  }
35
63
  setExcessEnergy(val) {
36
- this.excessEnergy = val;
64
+ this._excessEnergy = val;
65
+ this.calculatePersistenceValues();
37
66
  this.recalculatePowerSharing();
38
67
  }
68
+ calculatePersistenceValues() {
69
+ const now = utils_1.Utils.nowMS();
70
+ const duration = now - this._lastPersistenceCalculation;
71
+ if (this.excessEnergy < 0) {
72
+ this._nextPersistEntry.drawnWattage += utils_1.Utils.kWh(this.excessEnergy * -1, duration);
73
+ }
74
+ else {
75
+ this._nextPersistEntry.injectedWattage += utils_1.Utils.kWh(this.excessEnergy, duration);
76
+ this._nextPersistEntry.selfConsumedWattage += utils_1.Utils.kWh(this.totalConsumption, duration);
77
+ }
78
+ this._lastPersistenceCalculation = now;
79
+ }
80
+ persist() {
81
+ var _a;
82
+ const obj = JSON.parse(JSON.stringify(this._nextPersistEntry));
83
+ if (obj.drawnWattage === 0 && obj.injectedWattage === 0 && obj.selfConsumedWattage === 0) {
84
+ return;
85
+ }
86
+ this._nextPersistEntry = new index_1.EnergyCalculation(this._lastPersistenceCalculation);
87
+ obj.endMs = this._lastPersistenceCalculation;
88
+ obj.earnedInjected = utils_1.Utils.round(obj.injectedWattage * ((_a = index_1.SettingsService.settings.injectWattagePrice) !== null && _a !== void 0 ? _a : 0.06), 4);
89
+ obj.savedSelfConsume = utils_1.Utils.round(obj.selfConsumedWattage * index_1.SettingsService.settings.wattagePrice, 4);
90
+ obj.costDrawn = utils_1.Utils.round(obj.selfConsumedWattage * index_1.SettingsService.settings.wattagePrice, 4);
91
+ obj.injectedWattage = utils_1.Utils.round(obj.injectedWattage, 4);
92
+ obj.selfConsumedWattage = utils_1.Utils.round(obj.selfConsumedWattage, 4);
93
+ obj.drawnWattage = utils_1.Utils.round(obj.drawnWattage, 4);
94
+ index_1.dbo === null || index_1.dbo === void 0 ? void 0 : index_1.dbo.persistEnergyManager(obj);
95
+ }
39
96
  }
40
97
  exports.JsObjectEnergyManager = JsObjectEnergyManager;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="iobroker" />
2
- import { ActuatorSettings } from '../../../models/actuatorSettings';
2
+ import { ActuatorSettings } from '../../../models/deviceSettings/actuatorSettings';
3
3
  import { DeviceInfo } from '../DeviceInfo';
4
4
  import { ZigbeeDevice } from './zigbeeDevice';
5
5
  import { DeviceType } from '../deviceType';
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZigbeeActuator = void 0;
4
4
  const utils_1 = require("../../services/utils/utils");
5
- const actuatorSettings_1 = require("../../../models/actuatorSettings");
5
+ const actuatorSettings_1 = require("../../../models/deviceSettings/actuatorSettings");
6
6
  const zigbeeDevice_1 = require("./zigbeeDevice");
7
7
  const logLevel_1 = require("../../../models/logLevel");
8
8
  class ZigbeeActuator extends zigbeeDevice_1.ZigbeeDevice {
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZigbeeAquaraMotion = void 0;
4
4
  const deviceType_1 = require("../deviceType");
5
- const persist_1 = require("../../services/dbo/persist");
6
5
  const CurrentIlluminationDataPoint_1 = require("../../../models/persistence/CurrentIlluminationDataPoint");
7
6
  const logLevel_1 = require("../../../models/logLevel");
8
7
  const zigbeeMotionSensor_1 = require("./zigbeeMotionSensor");
8
+ const index_1 = require("../../../index");
9
9
  class ZigbeeAquaraMotion extends zigbeeMotionSensor_1.ZigbeeMotionSensor {
10
10
  constructor(pInfo) {
11
11
  super(pInfo, deviceType_1.DeviceType.ZigbeeAquaraMotion);
@@ -21,7 +21,7 @@ class ZigbeeAquaraMotion extends zigbeeMotionSensor_1.ZigbeeMotionSensor {
21
21
  set currentIllumination(value) {
22
22
  var _a, _b, _c;
23
23
  this._illuminance = value;
24
- persist_1.Persist.persistCurrentIllumination(new CurrentIlluminationDataPoint_1.CurrentIlluminationDataPoint(this.info.room, this.info.devID, value, new Date(), (_c = (_b = (_a = this.room) === null || _a === void 0 ? void 0 : _a.LampenGroup) === null || _b === void 0 ? void 0 : _b.anyLightsOwn()) !== null && _c !== void 0 ? _c : false));
24
+ index_1.dbo === null || index_1.dbo === void 0 ? void 0 : index_1.dbo.persistCurrentIllumination(new CurrentIlluminationDataPoint_1.CurrentIlluminationDataPoint(this.info.room, this.info.devID, value, new Date(), (_c = (_b = (_a = this.room) === null || _a === void 0 ? void 0 : _a.LampenGroup) === null || _b === void 0 ? void 0 : _b.anyLightsOwn()) !== null && _c !== void 0 ? _c : false));
25
25
  }
26
26
  // Time after the last trigger until a motion event gets triggered again
27
27
  get motionTimeout() {
@@ -1,5 +1,5 @@
1
1
  /// <reference types="iobroker" />
2
- import { ActuatorSettings } from '../../../models/actuatorSettings';
2
+ import { ActuatorSettings } from '../../../models/deviceSettings/actuatorSettings';
3
3
  import { DeviceInfo } from '../DeviceInfo';
4
4
  import { ZigbeeDevice } from './zigbeeDevice';
5
5
  import { ExcessEnergyConsumerSettings } from '../../../models/excessEnergyConsumerSettings';
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZigbeeBlitzShp = void 0;
4
4
  const deviceType_1 = require("../deviceType");
5
- const actuatorSettings_1 = require("../../../models/actuatorSettings");
5
+ const actuatorSettings_1 = require("../../../models/deviceSettings/actuatorSettings");
6
6
  const zigbeeDevice_1 = require("./zigbeeDevice");
7
7
  const logLevel_1 = require("../../../models/logLevel");
8
8
  const excessEnergyConsumerSettings_1 = require("../../../models/excessEnergyConsumerSettings");
@@ -1,5 +1,5 @@
1
1
  /// <reference types="iobroker" />
2
- import { DimmerSettings } from '../../../models/dimmerSettings';
2
+ import { DimmerSettings } from '../../../models/deviceSettings/dimmerSettings';
3
3
  import { DeviceInfo } from '../DeviceInfo';
4
4
  import { iLamp } from '../iLamp';
5
5
  import { ZigbeeDevice } from './zigbeeDevice';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZigbeeIlluDimmer = void 0;
4
- const dimmerSettings_1 = require("../../../models/dimmerSettings");
4
+ const dimmerSettings_1 = require("../../../models/deviceSettings/dimmerSettings");
5
5
  const deviceType_1 = require("../deviceType");
6
6
  const utils_1 = require("../../services/utils/utils");
7
7
  const zigbeeDevice_1 = require("./zigbeeDevice");