hoffmation-base 3.0.0-alpha.41 → 3.0.0-alpha.42

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 (46) hide show
  1. package/lib/index.js +6 -3
  2. package/lib/models/action/batteryLevelChangeAction.d.ts +13 -0
  3. package/lib/models/action/batteryLevelChangeAction.js +14 -0
  4. package/lib/models/action/index.d.ts +1 -0
  5. package/lib/models/action/index.js +3 -1
  6. package/lib/models/command/blockAutomaticUntilCommand.js +1 -1
  7. package/lib/models/command/commandType.d.ts +1 -0
  8. package/lib/models/command/commandType.js +1 -0
  9. package/lib/models/deviceSettings/dachsSettings.d.ts +8 -0
  10. package/lib/models/deviceSettings/dachsSettings.js +10 -1
  11. package/lib/server/devices/baseDeviceInterfaces/iBatteryDevice.d.ts +9 -3
  12. package/lib/server/devices/dachs/dachs.d.ts +6 -2
  13. package/lib/server/devices/dachs/dachs.js +19 -2
  14. package/lib/server/devices/groups/lightGroup.js +2 -3
  15. package/lib/server/devices/hmIPDevices/hmIpGriff.d.ts +9 -0
  16. package/lib/server/devices/hmIPDevices/hmIpGriff.js +21 -0
  17. package/lib/server/devices/hmIPDevices/hmIpHeizung.d.ts +12 -3
  18. package/lib/server/devices/hmIPDevices/hmIpHeizung.js +32 -12
  19. package/lib/server/devices/hmIPDevices/hmIpPraezenz.d.ts +9 -1
  20. package/lib/server/devices/hmIPDevices/hmIpPraezenz.js +20 -0
  21. package/lib/server/devices/hmIPDevices/hmIpTaster.d.ts +13 -4
  22. package/lib/server/devices/hmIPDevices/hmIpTaster.js +28 -8
  23. package/lib/server/devices/hmIPDevices/hmIpTherm.d.ts +10 -1
  24. package/lib/server/devices/hmIPDevices/hmIpTherm.js +25 -5
  25. package/lib/server/devices/shelly/shellyTrv.d.ts +9 -1
  26. package/lib/server/devices/shelly/shellyTrv.js +20 -0
  27. package/lib/server/devices/zigbee/BaseDevices/zigbeeHeater.d.ts +19 -11
  28. package/lib/server/devices/zigbee/BaseDevices/zigbeeHeater.js +47 -27
  29. package/lib/server/devices/zigbee/BaseDevices/zigbeeMagnetContact.d.ts +16 -7
  30. package/lib/server/devices/zigbee/BaseDevices/zigbeeMagnetContact.js +45 -25
  31. package/lib/server/devices/zigbee/BaseDevices/zigbeeMotionSensor.d.ts +9 -1
  32. package/lib/server/devices/zigbee/BaseDevices/zigbeeMotionSensor.js +20 -0
  33. package/lib/server/devices/zigbee/zigbeeAquaraVibra.d.ts +9 -0
  34. package/lib/server/devices/zigbee/zigbeeAquaraVibra.js +20 -0
  35. package/lib/server/devices/zigbee/zigbeeAquaraWater.d.ts +18 -9
  36. package/lib/server/devices/zigbee/zigbeeAquaraWater.js +44 -24
  37. package/lib/server/devices/zigbee/zigbeeHeimanSmoke.d.ts +21 -12
  38. package/lib/server/devices/zigbee/zigbeeHeimanSmoke.js +37 -17
  39. package/lib/server/devices/zigbee/zigbeeSonoffTemp.d.ts +17 -9
  40. package/lib/server/devices/zigbee/zigbeeSonoffTemp.js +30 -10
  41. package/lib/server/services/ac/own-daikin-device.d.ts +8 -0
  42. package/lib/server/services/ac/own-daikin-device.js +8 -0
  43. package/lib/server/services/victron/victron-device.d.ts +15 -4
  44. package/lib/server/services/victron/victron-device.js +54 -12
  45. package/lib/tsconfig.tsbuildinfo +1 -1
  46. package/package.json +1 -1
@@ -4,14 +4,16 @@ exports.VictronDevice = void 0;
4
4
  const devices_1 = require("../../devices");
5
5
  const utils_1 = require("../utils");
6
6
  const models_1 = require("../../../models");
7
- const DeviceCapability_1 = require("../../devices/DeviceCapability");
8
7
  const log_service_1 = require("../log-service");
9
8
  const victron_mqtt_consumer_1 = require("victron-mqtt-consumer");
10
9
  const time_callback_service_1 = require("../time-callback-service");
11
10
  class VictronDevice {
12
11
  constructor(opts) {
13
12
  /** @inheritDoc */
14
- this.deviceCapabilities = [DeviceCapability_1.DeviceCapability.energyManager];
13
+ this.deviceCapabilities = [
14
+ devices_1.DeviceCapability.energyManager,
15
+ devices_1.DeviceCapability.batteryDriven,
16
+ ];
15
17
  /** @inheritDoc */
16
18
  this.deviceType = devices_1.DeviceType.Victron;
17
19
  this._excessEnergyConsumer = [];
@@ -19,6 +21,9 @@ class VictronDevice {
19
21
  this._iCalculationInterval = null;
20
22
  this._iDatabaseLoggerInterval = null;
21
23
  this._lastPersistenceCalculation = utils_1.Utils.nowMS();
24
+ this._lastBatteryPersist = 0;
25
+ this._lastBatteryLevel = -1;
26
+ this._batteryLevelCallbacks = [];
22
27
  this._excessEnergy = 0;
23
28
  this.settings = new models_1.VictronDeviceSettings();
24
29
  this._info = new devices_1.DeviceInfo();
@@ -31,6 +36,7 @@ class VictronDevice {
31
36
  this.loadDeviceSettings();
32
37
  this._victronConsumer = new victron_mqtt_consumer_1.VictronMqttConsumer(opts);
33
38
  this._iCalculationInterval = utils_1.Utils.guardedInterval(() => {
39
+ this.checkForBatteryChange();
34
40
  this.calculateExcessEnergy();
35
41
  }, 5 * 1000, this);
36
42
  this._iDatabaseLoggerInterval = utils_1.Utils.guardedInterval(() => {
@@ -38,9 +44,22 @@ class VictronDevice {
38
44
  }, 15 * 60 * 1000, this);
39
45
  this._nextPersistEntry = new models_1.EnergyCalculation(utils_1.Utils.nowMS());
40
46
  }
47
+ /** @inheritDoc */
48
+ get lastBatteryPersist() {
49
+ return this._lastBatteryPersist;
50
+ }
41
51
  get info() {
42
52
  return this._info;
43
53
  }
54
+ /** @inheritDoc */
55
+ get battery() {
56
+ const level = this.data.battery.soc;
57
+ if (level == null) {
58
+ this.log(models_1.LogLevel.Debug, 'No battery data available from Victron device.');
59
+ return -1;
60
+ }
61
+ return level * 100;
62
+ }
44
63
  get victronConsumer() {
45
64
  return this._victronConsumer;
46
65
  }
@@ -60,6 +79,10 @@ class VictronDevice {
60
79
  var _a;
61
80
  return (_a = this.info.allDevicesKey) !== null && _a !== void 0 ? _a : `victron-${this.info.room}-${this.info.customName}`;
62
81
  }
82
+ /** @inheritDoc */
83
+ addBatteryLevelCallback(pCallback) {
84
+ this._batteryLevelCallbacks.push(pCallback);
85
+ }
63
86
  addExcessConsumer(device) {
64
87
  this._excessEnergyConsumer.push(device);
65
88
  }
@@ -120,6 +143,16 @@ class VictronDevice {
120
143
  (_a = utils_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.addDevice(this);
121
144
  }, 5000, this);
122
145
  }
146
+ /** @inheritDoc */
147
+ persistBatteryDevice() {
148
+ var _a;
149
+ const now = utils_1.Utils.nowMS();
150
+ if (this._lastBatteryPersist + 60000 > now) {
151
+ return;
152
+ }
153
+ (_a = utils_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistBatteryDevice(this);
154
+ this._lastBatteryPersist = now;
155
+ }
123
156
  toJSON() {
124
157
  return utils_1.Utils.jsonFilter(this, ['_victronConsumer']);
125
158
  }
@@ -142,11 +175,11 @@ class VictronDevice {
142
175
  let neededBatteryWattage = 0;
143
176
  const timeOfDay = time_callback_service_1.TimeCallbackService.dayType(new time_callback_service_1.SunTimeOffsets());
144
177
  if (this.settings.hasBattery && timeOfDay !== models_1.TimeOfDay.AfterSunset && timeOfDay !== models_1.TimeOfDay.Night) {
145
- if (this.data.battery.soc == null) {
178
+ if (this.battery < 0) {
146
179
  this.log(models_1.LogLevel.Debug, 'No battery data available from Victron device.');
147
180
  return;
148
181
  }
149
- neededBatteryWattage = ((1 - this.data.battery.soc) * this.settings.batteryCapacityWattage) / hoursTilSunset;
182
+ neededBatteryWattage = ((1 - this.battery / 100.0) * this.settings.batteryCapacityWattage) / hoursTilSunset;
150
183
  // Step 2: Calculate expected solar output
151
184
  const solarOutput = (_a = this.data.pvInverter.power) !== null && _a !== void 0 ? _a : 0;
152
185
  // Step 3: Calculate expected base consumption
@@ -155,22 +188,22 @@ class VictronDevice {
155
188
  this._excessEnergy = solarOutput - neededBatteryWattage - baseConsumption;
156
189
  }
157
190
  let isSocTooLow = false;
158
- if (this.data.battery.dcPower !== null && this.data.battery.soc !== null) {
191
+ if (this.data.battery.dcPower !== null && this.battery > -1) {
159
192
  if (timeOfDay === models_1.TimeOfDay.Night) {
160
- isSocTooLow = this.data.battery.soc < 0.5;
193
+ isSocTooLow = this.battery < 50;
161
194
  }
162
195
  else if (timeOfDay === models_1.TimeOfDay.AfterSunset) {
163
- isSocTooLow = this.data.battery.soc < 0.75;
196
+ isSocTooLow = this.battery < 75;
164
197
  }
165
198
  else if (hoursTilSunset > 4) {
166
- isSocTooLow = this.data.battery.soc < 0.7;
199
+ isSocTooLow = this.battery < 70;
167
200
  }
168
201
  else {
169
- isSocTooLow = this.data.battery.soc < 0.8;
202
+ isSocTooLow = this.battery < 80;
170
203
  }
171
204
  }
172
205
  // Whilst calculated spare energy is more precise, we don't mind using the battery as a buffer, if it is full enough.
173
- if (this.data.battery.dcPower !== null && this.data.battery.soc !== null && !isSocTooLow) {
206
+ if (this.data.battery.dcPower !== null && this.battery > -1 && !isSocTooLow) {
174
207
  this._excessEnergy = this.settings.maximumBatteryDischargeWattage - Math.max(this.data.battery.dcPower, 0);
175
208
  }
176
209
  this.calculatePersistenceValues();
@@ -202,8 +235,7 @@ class VictronDevice {
202
235
  }
203
236
  }
204
237
  persist() {
205
- var _a;
206
- this._nextPersistEntry.batteryLevel = ((_a = this.data.battery.soc) !== null && _a !== void 0 ? _a : 0) / 100;
238
+ this._nextPersistEntry.batteryLevel = this.battery / 100;
207
239
  this._nextPersistEntry.batteryStoredKwH =
208
240
  (this._nextPersistEntry.batteryLevel * this.settings.batteryCapacityWattage) / 1000;
209
241
  const obj = JSON.parse(JSON.stringify(this._nextPersistEntry));
@@ -220,5 +252,15 @@ class VictronDevice {
220
252
  this._nextPersistEntry.selfConsumedKwH += utils_1.Utils.kWh(this.selfConsumingWattage, duration);
221
253
  this._lastPersistenceCalculation = now;
222
254
  }
255
+ checkForBatteryChange() {
256
+ const newLevel = this.battery;
257
+ if (newLevel == this._lastBatteryLevel) {
258
+ return;
259
+ }
260
+ for (const cb of this._batteryLevelCallbacks) {
261
+ cb(new models_1.BatteryLevelChangeAction(this));
262
+ }
263
+ this._lastBatteryLevel = newLevel;
264
+ }
223
265
  }
224
266
  exports.VictronDevice = VictronDevice;