iobroker.zendure-solarflow 2.0.4 → 3.0.0-alpha.3

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 (68) hide show
  1. package/README.md +8 -5
  2. package/admin/build/index.js +35 -35
  3. package/admin/build/index.js.map +2 -2
  4. package/build/constants/constants.js +41 -0
  5. package/build/constants/constants.js.map +7 -0
  6. package/build/helpers/helpers.js +93 -96
  7. package/build/helpers/helpers.js.map +2 -2
  8. package/build/main.js +108 -180
  9. package/build/main.js.map +2 -2
  10. package/build/models/IDeviceAutomationPayload.js.map +1 -1
  11. package/build/models/{IPack2Device.js → IDevicePack.js} +3 -3
  12. package/build/models/IDevicePack.js.map +7 -0
  13. package/build/models/{ISolarFlowDeviceDetails.js → IHaDeviceListData.js} +3 -3
  14. package/build/models/IHaDeviceListData.js.map +7 -0
  15. package/build/models/{ISolarflowDevRegisterResponse.js → IZenHaDeviceDetails.js} +3 -3
  16. package/build/models/IZenHaDeviceDetails.js.map +7 -0
  17. package/build/models/{ISolarFlowPaths.js → IZenHaMqttData.js} +3 -3
  18. package/build/models/IZenHaMqttData.js.map +7 -0
  19. package/build/models/deviceModels/Ace1500.js +77 -0
  20. package/build/models/deviceModels/Ace1500.js.map +7 -0
  21. package/build/models/deviceModels/Aio2400.js +121 -0
  22. package/build/models/deviceModels/Aio2400.js.map +7 -0
  23. package/build/models/deviceModels/Hyper2000.js +200 -0
  24. package/build/models/deviceModels/Hyper2000.js.map +7 -0
  25. package/build/models/deviceModels/Sf2400Ac.js +146 -0
  26. package/build/models/deviceModels/Sf2400Ac.js.map +7 -0
  27. package/build/models/deviceModels/Sf800.js +144 -0
  28. package/build/models/deviceModels/Sf800.js.map +7 -0
  29. package/build/models/deviceModels/SfHub1200.js +179 -0
  30. package/build/models/deviceModels/SfHub1200.js.map +7 -0
  31. package/build/models/deviceModels/SfHub2000.js +177 -0
  32. package/build/models/deviceModels/SfHub2000.js.map +7 -0
  33. package/build/models/deviceModels/ZenHaDevice.js +1093 -0
  34. package/build/models/deviceModels/ZenHaDevice.js.map +7 -0
  35. package/build/services/jobSchedule.js +19 -58
  36. package/build/services/jobSchedule.js.map +2 -2
  37. package/build/services/mqttCloudZenService.js +79 -0
  38. package/build/services/mqttCloudZenService.js.map +7 -0
  39. package/build/services/mqttLocalService.js +70 -0
  40. package/build/services/mqttLocalService.js.map +7 -0
  41. package/build/services/mqttSharedService.js +432 -0
  42. package/build/services/mqttSharedService.js.map +7 -0
  43. package/build/services/zenWebService.js +84 -0
  44. package/build/services/zenWebService.js.map +7 -0
  45. package/io-package.json +70 -27
  46. package/package.json +2 -2
  47. package/build/constants/paths.js +0 -52
  48. package/build/constants/paths.js.map +0 -7
  49. package/build/helpers/createSolarFlowLocalStates.js +0 -113
  50. package/build/helpers/createSolarFlowLocalStates.js.map +0 -7
  51. package/build/helpers/createSolarFlowStates.js +0 -193
  52. package/build/helpers/createSolarFlowStates.js.map +0 -7
  53. package/build/models/IPack2Device.js.map +0 -7
  54. package/build/models/ISolarFlowDeviceDetails.js.map +0 -7
  55. package/build/models/ISolarFlowPaths.js.map +0 -7
  56. package/build/models/ISolarflowDevRegisterResponse.js.map +0 -7
  57. package/build/services/adapterService.js +0 -142
  58. package/build/services/adapterService.js.map +0 -7
  59. package/build/services/calculationService.js +0 -350
  60. package/build/services/calculationService.js.map +0 -7
  61. package/build/services/fallbackMqttService.js +0 -461
  62. package/build/services/fallbackMqttService.js.map +0 -7
  63. package/build/services/fallbackWebService.js +0 -80
  64. package/build/services/fallbackWebService.js.map +0 -7
  65. package/build/services/mqttService.js +0 -1545
  66. package/build/services/mqttService.js.map +0 -7
  67. package/build/services/webService.js +0 -119
  68. package/build/services/webService.js.map +0 -7
@@ -0,0 +1,1093 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var ZenHaDevice_exports = {};
20
+ __export(ZenHaDevice_exports, {
21
+ ZenHaDevice: () => ZenHaDevice
22
+ });
23
+ module.exports = __toCommonJS(ZenHaDevice_exports);
24
+ var import_constants = require("../../constants/constants");
25
+ var import_createCalculationStates = require("../../helpers/createCalculationStates");
26
+ var import_timeHelper = require("../../helpers/timeHelper");
27
+ var import_mqttSharedService = require("../../services/mqttSharedService");
28
+ class ZenHaDevice {
29
+ constructor(_adapter, _productKey, _deviceKey, _productName, _deviceName, _zenHaDeviceDetails) {
30
+ this.batteries = [];
31
+ this.iotTopic = "";
32
+ this.functionTopic = "";
33
+ this.maxInputLimit = 0;
34
+ this.maxOutputLimit = 0;
35
+ this.states = [];
36
+ this.controlStates = [];
37
+ this.addOrUpdatePackData = async (packData, isSolarFlow) => {
38
+ if (this.adapter && this.productKey && this.deviceKey) {
39
+ await packData.forEach(async (x) => {
40
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
41
+ if (x.sn && this.adapter) {
42
+ let batType = "";
43
+ if (this.productKey == "yWF7hV") {
44
+ batType = "AIO2400";
45
+ } else if (x.sn.startsWith("A")) {
46
+ batType = "AB1000";
47
+ } else if (x.sn.startsWith("B")) {
48
+ batType = "AB1000S";
49
+ } else if (x.sn.startsWith("C")) {
50
+ if (x.sn[3] == "F") {
51
+ batType = "AB2000S";
52
+ } else {
53
+ batType = "AB2000";
54
+ }
55
+ } else if (x.sn.startsWith("F")) {
56
+ batType = "AB3000X";
57
+ }
58
+ if (!this.batteries.some((y) => y.packSn == x.sn)) {
59
+ this.batteries.push({
60
+ packSn: x.sn,
61
+ type: batType
62
+ });
63
+ this.adapter.log.debug(
64
+ `[addOrUpdatePackData] Added battery ${batType} with SN ${x.sn} on deviceKey ${this.deviceKey} to batteries array!`
65
+ );
66
+ }
67
+ const key = (this.productKey + "." + this.deviceKey + ".packData." + x.sn).replace(this.adapter.FORBIDDEN_CHARS, "");
68
+ await ((_a = this.adapter) == null ? void 0 : _a.extendObject(key, {
69
+ type: "channel",
70
+ common: {
71
+ name: {
72
+ de: batType,
73
+ en: batType
74
+ }
75
+ },
76
+ native: {}
77
+ }));
78
+ await ((_b = this.adapter) == null ? void 0 : _b.extendObject(key + ".model", {
79
+ type: "state",
80
+ common: {
81
+ name: {
82
+ de: "Batterietyp",
83
+ en: "Battery type"
84
+ },
85
+ type: "string",
86
+ desc: "model",
87
+ role: "value",
88
+ read: true,
89
+ write: false
90
+ },
91
+ native: {}
92
+ }));
93
+ await ((_c = this.adapter) == null ? void 0 : _c.setState(key + ".model", batType, true));
94
+ await ((_d = this.adapter) == null ? void 0 : _d.extendObject(key + ".sn", {
95
+ type: "state",
96
+ common: {
97
+ name: {
98
+ de: "Seriennummer",
99
+ en: "Serial id"
100
+ },
101
+ type: "string",
102
+ desc: "Serial ID",
103
+ role: "value",
104
+ read: true,
105
+ write: false
106
+ },
107
+ native: {}
108
+ }));
109
+ await ((_e = this.adapter) == null ? void 0 : _e.setState(key + ".sn", x.sn, true));
110
+ if (x.socLevel) {
111
+ await ((_f = this.adapter) == null ? void 0 : _f.extendObject(key + ".socLevel", {
112
+ type: "state",
113
+ common: {
114
+ name: {
115
+ de: "SOC der Batterie",
116
+ en: "soc of battery"
117
+ },
118
+ type: "number",
119
+ desc: "SOC Level",
120
+ role: "value",
121
+ read: true,
122
+ write: false,
123
+ unit: "%"
124
+ },
125
+ native: {}
126
+ }));
127
+ await ((_g = this.adapter) == null ? void 0 : _g.setState(key + ".socLevel", x.socLevel, true));
128
+ }
129
+ if (x.maxTemp) {
130
+ await ((_h = this.adapter) == null ? void 0 : _h.extendObject(key + ".maxTemp", {
131
+ type: "state",
132
+ common: {
133
+ name: {
134
+ de: "Max. Temperatur der Batterie",
135
+ en: "max temp. of battery"
136
+ },
137
+ type: "number",
138
+ desc: "Max. Temp",
139
+ role: "value",
140
+ read: true,
141
+ write: false,
142
+ unit: "\xB0C"
143
+ },
144
+ native: {}
145
+ }));
146
+ await ((_i = this.adapter) == null ? void 0 : _i.setState(
147
+ key + ".maxTemp",
148
+ x.maxTemp / 10 - 273.15,
149
+ true
150
+ ));
151
+ }
152
+ if (x.minVol) {
153
+ await ((_j = this.adapter) == null ? void 0 : _j.extendObject(key + ".minVol", {
154
+ type: "state",
155
+ common: {
156
+ name: "minVol",
157
+ type: "number",
158
+ desc: "minVol",
159
+ role: "value",
160
+ read: true,
161
+ write: false,
162
+ unit: "V"
163
+ },
164
+ native: {}
165
+ }));
166
+ await ((_k = this.adapter) == null ? void 0 : _k.setState(key + ".minVol", x.minVol / 100, true));
167
+ }
168
+ if (x.batcur) {
169
+ await ((_l = this.adapter) == null ? void 0 : _l.extendObject(key + ".batcur", {
170
+ type: "state",
171
+ common: {
172
+ name: "batcur",
173
+ type: "number",
174
+ desc: "batcur",
175
+ role: "value",
176
+ read: true,
177
+ write: false,
178
+ unit: "A"
179
+ },
180
+ native: {}
181
+ }));
182
+ await ((_m = this.adapter) == null ? void 0 : _m.setState(key + ".batcur", x.batcur / 10, true));
183
+ }
184
+ if (x.maxVol) {
185
+ await ((_n = this.adapter) == null ? void 0 : _n.extendObject(key + ".maxVol", {
186
+ type: "state",
187
+ common: {
188
+ name: "maxVol",
189
+ type: "number",
190
+ desc: "maxVol",
191
+ role: "value",
192
+ read: true,
193
+ write: false,
194
+ unit: "V"
195
+ },
196
+ native: {}
197
+ }));
198
+ await ((_o = this.adapter) == null ? void 0 : _o.setState(key + ".maxVol", x.maxVol / 100, true));
199
+ }
200
+ if (x.totalVol) {
201
+ await ((_p = this.adapter) == null ? void 0 : _p.extendObject(key + ".totalVol", {
202
+ type: "state",
203
+ common: {
204
+ name: "totalVol",
205
+ type: "number",
206
+ desc: "totalVol",
207
+ role: "value",
208
+ read: true,
209
+ write: false,
210
+ unit: "V"
211
+ },
212
+ native: {}
213
+ }));
214
+ const totalVol = x.totalVol / 100;
215
+ await ((_q = this.adapter) == null ? void 0 : _q.setState(key + ".totalVol", totalVol, true));
216
+ if (isSolarFlow) {
217
+ this.checkVoltage(totalVol);
218
+ }
219
+ }
220
+ if (x.soh) {
221
+ await ((_r = this.adapter) == null ? void 0 : _r.extendObject(key + ".soh", {
222
+ type: "state",
223
+ common: {
224
+ name: {
225
+ de: "Gesundheitszustand",
226
+ en: "State of Health"
227
+ },
228
+ type: "number",
229
+ desc: "State of Health",
230
+ role: "value",
231
+ read: true,
232
+ write: false,
233
+ unit: "%"
234
+ },
235
+ native: {}
236
+ }));
237
+ await ((_s = this.adapter) == null ? void 0 : _s.setState(key + ".soh", x.soh / 10, true));
238
+ }
239
+ if (x.power) {
240
+ await ((_t = this.adapter) == null ? void 0 : _t.extendObject(key + ".power", {
241
+ type: "state",
242
+ common: {
243
+ name: {
244
+ de: "Energie",
245
+ en: "Power"
246
+ },
247
+ type: "number",
248
+ desc: "Power",
249
+ read: true,
250
+ write: false,
251
+ role: "value.power",
252
+ unit: "W"
253
+ },
254
+ native: {}
255
+ }));
256
+ await ((_u = this.adapter) == null ? void 0 : _u.setState(key + ".power", x.power, true));
257
+ }
258
+ let found = false;
259
+ Object.entries(x).forEach(([key2, value]) => {
260
+ var _a2;
261
+ import_mqttSharedService.knownPackDataProperties.forEach((property) => {
262
+ if (property == key2) {
263
+ found = true;
264
+ }
265
+ });
266
+ if (found) {
267
+ } else {
268
+ (_a2 = this.adapter) == null ? void 0 : _a2.log.debug(
269
+ `[addOrUpdatePackData] ${key2} with value ${value} is a UNKNOWN PackData Mqtt Property!`
270
+ );
271
+ }
272
+ });
273
+ }
274
+ });
275
+ }
276
+ };
277
+ this.calculateSocAndEnergy = async (stateKey, value) => {
278
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
279
+ this.adapter.log.debug(
280
+ `[calculateSocAndEnergy] Calculating for: ${this.productKey}.${this.deviceKey} and stateKey ${stateKey}!`
281
+ );
282
+ let energyWhMax = void 0;
283
+ const minSoc = (_a = await this.adapter.getStateAsync(
284
+ `${this.productKey}.${this.deviceKey}.minSoc`
285
+ )) == null ? void 0 : _a.val;
286
+ const currentSoc = (_b = await this.adapter.getStateAsync(
287
+ `${this.productKey}.${this.deviceKey}.electricLevel`
288
+ )) == null ? void 0 : _b.val;
289
+ if (currentSoc && minSoc && Number(currentSoc) < Number(minSoc)) {
290
+ this.adapter.log.debug(
291
+ `[calculateSocAndEnergy] Don't calculate, currentSoc (${Number(currentSoc)}) is lower than minSoc (${Number(minSoc)})!`
292
+ );
293
+ return;
294
+ }
295
+ const currentEnergyState = await ((_c = this.adapter) == null ? void 0 : _c.getStateAsync(
296
+ this.productKey + "." + this.deviceKey + ".calculations.energyWh"
297
+ ));
298
+ const currentEnergyMaxState = await ((_d = this.adapter) == null ? void 0 : _d.getStateAsync(
299
+ this.productKey + "." + this.deviceKey + ".calculations.energyWhMax"
300
+ ));
301
+ const lowVoltageBlock = await ((_e = this.adapter) == null ? void 0 : _e.getStateAsync(
302
+ this.productKey + "." + this.deviceKey + ".control.lowVoltageBlock"
303
+ ));
304
+ const currentMaxValue = Number(
305
+ currentEnergyMaxState ? currentEnergyMaxState.val : 0
306
+ );
307
+ const currentEnergyWh = (currentEnergyState == null ? void 0 : currentEnergyState.val) ? Number(currentEnergyState == null ? void 0 : currentEnergyState.val) : 0;
308
+ if (this.productKey == "yWF7hV") {
309
+ energyWhMax = 2400;
310
+ } else {
311
+ for (let i = 0; i < this.batteries.length; i++) {
312
+ if (this.batteries[i].type == "AB1000") {
313
+ energyWhMax = (energyWhMax ? energyWhMax : 0) + 960;
314
+ } else if (this.batteries[i].type == "AB2000") {
315
+ energyWhMax = (energyWhMax ? energyWhMax : 0) + 1920;
316
+ }
317
+ }
318
+ }
319
+ let newEnergyWh = stateKey == "outputPack" ? currentEnergyWh + value : currentEnergyWh - value;
320
+ if (stateKey == "outputPack" && energyWhMax != void 0 && newEnergyWh > energyWhMax) {
321
+ newEnergyWh = energyWhMax;
322
+ this.adapter.log.debug(
323
+ `[calculateSocAndEnergy] newEnergyWh (${newEnergyWh}) is greater than energyWhMax (${energyWhMax}), don't extend value!`
324
+ );
325
+ }
326
+ if (newEnergyWh > 0) {
327
+ (_f = this.adapter) == null ? void 0 : _f.setState(
328
+ `${this.productKey}.${this.deviceKey}.calculations.energyWh`,
329
+ newEnergyWh,
330
+ true
331
+ );
332
+ this.adapter.log.debug(
333
+ `[calculateSocAndEnergy] set '${this.productKey}.${this.deviceKey}.calculations.energyWh' to ${newEnergyWh}!`
334
+ );
335
+ if (currentEnergyMaxState) {
336
+ const soc = Number((newEnergyWh / currentMaxValue * 100).toFixed(1));
337
+ await ((_g = this.adapter) == null ? void 0 : _g.setState(
338
+ `${this.productKey}.${this.deviceKey}.calculations.soc`,
339
+ soc > 100 ? 100 : soc,
340
+ true
341
+ ));
342
+ if (newEnergyWh > currentMaxValue && !(lowVoltageBlock == null ? void 0 : lowVoltageBlock.val)) {
343
+ await ((_h = this.adapter) == null ? void 0 : _h.setState(
344
+ `${this.productKey}.${this.deviceKey}.calculations.energyWhMax`,
345
+ newEnergyWh,
346
+ true
347
+ ));
348
+ }
349
+ const currentOutputPackPower = await ((_i = this.adapter) == null ? void 0 : _i.getStateAsync(
350
+ `${this.productKey}.${this.deviceKey}.outputPackPower`
351
+ ));
352
+ const currentPackInputPower = await ((_j = this.adapter) == null ? void 0 : _j.getStateAsync(
353
+ this.productKey + "." + this.deviceKey + ".packInputPower"
354
+ ));
355
+ if (stateKey == "outputPack" && (currentOutputPackPower == null ? void 0 : currentOutputPackPower.val) != null && currentOutputPackPower != void 0) {
356
+ const toCharge = currentMaxValue - newEnergyWh;
357
+ const remainHoursAsDecimal = toCharge / Number(currentOutputPackPower.val);
358
+ if (remainHoursAsDecimal < 48) {
359
+ const remainFormatted = (0, import_timeHelper.toHoursAndMinutes)(
360
+ Math.round(remainHoursAsDecimal * 60)
361
+ );
362
+ await ((_k = this.adapter) == null ? void 0 : _k.setState(
363
+ `${this.productKey}.${this.deviceKey}.calculations.remainInputTime`,
364
+ remainFormatted,
365
+ true
366
+ ));
367
+ } else {
368
+ await ((_l = this.adapter) == null ? void 0 : _l.setState(
369
+ `${this.productKey}.${this.deviceKey}.calculations.remainInputTime`,
370
+ "",
371
+ true
372
+ ));
373
+ }
374
+ } else if (stateKey == "packInput" && currentPackInputPower != null && currentPackInputPower != void 0) {
375
+ const remainHoursAsDecimal = newEnergyWh / Number(currentPackInputPower.val);
376
+ const remainFormatted = (0, import_timeHelper.toHoursAndMinutes)(
377
+ Math.round(remainHoursAsDecimal * 60)
378
+ );
379
+ if (remainHoursAsDecimal < 48) {
380
+ await ((_m = this.adapter) == null ? void 0 : _m.setState(
381
+ `${this.productKey}.${this.deviceKey}.calculations.remainOutTime`,
382
+ remainFormatted,
383
+ true
384
+ ));
385
+ } else {
386
+ await ((_n = this.adapter) == null ? void 0 : _n.setState(
387
+ `${this.productKey}.${this.deviceKey}.calculations.remainOutTime`,
388
+ "",
389
+ true
390
+ ));
391
+ }
392
+ }
393
+ }
394
+ } else if (newEnergyWh <= 0 && stateKey == "outputPack") {
395
+ await ((_o = this.adapter) == null ? void 0 : _o.setState(
396
+ `${this.productKey}.${this.deviceKey}.calculations.remainInputTime`,
397
+ "",
398
+ true
399
+ ));
400
+ } else if (newEnergyWh <= 0 && stateKey == "packInput") {
401
+ await ((_p = this.adapter) == null ? void 0 : _p.setState(
402
+ `${this.productKey}.${this.deviceKey}.calculations.remainOutTime`,
403
+ "",
404
+ true
405
+ ));
406
+ const newEnergyWhPositive = Math.abs(newEnergyWh);
407
+ if (energyWhMax && currentMaxValue + newEnergyWhPositive <= energyWhMax) {
408
+ await ((_q = this.adapter) == null ? void 0 : _q.setState(
409
+ `${this.productKey}.${this.deviceKey}.calculations.energyWhMax`,
410
+ currentMaxValue + newEnergyWhPositive,
411
+ true
412
+ ));
413
+ }
414
+ }
415
+ };
416
+ var _a, _b;
417
+ this.zenHaDeviceDetails = _zenHaDeviceDetails;
418
+ this.adapter = _adapter;
419
+ this.productKey = _productKey;
420
+ this.deviceKey = _deviceKey;
421
+ this.deviceName = _deviceName;
422
+ this.productName = _productName;
423
+ this.iotTopic = `iot/${_productKey}/${_deviceKey}/properties/write`;
424
+ this.functionTopic = `iot/${_productKey}/${_deviceKey}/function/invoke`;
425
+ this.createSolarFlowStates();
426
+ this.subscribeReportTopic();
427
+ this.subscribeIotTopic();
428
+ this.adapter.setTimeout(() => {
429
+ this.triggerFullTelemetryUpdate();
430
+ }, 5e3);
431
+ if ((_a = this.zenHaDeviceDetails) == null ? void 0 : _a.online) {
432
+ this.updateSolarFlowState("wifiState", "Connected");
433
+ } else if (((_b = this.zenHaDeviceDetails) == null ? void 0 : _b.online) == false) {
434
+ this.updateSolarFlowState("wifiState", "Disconnected");
435
+ }
436
+ }
437
+ async createSolarFlowStates() {
438
+ var _a, _b, _c, _d, _e;
439
+ const productKey = this.productKey.replace(
440
+ this.adapter.FORBIDDEN_CHARS,
441
+ ""
442
+ );
443
+ const deviceKey = this.deviceKey.replace(this.adapter.FORBIDDEN_CHARS, "");
444
+ this.adapter.log.debug(
445
+ `[createSolarFlowStates] Creating or updating SolarFlow states for ${this.productName} (${productKey}/${deviceKey}) and name '${this.deviceName}'.`
446
+ );
447
+ await ((_a = this.adapter) == null ? void 0 : _a.extendObject(productKey, {
448
+ type: "device",
449
+ common: {
450
+ name: {
451
+ de: `${this.productName} (${productKey})`,
452
+ en: `${this.productName} (${productKey})`
453
+ }
454
+ },
455
+ native: {}
456
+ }));
457
+ await ((_b = this.adapter) == null ? void 0 : _b.extendObject(productKey + "." + deviceKey, {
458
+ type: "channel",
459
+ common: {
460
+ name: {
461
+ de: `${this.deviceName} (${deviceKey})`,
462
+ en: `${this.deviceName} (${deviceKey})`
463
+ }
464
+ },
465
+ native: {}
466
+ }));
467
+ await ((_c = this.adapter) == null ? void 0 : _c.extendObject(`${productKey}.${deviceKey}.packData`, {
468
+ type: "channel",
469
+ common: {
470
+ name: {
471
+ de: "Batterie Packs",
472
+ en: "Battery packs"
473
+ }
474
+ },
475
+ native: {}
476
+ }));
477
+ this.states.forEach(async (state) => {
478
+ var _a2;
479
+ await ((_a2 = this.adapter) == null ? void 0 : _a2.extendObject(
480
+ `${productKey}.${deviceKey}.${state.title}`,
481
+ {
482
+ type: "state",
483
+ common: {
484
+ name: {
485
+ de: state.nameDe,
486
+ en: state.nameEn
487
+ },
488
+ type: state.type,
489
+ desc: state.title,
490
+ role: state.role,
491
+ read: true,
492
+ write: false,
493
+ unit: state.unit,
494
+ states: state.states
495
+ },
496
+ native: {}
497
+ }
498
+ ));
499
+ });
500
+ await ((_d = this.adapter) == null ? void 0 : _d.extendObject(`${productKey}.${deviceKey}.control`, {
501
+ type: "channel",
502
+ common: {
503
+ name: {
504
+ de: "Steuerung f\xFCr Ger\xE4t " + deviceKey,
505
+ en: "Control for device " + deviceKey
506
+ }
507
+ },
508
+ native: {}
509
+ }));
510
+ this.controlStates.forEach(async (state) => {
511
+ var _a2, _b2;
512
+ await ((_a2 = this.adapter) == null ? void 0 : _a2.extendObject(
513
+ `${productKey}.${deviceKey}.control.${state.title}`,
514
+ {
515
+ type: "state",
516
+ common: {
517
+ name: {
518
+ de: state.nameDe,
519
+ en: state.nameEn
520
+ },
521
+ type: state.type,
522
+ desc: state.title,
523
+ role: state.role,
524
+ read: true,
525
+ write: true,
526
+ unit: state.unit,
527
+ states: state.states
528
+ },
529
+ native: {}
530
+ }
531
+ ));
532
+ (_b2 = this.adapter) == null ? void 0 : _b2.subscribeStates(
533
+ `${productKey}.${deviceKey}.control.${state.title}`
534
+ );
535
+ });
536
+ if (this.adapter.config.useCalculation) {
537
+ await ((_e = this.adapter) == null ? void 0 : _e.extendObject(
538
+ `${productKey}.${deviceKey}.calculations`,
539
+ {
540
+ type: "channel",
541
+ common: {
542
+ name: {
543
+ de: "Berechnungen f\xFCr Ger\xE4t " + deviceKey,
544
+ en: "Calculations for Device " + deviceKey
545
+ }
546
+ },
547
+ native: {}
548
+ }
549
+ ));
550
+ await (0, import_createCalculationStates.createCalculationStates)(this.adapter, productKey, deviceKey);
551
+ }
552
+ }
553
+ subscribeReportTopic() {
554
+ var _a;
555
+ const reportTopic = `/${this.productKey}/${this.deviceKey}/#`;
556
+ if (this.adapter) {
557
+ this.adapter.log.debug(
558
+ `[subscribeReportTopic] Subscribing to MQTT Topic: ${reportTopic}`
559
+ );
560
+ (_a = this.adapter.mqttClient) == null ? void 0 : _a.subscribe(reportTopic, import_mqttSharedService.onSubscribeReportTopic);
561
+ }
562
+ }
563
+ subscribeIotTopic() {
564
+ var _a, _b, _c;
565
+ const iotTopic = `iot/${this.productKey}/${this.deviceKey}/#`;
566
+ (_a = this.adapter) == null ? void 0 : _a.log.debug(
567
+ `[subscribeIotTopic] Subscribing to MQTT Topic: ${iotTopic}`
568
+ );
569
+ (_c = (_b = this.adapter) == null ? void 0 : _b.mqttClient) == null ? void 0 : _c.subscribe(iotTopic, (error) => {
570
+ (0, import_mqttSharedService.onSubscribeIotTopic)(error, this.productKey, this.deviceKey);
571
+ });
572
+ }
573
+ setDeviceAutomationInOutLimit(limit) {
574
+ var _a;
575
+ (_a = this.adapter) == null ? void 0 : _a.log.error(
576
+ `[setAcMode] Method setDeviceAutomationInOutLimit (set to ${limit}) not defined in base class!`
577
+ );
578
+ return;
579
+ }
580
+ setAcMode(acMode) {
581
+ var _a;
582
+ (_a = this.adapter) == null ? void 0 : _a.log.error(
583
+ `[setAcMode] Method setAcMode (set to ${acMode}) not defined in base class!`
584
+ );
585
+ return;
586
+ }
587
+ setDcSwitch(dcSwitch) {
588
+ var _a;
589
+ (_a = this.adapter) == null ? void 0 : _a.log.error(
590
+ `[setAcMode] Method setDcSwitch (set to ${dcSwitch}) not defined in base class!`
591
+ );
592
+ return;
593
+ }
594
+ setAcSwitch(acSwitch) {
595
+ var _a;
596
+ (_a = this.adapter) == null ? void 0 : _a.log.error(
597
+ `[setAcMode] Method setAcSwitch (set to ${acSwitch}) not defined in base class!`
598
+ );
599
+ return;
600
+ }
601
+ setHubState(hubState) {
602
+ var _a;
603
+ if (this.adapter.mqttClient && this.productKey && this.deviceKey) {
604
+ if (hubState == 0 || hubState == 1) {
605
+ const topic = `iot/${this.productKey}/${this.deviceKey}/properties/write`;
606
+ const socSetLimit = { properties: { hubState } };
607
+ this.adapter.log.debug(
608
+ `[setHubState] Setting Hub State for deviceKey ${this.deviceKey} to ${hubState}!`
609
+ );
610
+ (_a = this.adapter.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(socSetLimit));
611
+ } else {
612
+ this.adapter.log.debug(`[setHubState] Hub state is not 0 or 1!`);
613
+ }
614
+ }
615
+ }
616
+ setPassMode(passMode) {
617
+ var _a;
618
+ if (this.adapter.mqttClient && this.productKey && this.deviceKey) {
619
+ const topic = `iot/${this.productKey}/${this.deviceKey}/properties/write`;
620
+ const setPassModeContent = { properties: { passMode } };
621
+ this.adapter.log.debug(
622
+ `[setPassMode] Set passMode for deviceKey ${this.deviceKey} to ${passMode}!`
623
+ );
624
+ (_a = this.adapter.mqttClient) == null ? void 0 : _a.publish(
625
+ topic,
626
+ JSON.stringify(setPassModeContent)
627
+ );
628
+ }
629
+ }
630
+ setAutoRecover(autoRecover) {
631
+ var _a;
632
+ if (this.adapter.mqttClient && this.productKey && this.deviceKey) {
633
+ const topic = `iot/${this.productKey}/${this.deviceKey}/properties/write`;
634
+ const setAutoRecoverContent = {
635
+ properties: { autoRecover: autoRecover ? 1 : 0 }
636
+ };
637
+ this.adapter.log.debug(
638
+ `[setAutoRecover] Set autoRecover for deviceKey ${this.deviceKey} to ${autoRecover}!`
639
+ );
640
+ (_a = this.adapter.mqttClient) == null ? void 0 : _a.publish(
641
+ topic,
642
+ JSON.stringify(setAutoRecoverContent)
643
+ );
644
+ }
645
+ }
646
+ /**
647
+ * Will set the discharge limit (minSoc)
648
+ * @param socSet the desired minimum soc
649
+ * @returns void
650
+ */
651
+ setDischargeLimit(minSoc) {
652
+ var _a;
653
+ if (this.adapter.mqttClient && this.productKey && this.deviceKey) {
654
+ if (minSoc >= 0 && minSoc <= 50) {
655
+ const topic = `iot/${this.productKey}/${this.deviceKey}/properties/write`;
656
+ const socSetLimit = { properties: { minSoc: minSoc * 10 } };
657
+ this.adapter.log.debug(
658
+ `[setDischargeLimit] Setting Discharge Limit for device key ${this.deviceKey} to ${minSoc}!`
659
+ );
660
+ (_a = this.adapter.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(socSetLimit));
661
+ } else {
662
+ this.adapter.log.debug(
663
+ `[setDischargeLimit] Discharge limit is not in range 0<>50!`
664
+ );
665
+ }
666
+ }
667
+ }
668
+ /**
669
+ * Will set the maximum charge limit
670
+ * @param socSet the desired max SOC
671
+ * @returns void
672
+ */
673
+ setChargeLimit(socSet) {
674
+ var _a;
675
+ if (this.adapter.mqttClient && this.productKey && this.deviceKey) {
676
+ if (socSet >= 40 && socSet <= 100) {
677
+ const socSetLimit = { properties: { socSet: socSet * 10 } };
678
+ this.adapter.log.debug(
679
+ `[setChargeLimit] Setting ChargeLimit for device key ${this.deviceKey} to ${socSet}!`
680
+ );
681
+ (_a = this.adapter.mqttClient) == null ? void 0 : _a.publish(
682
+ this.iotTopic,
683
+ JSON.stringify(socSetLimit)
684
+ );
685
+ } else {
686
+ this.adapter.log.debug(
687
+ `[setChargeLimit] Charge limit is not in range 40<>100!`
688
+ );
689
+ }
690
+ }
691
+ }
692
+ /**
693
+ * Will set the 'energy plan'
694
+ * @param autoModel autoModel value, like 8 for smart matching
695
+ * @returns void
696
+ */
697
+ setAutoModel(autoModel) {
698
+ var _a;
699
+ if (this.adapter.mqttClient && this.productKey && this.deviceKey) {
700
+ let setAutoModelContent = { properties: { autoModel } };
701
+ switch (autoModel) {
702
+ case 8: {
703
+ setAutoModelContent = {
704
+ properties: {
705
+ autoModelProgram: 1,
706
+ autoModelValue: {
707
+ chargingType: 0,
708
+ chargingPower: 0,
709
+ outPower: 0
710
+ },
711
+ msgType: 1,
712
+ autoModel: 8
713
+ }
714
+ };
715
+ break;
716
+ }
717
+ case 9:
718
+ setAutoModelContent = {
719
+ properties: {
720
+ autoModelProgram: 2,
721
+ autoModelValue: {
722
+ chargingType: 3,
723
+ chargingPower: 0,
724
+ outPower: 0
725
+ },
726
+ msgType: 1,
727
+ autoModel: 9
728
+ }
729
+ };
730
+ break;
731
+ }
732
+ this.adapter.log.debug(
733
+ `[setAutoModel] Setting autoModel for device key ${this.deviceKey} to ${autoModel}!`
734
+ );
735
+ (_a = this.adapter.mqttClient) == null ? void 0 : _a.publish(
736
+ this.iotTopic,
737
+ JSON.stringify(setAutoModelContent)
738
+ );
739
+ }
740
+ }
741
+ async setOutputLimit(limit) {
742
+ var _a, _b, _c;
743
+ if (this.adapter.mqttClient && this.productKey && this.deviceKey) {
744
+ const autoModel = (_a = await this.adapter.getStateAsync(
745
+ this.productKey + "." + this.deviceKey + ".autoModel"
746
+ )) == null ? void 0 : _a.val;
747
+ if (autoModel != 0) {
748
+ this.adapter.log.warn(
749
+ "Operation mode (autoModel) is not set to '0', we can't set the output limit!"
750
+ );
751
+ return;
752
+ }
753
+ if (limit) {
754
+ limit = Math.round(limit);
755
+ } else {
756
+ limit = 0;
757
+ }
758
+ if (limit > this.maxOutputLimit) {
759
+ limit = this.maxOutputLimit;
760
+ }
761
+ if (limit < 100 && limit != 90 && limit != 60 && limit != 30 && limit != 0 && (this.productKey == "73bktv" || this.productKey == "a8yh63")) {
762
+ if (limit < 100 && limit > 90) {
763
+ limit = 90;
764
+ } else if (limit > 60 && limit < 90) {
765
+ limit = 60;
766
+ } else if (limit > 30 && limit < 60) {
767
+ limit = 30;
768
+ } else if (limit < 30) {
769
+ limit = 30;
770
+ }
771
+ }
772
+ if (this.adapter.config.useLowVoltageBlock) {
773
+ const lowVoltageBlockState = await this.adapter.getStateAsync(
774
+ this.productKey + "." + this.deviceKey + ".control.lowVoltageBlock"
775
+ );
776
+ if (lowVoltageBlockState && lowVoltageBlockState.val && lowVoltageBlockState.val == true) {
777
+ limit = 0;
778
+ }
779
+ const fullChargeNeeded = await this.adapter.getStateAsync(
780
+ this.productKey + "." + this.deviceKey + ".control.fullChargeNeeded"
781
+ );
782
+ if (fullChargeNeeded && fullChargeNeeded.val && fullChargeNeeded.val == true) {
783
+ limit = 0;
784
+ }
785
+ }
786
+ const currentLimit = (_b = await this.adapter.getStateAsync(
787
+ this.productKey + "." + this.deviceKey + ".outputLimit"
788
+ )) == null ? void 0 : _b.val;
789
+ if (currentLimit != null && currentLimit != void 0) {
790
+ if (currentLimit != limit) {
791
+ const outputlimit = { properties: { outputLimit: limit } };
792
+ this.adapter.msgCounter += 1;
793
+ const timestamp = /* @__PURE__ */ new Date();
794
+ timestamp.setMilliseconds(0);
795
+ (_c = this.adapter.mqttClient) == null ? void 0 : _c.publish(
796
+ this.iotTopic,
797
+ JSON.stringify(outputlimit)
798
+ );
799
+ }
800
+ }
801
+ }
802
+ }
803
+ setInputLimit(limit) {
804
+ var _a;
805
+ if (this.adapter.mqttClient && this.productKey && this.deviceKey) {
806
+ if (limit) {
807
+ limit = Math.round(limit);
808
+ } else {
809
+ limit = 0;
810
+ }
811
+ if (limit < 0) {
812
+ limit = 0;
813
+ } else if (limit > 0 && limit <= 30) {
814
+ limit = 30;
815
+ } else if (limit > -this.maxInputLimit) {
816
+ limit = -this.maxInputLimit;
817
+ }
818
+ if (this.productKey.includes("8bm93h")) {
819
+ limit = Math.ceil(limit / 100) * 100;
820
+ }
821
+ const inputLimitContent = { properties: { inputLimit: limit } };
822
+ (_a = this.adapter.mqttClient) == null ? void 0 : _a.publish(
823
+ this.iotTopic,
824
+ JSON.stringify(inputLimitContent)
825
+ );
826
+ }
827
+ }
828
+ setSmartMode(smartModeOn) {
829
+ var _a;
830
+ if (this.adapter.mqttClient && this.productKey && this.deviceKey) {
831
+ const setSmartModeContent = {
832
+ properties: { smartMode: smartModeOn ? 1 : 0 }
833
+ };
834
+ this.adapter.log.debug(
835
+ `[setBuzzer] Setting Smart Mode for device key ${this.deviceKey} to ${smartModeOn}!`
836
+ );
837
+ (_a = this.adapter.mqttClient) == null ? void 0 : _a.publish(
838
+ this.iotTopic,
839
+ JSON.stringify(setSmartModeContent)
840
+ );
841
+ }
842
+ }
843
+ setBuzzerSwitch(buzzerOn) {
844
+ var _a;
845
+ if (this.adapter.mqttClient && this.productKey && this.deviceKey) {
846
+ const setBuzzerSwitchContent = {
847
+ properties: { buzzerSwitch: buzzerOn ? 1 : 0 }
848
+ };
849
+ this.adapter.log.debug(
850
+ `[setBuzzer] Setting Buzzer for device key ${this.deviceKey} to ${buzzerOn}!`
851
+ );
852
+ (_a = this.adapter.mqttClient) == null ? void 0 : _a.publish(
853
+ this.iotTopic,
854
+ JSON.stringify(setBuzzerSwitchContent)
855
+ );
856
+ }
857
+ }
858
+ triggerFullTelemetryUpdate() {
859
+ var _a;
860
+ if (this.adapter.mqttClient && this.productKey && this.deviceKey) {
861
+ const topic = `iot/${this.productKey}/${this.deviceKey}/properties/read`;
862
+ const getAllContent = { properties: ["getAll"] };
863
+ this.adapter.log.debug(
864
+ `[triggerFullTelemetryUpdate] Triggering full telemetry update for device key ${this.deviceKey}!`
865
+ );
866
+ (_a = this.adapter.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(getAllContent));
867
+ }
868
+ }
869
+ async updateSolarFlowState(state, val) {
870
+ var _a, _b;
871
+ const currentValue = await this.adapter.getStateAsync(
872
+ `${this.productKey}.${this.deviceKey}.${state}`
873
+ );
874
+ await ((_a = this.adapter) == null ? void 0 : _a.setState(
875
+ `${this.productKey}.${this.deviceKey}.${state}`,
876
+ val,
877
+ true
878
+ ));
879
+ if ((currentValue == null ? void 0 : currentValue.val) != val) {
880
+ await ((_b = this.adapter) == null ? void 0 : _b.setState(
881
+ `${this.productKey}.${this.deviceKey}.lastUpdate`,
882
+ (/* @__PURE__ */ new Date()).getTime(),
883
+ true
884
+ ));
885
+ }
886
+ }
887
+ async updateSolarFlowControlState(state, val) {
888
+ var _a, _b;
889
+ const stateExist = await ((_a = this.adapter) == null ? void 0 : _a.objectExists(
890
+ `${this.productKey}.${this.deviceKey}.control.${state}`
891
+ ));
892
+ if (stateExist) {
893
+ await ((_b = this.adapter) == null ? void 0 : _b.setState(
894
+ `${this.productKey}.${this.deviceKey}.control.${state}`,
895
+ val,
896
+ true
897
+ ));
898
+ }
899
+ }
900
+ async checkVoltage(voltage) {
901
+ var _a, _b, _c, _d;
902
+ if (voltage < 46.1) {
903
+ if (this.adapter.config.useCalculation) {
904
+ this.setSocToZero();
905
+ }
906
+ if (this.adapter.config.useLowVoltageBlock) {
907
+ await ((_a = this.adapter) == null ? void 0 : _a.setState(
908
+ `${this.productKey}.${this.deviceKey}.control.lowVoltageBlock`,
909
+ true,
910
+ true
911
+ ));
912
+ const autoModel = (_b = await this.adapter.getStateAsync(
913
+ this.productKey + "." + this.deviceKey + ".autoModel"
914
+ )) == null ? void 0 : _b.val;
915
+ if (autoModel == 8) {
916
+ this.setDeviceAutomationInOutLimit(0);
917
+ } else {
918
+ this.setOutputLimit(0);
919
+ }
920
+ if (this.adapter.config.forceShutdownOnLowVoltage) {
921
+ const currentSoc = await this.adapter.getStateAsync(
922
+ `${this.productKey}.${this.deviceKey}.electricLevel`
923
+ );
924
+ if (currentSoc && Number(currentSoc.val) > 50) {
925
+ if (this.adapter.config.fullChargeIfNeeded) {
926
+ await ((_c = this.adapter) == null ? void 0 : _c.setState(
927
+ `${this.productKey}.${this.deviceKey}.control.fullChargeNeeded`,
928
+ true,
929
+ true
930
+ ));
931
+ }
932
+ } else {
933
+ if (currentSoc && currentSoc.val) {
934
+ this.setDischargeLimit(Number(currentSoc.val));
935
+ }
936
+ const hubState = await this.adapter.getStateAsync(
937
+ `${this.productKey}.${this.deviceKey}.hubState`
938
+ );
939
+ if (!hubState || Number(hubState.val) != 1) {
940
+ this.adapter.log.warn(
941
+ `[checkVoltage] hubState is not set to 'Stop output and shut down', device will NOT go offline!`
942
+ );
943
+ }
944
+ }
945
+ }
946
+ }
947
+ } else if (voltage >= 47.5) {
948
+ const lowVoltageBlock = await this.adapter.getStateAsync(
949
+ `${this.productKey}.${this.deviceKey}.control.lowVoltageBlock`
950
+ );
951
+ if (lowVoltageBlock && lowVoltageBlock.val == true) {
952
+ await ((_d = this.adapter) == null ? void 0 : _d.setState(
953
+ `${this.productKey}.${this.deviceKey}.control.lowVoltageBlock`,
954
+ false,
955
+ true
956
+ ));
957
+ if (this.adapter.config.useLowVoltageBlock && this.adapter.config.forceShutdownOnLowVoltage) {
958
+ this.setDischargeLimit(
959
+ this.adapter.config.dischargeLimit ? this.adapter.config.dischargeLimit : 5
960
+ );
961
+ }
962
+ }
963
+ }
964
+ }
965
+ /**
966
+ * Calculates the energy for all items in 'calculationStateKeys'.
967
+ *
968
+ * @returns Promise<void>
969
+ *
970
+ * @beta
971
+ */
972
+ calculateEnergy() {
973
+ import_constants.calculationStateKeys.forEach(async (stateKey) => {
974
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
975
+ let stateNameEnergyWh = "";
976
+ let stateNameEnergykWh = "";
977
+ let stateNamePower = "";
978
+ if (stateKey == "pvPower1") {
979
+ stateNameEnergyWh = `${this.productKey}.${this.deviceKey}.calculations.solarInputPv1EnergyTodayWh`;
980
+ stateNameEnergykWh = `${this.productKey}.${this.deviceKey}.calculations.solarInputPv1EnergyTodaykWh`;
981
+ stateNamePower = `${this.productKey}.${this.deviceKey}.pvPower1`;
982
+ } else if (stateKey == "pvPower2") {
983
+ stateNameEnergyWh = `${this.productKey}.${this.deviceKey}.calculations.solarInputPv2EnergyTodayWh`;
984
+ stateNameEnergykWh = `${this.productKey}.${this.deviceKey}.calculations.solarInputPv2EnergyTodaykWh`;
985
+ stateNamePower = `${this.productKey}.${this.deviceKey}.pvPower2`;
986
+ } else {
987
+ stateNameEnergyWh = `${this.productKey}.${this.deviceKey}.calculations.${stateKey}EnergyTodayWh`;
988
+ stateNameEnergykWh = `${this.productKey}.${this.deviceKey}.calculations.${stateKey}EnergyTodaykWh`;
989
+ stateNamePower = `${this.productKey}.${this.deviceKey}.${stateKey}Power`;
990
+ }
991
+ const currentPowerState = await ((_a = this.adapter) == null ? void 0 : _a.getStateAsync(stateNamePower));
992
+ const currentEnergyState = await ((_b = this.adapter) == null ? void 0 : _b.getStateAsync(stateNameEnergyWh));
993
+ if ((currentEnergyState == null ? void 0 : currentEnergyState.val) == 0) {
994
+ await ((_c = this.adapter) == null ? void 0 : _c.setState(stateNameEnergyWh, 1e-6, true));
995
+ } else if (currentEnergyState && currentEnergyState.lc && currentPowerState && currentPowerState.val != void 0 && currentPowerState.val != null) {
996
+ const timeFrame = 3e4;
997
+ const addEnergyValue = Number(currentPowerState.val) * timeFrame / 36e5;
998
+ let newEnergyValue = Number(currentEnergyState.val) + addEnergyValue;
999
+ if (newEnergyValue < 0) {
1000
+ newEnergyValue = 0;
1001
+ }
1002
+ await ((_d = this.adapter) == null ? void 0 : _d.setState(stateNameEnergyWh, newEnergyValue, true));
1003
+ await ((_e = this.adapter) == null ? void 0 : _e.setState(
1004
+ stateNameEnergykWh,
1005
+ Number((newEnergyValue / 1e3).toFixed(2)),
1006
+ true
1007
+ ));
1008
+ if ((stateKey == "outputPack" || stateKey == "packInput") && addEnergyValue > 0) {
1009
+ await this.calculateSocAndEnergy(stateKey, addEnergyValue);
1010
+ } else {
1011
+ if (stateKey == "outputPack") {
1012
+ await ((_f = this.adapter) == null ? void 0 : _f.setState(
1013
+ `${this.productKey}.${this.deviceKey}.calculations.remainInputTime`,
1014
+ "",
1015
+ true
1016
+ ));
1017
+ } else if (stateKey == "packInput") {
1018
+ await ((_g = this.adapter) == null ? void 0 : _g.setState(
1019
+ `${this.productKey}.${this.deviceKey}.calculations.remainOutTime`,
1020
+ "",
1021
+ true
1022
+ ));
1023
+ }
1024
+ }
1025
+ } else {
1026
+ await ((_h = this.adapter) == null ? void 0 : _h.setState(stateNameEnergyWh, 0, true));
1027
+ await ((_i = this.adapter) == null ? void 0 : _i.setState(stateNameEnergykWh, 0, true));
1028
+ }
1029
+ });
1030
+ }
1031
+ async setSocToZero() {
1032
+ var _a, _b, _c;
1033
+ await ((_a = this.adapter) == null ? void 0 : _a.setState(
1034
+ `${this.productKey}.${this.deviceKey}.calculations.soc`,
1035
+ 0,
1036
+ true
1037
+ ));
1038
+ const energyWhState = await this.adapter.getStateAsync(
1039
+ `${this.productKey}.${this.deviceKey}.calculations.energyWh`
1040
+ );
1041
+ const energyWhMaxState = await this.adapter.getStateAsync(
1042
+ `${this.productKey}.${this.deviceKey}.calculations.energyWhMax`
1043
+ );
1044
+ const newMax = Number(energyWhMaxState == null ? void 0 : energyWhMaxState.val) - Number(energyWhState == null ? void 0 : energyWhState.val);
1045
+ await ((_b = this.adapter) == null ? void 0 : _b.setState(
1046
+ `${this.productKey}.${this.deviceKey}.calculations.energyWhMax`,
1047
+ newMax,
1048
+ true
1049
+ ));
1050
+ await ((_c = this.adapter) == null ? void 0 : _c.setState(
1051
+ `${this.productKey}.${this.deviceKey}.calculations.energyWh`,
1052
+ 0,
1053
+ true
1054
+ ));
1055
+ }
1056
+ async setEnergyWhMax() {
1057
+ var _a, _b;
1058
+ const currentEnergyState = await ((_a = this.adapter) == null ? void 0 : _a.getStateAsync(
1059
+ this.productKey + "." + this.deviceKey + ".calculations.energyWh"
1060
+ ));
1061
+ if (currentEnergyState) {
1062
+ await ((_b = this.adapter) == null ? void 0 : _b.setState(
1063
+ `${this.productKey}.${this.deviceKey}.calculations.energyWhMax`,
1064
+ currentEnergyState == null ? void 0 : currentEnergyState.val,
1065
+ true
1066
+ ));
1067
+ }
1068
+ }
1069
+ resetValuesForDevice() {
1070
+ import_constants.calculationStateKeys.forEach(async (stateKey) => {
1071
+ var _a, _b;
1072
+ let stateNameEnergyWh = "";
1073
+ let stateNameEnergykWh = "";
1074
+ if (stateKey == "pvPower1") {
1075
+ stateNameEnergyWh = `${this.productKey}.${this.deviceKey}.calculations.solarInputPv1EnergyTodayWh`;
1076
+ stateNameEnergykWh = `${this.productKey}.${this.deviceKey}.calculations.solarInputPv1EnergyTodaykWh`;
1077
+ } else if (stateKey == "pvPower2") {
1078
+ stateNameEnergyWh = `${this.productKey}.${this.deviceKey}.calculations.solarInputPv2EnergyTodayWh`;
1079
+ stateNameEnergykWh = `${this.productKey}.${this.deviceKey}.calculations.solarInputPv2EnergyTodaykWh`;
1080
+ } else {
1081
+ stateNameEnergyWh = `${this.productKey}.${this.deviceKey}.calculations.${stateKey}EnergyTodayWh`;
1082
+ stateNameEnergykWh = `${this.productKey}.${this.deviceKey}.calculations.${stateKey}EnergyTodaykWh`;
1083
+ }
1084
+ await ((_a = this.adapter) == null ? void 0 : _a.setState(stateNameEnergyWh, 0, true));
1085
+ await ((_b = this.adapter) == null ? void 0 : _b.setState(stateNameEnergykWh, 0, true));
1086
+ });
1087
+ }
1088
+ }
1089
+ // Annotate the CommonJS export names for ESM import in node:
1090
+ 0 && (module.exports = {
1091
+ ZenHaDevice
1092
+ });
1093
+ //# sourceMappingURL=ZenHaDevice.js.map