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
@@ -1,1545 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var mqttService_exports = {};
30
- __export(mqttService_exports, {
31
- addOrUpdatePackData: () => addOrUpdatePackData,
32
- connectCloudMqttClient: () => connectCloudMqttClient,
33
- connectLocalMqttClient: () => connectLocalMqttClient,
34
- setAcMode: () => setAcMode,
35
- setAcSwitch: () => setAcSwitch,
36
- setAutoModel: () => setAutoModel,
37
- setAutoRecover: () => setAutoRecover,
38
- setBuzzerSwitch: () => setBuzzerSwitch,
39
- setChargeLimit: () => setChargeLimit,
40
- setDcSwitch: () => setDcSwitch,
41
- setDeviceAutomationInOutLimit: () => setDeviceAutomationInOutLimit,
42
- setDischargeLimit: () => setDischargeLimit,
43
- setHubState: () => setHubState,
44
- setInputLimit: () => setInputLimit,
45
- setOutputLimit: () => setOutputLimit,
46
- setPassMode: () => setPassMode,
47
- setSmartMode: () => setSmartMode,
48
- subscribeIotTopic: () => subscribeIotTopic,
49
- subscribeReportTopic: () => subscribeReportTopic,
50
- triggerFullTelemetryUpdate: () => triggerFullTelemetryUpdate
51
- });
52
- module.exports = __toCommonJS(mqttService_exports);
53
- var mqtt = __toESM(require("mqtt"));
54
- var import_adapterService = require("./adapterService");
55
- var import_calculationService = require("./calculationService");
56
- var import_jobSchedule = require("./jobSchedule");
57
- var import_createSolarFlowLocalStates = require("../helpers/createSolarFlowLocalStates");
58
- var import_createSolarFlowStates = require("../helpers/createSolarFlowStates");
59
- var import_helpers = require("../helpers/helpers");
60
- let adapter = void 0;
61
- const knownPackDataProperties = [
62
- "sn",
63
- "totalVol",
64
- "maxVol",
65
- "minVol",
66
- "socLevel",
67
- "maxTemp",
68
- "soh",
69
- "power",
70
- "batcur"
71
- ];
72
- const addOrUpdatePackData = async (productKey, deviceKey, packData, isSolarFlow) => {
73
- if (adapter && productKey && deviceKey) {
74
- await packData.forEach(async (x) => {
75
- if (x.sn && adapter) {
76
- let batType = "";
77
- if (productKey == "yWF7hV") {
78
- batType = "AIO2400";
79
- } else if (x.sn.startsWith("A")) {
80
- batType = "AB1000";
81
- } else if (x.sn.startsWith("B")) {
82
- batType = "AB1000S";
83
- } else if (x.sn.startsWith("C")) {
84
- if (x.sn[3] == "F") {
85
- batType = "AB2000S";
86
- } else {
87
- batType = "AB2000";
88
- }
89
- } else if (x.sn.startsWith("F")) {
90
- batType = "AB3000X";
91
- }
92
- if (!adapter.pack2Devices.some(
93
- (y) => y.packSn == x.sn && y.deviceKey == deviceKey
94
- )) {
95
- adapter.pack2Devices.push({
96
- packSn: x.sn,
97
- deviceKey,
98
- type: batType
99
- });
100
- adapter.log.debug(
101
- `[addOrUpdatePackData] Added battery ${batType} with SN ${x.sn} on deviceKey ${deviceKey} to pack2Devices!`
102
- );
103
- }
104
- const key = (productKey + "." + deviceKey + ".packData." + x.sn).replace(adapter.FORBIDDEN_CHARS, "");
105
- await (adapter == null ? void 0 : adapter.extendObject(key, {
106
- type: "channel",
107
- common: {
108
- name: {
109
- de: batType,
110
- en: batType
111
- }
112
- },
113
- native: {}
114
- }));
115
- await (adapter == null ? void 0 : adapter.extendObject(key + ".model", {
116
- type: "state",
117
- common: {
118
- name: {
119
- de: "Batterietyp",
120
- en: "Battery type"
121
- },
122
- type: "string",
123
- desc: "model",
124
- role: "value",
125
- read: true,
126
- write: false
127
- },
128
- native: {}
129
- }));
130
- await (adapter == null ? void 0 : adapter.setState(key + ".model", batType, true));
131
- await (adapter == null ? void 0 : adapter.extendObject(key + ".sn", {
132
- type: "state",
133
- common: {
134
- name: {
135
- de: "Seriennummer",
136
- en: "Serial id"
137
- },
138
- type: "string",
139
- desc: "Serial ID",
140
- role: "value",
141
- read: true,
142
- write: false
143
- },
144
- native: {}
145
- }));
146
- await (adapter == null ? void 0 : adapter.setState(key + ".sn", x.sn, true));
147
- if (x.socLevel) {
148
- await (adapter == null ? void 0 : adapter.extendObject(key + ".socLevel", {
149
- type: "state",
150
- common: {
151
- name: {
152
- de: "SOC der Batterie",
153
- en: "soc of battery"
154
- },
155
- type: "number",
156
- desc: "SOC Level",
157
- role: "value",
158
- read: true,
159
- write: false,
160
- unit: "%"
161
- },
162
- native: {}
163
- }));
164
- await (adapter == null ? void 0 : adapter.setState(key + ".socLevel", x.socLevel, true));
165
- }
166
- if (x.maxTemp) {
167
- await (adapter == null ? void 0 : adapter.extendObject(key + ".maxTemp", {
168
- type: "state",
169
- common: {
170
- name: {
171
- de: "Max. Temperatur der Batterie",
172
- en: "max temp. of battery"
173
- },
174
- type: "number",
175
- desc: "Max. Temp",
176
- role: "value",
177
- read: true,
178
- write: false,
179
- unit: "\xB0C"
180
- },
181
- native: {}
182
- }));
183
- await (adapter == null ? void 0 : adapter.setState(
184
- key + ".maxTemp",
185
- x.maxTemp / 10 - 273.15,
186
- true
187
- ));
188
- }
189
- if (x.minVol) {
190
- await (adapter == null ? void 0 : adapter.extendObject(key + ".minVol", {
191
- type: "state",
192
- common: {
193
- name: "minVol",
194
- type: "number",
195
- desc: "minVol",
196
- role: "value",
197
- read: true,
198
- write: false,
199
- unit: "V"
200
- },
201
- native: {}
202
- }));
203
- await (adapter == null ? void 0 : adapter.setState(key + ".minVol", x.minVol / 100, true));
204
- }
205
- if (x.batcur) {
206
- await (adapter == null ? void 0 : adapter.extendObject(key + ".batcur", {
207
- type: "state",
208
- common: {
209
- name: "batcur",
210
- type: "number",
211
- desc: "batcur",
212
- role: "value",
213
- read: true,
214
- write: false,
215
- unit: "A"
216
- },
217
- native: {}
218
- }));
219
- await (adapter == null ? void 0 : adapter.setState(key + ".batcur", x.batcur / 10, true));
220
- }
221
- if (x.maxVol) {
222
- await (adapter == null ? void 0 : adapter.extendObject(key + ".maxVol", {
223
- type: "state",
224
- common: {
225
- name: "maxVol",
226
- type: "number",
227
- desc: "maxVol",
228
- role: "value",
229
- read: true,
230
- write: false,
231
- unit: "V"
232
- },
233
- native: {}
234
- }));
235
- await (adapter == null ? void 0 : adapter.setState(key + ".maxVol", x.maxVol / 100, true));
236
- }
237
- if (x.totalVol) {
238
- await (adapter == null ? void 0 : adapter.extendObject(key + ".totalVol", {
239
- type: "state",
240
- common: {
241
- name: "totalVol",
242
- type: "number",
243
- desc: "totalVol",
244
- role: "value",
245
- read: true,
246
- write: false,
247
- unit: "V"
248
- },
249
- native: {}
250
- }));
251
- const totalVol = x.totalVol / 100;
252
- await (adapter == null ? void 0 : adapter.setState(key + ".totalVol", totalVol, true));
253
- if (isSolarFlow) {
254
- (0, import_adapterService.checkVoltage)(adapter, productKey, deviceKey, totalVol);
255
- }
256
- }
257
- if (x.soh) {
258
- await (adapter == null ? void 0 : adapter.extendObject(key + ".soh", {
259
- type: "state",
260
- common: {
261
- name: {
262
- de: "Gesundheitszustand",
263
- en: "State of Health"
264
- },
265
- type: "number",
266
- desc: "State of Health",
267
- role: "value",
268
- read: true,
269
- write: false,
270
- unit: "%"
271
- },
272
- native: {}
273
- }));
274
- await (adapter == null ? void 0 : adapter.setState(key + ".soh", x.soh / 10, true));
275
- }
276
- if (x.power) {
277
- await (adapter == null ? void 0 : adapter.extendObject(key + ".power", {
278
- type: "state",
279
- common: {
280
- name: {
281
- de: "Energie",
282
- en: "Power"
283
- },
284
- type: "number",
285
- desc: "Power",
286
- read: true,
287
- write: false,
288
- role: "value.power",
289
- unit: "W"
290
- },
291
- native: {}
292
- }));
293
- await (adapter == null ? void 0 : adapter.setState(key + ".power", x.power, true));
294
- }
295
- let found = false;
296
- Object.entries(x).forEach(([key2, value]) => {
297
- knownPackDataProperties.forEach((property) => {
298
- if (property == key2) {
299
- found = true;
300
- }
301
- });
302
- if (found) {
303
- } else {
304
- adapter == null ? void 0 : adapter.log.debug(
305
- `[addOrUpdatePackData] ${key2} with value ${value} is a UNKNOWN PackData Mqtt Property!`
306
- );
307
- }
308
- });
309
- }
310
- });
311
- }
312
- };
313
- const onMessage = async (topic, message) => {
314
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a;
315
- if (adapter) {
316
- if (topic.toLowerCase().includes("loginOut/force")) {
317
- }
318
- const topicSplitted = topic.replace("/server/app", "").split("/");
319
- const productKey = topicSplitted[1];
320
- const deviceKey = topicSplitted[2];
321
- let obj = {};
322
- try {
323
- obj = JSON.parse(message.toString());
324
- } catch (e) {
325
- const txt = message.toString();
326
- adapter.log.error(`[onMessage] JSON Parse error!`);
327
- adapter.log.debug(`[onMessage] JSON Parse error: ${txt}!`);
328
- }
329
- let isSolarFlow = false;
330
- const productName = await adapter.getStateAsync(
331
- `${productKey}.${deviceKey}.productName`
332
- );
333
- if (adapter.log.level == "debug") {
334
- adapter.log.debug(
335
- `[onMessage] MQTT message on topic '${topic}': ${message.toString()}`
336
- );
337
- }
338
- if (obj.timestamp) {
339
- const currentTimeStamp = (/* @__PURE__ */ new Date()).getTime() / 1e3;
340
- const diff = currentTimeStamp - obj.timestamp;
341
- if (diff > 600) {
342
- (0, import_adapterService.updateSolarFlowState)(
343
- adapter,
344
- productKey,
345
- deviceKey,
346
- "wifiState",
347
- "Disconnected"
348
- );
349
- } else {
350
- (0, import_adapterService.updateSolarFlowState)(
351
- adapter,
352
- productKey,
353
- deviceKey,
354
- "wifiState",
355
- "Connected"
356
- );
357
- }
358
- }
359
- if (productKey != "8bM93H") {
360
- isSolarFlow = true;
361
- }
362
- (0, import_adapterService.updateSolarFlowState)(
363
- adapter,
364
- productKey,
365
- deviceKey,
366
- "lastUpdate",
367
- (/* @__PURE__ */ new Date()).getTime()
368
- );
369
- if (obj.function == "deviceAutomation" && obj.success == 1) {
370
- const currentValue = await adapter.getStateAsync(
371
- productKey + "." + deviceKey + ".control.setDeviceAutomationInOutLimit"
372
- );
373
- (0, import_adapterService.updateSolarFlowControlState)(
374
- adapter,
375
- productKey,
376
- deviceKey,
377
- "setDeviceAutomationInOutLimit",
378
- (currentValue == null ? void 0 : currentValue.val) ? currentValue.val : 0
379
- );
380
- } else if (obj.function == "deviceAutomation" && obj.success == 0) {
381
- adapter == null ? void 0 : adapter.log.warn(
382
- `[onMessage] device automation failed for ${productName == null ? void 0 : productName.val}: ${productKey}/${deviceKey}!`
383
- );
384
- }
385
- if (((_a = obj.properties) == null ? void 0 : _a.autoModel) != null && ((_b = obj.properties) == null ? void 0 : _b.autoModel) != void 0) {
386
- (0, import_adapterService.updateSolarFlowState)(
387
- adapter,
388
- productKey,
389
- deviceKey,
390
- "autoModel",
391
- obj.properties.autoModel
392
- );
393
- (0, import_adapterService.updateSolarFlowControlState)(
394
- adapter,
395
- productKey,
396
- deviceKey,
397
- "autoModel",
398
- obj.properties.autoModel
399
- );
400
- }
401
- if (((_c = obj.properties) == null ? void 0 : _c.heatState) != null && ((_d = obj.properties) == null ? void 0 : _d.heatState) != void 0) {
402
- const value = ((_e = obj.properties) == null ? void 0 : _e.heatState) == 0 ? false : true;
403
- (0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "heatState", value);
404
- }
405
- if (((_f = obj.properties) == null ? void 0 : _f.electricLevel) != null && ((_g = obj.properties) == null ? void 0 : _g.electricLevel) != void 0) {
406
- (0, import_adapterService.updateSolarFlowState)(
407
- adapter,
408
- productKey,
409
- deviceKey,
410
- "electricLevel",
411
- obj.properties.electricLevel
412
- );
413
- if ((adapter == null ? void 0 : adapter.config.useCalculation) && obj.properties.electricLevel == 100 && isSolarFlow) {
414
- (0, import_calculationService.setEnergyWhMax)(adapter, productKey, deviceKey);
415
- }
416
- if (obj.properties.electricLevel == 100) {
417
- const fullChargeNeeded = await adapter.getStateAsync(
418
- productKey + "." + deviceKey + ".control.fullChargeNeeded"
419
- );
420
- if (fullChargeNeeded && fullChargeNeeded.val && fullChargeNeeded.val == true) {
421
- await (adapter == null ? void 0 : adapter.setState(
422
- `${productKey}.${deviceKey}.control.fullChargeNeeded`,
423
- false,
424
- true
425
- ));
426
- }
427
- }
428
- const minSoc = await (adapter == null ? void 0 : adapter.getStateAsync(
429
- `${productKey}.${deviceKey}.minSoc`
430
- ));
431
- if ((adapter == null ? void 0 : adapter.config.useCalculation) && minSoc && minSoc.val && obj.properties.electricLevel == Number(minSoc.val) && isSolarFlow) {
432
- (0, import_calculationService.setSocToZero)(adapter, productKey, deviceKey);
433
- }
434
- }
435
- if (obj.power != null && obj.power != void 0) {
436
- const value = obj.power / 10;
437
- (0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "power", value);
438
- }
439
- if (((_h = obj.properties) == null ? void 0 : _h.packState) != null && ((_i = obj.properties) == null ? void 0 : _i.packState) != void 0) {
440
- const value = ((_j = obj.properties) == null ? void 0 : _j.packState) == 0 ? "Idle" : ((_k = obj.properties) == null ? void 0 : _k.packState) == 1 ? "Charging" : ((_l = obj.properties) == null ? void 0 : _l.packState) == 2 ? "Discharging" : "Unknown";
441
- (0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "packState", value);
442
- if ((_m = obj.properties) == null ? void 0 : _m.packState) {
443
- (0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "packPower", 0);
444
- }
445
- }
446
- if (((_n = obj.properties) == null ? void 0 : _n.passMode) != null && ((_o = obj.properties) == null ? void 0 : _o.passMode) != void 0) {
447
- const value = ((_p = obj.properties) == null ? void 0 : _p.passMode) == 0 ? "Automatic" : ((_q = obj.properties) == null ? void 0 : _q.passMode) == 1 ? "Always off" : ((_r = obj.properties) == null ? void 0 : _r.passMode) == 2 ? "Always on" : "Unknown";
448
- (0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "passMode", value);
449
- (0, import_adapterService.updateSolarFlowControlState)(
450
- adapter,
451
- productKey,
452
- deviceKey,
453
- "passMode",
454
- (_s = obj.properties) == null ? void 0 : _s.passMode
455
- );
456
- }
457
- if (((_t = obj.properties) == null ? void 0 : _t.pass) != null && ((_u = obj.properties) == null ? void 0 : _u.pass) != void 0) {
458
- const value = ((_v = obj.properties) == null ? void 0 : _v.pass) == 0 ? false : true;
459
- (0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "pass", value);
460
- }
461
- if (((_w = obj.properties) == null ? void 0 : _w.autoRecover) != null && ((_x = obj.properties) == null ? void 0 : _x.autoRecover) != void 0) {
462
- const value = ((_y = obj.properties) == null ? void 0 : _y.autoRecover) == 0 ? false : true;
463
- (0, import_adapterService.updateSolarFlowState)(
464
- adapter,
465
- productKey,
466
- deviceKey,
467
- "autoRecover",
468
- value
469
- );
470
- (0, import_adapterService.updateSolarFlowControlState)(
471
- adapter,
472
- productKey,
473
- deviceKey,
474
- "autoRecover",
475
- value
476
- );
477
- }
478
- if (((_z = obj.properties) == null ? void 0 : _z.outputHomePower) != null && ((_A = obj.properties) == null ? void 0 : _A.outputHomePower) != void 0) {
479
- (0, import_adapterService.updateSolarFlowState)(
480
- adapter,
481
- productKey,
482
- deviceKey,
483
- "outputHomePower",
484
- obj.properties.outputHomePower
485
- );
486
- }
487
- if (((_B = obj.properties) == null ? void 0 : _B.energyPower) != null && ((_C = obj.properties) == null ? void 0 : _C.energyPower) != void 0) {
488
- (0, import_adapterService.updateSolarFlowState)(
489
- adapter,
490
- productKey,
491
- deviceKey,
492
- "energyPower",
493
- obj.properties.energyPower
494
- );
495
- }
496
- if (((_D = obj.properties) == null ? void 0 : _D.outputLimit) != null && ((_E = obj.properties) == null ? void 0 : _E.outputLimit) != void 0) {
497
- (0, import_adapterService.updateSolarFlowState)(
498
- adapter,
499
- productKey,
500
- deviceKey,
501
- "outputLimit",
502
- obj.properties.outputLimit
503
- );
504
- (0, import_adapterService.updateSolarFlowControlState)(
505
- adapter,
506
- productKey,
507
- deviceKey,
508
- "setOutputLimit",
509
- obj.properties.outputLimit
510
- );
511
- }
512
- if (((_F = obj.properties) == null ? void 0 : _F.smartMode) != null && ((_G = obj.properties) == null ? void 0 : _G.smartMode) != void 0) {
513
- const value = ((_H = obj.properties) == null ? void 0 : _H.smartMode) == 0 ? false : true;
514
- (0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "smartMode", value);
515
- (0, import_adapterService.updateSolarFlowControlState)(
516
- adapter,
517
- productKey,
518
- deviceKey,
519
- "smartMode",
520
- value
521
- );
522
- }
523
- if (((_I = obj.properties) == null ? void 0 : _I.buzzerSwitch) != null && ((_J = obj.properties) == null ? void 0 : _J.buzzerSwitch) != void 0) {
524
- const value = ((_K = obj.properties) == null ? void 0 : _K.buzzerSwitch) == 0 ? false : true;
525
- (0, import_adapterService.updateSolarFlowState)(
526
- adapter,
527
- productKey,
528
- deviceKey,
529
- "buzzerSwitch",
530
- value
531
- );
532
- (0, import_adapterService.updateSolarFlowControlState)(
533
- adapter,
534
- productKey,
535
- deviceKey,
536
- "buzzerSwitch",
537
- value
538
- );
539
- }
540
- if (((_L = obj.properties) == null ? void 0 : _L.outputPackPower) != null && ((_M = obj.properties) == null ? void 0 : _M.outputPackPower) != void 0) {
541
- (0, import_adapterService.updateSolarFlowState)(
542
- adapter,
543
- productKey,
544
- deviceKey,
545
- "outputPackPower",
546
- obj.properties.outputPackPower
547
- );
548
- if (((_N = obj.properties) == null ? void 0 : _N.outputPackPower) > 0) {
549
- (0, import_adapterService.updateSolarFlowState)(
550
- adapter,
551
- productKey,
552
- deviceKey,
553
- "packPower",
554
- obj.properties.outputPackPower
555
- );
556
- } else if (((_O = obj.properties) == null ? void 0 : _O.outputPackPower) == 0) {
557
- const packInputPower = await (adapter == null ? void 0 : adapter.getStateAsync(
558
- productKey + "." + deviceKey + ".packInputPower"
559
- ));
560
- if ((packInputPower == null ? void 0 : packInputPower.val) == 0) {
561
- (0, import_adapterService.updateSolarFlowState)(
562
- adapter,
563
- productKey,
564
- deviceKey,
565
- "packPower",
566
- -Math.abs(obj.properties.outputPackPower)
567
- );
568
- }
569
- }
570
- (0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "packInputPower", 0);
571
- }
572
- if (((_P = obj.properties) == null ? void 0 : _P.packInputPower) != null && ((_Q = obj.properties) == null ? void 0 : _Q.packInputPower) != void 0) {
573
- (0, import_adapterService.updateSolarFlowState)(
574
- adapter,
575
- productKey,
576
- deviceKey,
577
- "packInputPower",
578
- obj.properties.packInputPower
579
- );
580
- if (((_R = obj.properties) == null ? void 0 : _R.packInputPower) > 0) {
581
- (0, import_adapterService.updateSolarFlowState)(
582
- adapter,
583
- productKey,
584
- deviceKey,
585
- "packPower",
586
- -Math.abs(obj.properties.packInputPower)
587
- );
588
- } else if (((_S = obj.properties) == null ? void 0 : _S.packInputPower) == 0) {
589
- const outputPackPower = await (adapter == null ? void 0 : adapter.getStateAsync(
590
- productKey + "." + deviceKey + ".outputPackPower"
591
- ));
592
- if ((outputPackPower == null ? void 0 : outputPackPower.val) == 0) {
593
- (0, import_adapterService.updateSolarFlowState)(
594
- adapter,
595
- productKey,
596
- deviceKey,
597
- "packPower",
598
- -Math.abs(obj.properties.packInputPower)
599
- );
600
- }
601
- }
602
- (0, import_adapterService.updateSolarFlowState)(
603
- adapter,
604
- productKey,
605
- deviceKey,
606
- "outputPackPower",
607
- 0
608
- );
609
- }
610
- if (((_T = obj.properties) == null ? void 0 : _T.solarInputPower) != null && ((_U = obj.properties) == null ? void 0 : _U.solarInputPower) != void 0) {
611
- (0, import_adapterService.updateSolarFlowState)(
612
- adapter,
613
- productKey,
614
- deviceKey,
615
- "solarInputPower",
616
- obj.properties.solarInputPower
617
- );
618
- }
619
- if (((_V = obj.properties) == null ? void 0 : _V.pvPower1) != null && ((_W = obj.properties) == null ? void 0 : _W.pvPower1) != void 0) {
620
- (0, import_adapterService.updateSolarFlowState)(
621
- adapter,
622
- productKey,
623
- deviceKey,
624
- "pvPower2",
625
- // Reversed to adjust like offical app
626
- obj.properties.pvPower1
627
- );
628
- }
629
- if (((_X = obj.properties) == null ? void 0 : _X.pvPower2) != null && ((_Y = obj.properties) == null ? void 0 : _Y.pvPower2) != void 0) {
630
- (0, import_adapterService.updateSolarFlowState)(
631
- adapter,
632
- productKey,
633
- deviceKey,
634
- "pvPower1",
635
- // Reversed to adjust like offical app
636
- obj.properties.pvPower2
637
- );
638
- }
639
- if (((_Z = obj.properties) == null ? void 0 : _Z.solarPower1) != null && ((__ = obj.properties) == null ? void 0 : __.solarPower1) != void 0) {
640
- (0, import_adapterService.updateSolarFlowState)(
641
- adapter,
642
- productKey,
643
- deviceKey,
644
- "pvPower1",
645
- obj.properties.solarPower1
646
- );
647
- }
648
- if (((_$ = obj.properties) == null ? void 0 : _$.solarPower2) != null && ((_aa = obj.properties) == null ? void 0 : _aa.solarPower2) != void 0) {
649
- (0, import_adapterService.updateSolarFlowState)(
650
- adapter,
651
- productKey,
652
- deviceKey,
653
- "pvPower2",
654
- obj.properties.solarPower2
655
- );
656
- }
657
- if (((_ba = obj.properties) == null ? void 0 : _ba.solarPower3) != null && ((_ca = obj.properties) == null ? void 0 : _ca.solarPower3) != void 0) {
658
- (0, import_adapterService.updateSolarFlowState)(
659
- adapter,
660
- productKey,
661
- deviceKey,
662
- "pvPower3",
663
- obj.properties.solarPower3
664
- );
665
- }
666
- if (((_da = obj.properties) == null ? void 0 : _da.solarPower4) != null && ((_ea = obj.properties) == null ? void 0 : _ea.solarPower4) != void 0) {
667
- (0, import_adapterService.updateSolarFlowState)(
668
- adapter,
669
- productKey,
670
- deviceKey,
671
- "pvPower4",
672
- obj.properties.solarPower4
673
- );
674
- }
675
- if (((_fa = obj.properties) == null ? void 0 : _fa.remainOutTime) != null && ((_ga = obj.properties) == null ? void 0 : _ga.remainOutTime) != void 0) {
676
- (0, import_adapterService.updateSolarFlowState)(
677
- adapter,
678
- productKey,
679
- deviceKey,
680
- "remainOutTime",
681
- obj.properties.remainOutTime
682
- );
683
- }
684
- if (((_ha = obj.properties) == null ? void 0 : _ha.remainInputTime) != null && ((_ia = obj.properties) == null ? void 0 : _ia.remainInputTime) != void 0) {
685
- (0, import_adapterService.updateSolarFlowState)(
686
- adapter,
687
- productKey,
688
- deviceKey,
689
- "remainInputTime",
690
- obj.properties.remainInputTime
691
- );
692
- }
693
- if (((_ja = obj.properties) == null ? void 0 : _ja.socSet) != null && ((_ka = obj.properties) == null ? void 0 : _ka.socSet) != void 0) {
694
- (0, import_adapterService.updateSolarFlowState)(
695
- adapter,
696
- productKey,
697
- deviceKey,
698
- "socSet",
699
- Number(obj.properties.socSet) / 10
700
- );
701
- (0, import_adapterService.updateSolarFlowControlState)(
702
- adapter,
703
- productKey,
704
- deviceKey,
705
- "chargeLimit",
706
- Number(obj.properties.socSet) / 10
707
- );
708
- }
709
- if (((_la = obj.properties) == null ? void 0 : _la.minSoc) != null && ((_ma = obj.properties) == null ? void 0 : _ma.minSoc) != void 0) {
710
- (0, import_adapterService.updateSolarFlowState)(
711
- adapter,
712
- productKey,
713
- deviceKey,
714
- "minSoc",
715
- Number(obj.properties.minSoc) / 10
716
- );
717
- (0, import_adapterService.updateSolarFlowControlState)(
718
- adapter,
719
- productKey,
720
- deviceKey,
721
- "dischargeLimit",
722
- Number(obj.properties.minSoc) / 10
723
- );
724
- }
725
- if (((_na = obj.properties) == null ? void 0 : _na.inputLimit) != null && ((_oa = obj.properties) == null ? void 0 : _oa.inputLimit) != void 0) {
726
- (0, import_adapterService.updateSolarFlowState)(
727
- adapter,
728
- productKey,
729
- deviceKey,
730
- "inputLimit",
731
- obj.properties.inputLimit
732
- );
733
- if (((_pa = productName == null ? void 0 : productName.val) == null ? void 0 : _pa.toString().toLowerCase().includes("solarflow")) || ((_qa = productName == null ? void 0 : productName.val) == null ? void 0 : _qa.toString().toLowerCase().includes("ace")) || ((_ra = productName == null ? void 0 : productName.val) == null ? void 0 : _ra.toString().toLowerCase().includes("hyper"))) {
734
- (0, import_adapterService.updateSolarFlowControlState)(
735
- adapter,
736
- productKey,
737
- deviceKey,
738
- "setInputLimit",
739
- obj.properties.inputLimit
740
- );
741
- }
742
- }
743
- if (((_sa = obj.properties) == null ? void 0 : _sa.gridInputPower) != null && ((_ta = obj.properties) == null ? void 0 : _ta.gridInputPower) != void 0) {
744
- (0, import_adapterService.updateSolarFlowState)(
745
- adapter,
746
- productKey,
747
- deviceKey,
748
- "gridInputPower",
749
- obj.properties.gridInputPower
750
- );
751
- }
752
- if (((_ua = obj.properties) == null ? void 0 : _ua.acMode) != null && ((_va = obj.properties) == null ? void 0 : _va.acMode) != void 0) {
753
- (0, import_adapterService.updateSolarFlowState)(
754
- adapter,
755
- productKey,
756
- deviceKey,
757
- "acMode",
758
- obj.properties.acMode
759
- );
760
- (0, import_adapterService.updateSolarFlowControlState)(
761
- adapter,
762
- productKey,
763
- deviceKey,
764
- "acMode",
765
- obj.properties.acMode
766
- );
767
- }
768
- if (((_wa = obj.properties) == null ? void 0 : _wa.hyperTmp) != null && ((_xa = obj.properties) == null ? void 0 : _xa.hyperTmp) != void 0) {
769
- (0, import_adapterService.updateSolarFlowState)(
770
- adapter,
771
- productKey,
772
- deviceKey,
773
- "hyperTmp",
774
- obj.properties.hyperTmp / 10 - 273.15
775
- );
776
- }
777
- if (((_ya = obj.properties) == null ? void 0 : _ya.acOutputPower) != null && ((_za = obj.properties) == null ? void 0 : _za.acOutputPower) != void 0) {
778
- (0, import_adapterService.updateSolarFlowState)(
779
- adapter,
780
- productKey,
781
- deviceKey,
782
- "acOutputPower",
783
- obj.properties.acOutputPower
784
- );
785
- }
786
- if (((_Aa = obj.properties) == null ? void 0 : _Aa.gridPower) != null && ((_Ba = obj.properties) == null ? void 0 : _Ba.gridPower) != void 0) {
787
- (0, import_adapterService.updateSolarFlowState)(
788
- adapter,
789
- productKey,
790
- deviceKey,
791
- "gridInputPower",
792
- obj.properties.gridPower
793
- );
794
- }
795
- if (((_Ca = obj.properties) == null ? void 0 : _Ca.acSwitch) != null && ((_Da = obj.properties) == null ? void 0 : _Da.acSwitch) != void 0) {
796
- const value = ((_Ea = obj.properties) == null ? void 0 : _Ea.acSwitch) == 0 ? false : true;
797
- (0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "acSwitch", value);
798
- (0, import_adapterService.updateSolarFlowControlState)(
799
- adapter,
800
- productKey,
801
- deviceKey,
802
- "acSwitch",
803
- value
804
- );
805
- }
806
- if (((_Fa = obj.properties) == null ? void 0 : _Fa.dcSwitch) != null && ((_Ga = obj.properties) == null ? void 0 : _Ga.dcSwitch) != void 0) {
807
- const value = ((_Ha = obj.properties) == null ? void 0 : _Ha.dcSwitch) == 0 ? false : true;
808
- (0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "dcSwitch", value);
809
- (0, import_adapterService.updateSolarFlowControlState)(
810
- adapter,
811
- productKey,
812
- deviceKey,
813
- "dcSwitch",
814
- value
815
- );
816
- }
817
- if (((_Ia = obj.properties) == null ? void 0 : _Ia.dcOutputPower) != null && ((_Ja = obj.properties) == null ? void 0 : _Ja.dcOutputPower) != void 0) {
818
- (0, import_adapterService.updateSolarFlowState)(
819
- adapter,
820
- productKey,
821
- deviceKey,
822
- "dcOutputPower",
823
- obj.properties.dcOutputPower
824
- );
825
- }
826
- if (((_Ka = obj.properties) == null ? void 0 : _Ka.pvBrand) != null && ((_La = obj.properties) == null ? void 0 : _La.pvBrand) != void 0) {
827
- const value = ((_Ma = obj.properties) == null ? void 0 : _Ma.pvBrand) == 0 ? "Others" : ((_Na = obj.properties) == null ? void 0 : _Na.pvBrand) == 1 ? "Hoymiles" : ((_Oa = obj.properties) == null ? void 0 : _Oa.pvBrand) == 2 ? "Enphase" : ((_Pa = obj.properties) == null ? void 0 : _Pa.pvBrand) == 3 ? "APSystems" : ((_Qa = obj.properties) == null ? void 0 : _Qa.pvBrand) == 4 ? "Anker" : ((_Ra = obj.properties) == null ? void 0 : _Ra.pvBrand) == 5 ? "Deye" : ((_Sa = obj.properties) == null ? void 0 : _Sa.pvBrand) == 6 ? "Bosswerk" : "Unknown";
828
- (0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "pvBrand", value);
829
- }
830
- if (((_Ta = obj.properties) == null ? void 0 : _Ta.inverseMaxPower) != null && ((_Ua = obj.properties) == null ? void 0 : _Ua.inverseMaxPower) != void 0) {
831
- (0, import_adapterService.updateSolarFlowState)(
832
- adapter,
833
- productKey,
834
- deviceKey,
835
- "inverseMaxPower",
836
- obj.properties.inverseMaxPower
837
- );
838
- }
839
- if (((_Va = obj.properties) == null ? void 0 : _Va.wifiState) != null && ((_Wa = obj.properties) == null ? void 0 : _Wa.wifiState) != void 0) {
840
- (0, import_adapterService.updateSolarFlowState)(
841
- adapter,
842
- productKey,
843
- deviceKey,
844
- "wifiState",
845
- obj.properties.wifiState == 1 ? "Connected" : "Disconnected"
846
- );
847
- }
848
- if (((_Xa = obj.properties) == null ? void 0 : _Xa.packNum) != null && ((_Ya = obj.properties) == null ? void 0 : _Ya.packNum) != void 0) {
849
- (0, import_adapterService.updateSolarFlowState)(
850
- adapter,
851
- productKey,
852
- deviceKey,
853
- "packNum",
854
- obj.properties.packNum
855
- );
856
- }
857
- if (((_Za = obj.properties) == null ? void 0 : _Za.hubState) != null && ((__a = obj.properties) == null ? void 0 : __a.hubState) != void 0) {
858
- (0, import_adapterService.updateSolarFlowState)(
859
- adapter,
860
- productKey,
861
- deviceKey,
862
- "hubState",
863
- obj.properties.hubState
864
- );
865
- (0, import_adapterService.updateSolarFlowControlState)(
866
- adapter,
867
- productKey,
868
- deviceKey,
869
- "hubState",
870
- obj.properties.hubState
871
- );
872
- }
873
- if (obj.packData) {
874
- addOrUpdatePackData(productKey, deviceKey, obj.packData, isSolarFlow);
875
- }
876
- if (obj.properties && adapter.log.level == "debug") {
877
- const _productName = (_$a = productName == null ? void 0 : productName.val) == null ? void 0 : _$a.toString();
878
- if (_productName) {
879
- const states = (0, import_createSolarFlowStates.getStateDefinition)(_productName);
880
- let found = false;
881
- Object.entries(obj.properties).forEach(([key, value]) => {
882
- states.forEach((state) => {
883
- if (state.title == key) {
884
- found = true;
885
- }
886
- });
887
- if (found) {
888
- } else {
889
- adapter == null ? void 0 : adapter.log.debug(
890
- `[onMessage] ${productName == null ? void 0 : productName.val}: ${key} with value ${JSON.stringify(value)} is a UNKNOWN Mqtt Property!`
891
- );
892
- }
893
- });
894
- }
895
- }
896
- }
897
- };
898
- const setAcMode = async (adapter2, productKey, deviceKey, acMode) => {
899
- var _a;
900
- if (adapter2.mqttClient && productKey && deviceKey) {
901
- if (acMode >= 0 && acMode <= 3) {
902
- const topic = `iot/${productKey}/${deviceKey}/properties/write`;
903
- const setAcMode2 = { properties: { acMode } };
904
- adapter2.log.debug(`[setAcMode] Set AC mode to ${acMode}!`);
905
- (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(setAcMode2));
906
- const smartMode = await adapter2.getStateAsync(
907
- productKey + "." + deviceKey + ".control.smartMode"
908
- );
909
- if (smartMode && !smartMode.val) {
910
- adapter2.log.warn(
911
- `[setAcMode] AC mode was switched and smartMode is false - changes will be written to flash memory. In the worst case, the device may break or changes may no longer be saved!`
912
- );
913
- }
914
- } else {
915
- adapter2.log.error(`[setAcMode] AC mode must be a value between 0 and 3!`);
916
- }
917
- }
918
- };
919
- const setChargeLimit = async (adapter2, productKey, deviceKey, socSet) => {
920
- var _a;
921
- if (adapter2.mqttClient && productKey && deviceKey) {
922
- if (socSet >= 40 && socSet <= 100) {
923
- const topic = `iot/${productKey}/${deviceKey}/properties/write`;
924
- const socSetLimit = { properties: { socSet: socSet * 10 } };
925
- adapter2.log.debug(
926
- `[setChargeLimit] Setting ChargeLimit for device key ${deviceKey} to ${socSet}!`
927
- );
928
- (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(socSetLimit));
929
- } else {
930
- adapter2.log.debug(
931
- `[setChargeLimit] Charge limit is not in range 40<>100!`
932
- );
933
- }
934
- }
935
- };
936
- const setDischargeLimit = async (adapter2, productKey, deviceKey, minSoc) => {
937
- var _a;
938
- if (adapter2.mqttClient && productKey && deviceKey) {
939
- if (minSoc >= 0 && minSoc <= 50) {
940
- const topic = `iot/${productKey}/${deviceKey}/properties/write`;
941
- const socSetLimit = { properties: { minSoc: minSoc * 10 } };
942
- adapter2.log.debug(
943
- `[setDischargeLimit] Setting Discharge Limit for device key ${deviceKey} to ${minSoc}!`
944
- );
945
- (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(socSetLimit));
946
- } else {
947
- adapter2.log.debug(
948
- `[setDischargeLimit] Discharge limit is not in range 0<>50!`
949
- );
950
- }
951
- }
952
- };
953
- const setHubState = async (adapter2, productKey, deviceKey, hubState) => {
954
- var _a;
955
- if (adapter2.mqttClient && productKey && deviceKey) {
956
- if (hubState == 0 || hubState == 1) {
957
- const topic = `iot/${productKey}/${deviceKey}/properties/write`;
958
- const socSetLimit = { properties: { hubState } };
959
- adapter2.log.debug(
960
- `[setHubState] Setting Hub State for device key ${deviceKey} to ${hubState}!`
961
- );
962
- (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(socSetLimit));
963
- } else {
964
- adapter2.log.debug(`[setHubState] Hub state is not 0 or 1!`);
965
- }
966
- }
967
- };
968
- const setDeviceAutomationInOutLimit = async (adapter2, productKey, deviceKey, limit) => {
969
- var _a, _b;
970
- if (adapter2.mqttClient && productKey && deviceKey) {
971
- adapter2.log.debug(
972
- `[setDeviceAutomationInOutLimit] Set device Automation limit to ${limit}!`
973
- );
974
- if (limit) {
975
- limit = Math.round(limit);
976
- } else {
977
- limit = 0;
978
- }
979
- if (adapter2.config.useLowVoltageBlock) {
980
- const lowVoltageBlockState = await adapter2.getStateAsync(
981
- productKey + "." + deviceKey + ".control.lowVoltageBlock"
982
- );
983
- if (lowVoltageBlockState && lowVoltageBlockState.val && lowVoltageBlockState.val == true && limit > 0) {
984
- limit = 0;
985
- }
986
- const fullChargeNeeded = await adapter2.getStateAsync(
987
- productKey + "." + deviceKey + ".control.fullChargeNeeded"
988
- );
989
- if (fullChargeNeeded && fullChargeNeeded.val && fullChargeNeeded.val == true && limit > 0) {
990
- limit = 0;
991
- }
992
- }
993
- if (limit < 0) {
994
- limit = -(0, import_helpers.getMinAndMaxInputLimitForProductKey)(productKey, -limit);
995
- } else {
996
- limit = (0, import_helpers.getMinAndMaxOutputLimitForProductKey)(productKey, limit);
997
- }
998
- const topic = `iot/${productKey}/${deviceKey}/function/invoke`;
999
- adapter2.msgCounter += 1;
1000
- const timestamp = /* @__PURE__ */ new Date();
1001
- timestamp.setMilliseconds(0);
1002
- let _arguments = [];
1003
- const productName = (0, import_helpers.getProductNameFromProductKey)(productKey);
1004
- if (productName.toLowerCase().includes("2400 ac") || productName.toLowerCase().includes("solarflow 800")) {
1005
- adapter2.log.debug(
1006
- `[setDeviceAutomationInOutLimit] Using HEMS Variant of device automation, as device '${productName}' detected!`
1007
- );
1008
- const hemsEP = {
1009
- arguments: {
1010
- outputPower: limit > 0 ? limit : 0,
1011
- chargeState: limit > 0 ? 0 : 1,
1012
- chargePower: limit > 0 ? 0 : -limit,
1013
- mode: 9
1014
- },
1015
- function: "hemsEP",
1016
- messageId: adapter2.msgCounter,
1017
- deviceKey,
1018
- timestamp: timestamp.getTime() / 1e3
1019
- };
1020
- (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(hemsEP));
1021
- return;
1022
- } else if (productName.toLowerCase().includes("hyper")) {
1023
- if (limit < 0) {
1024
- adapter2.log.debug(
1025
- `[setDeviceAutomationInOutLimit] Using CHARGE variant of HYPER device automation, as device '${productName}' detected and limit is negative!`
1026
- );
1027
- _arguments = [
1028
- {
1029
- autoModelProgram: 1,
1030
- autoModelValue: {
1031
- chargingType: 1,
1032
- price: 2,
1033
- chargingPower: -limit,
1034
- prices: [
1035
- 1,
1036
- 1,
1037
- 1,
1038
- 1,
1039
- 1,
1040
- 1,
1041
- 1,
1042
- 1,
1043
- 1,
1044
- 1,
1045
- 1,
1046
- 1,
1047
- 1,
1048
- 1,
1049
- 1,
1050
- 1,
1051
- 1,
1052
- 1,
1053
- 1,
1054
- 1,
1055
- 1,
1056
- 1,
1057
- 1,
1058
- 1
1059
- ],
1060
- outPower: 0,
1061
- freq: 0
1062
- },
1063
- msgType: 1,
1064
- autoModel: 8
1065
- }
1066
- ];
1067
- } else {
1068
- adapter2.log.debug(
1069
- `[setDeviceAutomationInOutLimit] Using FEED IN variant of HYPER device automation, as device '${productName}' detected and limit is positive!`
1070
- );
1071
- _arguments = [
1072
- {
1073
- autoModelProgram: 2,
1074
- autoModelValue: {
1075
- chargingType: 0,
1076
- chargingPower: 0,
1077
- freq: 0,
1078
- outPower: limit
1079
- },
1080
- msgType: 1,
1081
- autoModel: 8
1082
- }
1083
- ];
1084
- }
1085
- } else {
1086
- if (limit < 0) {
1087
- adapter2.log.debug(
1088
- `[setDeviceAutomationInOutLimit] Using CHARGE variant of HUB device automation, as device '${productName}' detected and limit is negative!`
1089
- );
1090
- _arguments = [
1091
- {
1092
- autoModelProgram: 2,
1093
- autoModelValue: {
1094
- chargingType: 1,
1095
- chargingPower: -limit,
1096
- freq: 0,
1097
- outPower: 0
1098
- },
1099
- msgType: 1,
1100
- autoModel: 8
1101
- }
1102
- ];
1103
- } else {
1104
- adapter2.log.debug(
1105
- `[setDeviceAutomationInOutLimit] Using FEED IN variant of Hub device automation, as device '${productName}' detected and limit is positive!`
1106
- );
1107
- _arguments = [
1108
- {
1109
- autoModelProgram: 2,
1110
- autoModelValue: limit,
1111
- msgType: 1,
1112
- autoModel: 8
1113
- }
1114
- ];
1115
- }
1116
- }
1117
- const deviceAutomation = {
1118
- arguments: _arguments,
1119
- function: "deviceAutomation",
1120
- messageId: adapter2.msgCounter,
1121
- deviceKey,
1122
- timestamp: timestamp.getTime() / 1e3
1123
- };
1124
- (_b = adapter2.mqttClient) == null ? void 0 : _b.publish(topic, JSON.stringify(deviceAutomation));
1125
- }
1126
- };
1127
- const setOutputLimit = async (adapter2, productKey, deviceKey, limit) => {
1128
- var _a, _b, _c;
1129
- if (adapter2.mqttClient && productKey && deviceKey) {
1130
- const autoModel = (_a = await adapter2.getStateAsync(productKey + "." + deviceKey + ".autoModel")) == null ? void 0 : _a.val;
1131
- if (autoModel != 0) {
1132
- adapter2.log.warn(
1133
- "Operation mode (autoModel) is not set to '0', we can't set the output limit!"
1134
- );
1135
- return;
1136
- }
1137
- if (limit) {
1138
- limit = Math.round(limit);
1139
- } else {
1140
- limit = 0;
1141
- }
1142
- if (adapter2.config.useLowVoltageBlock) {
1143
- const lowVoltageBlockState = await adapter2.getStateAsync(
1144
- productKey + "." + deviceKey + ".control.lowVoltageBlock"
1145
- );
1146
- if (lowVoltageBlockState && lowVoltageBlockState.val && lowVoltageBlockState.val == true) {
1147
- limit = 0;
1148
- }
1149
- const fullChargeNeeded = await adapter2.getStateAsync(
1150
- productKey + "." + deviceKey + ".control.fullChargeNeeded"
1151
- );
1152
- if (fullChargeNeeded && fullChargeNeeded.val && fullChargeNeeded.val == true) {
1153
- limit = 0;
1154
- }
1155
- }
1156
- const currentLimit = (_b = await adapter2.getStateAsync(productKey + "." + deviceKey + ".outputLimit")) == null ? void 0 : _b.val;
1157
- if (currentLimit != null && currentLimit != void 0) {
1158
- if (currentLimit != limit) {
1159
- limit = (0, import_helpers.getMinAndMaxOutputLimitForProductKey)(productKey, limit);
1160
- const topic = `iot/${productKey}/${deviceKey}/properties/write`;
1161
- const outputlimit = { properties: { outputLimit: limit } };
1162
- adapter2.msgCounter += 1;
1163
- const timestamp = /* @__PURE__ */ new Date();
1164
- timestamp.setMilliseconds(0);
1165
- (_c = adapter2.mqttClient) == null ? void 0 : _c.publish(topic, JSON.stringify(outputlimit));
1166
- }
1167
- }
1168
- }
1169
- };
1170
- const setInputLimit = async (adapter2, productKey, deviceKey, limit) => {
1171
- var _a;
1172
- if (adapter2.mqttClient && productKey && deviceKey) {
1173
- if (limit) {
1174
- limit = Math.round(limit);
1175
- } else {
1176
- limit = 0;
1177
- }
1178
- limit = (0, import_helpers.getMinAndMaxInputLimitForProductKey)(productKey, limit);
1179
- const topic = `iot/${productKey}/${deviceKey}/properties/write`;
1180
- const inputLimitContent = { properties: { inputLimit: limit } };
1181
- (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(inputLimitContent));
1182
- }
1183
- };
1184
- const setSmartMode = async (adapter2, productKey, deviceKey, smartModeOn) => {
1185
- var _a;
1186
- if (adapter2.mqttClient && productKey && deviceKey) {
1187
- const topic = `iot/${productKey}/${deviceKey}/properties/write`;
1188
- const setSmartModeContent = {
1189
- properties: { smartMode: smartModeOn ? 1 : 0 }
1190
- };
1191
- adapter2.log.debug(
1192
- `[setBuzzer] Setting Smart Mode for device key ${deviceKey} to ${smartModeOn}!`
1193
- );
1194
- (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(setSmartModeContent));
1195
- }
1196
- };
1197
- const setBuzzerSwitch = async (adapter2, productKey, deviceKey, buzzerOn) => {
1198
- var _a;
1199
- if (adapter2.mqttClient && productKey && deviceKey) {
1200
- const topic = `iot/${productKey}/${deviceKey}/properties/write`;
1201
- const setBuzzerSwitchContent = {
1202
- properties: { buzzerSwitch: buzzerOn ? 1 : 0 }
1203
- };
1204
- adapter2.log.debug(
1205
- `[setBuzzer] Setting Buzzer for device key ${deviceKey} to ${buzzerOn}!`
1206
- );
1207
- (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(setBuzzerSwitchContent));
1208
- }
1209
- };
1210
- const setAutoModel = async (adapter2, productKey, deviceKey, autoModel) => {
1211
- var _a;
1212
- if (adapter2.mqttClient && productKey && deviceKey) {
1213
- const topic = `iot/${productKey}/${deviceKey}/properties/write`;
1214
- let setAutoModelContent = { properties: { autoModel } };
1215
- switch (autoModel) {
1216
- case 8:
1217
- setAutoModelContent = {
1218
- properties: {
1219
- autoModelProgram: 1,
1220
- autoModelValue: { chargingType: 0, chargingPower: 0, outPower: 0 },
1221
- msgType: 1,
1222
- autoModel: 8
1223
- }
1224
- };
1225
- break;
1226
- case 9:
1227
- setAutoModelContent = {
1228
- properties: {
1229
- autoModelProgram: 2,
1230
- autoModelValue: { chargingType: 3, chargingPower: 0, outPower: 0 },
1231
- msgType: 1,
1232
- autoModel: 9
1233
- }
1234
- };
1235
- break;
1236
- }
1237
- adapter2.log.debug(
1238
- `[setAutoModel] Setting autoModel for device key ${deviceKey} to ${autoModel}!`
1239
- );
1240
- (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(setAutoModelContent));
1241
- }
1242
- };
1243
- const triggerFullTelemetryUpdate = async (adapter2, productKey, deviceKey) => {
1244
- var _a;
1245
- if (adapter2.mqttClient && productKey && deviceKey) {
1246
- const topic = `iot/${productKey}/${deviceKey}/properties/read`;
1247
- const getAllContent = { properties: ["getAll"] };
1248
- adapter2.log.debug(
1249
- `[triggerFullTelemetryUpdate] Triggering full telemetry update for device key ${deviceKey}!`
1250
- );
1251
- (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(getAllContent));
1252
- }
1253
- };
1254
- const setPassMode = async (adapter2, productKey, deviceKey, passMode) => {
1255
- var _a;
1256
- if (adapter2.mqttClient && productKey && deviceKey) {
1257
- const topic = `iot/${productKey}/${deviceKey}/properties/write`;
1258
- const setPassModeContent = { properties: { passMode } };
1259
- adapter2.log.debug(
1260
- `[setPassMode] Set passMode for device ${deviceKey} to ${passMode}!`
1261
- );
1262
- (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(setPassModeContent));
1263
- }
1264
- };
1265
- const setAutoRecover = async (adapter2, productKey, deviceKey, autoRecover) => {
1266
- var _a;
1267
- if (adapter2.mqttClient && productKey && deviceKey) {
1268
- const topic = `iot/${productKey}/${deviceKey}/properties/write`;
1269
- const setAutoRecoverContent = {
1270
- properties: { autoRecover: autoRecover ? 1 : 0 }
1271
- };
1272
- adapter2.log.debug(
1273
- `[setAutoRecover] Set autoRecover for device ${deviceKey} to ${autoRecover}!`
1274
- );
1275
- (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(setAutoRecoverContent));
1276
- }
1277
- };
1278
- const setDcSwitch = async (adapter2, productKey, deviceKey, dcSwitch) => {
1279
- var _a;
1280
- if (adapter2.mqttClient && productKey && deviceKey) {
1281
- const topic = `iot/${productKey}/${deviceKey}/properties/write`;
1282
- const setDcSwitchContent = {
1283
- properties: { dcSwitch: dcSwitch ? 1 : 0 }
1284
- };
1285
- adapter2.log.debug(
1286
- `[setDcSwitch] Set DC Switch for device ${deviceKey} to ${dcSwitch}!`
1287
- );
1288
- (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(setDcSwitchContent));
1289
- }
1290
- };
1291
- const setAcSwitch = async (adapter2, productKey, deviceKey, acSwitch) => {
1292
- var _a;
1293
- if (adapter2.mqttClient && productKey && deviceKey) {
1294
- const topic = `iot/${productKey}/${deviceKey}/properties/write`;
1295
- const setAcSwitchContent = {
1296
- properties: { acSwitch: acSwitch ? 1 : 0 }
1297
- };
1298
- adapter2.log.debug(
1299
- `[setAcSwitch] Set AC Switch for device ${deviceKey} to ${acSwitch}!`
1300
- );
1301
- (_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(setAcSwitchContent));
1302
- }
1303
- };
1304
- const onConnected = () => {
1305
- adapter == null ? void 0 : adapter.log.info("[onConnected] Connected with MQTT!");
1306
- };
1307
- const onError = (error) => {
1308
- adapter == null ? void 0 : adapter.log.error("Connection to MQTT failed! Error: " + error);
1309
- };
1310
- const onSubscribeReportTopic = (error) => {
1311
- if (error) {
1312
- adapter == null ? void 0 : adapter.log.error("Subscription to MQTT failed! Error: " + error);
1313
- } else {
1314
- adapter == null ? void 0 : adapter.log.debug("Subscription of Report Topic successful!");
1315
- }
1316
- };
1317
- const onSubscribeIotTopic = (error, productKey, deviceKey) => {
1318
- if (error) {
1319
- adapter == null ? void 0 : adapter.log.error("Subscription to MQTT failed! Error: " + error);
1320
- } else if (adapter) {
1321
- adapter == null ? void 0 : adapter.log.debug("Subscription of IOT Topic successful!");
1322
- triggerFullTelemetryUpdate(adapter, productKey, deviceKey);
1323
- }
1324
- };
1325
- const subscribeReportTopic = (productKey, deviceKey, timeout) => {
1326
- const reportTopic = `/${productKey}/${deviceKey}/#`;
1327
- setTimeout(() => {
1328
- var _a;
1329
- if (adapter) {
1330
- adapter.log.debug(
1331
- `[subscribeReportTopic] Subscribing to MQTT Topic: ${reportTopic}`
1332
- );
1333
- (_a = adapter.mqttClient) == null ? void 0 : _a.subscribe(reportTopic, onSubscribeReportTopic);
1334
- }
1335
- }, timeout);
1336
- };
1337
- const subscribeIotTopic = (productKey, deviceKey, timeout) => {
1338
- const iotTopic = `iot/${productKey}/${deviceKey}/#`;
1339
- setTimeout(() => {
1340
- var _a;
1341
- adapter == null ? void 0 : adapter.log.debug(
1342
- `[subscribeIotTopic] Subscribing to MQTT Topic: ${iotTopic}`
1343
- );
1344
- (_a = adapter == null ? void 0 : adapter.mqttClient) == null ? void 0 : _a.subscribe(iotTopic, (error) => {
1345
- onSubscribeIotTopic(error, productKey, deviceKey);
1346
- });
1347
- }, timeout);
1348
- };
1349
- const connectCloudMqttClient = (_adapter) => {
1350
- var _a, _b;
1351
- adapter = _adapter;
1352
- if (!((_a = adapter.paths) == null ? void 0 : _a.mqttPassword)) {
1353
- adapter.log.error(`[connectCloudMqttClient] MQTT Password is missing!`);
1354
- return;
1355
- }
1356
- const mqttPassword = atob((_b = adapter.paths) == null ? void 0 : _b.mqttPassword);
1357
- const options = {
1358
- clientId: adapter.accessToken,
1359
- username: "zenApp",
1360
- password: mqttPassword,
1361
- clean: true,
1362
- protocolVersion: 5
1363
- };
1364
- if (mqtt && adapter && adapter.paths && adapter.deviceList) {
1365
- adapter.log.debug(
1366
- `[connectCloudMqttClient] Connecting to MQTT broker ${adapter.paths.mqttUrl + ":" + adapter.paths.mqttPort}...`
1367
- );
1368
- adapter.mqttClient = mqtt.connect(
1369
- "mqtt://" + adapter.paths.mqttUrl + ":" + adapter.paths.mqttPort,
1370
- options
1371
- );
1372
- if (adapter && adapter.mqttClient) {
1373
- adapter.mqttClient.on("connect", onConnected);
1374
- adapter.mqttClient.on("error", onError);
1375
- adapter.deviceList.forEach(
1376
- (device, index) => {
1377
- var _a2;
1378
- if (adapter) {
1379
- let connectIot = true;
1380
- if (device.productKey == "s3Xk4x") {
1381
- const smartPlugReportTopic = `/server/app/${adapter.userId}/${device.id}/smart/power`;
1382
- (_a2 = adapter.mqttClient) == null ? void 0 : _a2.subscribe(
1383
- smartPlugReportTopic,
1384
- onSubscribeReportTopic
1385
- );
1386
- connectIot = false;
1387
- }
1388
- subscribeReportTopic(
1389
- device.productKey,
1390
- device.deviceKey,
1391
- 1e3 * index
1392
- );
1393
- if (connectIot) {
1394
- subscribeIotTopic(
1395
- device.productKey,
1396
- device.deviceKey,
1397
- 1e3 * index
1398
- );
1399
- }
1400
- if (device.packList && device.packList.length > 0) {
1401
- device.packList.forEach(async (subDevice) => {
1402
- if (subDevice.productName.toLocaleLowerCase() == "ace 1500") {
1403
- subscribeReportTopic(
1404
- subDevice.productKey,
1405
- subDevice.deviceKey,
1406
- 1e3 * index
1407
- );
1408
- subscribeIotTopic(
1409
- subDevice.productKey,
1410
- subDevice.deviceKey,
1411
- 2e3 * index
1412
- );
1413
- }
1414
- });
1415
- }
1416
- }
1417
- }
1418
- );
1419
- adapter.mqttClient.on("message", onMessage);
1420
- (0, import_jobSchedule.startResetValuesJob)(adapter);
1421
- (0, import_jobSchedule.startCheckStatesAndConnectionJob)(adapter);
1422
- if (adapter.config.useCalculation) {
1423
- (0, import_jobSchedule.startCalculationJob)(adapter);
1424
- }
1425
- }
1426
- }
1427
- };
1428
- const connectLocalMqttClient = (_adapter) => {
1429
- adapter = _adapter;
1430
- const options = {
1431
- clientId: "ioBroker.zendure-solarflow." + adapter.instance
1432
- };
1433
- if (mqtt && adapter && adapter.config && adapter.config.localMqttUrl) {
1434
- adapter.log.debug(
1435
- `[connectLocalMqttClient] Connecting to MQTT broker ${adapter.config.localMqttUrl + ":1883"}...`
1436
- );
1437
- adapter.mqttClient = mqtt.connect(
1438
- "mqtt://" + adapter.config.localMqttUrl + ":1883",
1439
- options
1440
- );
1441
- if (adapter && adapter.mqttClient) {
1442
- adapter.mqttClient.on("connect", onConnected);
1443
- adapter.mqttClient.on("error", onError);
1444
- adapter.setState("info.connection", true, true);
1445
- if (adapter.config.localDevice1ProductKey && adapter.config.localDevice1DeviceKey) {
1446
- (0, import_createSolarFlowLocalStates.createSolarFlowLocalStates)(
1447
- adapter,
1448
- adapter.config.localDevice1ProductKey,
1449
- adapter.config.localDevice1DeviceKey
1450
- );
1451
- subscribeReportTopic(
1452
- adapter.config.localDevice1ProductKey,
1453
- adapter.config.localDevice1DeviceKey,
1454
- 1e3
1455
- );
1456
- subscribeIotTopic(
1457
- adapter.config.localDevice1ProductKey,
1458
- adapter.config.localDevice1DeviceKey,
1459
- 1e3
1460
- );
1461
- }
1462
- if (adapter.config.localDevice2ProductKey && adapter.config.localDevice2DeviceKey) {
1463
- (0, import_createSolarFlowLocalStates.createSolarFlowLocalStates)(
1464
- adapter,
1465
- adapter.config.localDevice2ProductKey,
1466
- adapter.config.localDevice2DeviceKey
1467
- );
1468
- subscribeReportTopic(
1469
- adapter.config.localDevice2ProductKey,
1470
- adapter.config.localDevice2DeviceKey,
1471
- 2e3
1472
- );
1473
- subscribeIotTopic(
1474
- adapter.config.localDevice2ProductKey,
1475
- adapter.config.localDevice2DeviceKey,
1476
- 2e3
1477
- );
1478
- }
1479
- if (adapter.config.localDevice3ProductKey && adapter.config.localDevice3DeviceKey) {
1480
- (0, import_createSolarFlowLocalStates.createSolarFlowLocalStates)(
1481
- adapter,
1482
- adapter.config.localDevice3ProductKey,
1483
- adapter.config.localDevice3DeviceKey
1484
- );
1485
- subscribeReportTopic(
1486
- adapter.config.localDevice3ProductKey,
1487
- adapter.config.localDevice3DeviceKey,
1488
- 2e3
1489
- );
1490
- subscribeIotTopic(
1491
- adapter.config.localDevice3ProductKey,
1492
- adapter.config.localDevice3DeviceKey,
1493
- 2e3
1494
- );
1495
- }
1496
- if (adapter.config.localDevice4ProductKey && adapter.config.localDevice4DeviceKey) {
1497
- (0, import_createSolarFlowLocalStates.createSolarFlowLocalStates)(
1498
- adapter,
1499
- adapter.config.localDevice4ProductKey,
1500
- adapter.config.localDevice4DeviceKey
1501
- );
1502
- subscribeReportTopic(
1503
- adapter.config.localDevice4ProductKey,
1504
- adapter.config.localDevice4DeviceKey,
1505
- 2e3
1506
- );
1507
- subscribeIotTopic(
1508
- adapter.config.localDevice4ProductKey,
1509
- adapter.config.localDevice4DeviceKey,
1510
- 2e3
1511
- );
1512
- }
1513
- adapter.mqttClient.on("message", onMessage);
1514
- (0, import_jobSchedule.startResetValuesJob)(adapter);
1515
- (0, import_jobSchedule.startCheckStatesAndConnectionJob)(adapter);
1516
- if (adapter.config.useCalculation) {
1517
- (0, import_jobSchedule.startCalculationJob)(adapter);
1518
- }
1519
- }
1520
- }
1521
- };
1522
- // Annotate the CommonJS export names for ESM import in node:
1523
- 0 && (module.exports = {
1524
- addOrUpdatePackData,
1525
- connectCloudMqttClient,
1526
- connectLocalMqttClient,
1527
- setAcMode,
1528
- setAcSwitch,
1529
- setAutoModel,
1530
- setAutoRecover,
1531
- setBuzzerSwitch,
1532
- setChargeLimit,
1533
- setDcSwitch,
1534
- setDeviceAutomationInOutLimit,
1535
- setDischargeLimit,
1536
- setHubState,
1537
- setInputLimit,
1538
- setOutputLimit,
1539
- setPassMode,
1540
- setSmartMode,
1541
- subscribeIotTopic,
1542
- subscribeReportTopic,
1543
- triggerFullTelemetryUpdate
1544
- });
1545
- //# sourceMappingURL=mqttService.js.map