iobroker.zendure-solarflow 1.2.6 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/admin/build/index.js.map +2 -2
- package/build/helpers/createControlStates.js +62 -0
- package/build/helpers/createControlStates.js.map +2 -2
- package/build/helpers/createSolarFlowStates.js +15 -0
- package/build/helpers/createSolarFlowStates.js.map +2 -2
- package/build/main.js +20 -1
- package/build/main.js.map +2 -2
- package/build/services/calculationService.js +63 -14
- package/build/services/calculationService.js.map +2 -2
- package/build/services/mqttService.js +218 -174
- package/build/services/mqttService.js.map +2 -2
- package/io-package.json +27 -27
- package/package.json +1 -1
|
@@ -30,144 +30,133 @@ var mqttService_exports = {};
|
|
|
30
30
|
__export(mqttService_exports, {
|
|
31
31
|
addOrUpdatePackData: () => addOrUpdatePackData,
|
|
32
32
|
connectMqttClient: () => connectMqttClient,
|
|
33
|
+
setAutoRecover: () => setAutoRecover,
|
|
34
|
+
setBuzzerSwitch: () => setBuzzerSwitch,
|
|
33
35
|
setChargeLimit: () => setChargeLimit,
|
|
34
36
|
setDischargeLimit: () => setDischargeLimit,
|
|
35
|
-
setOutputLimit: () => setOutputLimit
|
|
37
|
+
setOutputLimit: () => setOutputLimit,
|
|
38
|
+
setPassMode: () => setPassMode,
|
|
39
|
+
triggerFullTelemetryUpdate: () => triggerFullTelemetryUpdate
|
|
36
40
|
});
|
|
37
41
|
module.exports = __toCommonJS(mqttService_exports);
|
|
38
42
|
var mqtt = __toESM(require("mqtt"));
|
|
39
43
|
var import_adapterService = require("./adapterService");
|
|
40
|
-
var import_timeHelper = require("../helpers/timeHelper");
|
|
41
44
|
var import_calculationService = require("./calculationService");
|
|
42
45
|
let adapter = void 0;
|
|
43
|
-
const
|
|
44
|
-
adapter
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const onSubscribe = (error) => {
|
|
50
|
-
if (error) {
|
|
51
|
-
adapter == null ? void 0 : adapter.log.error("Subscription to MQTT failed! Error: " + error);
|
|
52
|
-
} else {
|
|
53
|
-
adapter == null ? void 0 : adapter.log.debug("Subscription successful!");
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const addOrUpdatePackData = async (adapter2, productKey, deviceKey, packData) => {
|
|
57
|
-
await packData.forEach(async (x) => {
|
|
58
|
-
if (x.sn) {
|
|
59
|
-
const key = (productKey + "." + deviceKey + ".packData." + x.sn).replace(
|
|
60
|
-
adapter2.FORBIDDEN_CHARS,
|
|
61
|
-
""
|
|
62
|
-
);
|
|
63
|
-
await (adapter2 == null ? void 0 : adapter2.extendObjectAsync(key + ".sn", {
|
|
64
|
-
type: "state",
|
|
65
|
-
common: {
|
|
66
|
-
name: {
|
|
67
|
-
de: "Seriennummer",
|
|
68
|
-
en: "Serial id"
|
|
69
|
-
},
|
|
70
|
-
type: "string",
|
|
71
|
-
desc: "Serial ID",
|
|
72
|
-
role: "value",
|
|
73
|
-
read: true,
|
|
74
|
-
write: false
|
|
75
|
-
},
|
|
76
|
-
native: {}
|
|
77
|
-
}));
|
|
78
|
-
await (adapter2 == null ? void 0 : adapter2.setStateAsync(key + ".sn", x.sn, true));
|
|
79
|
-
if (x.socLevel) {
|
|
80
|
-
await (adapter2 == null ? void 0 : adapter2.extendObjectAsync(key + ".socLevel", {
|
|
46
|
+
const addOrUpdatePackData = async (productKey, deviceKey, packData) => {
|
|
47
|
+
if (adapter && productKey && deviceKey) {
|
|
48
|
+
await packData.forEach(async (x) => {
|
|
49
|
+
if (x.sn && adapter) {
|
|
50
|
+
const key = (productKey + "." + deviceKey + ".packData." + x.sn).replace(adapter.FORBIDDEN_CHARS, "");
|
|
51
|
+
await (adapter == null ? void 0 : adapter.extendObjectAsync(key + ".sn", {
|
|
81
52
|
type: "state",
|
|
82
53
|
common: {
|
|
83
54
|
name: {
|
|
84
|
-
de: "
|
|
85
|
-
en: "
|
|
55
|
+
de: "Seriennummer",
|
|
56
|
+
en: "Serial id"
|
|
86
57
|
},
|
|
87
|
-
type: "
|
|
88
|
-
desc: "
|
|
58
|
+
type: "string",
|
|
59
|
+
desc: "Serial ID",
|
|
89
60
|
role: "value",
|
|
90
61
|
read: true,
|
|
91
62
|
write: false
|
|
92
63
|
},
|
|
93
64
|
native: {}
|
|
94
65
|
}));
|
|
95
|
-
await (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
66
|
+
await (adapter == null ? void 0 : adapter.setStateAsync(key + ".sn", x.sn, true));
|
|
67
|
+
if (x.socLevel) {
|
|
68
|
+
await (adapter == null ? void 0 : adapter.extendObjectAsync(key + ".socLevel", {
|
|
69
|
+
type: "state",
|
|
70
|
+
common: {
|
|
71
|
+
name: {
|
|
72
|
+
de: "SOC der Batterie",
|
|
73
|
+
en: "soc of battery"
|
|
74
|
+
},
|
|
75
|
+
type: "number",
|
|
76
|
+
desc: "SOC Level",
|
|
77
|
+
role: "value",
|
|
78
|
+
read: true,
|
|
79
|
+
write: false
|
|
104
80
|
},
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
81
|
+
native: {}
|
|
82
|
+
}));
|
|
83
|
+
await (adapter == null ? void 0 : adapter.setStateAsync(key + ".socLevel", x.socLevel, true));
|
|
84
|
+
}
|
|
85
|
+
if (x.maxTemp) {
|
|
86
|
+
await (adapter == null ? void 0 : adapter.extendObjectAsync(key + ".maxTemp", {
|
|
87
|
+
type: "state",
|
|
88
|
+
common: {
|
|
89
|
+
name: {
|
|
90
|
+
de: "Max. Temperatur der Batterie",
|
|
91
|
+
en: "max temp. of battery"
|
|
92
|
+
},
|
|
93
|
+
type: "number",
|
|
94
|
+
desc: "Max. Temp",
|
|
95
|
+
role: "value",
|
|
96
|
+
read: true,
|
|
97
|
+
write: false
|
|
98
|
+
},
|
|
99
|
+
native: {}
|
|
100
|
+
}));
|
|
101
|
+
await (adapter == null ? void 0 : adapter.setStateAsync(
|
|
102
|
+
key + ".maxTemp",
|
|
103
|
+
x.maxTemp / 10 - 273.15,
|
|
104
|
+
true
|
|
105
|
+
));
|
|
106
|
+
}
|
|
107
|
+
if (x.minVol) {
|
|
108
|
+
await (adapter == null ? void 0 : adapter.extendObjectAsync(key + ".minVol", {
|
|
109
|
+
type: "state",
|
|
110
|
+
common: {
|
|
111
|
+
name: "minVol",
|
|
112
|
+
type: "number",
|
|
113
|
+
desc: "minVol",
|
|
114
|
+
role: "value",
|
|
115
|
+
read: true,
|
|
116
|
+
write: false
|
|
117
|
+
},
|
|
118
|
+
native: {}
|
|
119
|
+
}));
|
|
120
|
+
await (adapter == null ? void 0 : adapter.setStateAsync(key + ".minVol", x.minVol / 100, true));
|
|
121
|
+
}
|
|
122
|
+
if (x.maxVol) {
|
|
123
|
+
await (adapter == null ? void 0 : adapter.extendObjectAsync(key + ".maxVol", {
|
|
124
|
+
type: "state",
|
|
125
|
+
common: {
|
|
126
|
+
name: "maxVol",
|
|
127
|
+
type: "number",
|
|
128
|
+
desc: "maxVol",
|
|
129
|
+
role: "value",
|
|
130
|
+
read: true,
|
|
131
|
+
write: false
|
|
132
|
+
},
|
|
133
|
+
native: {}
|
|
134
|
+
}));
|
|
135
|
+
await (adapter == null ? void 0 : adapter.setStateAsync(key + ".maxVol", x.maxVol / 100, true));
|
|
136
|
+
}
|
|
137
|
+
if (x.totalVol) {
|
|
138
|
+
await (adapter == null ? void 0 : adapter.extendObjectAsync(key + ".totalVol", {
|
|
139
|
+
type: "state",
|
|
140
|
+
common: {
|
|
141
|
+
name: "totalVol",
|
|
142
|
+
type: "number",
|
|
143
|
+
desc: "totalVol",
|
|
144
|
+
role: "value",
|
|
145
|
+
read: true,
|
|
146
|
+
write: false
|
|
147
|
+
},
|
|
148
|
+
native: {}
|
|
149
|
+
}));
|
|
150
|
+
const totalVol = x.totalVol / 100;
|
|
151
|
+
await (adapter == null ? void 0 : adapter.setStateAsync(key + ".totalVol", totalVol, true));
|
|
152
|
+
(0, import_adapterService.checkVoltage)(adapter, productKey, deviceKey, totalVol);
|
|
153
|
+
}
|
|
165
154
|
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
168
157
|
};
|
|
169
158
|
const onMessage = async (topic, message) => {
|
|
170
|
-
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;
|
|
159
|
+
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;
|
|
171
160
|
if (adapter) {
|
|
172
161
|
const splitted = topic.split("/");
|
|
173
162
|
const productKey = splitted[1];
|
|
@@ -206,7 +195,13 @@ const onMessage = async (topic, message) => {
|
|
|
206
195
|
}
|
|
207
196
|
if (((_p = obj.properties) == null ? void 0 : _p.autoRecover) != null && ((_q = obj.properties) == null ? void 0 : _q.autoRecover) != void 0) {
|
|
208
197
|
const value = ((_r = obj.properties) == null ? void 0 : _r.autoRecover) == 0 ? false : true;
|
|
209
|
-
(0, import_adapterService.updateSolarFlowState)(
|
|
198
|
+
(0, import_adapterService.updateSolarFlowState)(
|
|
199
|
+
adapter,
|
|
200
|
+
productKey,
|
|
201
|
+
deviceKey,
|
|
202
|
+
"autoRecover",
|
|
203
|
+
value
|
|
204
|
+
);
|
|
210
205
|
}
|
|
211
206
|
if (((_s = obj.properties) == null ? void 0 : _s.outputHomePower) != null && ((_t = obj.properties) == null ? void 0 : _t.outputHomePower) != void 0) {
|
|
212
207
|
(0, import_adapterService.updateSolarFlowState)(
|
|
@@ -226,7 +221,17 @@ const onMessage = async (topic, message) => {
|
|
|
226
221
|
obj.properties.outputLimit
|
|
227
222
|
);
|
|
228
223
|
}
|
|
229
|
-
if (((_w = obj.properties) == null ? void 0 : _w.
|
|
224
|
+
if (((_w = obj.properties) == null ? void 0 : _w.buzzerSwitch) != null && ((_x = obj.properties) == null ? void 0 : _x.buzzerSwitch) != void 0) {
|
|
225
|
+
const value = ((_y = obj.properties) == null ? void 0 : _y.buzzerSwitch) == 0 ? false : true;
|
|
226
|
+
(0, import_adapterService.updateSolarFlowState)(
|
|
227
|
+
adapter,
|
|
228
|
+
productKey,
|
|
229
|
+
deviceKey,
|
|
230
|
+
"buzzerSwitch",
|
|
231
|
+
value
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
if (((_z = obj.properties) == null ? void 0 : _z.outputPackPower) != null && ((_A = obj.properties) == null ? void 0 : _A.outputPackPower) != void 0) {
|
|
230
235
|
(0, import_adapterService.updateSolarFlowState)(
|
|
231
236
|
adapter,
|
|
232
237
|
productKey,
|
|
@@ -236,7 +241,7 @@ const onMessage = async (topic, message) => {
|
|
|
236
241
|
);
|
|
237
242
|
(0, import_adapterService.updateSolarFlowState)(adapter, productKey, deviceKey, "packInputPower", 0);
|
|
238
243
|
}
|
|
239
|
-
if (((
|
|
244
|
+
if (((_B = obj.properties) == null ? void 0 : _B.packInputPower) != null && ((_C = obj.properties) == null ? void 0 : _C.packInputPower) != void 0) {
|
|
240
245
|
(0, import_adapterService.updateSolarFlowState)(
|
|
241
246
|
adapter,
|
|
242
247
|
productKey,
|
|
@@ -252,7 +257,7 @@ const onMessage = async (topic, message) => {
|
|
|
252
257
|
0
|
|
253
258
|
);
|
|
254
259
|
}
|
|
255
|
-
if (((
|
|
260
|
+
if (((_D = obj.properties) == null ? void 0 : _D.solarInputPower) != null && ((_E = obj.properties) == null ? void 0 : _E.solarInputPower) != void 0) {
|
|
256
261
|
(0, import_adapterService.updateSolarFlowState)(
|
|
257
262
|
adapter,
|
|
258
263
|
productKey,
|
|
@@ -261,7 +266,7 @@ const onMessage = async (topic, message) => {
|
|
|
261
266
|
obj.properties.solarInputPower
|
|
262
267
|
);
|
|
263
268
|
}
|
|
264
|
-
if (((
|
|
269
|
+
if (((_F = obj.properties) == null ? void 0 : _F.pvPower1) != null && ((_G = obj.properties) == null ? void 0 : _G.pvPower1) != void 0) {
|
|
265
270
|
(0, import_adapterService.updateSolarFlowState)(
|
|
266
271
|
adapter,
|
|
267
272
|
productKey,
|
|
@@ -271,7 +276,7 @@ const onMessage = async (topic, message) => {
|
|
|
271
276
|
obj.properties.pvPower1
|
|
272
277
|
);
|
|
273
278
|
}
|
|
274
|
-
if (((
|
|
279
|
+
if (((_H = obj.properties) == null ? void 0 : _H.pvPower2) != null && ((_I = obj.properties) == null ? void 0 : _I.pvPower2) != void 0) {
|
|
275
280
|
(0, import_adapterService.updateSolarFlowState)(
|
|
276
281
|
adapter,
|
|
277
282
|
productKey,
|
|
@@ -281,7 +286,7 @@ const onMessage = async (topic, message) => {
|
|
|
281
286
|
obj.properties.pvPower2
|
|
282
287
|
);
|
|
283
288
|
}
|
|
284
|
-
if (((
|
|
289
|
+
if (((_J = obj.properties) == null ? void 0 : _J.solarPower1) != null && ((_K = obj.properties) == null ? void 0 : _K.solarPower1) != void 0) {
|
|
285
290
|
(0, import_adapterService.updateSolarFlowState)(
|
|
286
291
|
adapter,
|
|
287
292
|
productKey,
|
|
@@ -290,7 +295,7 @@ const onMessage = async (topic, message) => {
|
|
|
290
295
|
obj.properties.solarPower1
|
|
291
296
|
);
|
|
292
297
|
}
|
|
293
|
-
if (((
|
|
298
|
+
if (((_L = obj.properties) == null ? void 0 : _L.solarPower2) != null && ((_M = obj.properties) == null ? void 0 : _M.solarPower2) != void 0) {
|
|
294
299
|
(0, import_adapterService.updateSolarFlowState)(
|
|
295
300
|
adapter,
|
|
296
301
|
productKey,
|
|
@@ -299,7 +304,7 @@ const onMessage = async (topic, message) => {
|
|
|
299
304
|
obj.properties.solarPower2
|
|
300
305
|
);
|
|
301
306
|
}
|
|
302
|
-
if (((
|
|
307
|
+
if (((_N = obj.properties) == null ? void 0 : _N.remainOutTime) != null && ((_O = obj.properties) == null ? void 0 : _O.remainOutTime) != void 0) {
|
|
303
308
|
(0, import_adapterService.updateSolarFlowState)(
|
|
304
309
|
adapter,
|
|
305
310
|
productKey,
|
|
@@ -307,51 +312,17 @@ const onMessage = async (topic, message) => {
|
|
|
307
312
|
"remainOutTime",
|
|
308
313
|
obj.properties.remainOutTime
|
|
309
314
|
);
|
|
310
|
-
if (adapter.config.useCalculation) {
|
|
311
|
-
const packInputPower = Number(
|
|
312
|
-
(_M = await adapter.getStateAsync(
|
|
313
|
-
productKey + "." + deviceKey + ".packInputPower"
|
|
314
|
-
)) == null ? void 0 : _M.val
|
|
315
|
-
);
|
|
316
|
-
const outputPackPower = Number(
|
|
317
|
-
(_N = await adapter.getStateAsync(
|
|
318
|
-
productKey + "." + deviceKey + ".outputPackPower"
|
|
319
|
-
)) == null ? void 0 : _N.val
|
|
320
|
-
);
|
|
321
|
-
if (packInputPower && packInputPower > 0) {
|
|
322
|
-
(0, import_adapterService.updateSolarFlowState)(
|
|
323
|
-
adapter,
|
|
324
|
-
productKey,
|
|
325
|
-
deviceKey,
|
|
326
|
-
"calculations.remainOutTime",
|
|
327
|
-
obj.properties.remainOutTime < 59940 ? (0, import_timeHelper.toHoursAndMinutes)(obj.properties.remainOutTime) : ""
|
|
328
|
-
);
|
|
329
|
-
(0, import_adapterService.updateSolarFlowState)(
|
|
330
|
-
adapter,
|
|
331
|
-
productKey,
|
|
332
|
-
deviceKey,
|
|
333
|
-
"calculations.remainInputTime",
|
|
334
|
-
""
|
|
335
|
-
);
|
|
336
|
-
} else if (outputPackPower && outputPackPower > 0) {
|
|
337
|
-
(0, import_adapterService.updateSolarFlowState)(
|
|
338
|
-
adapter,
|
|
339
|
-
productKey,
|
|
340
|
-
deviceKey,
|
|
341
|
-
"calculations.remainInputTime",
|
|
342
|
-
obj.properties.remainInputTime < 59940 ? (0, import_timeHelper.toHoursAndMinutes)(obj.properties.remainInputTime) : ""
|
|
343
|
-
);
|
|
344
|
-
(0, import_adapterService.updateSolarFlowState)(
|
|
345
|
-
adapter,
|
|
346
|
-
productKey,
|
|
347
|
-
deviceKey,
|
|
348
|
-
"calculations.remainOutTime",
|
|
349
|
-
""
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
315
|
}
|
|
354
|
-
if (((
|
|
316
|
+
if (((_P = obj.properties) == null ? void 0 : _P.remainInputTime) != null && ((_Q = obj.properties) == null ? void 0 : _Q.remainInputTime) != void 0) {
|
|
317
|
+
(0, import_adapterService.updateSolarFlowState)(
|
|
318
|
+
adapter,
|
|
319
|
+
productKey,
|
|
320
|
+
deviceKey,
|
|
321
|
+
"remainInputTime",
|
|
322
|
+
obj.properties.remainInputTime
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
if (((_R = obj.properties) == null ? void 0 : _R.socSet) != null && ((_S = obj.properties) == null ? void 0 : _S.socSet) != void 0) {
|
|
355
326
|
(0, import_adapterService.updateSolarFlowState)(
|
|
356
327
|
adapter,
|
|
357
328
|
productKey,
|
|
@@ -360,7 +331,7 @@ const onMessage = async (topic, message) => {
|
|
|
360
331
|
Number(obj.properties.socSet) / 10
|
|
361
332
|
);
|
|
362
333
|
}
|
|
363
|
-
if (((
|
|
334
|
+
if (((_T = obj.properties) == null ? void 0 : _T.minSoc) != null && ((_U = obj.properties) == null ? void 0 : _U.minSoc) != void 0) {
|
|
364
335
|
(0, import_adapterService.updateSolarFlowState)(
|
|
365
336
|
adapter,
|
|
366
337
|
productKey,
|
|
@@ -370,7 +341,7 @@ const onMessage = async (topic, message) => {
|
|
|
370
341
|
);
|
|
371
342
|
}
|
|
372
343
|
if (obj.packData) {
|
|
373
|
-
addOrUpdatePackData(
|
|
344
|
+
addOrUpdatePackData(productKey, deviceKey, obj.packData);
|
|
374
345
|
}
|
|
375
346
|
}
|
|
376
347
|
if (adapter == null ? void 0 : adapter.mqttClient) {
|
|
@@ -443,6 +414,73 @@ const setOutputLimit = async (adapter2, productKey, deviceKey, limit) => {
|
|
|
443
414
|
}
|
|
444
415
|
}
|
|
445
416
|
};
|
|
417
|
+
const setBuzzerSwitch = async (adapter2, productKey, deviceKey, buzzerOn) => {
|
|
418
|
+
var _a;
|
|
419
|
+
if (adapter2.mqttClient && productKey && deviceKey) {
|
|
420
|
+
const topic = `iot/${productKey}/${deviceKey}/properties/write`;
|
|
421
|
+
const socSetLimit = { properties: { buzzerSwitch: buzzerOn ? 1 : 0 } };
|
|
422
|
+
adapter2.log.debug(
|
|
423
|
+
`[setBuzzer] Setting Buzzer for device key ${deviceKey} to ${buzzerOn}!`
|
|
424
|
+
);
|
|
425
|
+
(_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(socSetLimit));
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
const triggerFullTelemetryUpdate = async (adapter2, productKey, deviceKey) => {
|
|
429
|
+
var _a;
|
|
430
|
+
if (adapter2.mqttClient && productKey && deviceKey) {
|
|
431
|
+
const topic = `iot/${productKey}/${deviceKey}/properties/read`;
|
|
432
|
+
const getAllContent = { properties: ["getAll"] };
|
|
433
|
+
adapter2.log.debug(
|
|
434
|
+
`[triggerFullTelemetryUpdate] Triggering full telemetry update for device key ${deviceKey}!`
|
|
435
|
+
);
|
|
436
|
+
(_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(getAllContent));
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
const setPassMode = async (adapter2, productKey, deviceKey, passMode) => {
|
|
440
|
+
var _a;
|
|
441
|
+
if (adapter2.mqttClient && productKey && deviceKey) {
|
|
442
|
+
const topic = `iot/${productKey}/${deviceKey}/properties/write`;
|
|
443
|
+
const setPassModeContent = { properties: { passMode } };
|
|
444
|
+
adapter2.log.debug(
|
|
445
|
+
`[setPassMode] Set passMode for device ${deviceKey} to ${passMode}!`
|
|
446
|
+
);
|
|
447
|
+
(_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(setPassModeContent));
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
const setAutoRecover = async (adapter2, productKey, deviceKey, autoRecover) => {
|
|
451
|
+
var _a;
|
|
452
|
+
if (adapter2.mqttClient && productKey && deviceKey) {
|
|
453
|
+
const topic = `iot/${productKey}/${deviceKey}/properties/write`;
|
|
454
|
+
const setAutoRecoverContent = {
|
|
455
|
+
properties: { autoRecover: autoRecover ? 1 : 0 }
|
|
456
|
+
};
|
|
457
|
+
adapter2.log.debug(
|
|
458
|
+
`[setPassMode] Set autoRecover for device ${deviceKey} to ${autoRecover}!`
|
|
459
|
+
);
|
|
460
|
+
(_a = adapter2.mqttClient) == null ? void 0 : _a.publish(topic, JSON.stringify(setAutoRecoverContent));
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
const onConnected = () => {
|
|
464
|
+
adapter == null ? void 0 : adapter.log.info("[onConnected] Connected with MQTT!");
|
|
465
|
+
};
|
|
466
|
+
const onError = (error) => {
|
|
467
|
+
adapter == null ? void 0 : adapter.log.error("Connection to MQTT failed! Error: " + error);
|
|
468
|
+
};
|
|
469
|
+
const onSubscriberReportTopic = (error) => {
|
|
470
|
+
if (error) {
|
|
471
|
+
adapter == null ? void 0 : adapter.log.error("Subscription to MQTT failed! Error: " + error);
|
|
472
|
+
} else {
|
|
473
|
+
adapter == null ? void 0 : adapter.log.debug("Subscription of Report Topic successful!");
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
const onSubscribeIotTopic = (error, productKey, deviceKey) => {
|
|
477
|
+
if (error) {
|
|
478
|
+
adapter == null ? void 0 : adapter.log.error("Subscription to MQTT failed! Error: " + error);
|
|
479
|
+
} else if (adapter) {
|
|
480
|
+
adapter == null ? void 0 : adapter.log.debug("Subscription of IOT Topic successful!");
|
|
481
|
+
triggerFullTelemetryUpdate(adapter, productKey, deviceKey);
|
|
482
|
+
}
|
|
483
|
+
};
|
|
446
484
|
const connectMqttClient = (_adapter) => {
|
|
447
485
|
adapter = _adapter;
|
|
448
486
|
const options = {
|
|
@@ -469,11 +507,13 @@ const connectMqttClient = (_adapter) => {
|
|
|
469
507
|
adapter.log.debug(
|
|
470
508
|
`[connectMqttClient] Subscribing to MQTT Topic: ${reportTopic}`
|
|
471
509
|
);
|
|
472
|
-
(_a = adapter.mqttClient) == null ? void 0 : _a.subscribe(reportTopic,
|
|
510
|
+
(_a = adapter.mqttClient) == null ? void 0 : _a.subscribe(reportTopic, onSubscriberReportTopic);
|
|
473
511
|
adapter.log.debug(
|
|
474
512
|
`[connectMqttClient] Subscribing to MQTT Topic: ${iotTopic}`
|
|
475
513
|
);
|
|
476
|
-
(_b = adapter.mqttClient) == null ? void 0 : _b.subscribe(iotTopic,
|
|
514
|
+
(_b = adapter.mqttClient) == null ? void 0 : _b.subscribe(iotTopic, (error) => {
|
|
515
|
+
onSubscribeIotTopic(error, device.productKey, device.deviceKey);
|
|
516
|
+
});
|
|
477
517
|
}
|
|
478
518
|
});
|
|
479
519
|
adapter.mqttClient.on("message", onMessage);
|
|
@@ -484,8 +524,12 @@ const connectMqttClient = (_adapter) => {
|
|
|
484
524
|
0 && (module.exports = {
|
|
485
525
|
addOrUpdatePackData,
|
|
486
526
|
connectMqttClient,
|
|
527
|
+
setAutoRecover,
|
|
528
|
+
setBuzzerSwitch,
|
|
487
529
|
setChargeLimit,
|
|
488
530
|
setDischargeLimit,
|
|
489
|
-
setOutputLimit
|
|
531
|
+
setOutputLimit,
|
|
532
|
+
setPassMode,
|
|
533
|
+
triggerFullTelemetryUpdate
|
|
490
534
|
});
|
|
491
535
|
//# sourceMappingURL=mqttService.js.map
|