hoffmation-base 3.0.0-alpha.89 → 3.0.0-alpha.90
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/action/batteryLevelChangeAction.js +2 -2
- package/lib/models/iJsonOmitKeys.d.ts +9 -0
- package/lib/models/iJsonOmitKeys.js +2 -0
- package/lib/models/index.d.ts +1 -0
- package/lib/server/devices/IoBrokerBaseDevice.d.ts +4 -2
- package/lib/server/devices/IoBrokerBaseDevice.js +3 -1
- package/lib/server/devices/baseDeviceInterfaces/iBatteryDevice.d.ts +4 -13
- package/lib/server/devices/baseDeviceInterfaces/iHandleSensor.d.ts +10 -0
- package/lib/server/devices/baseDeviceInterfaces/iHumiditySensor.d.ts +3 -7
- package/lib/server/devices/baseDeviceInterfaces/iTemperatureSensor.d.ts +3 -7
- package/lib/server/devices/dachs/dachs.js +2 -5
- package/lib/server/devices/dachs/dachsTemperatureSensor.d.ts +2 -7
- package/lib/server/devices/dachs/dachsTemperatureSensor.js +9 -31
- package/lib/server/devices/deviceType.d.ts +1 -0
- package/lib/server/devices/deviceType.js +1 -0
- package/lib/server/devices/devices.js +5 -2
- package/lib/server/devices/groups/Window.d.ts +2 -3
- package/lib/server/devices/groups/Window.js +3 -3
- package/lib/server/devices/groups/windowGroup.js +2 -2
- package/lib/server/devices/hmIPDevices/hmIpGriff.d.ts +9 -35
- package/lib/server/devices/hmIPDevices/hmIpGriff.js +27 -171
- package/lib/server/devices/hmIPDevices/hmIpHeizgruppe.d.ts +5 -13
- package/lib/server/devices/hmIPDevices/hmIpHeizgruppe.js +30 -66
- package/lib/server/devices/hmIPDevices/hmIpHeizung.d.ts +4 -14
- package/lib/server/devices/hmIPDevices/hmIpHeizung.js +6 -39
- package/lib/server/devices/hmIPDevices/hmIpPraezenz.d.ts +5 -14
- package/lib/server/devices/hmIPDevices/hmIpPraezenz.js +6 -38
- package/lib/server/devices/hmIPDevices/hmIpRoll.js +2 -2
- package/lib/server/devices/hmIPDevices/hmIpTaster.d.ts +4 -14
- package/lib/server/devices/hmIPDevices/hmIpTaster.js +6 -38
- package/lib/server/devices/hmIPDevices/hmIpTherm.d.ts +4 -14
- package/lib/server/devices/hmIPDevices/hmIpTherm.js +6 -39
- package/lib/server/devices/models/WindowPosition.d.ts +3 -3
- package/lib/server/devices/models/WindowPosition.js +3 -3
- package/lib/server/devices/sharedFunctions/battery.d.ts +31 -0
- package/lib/server/devices/sharedFunctions/battery.js +65 -0
- package/lib/server/devices/sharedFunctions/handleSensor.d.ts +45 -0
- package/lib/server/devices/sharedFunctions/handleSensor.js +150 -0
- package/lib/server/devices/sharedFunctions/humiditySensor.d.ts +18 -0
- package/lib/server/devices/sharedFunctions/humiditySensor.js +46 -0
- package/lib/server/devices/sharedFunctions/index.d.ts +4 -0
- package/lib/server/devices/sharedFunctions/index.js +4 -0
- package/lib/server/devices/sharedFunctions/temperatureSensor.d.ts +31 -0
- package/lib/server/devices/sharedFunctions/temperatureSensor.js +57 -0
- package/lib/server/devices/shelly/shellyTrv.d.ts +5 -16
- package/lib/server/devices/shelly/shellyTrv.js +7 -41
- package/lib/server/devices/smartGarden/smartGardenDevice.d.ts +4 -16
- package/lib/server/devices/smartGarden/smartGardenDevice.js +7 -42
- package/lib/server/devices/smartGarden/smartGardenSensor.d.ts +3 -13
- package/lib/server/devices/smartGarden/smartGardenSensor.js +14 -57
- package/lib/server/devices/velux/veluxShutter.js +2 -2
- package/lib/server/devices/zigbee/BaseDevices/index.d.ts +1 -0
- package/lib/server/devices/zigbee/BaseDevices/index.js +3 -1
- package/lib/server/devices/zigbee/BaseDevices/zigbeeHeater.d.ts +5 -15
- package/lib/server/devices/zigbee/BaseDevices/zigbeeHeater.js +7 -40
- package/lib/server/devices/zigbee/BaseDevices/zigbeeMagnetContact.d.ts +4 -15
- package/lib/server/devices/zigbee/BaseDevices/zigbeeMagnetContact.js +7 -40
- package/lib/server/devices/zigbee/BaseDevices/zigbeeMotionSensor.d.ts +5 -16
- package/lib/server/devices/zigbee/BaseDevices/zigbeeMotionSensor.js +7 -41
- package/lib/server/devices/zigbee/BaseDevices/zigbeeShutter.js +2 -2
- package/lib/server/devices/zigbee/BaseDevices/zigbeeWindowHandle.d.ts +36 -0
- package/lib/server/devices/zigbee/BaseDevices/zigbeeWindowHandle.js +82 -0
- package/lib/server/devices/zigbee/index.d.ts +1 -0
- package/lib/server/devices/zigbee/index.js +1 -0
- package/lib/server/devices/zigbee/zigbeeAquaraVibra.d.ts +4 -16
- package/lib/server/devices/zigbee/zigbeeAquaraVibra.js +7 -41
- package/lib/server/devices/zigbee/zigbeeAquaraWater.d.ts +4 -16
- package/lib/server/devices/zigbee/zigbeeAquaraWater.js +7 -41
- package/lib/server/devices/zigbee/zigbeeHeimanSmoke.d.ts +4 -16
- package/lib/server/devices/zigbee/zigbeeHeimanSmoke.js +7 -41
- package/lib/server/devices/zigbee/zigbeeSodaHandle.d.ts +34 -0
- package/lib/server/devices/zigbee/zigbeeSodaHandle.js +96 -0
- package/lib/server/devices/zigbee/zigbeeSonoffTemp.d.ts +7 -27
- package/lib/server/devices/zigbee/zigbeeSonoffTemp.js +21 -94
- package/lib/server/services/dbo/postgreSqlPersist.js +1 -1
- package/lib/server/services/utils/utils.js +5 -1
- package/lib/server/services/victron/victron-device.d.ts +8 -15
- package/lib/server/services/victron/victron-device.js +22 -51
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -2,159 +2,86 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ZigbeeSonoffTemp = void 0;
|
|
4
4
|
const BaseDevices_1 = require("./BaseDevices");
|
|
5
|
-
const baseDeviceInterfaces_1 = require("../baseDeviceInterfaces");
|
|
6
5
|
const deviceType_1 = require("../deviceType");
|
|
7
6
|
const DeviceCapability_1 = require("../DeviceCapability");
|
|
8
7
|
const models_1 = require("../../../models");
|
|
9
|
-
const
|
|
8
|
+
const sharedFunctions_1 = require("../sharedFunctions");
|
|
10
9
|
class ZigbeeSonoffTemp extends BaseDevices_1.ZigbeeDevice {
|
|
11
10
|
constructor(pInfo) {
|
|
12
11
|
super(pInfo, deviceType_1.DeviceType.ZigbeeSonoffTemp);
|
|
13
12
|
/** @inheritDoc */
|
|
14
|
-
this.
|
|
15
|
-
this.persistTemperaturSensor();
|
|
16
|
-
}, 5 * 60 * 1000, this, false);
|
|
13
|
+
this.temperatureSensor = new sharedFunctions_1.TemperatureSensor(this);
|
|
17
14
|
/** @inheritDoc */
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this._battery = -99;
|
|
22
|
-
this._lastBatteryPersist = 0;
|
|
23
|
-
this._humidityCallbacks = [];
|
|
24
|
-
this._temperaturCallbacks = [];
|
|
25
|
-
this._humidity = baseDeviceInterfaces_1.UNDEFINED_TEMP_VALUE;
|
|
26
|
-
this._roomTemperature = baseDeviceInterfaces_1.UNDEFINED_TEMP_VALUE;
|
|
27
|
-
this._temperature = baseDeviceInterfaces_1.UNDEFINED_TEMP_VALUE;
|
|
28
|
-
this._lastBatteryLevel = -1;
|
|
29
|
-
this._batteryLevelCallbacks = [];
|
|
15
|
+
this.humiditySensor = new sharedFunctions_1.HumiditySensor(this);
|
|
16
|
+
/** @inheritDoc */
|
|
17
|
+
this.battery = new sharedFunctions_1.Battery(this);
|
|
30
18
|
this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.temperatureSensor);
|
|
31
19
|
this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.humiditySensor);
|
|
32
20
|
this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.batteryDriven);
|
|
33
21
|
}
|
|
34
22
|
/** @inheritDoc */
|
|
35
|
-
get
|
|
36
|
-
return this.
|
|
37
|
-
}
|
|
38
|
-
/** @inheritDoc */
|
|
39
|
-
get battery() {
|
|
40
|
-
return this._battery;
|
|
23
|
+
get batteryLevel() {
|
|
24
|
+
return this.battery.level;
|
|
41
25
|
}
|
|
42
26
|
/** @inheritDoc */
|
|
43
27
|
get roomTemperature() {
|
|
44
|
-
return this.
|
|
28
|
+
return this.temperatureSensor.roomTemperature;
|
|
45
29
|
}
|
|
46
30
|
/** @inheritDoc */
|
|
47
31
|
set roomTemperature(value) {
|
|
48
|
-
this.
|
|
32
|
+
this.temperatureSensor.roomTemperature = value;
|
|
49
33
|
}
|
|
50
34
|
/** @inheritDoc */
|
|
51
35
|
get humidity() {
|
|
52
|
-
return this.
|
|
53
|
-
}
|
|
54
|
-
set humidity(val) {
|
|
55
|
-
this._humidity = val;
|
|
56
|
-
for (const cb of this._humidityCallbacks) {
|
|
57
|
-
cb(new models_1.HumiditySensorChangeAction(this, val));
|
|
58
|
-
}
|
|
36
|
+
return this.humiditySensor.humidity;
|
|
59
37
|
}
|
|
60
38
|
/** @inheritDoc */
|
|
61
39
|
get iTemperature() {
|
|
62
|
-
return this.
|
|
40
|
+
return this.temperatureSensor.temperature;
|
|
63
41
|
}
|
|
64
42
|
/** @inheritDoc */
|
|
65
43
|
get sTemperature() {
|
|
66
|
-
return `${this.
|
|
67
|
-
}
|
|
68
|
-
set temperature(val) {
|
|
69
|
-
this._temperature = val;
|
|
70
|
-
for (const cb of this._temperaturCallbacks) {
|
|
71
|
-
cb(new models_1.TemperatureSensorChangeAction(this, val));
|
|
72
|
-
}
|
|
44
|
+
return `${this.temperatureSensor.temperature}°C`;
|
|
73
45
|
}
|
|
74
46
|
/** @inheritDoc */
|
|
75
47
|
addBatteryLevelCallback(pCallback) {
|
|
76
|
-
this.
|
|
48
|
+
this.battery.addBatteryLevelCallback(pCallback);
|
|
77
49
|
}
|
|
78
50
|
/** @inheritDoc */
|
|
79
51
|
update(idSplit, state, initial = false) {
|
|
80
52
|
super.update(idSplit, state, initial, true);
|
|
81
53
|
switch (idSplit[3]) {
|
|
82
54
|
case 'battery':
|
|
83
|
-
this.
|
|
84
|
-
this.
|
|
85
|
-
this.persistBatteryDevice();
|
|
86
|
-
if (this._battery < 20) {
|
|
55
|
+
this.battery.level = state.val;
|
|
56
|
+
if (this.batteryLevel < 20) {
|
|
87
57
|
this.log(models_1.LogLevel.Warn, 'Das Zigbee Gerät hat unter 20% Batterie.');
|
|
88
58
|
}
|
|
89
59
|
break;
|
|
90
60
|
case 'humidity':
|
|
91
|
-
this.humidity = state.val;
|
|
61
|
+
this.humiditySensor.humidity = state.val;
|
|
92
62
|
break;
|
|
93
63
|
case 'temperature':
|
|
94
|
-
this.temperature = state.val;
|
|
64
|
+
this.temperatureSensor.temperature = state.val;
|
|
95
65
|
break;
|
|
96
66
|
}
|
|
97
67
|
}
|
|
98
68
|
/** @inheritDoc */
|
|
99
69
|
addHumidityCallback(pCallback) {
|
|
100
|
-
this.
|
|
101
|
-
if (this._humidity > 0) {
|
|
102
|
-
pCallback(new models_1.HumiditySensorChangeAction(this, this._humidity));
|
|
103
|
-
}
|
|
70
|
+
this.humiditySensor.addHumidityCallback(pCallback);
|
|
104
71
|
}
|
|
105
72
|
/** @inheritDoc */
|
|
106
73
|
addTempChangeCallback(pCallback) {
|
|
107
|
-
this.
|
|
108
|
-
if (this._temperature > baseDeviceInterfaces_1.UNDEFINED_TEMP_VALUE) {
|
|
109
|
-
pCallback(new models_1.TemperatureSensorChangeAction(this, this._temperature));
|
|
110
|
-
}
|
|
74
|
+
this.temperatureSensor.addTempChangeCallback(pCallback);
|
|
111
75
|
}
|
|
112
76
|
/** @inheritDoc */
|
|
113
77
|
onTemperaturChange(newTemperatur) {
|
|
114
78
|
this.roomTemperature = newTemperatur;
|
|
115
79
|
}
|
|
116
80
|
/** @inheritDoc */
|
|
117
|
-
persistTemperaturSensor() {
|
|
118
|
-
var _a;
|
|
119
|
-
(_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistTemperatureSensor(this);
|
|
120
|
-
}
|
|
121
|
-
/** @inheritDoc */
|
|
122
|
-
persistHumiditySensor() {
|
|
123
|
-
var _a;
|
|
124
|
-
(_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistHumiditySensor(this);
|
|
125
|
-
}
|
|
126
|
-
/** @inheritDoc */
|
|
127
|
-
persistBatteryDevice() {
|
|
128
|
-
var _a;
|
|
129
|
-
const now = services_1.Utils.nowMS();
|
|
130
|
-
if (this._lastBatteryPersist + 60000 > now) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
(_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistBatteryDevice(this);
|
|
134
|
-
this._lastBatteryPersist = now;
|
|
135
|
-
}
|
|
136
|
-
/** @inheritDoc */
|
|
137
81
|
dispose() {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
if (this.persistHumiditySensorInterval) {
|
|
142
|
-
clearInterval(this.persistHumiditySensorInterval);
|
|
143
|
-
}
|
|
82
|
+
this.temperatureSensor.dispose();
|
|
83
|
+
this.humiditySensor.dispose();
|
|
144
84
|
super.dispose();
|
|
145
85
|
}
|
|
146
|
-
/**
|
|
147
|
-
* Checks whether the battery level did change and if so fires the callbacks
|
|
148
|
-
*/
|
|
149
|
-
checkForBatteryChange() {
|
|
150
|
-
const newLevel = this.battery;
|
|
151
|
-
if (newLevel == -1 || newLevel == this._lastBatteryLevel) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
for (const cb of this._batteryLevelCallbacks) {
|
|
155
|
-
cb(new models_1.BatteryLevelChangeAction(this));
|
|
156
|
-
}
|
|
157
|
-
this._lastBatteryLevel = newLevel;
|
|
158
|
-
}
|
|
159
86
|
}
|
|
160
87
|
exports.ZigbeeSonoffTemp = ZigbeeSonoffTemp;
|
|
@@ -433,7 +433,7 @@ values ('${device.id}', ${device.humidity}, '${new Date().toISOString()}');
|
|
|
433
433
|
persistBatteryDevice(device) {
|
|
434
434
|
this.query(`
|
|
435
435
|
insert into hoffmation_schema."BatteryDeviceData" ("deviceID", "battery", "date")
|
|
436
|
-
values ('${device.id}', ${utils_1.Utils.round(device.
|
|
436
|
+
values ('${device.id}', ${utils_1.Utils.round(device.batteryLevel, 1)}, '${new Date().toISOString()}');
|
|
437
437
|
`);
|
|
438
438
|
}
|
|
439
439
|
/** @inheritDoc */
|
|
@@ -85,9 +85,11 @@ class Utils {
|
|
|
85
85
|
'interval',
|
|
86
86
|
'timeouts',
|
|
87
87
|
'callback',
|
|
88
|
+
'callbacks',
|
|
88
89
|
'otaInfo',
|
|
89
90
|
'precalculatedDistancesMap',
|
|
90
91
|
'stateMap',
|
|
92
|
+
'jsonOmitKeys',
|
|
91
93
|
];
|
|
92
94
|
keysToOmit.push(...additionalOmitKeys);
|
|
93
95
|
const loweredOmitKeys = keysToOmit.map((key) => key.toLowerCase());
|
|
@@ -175,9 +177,11 @@ class Utils {
|
|
|
175
177
|
return modMin < modMax ? modToCheck <= modMax && modToCheck >= modMin : modToCheck > modMin || modToCheck < modMax;
|
|
176
178
|
}
|
|
177
179
|
static deepOmit(obj, keysToOmit, topLevelOmitKeys, level = 1, currentKey = '') {
|
|
180
|
+
var _a;
|
|
178
181
|
if (level > 10 && level < 20) {
|
|
179
182
|
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `DeepOmit Loop Level ${level} reached for ${currentKey}`);
|
|
180
183
|
}
|
|
184
|
+
const combinedOmmitKeys = [...keysToOmit, ...((_a = obj === null || obj === void 0 ? void 0 : obj.jsonOmitKeys) !== null && _a !== void 0 ? _a : [])];
|
|
181
185
|
// the inner function which will be called recursivley
|
|
182
186
|
return lodash_1.default.transform(obj, (result, value, key) => {
|
|
183
187
|
if (value === undefined || value === null) {
|
|
@@ -185,7 +189,7 @@ class Utils {
|
|
|
185
189
|
}
|
|
186
190
|
if (typeof key == 'string') {
|
|
187
191
|
const lowerKey = key.toLowerCase();
|
|
188
|
-
for (const checkKey of
|
|
192
|
+
for (const checkKey of combinedOmmitKeys) {
|
|
189
193
|
// if the key is in the index skip it
|
|
190
194
|
if (lowerKey.includes(checkKey)) {
|
|
191
195
|
return;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import { DeviceCapability, DeviceInfo, DeviceType, iBatteryDevice, iEnergyManager, iExcessEnergyConsumer } from '../../devices';
|
|
2
|
-
import {
|
|
1
|
+
import { Battery, DeviceCapability, DeviceInfo, DeviceType, iBatteryDevice, iEnergyManager, iExcessEnergyConsumer } from '../../devices';
|
|
2
|
+
import { iJsonOmitKeys, LogLevel, VictronDeviceSettings } from '../../../models';
|
|
3
3
|
import { LogDebugType } from '../log-service';
|
|
4
4
|
import { VictronDeviceData, VictronMqttConnectionOptions, VictronMqttConsumer } from 'victron-mqtt-consumer';
|
|
5
|
-
export declare class VictronDevice implements iEnergyManager, iBatteryDevice {
|
|
5
|
+
export declare class VictronDevice implements iEnergyManager, iBatteryDevice, iJsonOmitKeys {
|
|
6
|
+
/** @inheritDoc */
|
|
7
|
+
readonly jsonOmitKeys: string[];
|
|
6
8
|
/** @inheritDoc */
|
|
7
9
|
readonly deviceCapabilities: DeviceCapability[];
|
|
8
10
|
/** @inheritDoc */
|
|
9
11
|
deviceType: DeviceType;
|
|
10
12
|
/** @inheritDoc */
|
|
11
13
|
readonly settings: VictronDeviceSettings;
|
|
14
|
+
/** @inheritDoc */
|
|
15
|
+
readonly battery: Battery;
|
|
12
16
|
protected _info: DeviceInfo;
|
|
13
17
|
private readonly _victronConsumer;
|
|
14
18
|
private _excessEnergyConsumer;
|
|
@@ -18,19 +22,13 @@ export declare class VictronDevice implements iEnergyManager, iBatteryDevice {
|
|
|
18
22
|
private _iDatabaseLoggerInterval;
|
|
19
23
|
private _lastPersistenceCalculation;
|
|
20
24
|
private _nextPersistEntry;
|
|
21
|
-
private _lastBatteryPersist;
|
|
22
|
-
private _lastBatteryLevel;
|
|
23
|
-
private _batteryLevelCallbacks;
|
|
24
25
|
private _excessEnergy;
|
|
25
|
-
private _lastBatteryChangeReportMs;
|
|
26
26
|
constructor(opts: VictronMqttConnectionOptions);
|
|
27
27
|
/** @inheritDoc */
|
|
28
28
|
get acBlocked(): boolean;
|
|
29
|
-
/** @inheritDoc */
|
|
30
|
-
get lastBatteryPersist(): number;
|
|
31
29
|
get info(): DeviceInfo;
|
|
32
30
|
/** @inheritDoc */
|
|
33
|
-
get
|
|
31
|
+
get batteryLevel(): number;
|
|
34
32
|
get victronConsumer(): VictronMqttConsumer;
|
|
35
33
|
get data(): VictronDeviceData;
|
|
36
34
|
get excessEnergy(): number;
|
|
@@ -40,8 +38,6 @@ export declare class VictronDevice implements iEnergyManager, iBatteryDevice {
|
|
|
40
38
|
get injectingWattage(): number;
|
|
41
39
|
get drawingWattage(): number;
|
|
42
40
|
get selfConsumingWattage(): number;
|
|
43
|
-
/** @inheritDoc */
|
|
44
|
-
addBatteryLevelCallback(pCallback: (action: BatteryLevelChangeAction) => void): void;
|
|
45
41
|
addExcessConsumer(device: iExcessEnergyConsumer): void;
|
|
46
42
|
/** @inheritDoc */
|
|
47
43
|
dispose(): void;
|
|
@@ -50,8 +46,6 @@ export declare class VictronDevice implements iEnergyManager, iBatteryDevice {
|
|
|
50
46
|
loadDeviceSettings(): void;
|
|
51
47
|
log(level: LogLevel, message: string, debugType?: LogDebugType): void;
|
|
52
48
|
persistDeviceInfo(): void;
|
|
53
|
-
/** @inheritDoc */
|
|
54
|
-
persistBatteryDevice(): void;
|
|
55
49
|
toJSON(): Partial<VictronDevice>;
|
|
56
50
|
/**
|
|
57
51
|
* Changes the grid set point of the Victron device, to the desired value.
|
|
@@ -63,5 +57,4 @@ export declare class VictronDevice implements iEnergyManager, iBatteryDevice {
|
|
|
63
57
|
private turnOffAdditionalConsumer;
|
|
64
58
|
private persist;
|
|
65
59
|
private calculatePersistenceValues;
|
|
66
|
-
private checkForBatteryChange;
|
|
67
60
|
}
|
|
@@ -9,6 +9,8 @@ const victron_mqtt_consumer_1 = require("victron-mqtt-consumer");
|
|
|
9
9
|
const time_callback_service_1 = require("../time-callback-service");
|
|
10
10
|
class VictronDevice {
|
|
11
11
|
constructor(opts) {
|
|
12
|
+
/** @inheritDoc */
|
|
13
|
+
this.jsonOmitKeys = ['_victronConsumer', '_excessEnergyConsumer'];
|
|
12
14
|
/** @inheritDoc */
|
|
13
15
|
this.deviceCapabilities = [
|
|
14
16
|
devices_1.DeviceCapability.energyManager,
|
|
@@ -16,16 +18,14 @@ class VictronDevice {
|
|
|
16
18
|
];
|
|
17
19
|
/** @inheritDoc */
|
|
18
20
|
this.deviceType = devices_1.DeviceType.Victron;
|
|
21
|
+
/** @inheritDoc */
|
|
22
|
+
this.battery = new devices_1.Battery(this);
|
|
19
23
|
this._excessEnergyConsumer = [];
|
|
20
24
|
this.blockDeviceChangeTime = -1;
|
|
21
25
|
this._iCalculationInterval = null;
|
|
22
26
|
this._iDatabaseLoggerInterval = null;
|
|
23
27
|
this._lastPersistenceCalculation = utils_1.Utils.nowMS();
|
|
24
|
-
this._lastBatteryPersist = 0;
|
|
25
|
-
this._lastBatteryLevel = -1;
|
|
26
|
-
this._batteryLevelCallbacks = [];
|
|
27
28
|
this._excessEnergy = 0;
|
|
28
|
-
this._lastBatteryChangeReportMs = 0;
|
|
29
29
|
this.settings = new models_1.VictronDeviceSettings();
|
|
30
30
|
this._info = new devices_1.DeviceInfo();
|
|
31
31
|
this._info.fullName = 'Victron Device';
|
|
@@ -37,7 +37,9 @@ class VictronDevice {
|
|
|
37
37
|
this.loadDeviceSettings();
|
|
38
38
|
this._victronConsumer = new victron_mqtt_consumer_1.VictronMqttConsumer(opts);
|
|
39
39
|
this._iCalculationInterval = utils_1.Utils.guardedInterval(() => {
|
|
40
|
-
this.
|
|
40
|
+
if (this.data.battery.soc) {
|
|
41
|
+
this.battery.level = this.data.battery.soc;
|
|
42
|
+
}
|
|
41
43
|
this.calculateExcessEnergy();
|
|
42
44
|
}, 5 * 1000, this);
|
|
43
45
|
this._iDatabaseLoggerInterval = utils_1.Utils.guardedInterval(() => {
|
|
@@ -50,24 +52,20 @@ class VictronDevice {
|
|
|
50
52
|
if (this.settings.hasBattery) {
|
|
51
53
|
const hours = new Date().getHours();
|
|
52
54
|
if (hours < 6 || hours > 18) {
|
|
53
|
-
return this.
|
|
55
|
+
return this.batteryLevel < this.settings.minimumNightTimeAcBatteryLevel;
|
|
54
56
|
}
|
|
55
57
|
if (hours < 10 || hours > 16) {
|
|
56
|
-
return this.
|
|
58
|
+
return this.batteryLevel < this.settings.minimumTransientTimeAcBatteryLevel;
|
|
57
59
|
}
|
|
58
|
-
return this.
|
|
60
|
+
return this.batteryLevel < this.settings.minimumDayTimeAcBatteryLevel;
|
|
59
61
|
}
|
|
60
62
|
return false;
|
|
61
63
|
}
|
|
62
|
-
/** @inheritDoc */
|
|
63
|
-
get lastBatteryPersist() {
|
|
64
|
-
return this._lastBatteryPersist;
|
|
65
|
-
}
|
|
66
64
|
get info() {
|
|
67
65
|
return this._info;
|
|
68
66
|
}
|
|
69
67
|
/** @inheritDoc */
|
|
70
|
-
get
|
|
68
|
+
get batteryLevel() {
|
|
71
69
|
const level = this.data.battery.soc;
|
|
72
70
|
if (level == null) {
|
|
73
71
|
this.log(models_1.LogLevel.Debug, 'No battery data available from Victron device.');
|
|
@@ -106,10 +104,6 @@ class VictronDevice {
|
|
|
106
104
|
var _a;
|
|
107
105
|
return Math.max((_a = this.victronConsumer.data.system.power) !== null && _a !== void 0 ? _a : 0, 0) - this.drawingWattage;
|
|
108
106
|
}
|
|
109
|
-
/** @inheritDoc */
|
|
110
|
-
addBatteryLevelCallback(pCallback) {
|
|
111
|
-
this._batteryLevelCallbacks.push(pCallback);
|
|
112
|
-
}
|
|
113
107
|
addExcessConsumer(device) {
|
|
114
108
|
this._excessEnergyConsumer.push(device);
|
|
115
109
|
}
|
|
@@ -158,27 +152,17 @@ class VictronDevice {
|
|
|
158
152
|
(_a = utils_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.addDevice(this);
|
|
159
153
|
}, 5000, this);
|
|
160
154
|
}
|
|
161
|
-
/** @inheritDoc */
|
|
162
|
-
persistBatteryDevice() {
|
|
163
|
-
var _a;
|
|
164
|
-
const now = utils_1.Utils.nowMS();
|
|
165
|
-
if (this._lastBatteryPersist + 60000 > now) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
(_a = utils_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistBatteryDevice(this);
|
|
169
|
-
this._lastBatteryPersist = now;
|
|
170
|
-
}
|
|
171
155
|
toJSON() {
|
|
172
156
|
return {
|
|
173
157
|
...{
|
|
174
|
-
|
|
158
|
+
batteryLevel: this.batteryLevel,
|
|
175
159
|
acBlocked: this.acBlocked,
|
|
176
160
|
excessEnergy: this.excessEnergy,
|
|
177
161
|
drawingWattage: this.drawingWattage,
|
|
178
162
|
injectingWattage: this.injectingWattage,
|
|
179
163
|
selfConsumingWattage: this.selfConsumingWattage,
|
|
180
164
|
},
|
|
181
|
-
...utils_1.Utils.jsonFilter(this,
|
|
165
|
+
...utils_1.Utils.jsonFilter(this, this.jsonOmitKeys),
|
|
182
166
|
};
|
|
183
167
|
}
|
|
184
168
|
/**
|
|
@@ -200,11 +184,11 @@ class VictronDevice {
|
|
|
200
184
|
let neededBatteryWattage = 0;
|
|
201
185
|
const timeOfDay = time_callback_service_1.TimeCallbackService.dayType(new time_callback_service_1.SunTimeOffsets());
|
|
202
186
|
if (this.settings.hasBattery && timeOfDay !== models_1.TimeOfDay.AfterSunset && timeOfDay !== models_1.TimeOfDay.Night) {
|
|
203
|
-
if (this.
|
|
187
|
+
if (this.batteryLevel < 0) {
|
|
204
188
|
this.log(models_1.LogLevel.Debug, 'No battery data available from Victron device.');
|
|
205
189
|
return;
|
|
206
190
|
}
|
|
207
|
-
neededBatteryWattage = ((1 - this.
|
|
191
|
+
neededBatteryWattage = ((1 - this.batteryLevel / 100.0) * this.settings.batteryCapacityWattage) / hoursTilSunset;
|
|
208
192
|
// Step 2: Calculate expected solar output
|
|
209
193
|
const solarOutput = (_a = this.data.pvInverter.power) !== null && _a !== void 0 ? _a : 0;
|
|
210
194
|
// Step 3: Calculate expected base consumption
|
|
@@ -213,22 +197,22 @@ class VictronDevice {
|
|
|
213
197
|
this._excessEnergy = solarOutput - neededBatteryWattage - baseConsumption;
|
|
214
198
|
}
|
|
215
199
|
let isSocTooLow = false;
|
|
216
|
-
if (this.data.battery.dcPower !== null && this.
|
|
200
|
+
if (this.data.battery.dcPower !== null && this.batteryLevel > -1) {
|
|
217
201
|
if (timeOfDay === models_1.TimeOfDay.Night) {
|
|
218
|
-
isSocTooLow = this.
|
|
202
|
+
isSocTooLow = this.batteryLevel < 50;
|
|
219
203
|
}
|
|
220
204
|
else if (timeOfDay === models_1.TimeOfDay.AfterSunset) {
|
|
221
|
-
isSocTooLow = this.
|
|
205
|
+
isSocTooLow = this.batteryLevel < 75;
|
|
222
206
|
}
|
|
223
207
|
else if (hoursTilSunset > 4) {
|
|
224
|
-
isSocTooLow = this.
|
|
208
|
+
isSocTooLow = this.batteryLevel < 70;
|
|
225
209
|
}
|
|
226
210
|
else {
|
|
227
|
-
isSocTooLow = this.
|
|
211
|
+
isSocTooLow = this.batteryLevel < 80;
|
|
228
212
|
}
|
|
229
213
|
}
|
|
230
214
|
// Whilst calculated spare energy is more precise, we don't mind using the battery as a buffer, if it is full enough.
|
|
231
|
-
if (this.data.battery.dcPower !== null && this.
|
|
215
|
+
if (this.data.battery.dcPower !== null && this.batteryLevel > -1 && !isSocTooLow) {
|
|
232
216
|
this._excessEnergy = this.settings.maximumBatteryDischargeWattage - Math.max(this.data.battery.dcPower, 0);
|
|
233
217
|
}
|
|
234
218
|
this.calculatePersistenceValues();
|
|
@@ -260,7 +244,7 @@ class VictronDevice {
|
|
|
260
244
|
}
|
|
261
245
|
}
|
|
262
246
|
persist() {
|
|
263
|
-
this._nextPersistEntry.batteryLevel = this.
|
|
247
|
+
this._nextPersistEntry.batteryLevel = this.batteryLevel / 100;
|
|
264
248
|
this._nextPersistEntry.batteryStoredKwH =
|
|
265
249
|
(this._nextPersistEntry.batteryLevel * this.settings.batteryCapacityWattage) / 1000;
|
|
266
250
|
const obj = JSON.parse(JSON.stringify(this._nextPersistEntry));
|
|
@@ -277,18 +261,5 @@ class VictronDevice {
|
|
|
277
261
|
this._nextPersistEntry.selfConsumedKwH += utils_1.Utils.kWh(this.selfConsumingWattage, duration);
|
|
278
262
|
this._lastPersistenceCalculation = now;
|
|
279
263
|
}
|
|
280
|
-
checkForBatteryChange() {
|
|
281
|
-
const newLevel = this.battery;
|
|
282
|
-
if (newLevel == this._lastBatteryLevel &&
|
|
283
|
-
(this.settings.batteryReportingInterval < 0 ||
|
|
284
|
-
utils_1.Utils.nowMS() - this._lastBatteryChangeReportMs < this.settings.batteryReportingInterval * 60 * 1000)) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
this._lastBatteryChangeReportMs = utils_1.Utils.nowMS();
|
|
288
|
-
for (const cb of this._batteryLevelCallbacks) {
|
|
289
|
-
cb(new models_1.BatteryLevelChangeAction(this));
|
|
290
|
-
}
|
|
291
|
-
this._lastBatteryLevel = newLevel;
|
|
292
|
-
}
|
|
293
264
|
}
|
|
294
265
|
exports.VictronDevice = VictronDevice;
|