hoffmation-base 2.13.0 → 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.
- package/lib/models/persistence/EnergyCalculation.d.ts +2 -0
- package/lib/models/persistence/EnergyCalculation.js +5 -0
- package/lib/server/services/dbo/postgreSqlPersist.js +18 -2
- package/lib/server/services/victron/victron-device.js +4 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -9,6 +9,8 @@ export declare class EnergyCalculation {
|
|
|
9
9
|
earnedInjected: number;
|
|
10
10
|
savedSelfConsume: number;
|
|
11
11
|
endMs: number;
|
|
12
|
+
batteryStoredKwH: number;
|
|
13
|
+
batteryLevel: number;
|
|
12
14
|
constructor(startMs: number);
|
|
13
15
|
static persist(obj: EnergyCalculation, endMs: number, logger: (level: LogLevel, message: string, logDebugType?: LogDebugType) => void): boolean;
|
|
14
16
|
}
|
|
@@ -13,6 +13,9 @@ class EnergyCalculation {
|
|
|
13
13
|
this.earnedInjected = 0;
|
|
14
14
|
this.savedSelfConsume = 0;
|
|
15
15
|
this.endMs = 0;
|
|
16
|
+
this.batteryStoredKwH = 0;
|
|
17
|
+
// Battery Level in %
|
|
18
|
+
this.batteryLevel = 0.0;
|
|
16
19
|
}
|
|
17
20
|
static persist(obj, endMs, logger) {
|
|
18
21
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
@@ -30,6 +33,8 @@ class EnergyCalculation {
|
|
|
30
33
|
obj.injectedKwH = server_1.Utils.round(obj.injectedKwH, 4);
|
|
31
34
|
obj.selfConsumedKwH = server_1.Utils.round(obj.selfConsumedKwH, 4);
|
|
32
35
|
obj.drawnKwH = server_1.Utils.round(obj.drawnKwH, 4);
|
|
36
|
+
obj.batteryStoredKwH = server_1.Utils.round(obj.batteryStoredKwH, 3);
|
|
37
|
+
obj.batteryLevel = server_1.Utils.round(obj.batteryLevel, 3);
|
|
33
38
|
(_h = server_1.Utils.dbo) === null || _h === void 0 ? void 0 : _h.persistEnergyManager(obj);
|
|
34
39
|
logger(logLevel_1.LogLevel.Info, `Persisting energy Manager Data.`);
|
|
35
40
|
return true;
|
|
@@ -319,6 +319,22 @@ BEGIN
|
|
|
319
319
|
);
|
|
320
320
|
|
|
321
321
|
END IF;
|
|
322
|
+
|
|
323
|
+
IF (SELECT COUNT(column_name) = 0
|
|
324
|
+
FROM information_schema.columns
|
|
325
|
+
WHERE table_name = 'EnergyCalculation'
|
|
326
|
+
and column_name = 'batteryStoredKwH') Then
|
|
327
|
+
alter table hoffmation_schema."EnergyCalculation"
|
|
328
|
+
add "batteryStoredKwH" integer;
|
|
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;
|
|
322
338
|
END
|
|
323
339
|
$$;`);
|
|
324
340
|
this.initialized = true;
|
|
@@ -421,9 +437,9 @@ values ('${device.id}', ${device.currentIllumination}, '${new Date().toISOString
|
|
|
421
437
|
persistEnergyManager(calc) {
|
|
422
438
|
this.query(`
|
|
423
439
|
insert into hoffmation_schema."EnergyCalculation" ("startDate", "endDate", "selfConsumedKwH", "injectedKwH",
|
|
424
|
-
"drawnKwH")
|
|
440
|
+
"drawnKwH", "batteryStoredKwH", "batteryLevel")
|
|
425
441
|
values ('${new Date(calc.startMs).toISOString()}','${new Date(calc.endMs).toISOString()}',
|
|
426
|
-
${calc.selfConsumedKwH}, ${calc.injectedKwH}, ${calc.drawnKwH});
|
|
442
|
+
${calc.selfConsumedKwH}, ${calc.injectedKwH}, ${calc.drawnKwH}, ${calc.batteryStoredKwH}, ${calc.batteryLevel});
|
|
427
443
|
`);
|
|
428
444
|
}
|
|
429
445
|
persistSettings(id, settings, customName) {
|
|
@@ -185,6 +185,10 @@ class VictronDevice {
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
persist() {
|
|
188
|
+
var _a;
|
|
189
|
+
this._nextPersistEntry.batteryLevel = ((_a = this.data.battery.soc) !== null && _a !== void 0 ? _a : 0) / 100;
|
|
190
|
+
this._nextPersistEntry.batteryStoredKwH =
|
|
191
|
+
(this._nextPersistEntry.batteryLevel * this.settings.batteryCapacityWattage) / 1000;
|
|
188
192
|
const obj = JSON.parse(JSON.stringify(this._nextPersistEntry));
|
|
189
193
|
if (!models_1.EnergyCalculation.persist(obj, this._lastPersistenceCalculation, this.log.bind(this))) {
|
|
190
194
|
return;
|