hoffmation-base 2.13.1 → 2.13.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.
@@ -10,6 +10,7 @@ export declare class EnergyCalculation {
10
10
  savedSelfConsume: number;
11
11
  endMs: number;
12
12
  batteryStoredKwH: number;
13
+ batteryLevel: number;
13
14
  constructor(startMs: number);
14
15
  static persist(obj: EnergyCalculation, endMs: number, logger: (level: LogLevel, message: string, logDebugType?: LogDebugType) => void): boolean;
15
16
  }
@@ -14,6 +14,8 @@ class EnergyCalculation {
14
14
  this.savedSelfConsume = 0;
15
15
  this.endMs = 0;
16
16
  this.batteryStoredKwH = 0;
17
+ // Battery Level in %
18
+ this.batteryLevel = 0.0;
17
19
  }
18
20
  static persist(obj, endMs, logger) {
19
21
  var _a, _b, _c, _d, _e, _f, _g, _h;
@@ -32,6 +34,7 @@ class EnergyCalculation {
32
34
  obj.selfConsumedKwH = server_1.Utils.round(obj.selfConsumedKwH, 4);
33
35
  obj.drawnKwH = server_1.Utils.round(obj.drawnKwH, 4);
34
36
  obj.batteryStoredKwH = server_1.Utils.round(obj.batteryStoredKwH, 3);
37
+ obj.batteryLevel = server_1.Utils.round(obj.batteryLevel, 3);
35
38
  (_h = server_1.Utils.dbo) === null || _h === void 0 ? void 0 : _h.persistEnergyManager(obj);
36
39
  logger(logLevel_1.LogLevel.Info, `Persisting energy Manager Data.`);
37
40
  return true;
@@ -327,6 +327,14 @@ BEGIN
327
327
  alter table hoffmation_schema."EnergyCalculation"
328
328
  add "batteryStoredKwH" integer;
329
329
  END IF;
330
+
331
+ IF (SELECT COUNT(column_name) = 0
332
+ FROM information_schema.columns
333
+ WHERE table_name = 'EnergyCalculation'
334
+ and column_name = 'batteryLevel') Then
335
+ alter table hoffmation_schema."EnergyCalculation"
336
+ add "batteryLevel" double precision;
337
+ END IF;
330
338
  END
331
339
  $$;`);
332
340
  this.initialized = true;
@@ -429,9 +437,9 @@ values ('${device.id}', ${device.currentIllumination}, '${new Date().toISOString
429
437
  persistEnergyManager(calc) {
430
438
  this.query(`
431
439
  insert into hoffmation_schema."EnergyCalculation" ("startDate", "endDate", "selfConsumedKwH", "injectedKwH",
432
- "drawnKwH", "batteryStoredKwH")
440
+ "drawnKwH", "batteryStoredKwH", "batteryLevel")
433
441
  values ('${new Date(calc.startMs).toISOString()}','${new Date(calc.endMs).toISOString()}',
434
- ${calc.selfConsumedKwH}, ${calc.injectedKwH}, ${calc.drawnKwH}, ${calc.batteryStoredKwH});
442
+ ${calc.selfConsumedKwH}, ${calc.injectedKwH}, ${calc.drawnKwH}, ${calc.batteryStoredKwH}, ${calc.batteryLevel});
435
443
  `);
436
444
  }
437
445
  persistSettings(id, settings, customName) {
@@ -186,8 +186,9 @@ class VictronDevice {
186
186
  }
187
187
  persist() {
188
188
  var _a;
189
+ this._nextPersistEntry.batteryLevel = ((_a = this.data.battery.soc) !== null && _a !== void 0 ? _a : 0) / 100;
189
190
  this._nextPersistEntry.batteryStoredKwH =
190
- (((_a = this.data.battery.soc) !== null && _a !== void 0 ? _a : 0) * this.settings.batteryCapacityWattage) / 1000;
191
+ (this._nextPersistEntry.batteryLevel * this.settings.batteryCapacityWattage) / 1000;
191
192
  const obj = JSON.parse(JSON.stringify(this._nextPersistEntry));
192
193
  if (!models_1.EnergyCalculation.persist(obj, this._lastPersistenceCalculation, this.log.bind(this))) {
193
194
  return;