iobroker.zendure-solarflow 1.1.4 → 1.1.6

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.
@@ -19,12 +19,287 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var adapterService_exports = {};
20
20
  __export(adapterService_exports, {
21
21
  addOrUpdatePackData: () => addOrUpdatePackData,
22
+ calculateEnergy: () => calculateEnergy,
22
23
  createSolarFlowStates: () => createSolarFlowStates,
24
+ resetTodaysValues: () => resetTodaysValues,
23
25
  startCheckStatesTimer: () => startCheckStatesTimer,
24
26
  updateSolarFlowState: () => updateSolarFlowState
25
27
  });
26
28
  module.exports = __toCommonJS(adapterService_exports);
27
29
  var import_webService = require("./webService");
30
+ const createCalculationStates = async (adapter, productKey, deviceKey) => {
31
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(
32
+ productKey + "." + deviceKey + ".calculations.solarInputEnergyTodayWh",
33
+ {
34
+ type: "state",
35
+ common: {
36
+ name: {
37
+ de: "Heutiger Solarertrag (Wh)",
38
+ en: "Todays solar input (Wh)"
39
+ },
40
+ type: "number",
41
+ desc: "solarInputEnergyTodayWh",
42
+ role: "value.energy",
43
+ read: true,
44
+ write: false,
45
+ unit: "Wh"
46
+ },
47
+ native: {}
48
+ }
49
+ ));
50
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(
51
+ productKey + "." + deviceKey + ".calculations.solarInputEnergyTodaykWh",
52
+ {
53
+ type: "state",
54
+ common: {
55
+ name: {
56
+ de: "Heutiger Solarertrag (kWh)",
57
+ en: "Todays solar input (kWh)"
58
+ },
59
+ type: "number",
60
+ desc: "solarInputEnergyTodaykWh",
61
+ role: "value.energy",
62
+ read: true,
63
+ write: false,
64
+ unit: "kWh"
65
+ },
66
+ native: {}
67
+ }
68
+ ));
69
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(
70
+ productKey + "." + deviceKey + ".calculations.outputPackEnergyTodayWh",
71
+ {
72
+ type: "state",
73
+ common: {
74
+ name: {
75
+ de: "Heutige Ladung zum Akku (Wh)",
76
+ en: "todays charge energy to battery (Wh)"
77
+ },
78
+ type: "number",
79
+ desc: "outputPackEnergyTodayWh",
80
+ role: "value.energy",
81
+ read: true,
82
+ write: false,
83
+ unit: "Wh"
84
+ },
85
+ native: {}
86
+ }
87
+ ));
88
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(
89
+ productKey + "." + deviceKey + ".calculations.outputPackEnergyTodaykWh",
90
+ {
91
+ type: "state",
92
+ common: {
93
+ name: {
94
+ de: "Heutige Ladung zum Akku (kWh)",
95
+ en: "todays charge energy to battery (kWh)"
96
+ },
97
+ type: "number",
98
+ desc: "outputPackEnergyTodaykWh",
99
+ role: "value.energy",
100
+ read: true,
101
+ write: false,
102
+ unit: "kWh"
103
+ },
104
+ native: {}
105
+ }
106
+ ));
107
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(
108
+ productKey + "." + deviceKey + ".calculations.packInputEnergyTodayWh",
109
+ {
110
+ type: "state",
111
+ common: {
112
+ name: {
113
+ de: "Heutige Ladung zum Akku (Wh)",
114
+ en: "todays charge energy to battery (Wh)"
115
+ },
116
+ type: "number",
117
+ desc: "packInputEnergyTodayWh",
118
+ role: "value.energy",
119
+ read: true,
120
+ write: false,
121
+ unit: "Wh"
122
+ },
123
+ native: {}
124
+ }
125
+ ));
126
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(
127
+ productKey + "." + deviceKey + ".calculations.packInputEnergyTodaykWh",
128
+ {
129
+ type: "state",
130
+ common: {
131
+ name: {
132
+ de: "Heutige Einspeisung aus Akku (kWh)",
133
+ en: "Todays discharge energy from battery (kWh)"
134
+ },
135
+ type: "number",
136
+ desc: "packInputEnergyTodaykWh",
137
+ role: "value.energy",
138
+ read: true,
139
+ write: false,
140
+ unit: "kWh"
141
+ },
142
+ native: {}
143
+ }
144
+ ));
145
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(
146
+ productKey + "." + deviceKey + ".calculations.outputHomeEnergyTodayWh",
147
+ {
148
+ type: "state",
149
+ common: {
150
+ name: {
151
+ de: "Heutige Einspeisung ins Haus (Wh)",
152
+ en: "Todays input energy to home (Wh)"
153
+ },
154
+ type: "number",
155
+ desc: "outputHomeEnergyTodayWh",
156
+ role: "value.energy",
157
+ read: true,
158
+ write: false,
159
+ unit: "Wh"
160
+ },
161
+ native: {}
162
+ }
163
+ ));
164
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(
165
+ productKey + "." + deviceKey + ".calculations.outputHomeEnergyTodaykWh",
166
+ {
167
+ type: "state",
168
+ common: {
169
+ name: {
170
+ de: "Heutige Einspeisung ins Haus (kWh)",
171
+ en: "Todays input energy to home (kWh)"
172
+ },
173
+ type: "number",
174
+ desc: "outputHomeEnergyTodaykWh",
175
+ role: "value.energy",
176
+ read: true,
177
+ write: false,
178
+ unit: "kWh"
179
+ },
180
+ native: {}
181
+ }
182
+ ));
183
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(
184
+ productKey + "." + deviceKey + ".calculations.remainInputTime",
185
+ {
186
+ type: "state",
187
+ common: {
188
+ name: {
189
+ de: "Erwartete Ladedauer (hh:mm)",
190
+ en: "remaining charge time (hh:mm)"
191
+ },
192
+ type: "string",
193
+ desc: "calcRemainInputTime",
194
+ role: "value",
195
+ read: true,
196
+ write: false
197
+ },
198
+ native: {}
199
+ }
200
+ ));
201
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(
202
+ productKey + "." + deviceKey + ".calculations.remainOutTime",
203
+ {
204
+ type: "state",
205
+ common: {
206
+ name: {
207
+ de: "Erwartete Entladedauer (hh:mm)",
208
+ en: "remaining discharge time (hh:mm)"
209
+ },
210
+ type: "string",
211
+ desc: "calcRemainOutTime",
212
+ role: "value",
213
+ read: true,
214
+ write: false
215
+ },
216
+ native: {}
217
+ }
218
+ ));
219
+ };
220
+ const createControlStates = async (adapter, productKey, deviceKey) => {
221
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(productKey + "." + deviceKey + ".control", {
222
+ type: "channel",
223
+ common: {
224
+ name: {
225
+ de: "Steuerung f\xFCr Ger\xE4t " + deviceKey,
226
+ en: "Control for device " + deviceKey
227
+ }
228
+ },
229
+ native: {}
230
+ }));
231
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(
232
+ productKey + "." + deviceKey + ".control.setOutputLimit",
233
+ {
234
+ type: "state",
235
+ common: {
236
+ name: {
237
+ de: "Einzustellende Ausgangsleistung",
238
+ en: "Control of the output limit"
239
+ },
240
+ type: "number",
241
+ desc: "setOutputLimit",
242
+ role: "value.power",
243
+ read: true,
244
+ write: true,
245
+ min: 0,
246
+ unit: "W"
247
+ },
248
+ native: {}
249
+ }
250
+ ));
251
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(
252
+ productKey + "." + deviceKey + ".control.chargeLimit",
253
+ {
254
+ type: "state",
255
+ common: {
256
+ name: {
257
+ de: "Setzen des Lade-Limits",
258
+ en: "Control of the charge limit"
259
+ },
260
+ type: "number",
261
+ desc: "chargeLimit",
262
+ role: "value.battery",
263
+ read: true,
264
+ write: true,
265
+ min: 40,
266
+ max: 100,
267
+ unit: "%"
268
+ },
269
+ native: {}
270
+ }
271
+ ));
272
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(
273
+ productKey + "." + deviceKey + ".control.dischargeLimit",
274
+ {
275
+ type: "state",
276
+ common: {
277
+ name: {
278
+ de: "Setzen des Entlade-Limits",
279
+ en: "Control of the discharge limit"
280
+ },
281
+ type: "number",
282
+ desc: "dischargeLimit",
283
+ role: "value.battery",
284
+ read: true,
285
+ write: true,
286
+ min: 0,
287
+ max: 90,
288
+ unit: "%"
289
+ },
290
+ native: {}
291
+ }
292
+ ));
293
+ adapter == null ? void 0 : adapter.subscribeStates(
294
+ productKey + "." + deviceKey + ".control.setOutputLimit"
295
+ );
296
+ adapter == null ? void 0 : adapter.subscribeStates(
297
+ productKey + "." + deviceKey + ".control.chargeLimit"
298
+ );
299
+ adapter == null ? void 0 : adapter.subscribeStates(
300
+ productKey + "." + deviceKey + ".control.dischargeLimit"
301
+ );
302
+ };
28
303
  const createSolarFlowStates = async (adapter, productKey, deviceKey) => {
29
304
  productKey = productKey.replace(adapter.FORBIDDEN_CHARS, "");
30
305
  deviceKey = deviceKey.replace(adapter.FORBIDDEN_CHARS, "");
@@ -42,26 +317,19 @@ const createSolarFlowStates = async (adapter, productKey, deviceKey) => {
42
317
  },
43
318
  native: {}
44
319
  }));
45
- await (adapter == null ? void 0 : adapter.extendObjectAsync(productKey + "." + deviceKey + ".control", {
46
- type: "channel",
47
- common: {
48
- name: {
49
- de: "Steuerung f\xFCr Ger\xE4t " + deviceKey,
50
- en: "Control for device " + deviceKey
51
- }
52
- },
53
- native: {}
54
- }));
55
- await (adapter == null ? void 0 : adapter.extendObjectAsync(productKey + "." + deviceKey + ".calculations", {
56
- type: "channel",
57
- common: {
58
- name: {
59
- de: "Berechnungen f\xFCr Ger\xE4t " + deviceKey,
60
- en: "Calculations for Device " + deviceKey
61
- }
62
- },
63
- native: {}
64
- }));
320
+ await (adapter == null ? void 0 : adapter.extendObjectAsync(
321
+ productKey + "." + deviceKey + ".calculations",
322
+ {
323
+ type: "channel",
324
+ common: {
325
+ name: {
326
+ de: "Berechnungen f\xFCr Ger\xE4t " + deviceKey,
327
+ en: "Calculations for Device " + deviceKey
328
+ }
329
+ },
330
+ native: {}
331
+ }
332
+ ));
65
333
  await (adapter == null ? void 0 : adapter.extendObjectAsync(productKey + "." + deviceKey + ".packData", {
66
334
  type: "channel",
67
335
  common: {
@@ -235,7 +503,10 @@ const createSolarFlowStates = async (adapter, productKey, deviceKey) => {
235
503
  {
236
504
  type: "state",
237
505
  common: {
238
- name: { de: "Erwartete Entladedauer (Minuten)", en: "remaining discharge time (minutes)" },
506
+ name: {
507
+ de: "Erwartete Entladedauer (Minuten)",
508
+ en: "remaining discharge time (minutes)"
509
+ },
239
510
  type: "number",
240
511
  desc: "remainOutTime",
241
512
  role: "value.interval",
@@ -277,107 +548,20 @@ const createSolarFlowStates = async (adapter, productKey, deviceKey) => {
277
548
  native: {}
278
549
  }
279
550
  ));
280
- await (adapter == null ? void 0 : adapter.extendObjectAsync(
281
- productKey + "." + deviceKey + ".control.setOutputLimit",
282
- {
283
- type: "state",
284
- common: {
285
- name: {
286
- de: "Einzustellende Ausgangsleistung",
287
- en: "Control of the output limit"
288
- },
289
- type: "number",
290
- desc: "setOutputLimit",
291
- role: "value.power",
292
- read: true,
293
- write: true,
294
- min: 0,
295
- unit: "W"
296
- },
297
- native: {}
298
- }
299
- ));
300
- await (adapter == null ? void 0 : adapter.extendObjectAsync(
301
- productKey + "." + deviceKey + ".control.chargeLimit",
302
- {
303
- type: "state",
304
- common: {
305
- name: {
306
- de: "Setzen des Lade-Limits",
307
- en: "Control of the charge limit"
308
- },
309
- type: "number",
310
- desc: "chargeLimit",
311
- role: "value.battery",
312
- read: true,
313
- write: true,
314
- min: 40,
315
- max: 100,
316
- unit: "%"
317
- },
318
- native: {}
319
- }
320
- ));
321
- await (adapter == null ? void 0 : adapter.extendObjectAsync(
322
- productKey + "." + deviceKey + ".control.dischargeLimit",
323
- {
324
- type: "state",
325
- common: {
326
- name: {
327
- de: "Setzen des Entlade-Limits",
328
- en: "Control of the discharge limit"
329
- },
330
- type: "number",
331
- desc: "dischargeLimit",
332
- role: "value.battery",
333
- read: true,
334
- write: true,
335
- min: 0,
336
- max: 90,
337
- unit: "%"
338
- },
339
- native: {}
340
- }
341
- ));
342
- await (adapter == null ? void 0 : adapter.extendObjectAsync(
343
- productKey + "." + deviceKey + ".calculations.remainInputTime",
344
- {
345
- type: "state",
346
- common: {
347
- name: { de: "Erwartete Ladedauer (hh:mm)", en: "remaining charge time (hh:mm)" },
348
- type: "string",
349
- desc: "remainInputTime",
350
- role: "value",
351
- read: true,
352
- write: false
353
- },
354
- native: {}
355
- }
356
- ));
357
- await (adapter == null ? void 0 : adapter.extendObjectAsync(
358
- productKey + "." + deviceKey + ".calculations.remainOutTime",
359
- {
360
- type: "state",
361
- common: {
362
- name: { de: "Erwartete Entladedauer (hh:mm)", en: "remaining discharge time (hh:mm)" },
363
- type: "string",
364
- desc: "remainInputTime",
365
- role: "value",
366
- read: true,
367
- write: false
368
- },
369
- native: {}
370
- }
371
- ));
372
551
  adapter == null ? void 0 : adapter.subscribeStates(
373
- productKey + "." + deviceKey + ".control.setOutputLimit"
552
+ productKey + "." + deviceKey + ".solarInputPower"
374
553
  );
375
554
  adapter == null ? void 0 : adapter.subscribeStates(
376
- productKey + "." + deviceKey + ".control.chargeLimit"
555
+ productKey + "." + deviceKey + ".outputPackPower"
377
556
  );
378
557
  adapter == null ? void 0 : adapter.subscribeStates(
379
- productKey + "." + deviceKey + ".control.dischargeLimit"
558
+ productKey + "." + deviceKey + ".packInputPower"
380
559
  );
560
+ adapter == null ? void 0 : adapter.subscribeStates(
561
+ productKey + "." + deviceKey + ".outputHomePower"
562
+ );
563
+ await createControlStates(adapter, productKey, deviceKey);
564
+ await createCalculationStates(adapter, productKey, deviceKey);
381
565
  };
382
566
  const addOrUpdatePackData = async (adapter, productKey, deviceKey, packData) => {
383
567
  await packData.forEach(async (x) => {
@@ -485,11 +669,7 @@ const addOrUpdatePackData = async (adapter, productKey, deviceKey, packData) =>
485
669
  },
486
670
  native: {}
487
671
  }));
488
- await (adapter == null ? void 0 : adapter.setStateAsync(
489
- key + ".totalVol",
490
- x.totalVol / 100,
491
- true
492
- ));
672
+ await (adapter == null ? void 0 : adapter.setStateAsync(key + ".totalVol", x.totalVol / 100, true));
493
673
  }
494
674
  }
495
675
  });
@@ -504,25 +684,10 @@ const startCheckStatesTimer = async (adapter) => {
504
684
  adapter.interval = adapter.setInterval(async () => {
505
685
  (0, import_webService.getDeviceList)(adapter).then((deviceList) => {
506
686
  deviceList.forEach(async (device) => {
507
- var _a;
508
687
  const lastUpdate = await (adapter == null ? void 0 : adapter.getStateAsync(
509
688
  device.productKey + "." + device.deviceKey + ".lastUpdate"
510
689
  ));
511
690
  const tenMinutesAgo = Date.now() / 1e3 - 10 * 60;
512
- const oneDayAgo = new Date((/* @__PURE__ */ new Date()).getTime() - 1 * 24 * 60 * 60 * 1e3);
513
- if (adapter.lastLogin && adapter.lastLogin < oneDayAgo) {
514
- adapter.log.debug(
515
- `Last login for deviceKey ${device.deviceKey} was at ${adapter.lastLogin}, refreshing accessToken!`
516
- );
517
- if (adapter.config.userName && adapter.config.password) {
518
- (_a = (0, import_webService.login)(adapter)) == null ? void 0 : _a.then(
519
- (_accessToken) => {
520
- adapter.accessToken = _accessToken;
521
- adapter.connected = true;
522
- }
523
- );
524
- }
525
- }
526
691
  if (lastUpdate && lastUpdate.val && Number(lastUpdate.val) < tenMinutesAgo) {
527
692
  adapter.log.debug(
528
693
  `Last update for deviceKey ${device.deviceKey} was at ${new Date(
@@ -550,17 +715,40 @@ const startCheckStatesTimer = async (adapter) => {
550
715
  });
551
716
  }, 5e4);
552
717
  };
718
+ const calculateEnergy = async (adapter, productKey, deviceKey, stateKey, state) => {
719
+ const stateNameWh = productKey + "." + deviceKey + ".calculations." + stateKey + "EnergyTodayWh";
720
+ const stateNamekWh = productKey + "." + deviceKey + ".calculations." + stateKey + "EnergyTodaykWh";
721
+ const currentVal = await (adapter == null ? void 0 : adapter.getStateAsync(stateNameWh));
722
+ if (currentVal && currentVal.lc && state.val) {
723
+ const timeFrame = state.lc - (currentVal == null ? void 0 : currentVal.lc);
724
+ const newVal = Number(currentVal.val) + Number(state.val) * timeFrame / 36e8;
725
+ adapter == null ? void 0 : adapter.setStateAsync(stateNameWh, newVal, true);
726
+ adapter == null ? void 0 : adapter.setStateAsync(stateNamekWh, (newVal / 1e3).toFixed(2), true);
727
+ } else {
728
+ adapter == null ? void 0 : adapter.setStateAsync(stateNameWh, 0, true);
729
+ adapter == null ? void 0 : adapter.setStateAsync(stateNamekWh, 0, true);
730
+ }
731
+ };
732
+ const resetTodaysValues = async (adapter) => {
733
+ adapter.deviceList.forEach((device) => {
734
+ const names = ["packInput", "outputHome", "outputPack", "solarInput"];
735
+ names.forEach((name) => {
736
+ const stateNameWh = device.productKey + "." + device.deviceKey + ".calculations." + name + "EnergyTodayWh";
737
+ const stateNamekWh = device.productKey + "." + device.deviceKey + ".calculations." + name + "EnergyTodaykWh";
738
+ adapter == null ? void 0 : adapter.setStateAsync(stateNameWh, 0, true);
739
+ adapter == null ? void 0 : adapter.setStateAsync(stateNamekWh, 0, true);
740
+ });
741
+ });
742
+ };
553
743
  const updateSolarFlowState = async (adapter, productKey, deviceKey, state, val) => {
554
- adapter == null ? void 0 : adapter.setStateAsync(
555
- productKey + "." + deviceKey + "." + state,
556
- val,
557
- true
558
- );
744
+ adapter == null ? void 0 : adapter.setStateAsync(productKey + "." + deviceKey + "." + state, val, true);
559
745
  };
560
746
  // Annotate the CommonJS export names for ESM import in node:
561
747
  0 && (module.exports = {
562
748
  addOrUpdatePackData,
749
+ calculateEnergy,
563
750
  createSolarFlowStates,
751
+ resetTodaysValues,
564
752
  startCheckStatesTimer,
565
753
  updateSolarFlowState
566
754
  });