iobroker.homewizard 0.1.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/LICENSE +21 -0
- package/README.md +190 -0
- package/admin/homewizard.svg +6 -0
- package/admin/i18n/de/translations.json +16 -0
- package/admin/i18n/en/translations.json +16 -0
- package/admin/i18n/es/translations.json +16 -0
- package/admin/i18n/fr/translations.json +16 -0
- package/admin/i18n/it/translations.json +16 -0
- package/admin/i18n/nl/translations.json +16 -0
- package/admin/i18n/pl/translations.json +16 -0
- package/admin/i18n/pt/translations.json +16 -0
- package/admin/i18n/ru/translations.json +16 -0
- package/admin/i18n/uk/translations.json +16 -0
- package/admin/i18n/zh-cn/translations.json +16 -0
- package/admin/jsonConfig.json +99 -0
- package/build/lib/discovery.js +103 -0
- package/build/lib/discovery.js.map +7 -0
- package/build/lib/homewizard-client.js +193 -0
- package/build/lib/homewizard-client.js.map +7 -0
- package/build/lib/state-manager.js +749 -0
- package/build/lib/state-manager.js.map +7 -0
- package/build/lib/types.js +17 -0
- package/build/lib/types.js.map +7 -0
- package/build/lib/websocket-client.js +151 -0
- package/build/lib/websocket-client.js.map +7 -0
- package/build/main.js +441 -0
- package/build/main.js.map +7 -0
- package/io-package.json +136 -0
- package/package.json +77 -0
|
@@ -0,0 +1,749 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var state_manager_exports = {};
|
|
20
|
+
__export(state_manager_exports, {
|
|
21
|
+
StateManager: () => StateManager
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(state_manager_exports);
|
|
24
|
+
function sanitize(str) {
|
|
25
|
+
return str.replace(/[^a-zA-Z0-9_-]/g, "_").toLowerCase();
|
|
26
|
+
}
|
|
27
|
+
const MEASUREMENT_STATE_DEFS = [
|
|
28
|
+
// Power
|
|
29
|
+
{
|
|
30
|
+
key: "power_w",
|
|
31
|
+
id: "power_w",
|
|
32
|
+
name: "Total power",
|
|
33
|
+
type: "number",
|
|
34
|
+
role: "value.power",
|
|
35
|
+
unit: "W"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "power_l1_w",
|
|
39
|
+
id: "power_l1_w",
|
|
40
|
+
name: "Power L1",
|
|
41
|
+
type: "number",
|
|
42
|
+
role: "value.power",
|
|
43
|
+
unit: "W"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
key: "power_l2_w",
|
|
47
|
+
id: "power_l2_w",
|
|
48
|
+
name: "Power L2",
|
|
49
|
+
type: "number",
|
|
50
|
+
role: "value.power",
|
|
51
|
+
unit: "W"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
key: "power_l3_w",
|
|
55
|
+
id: "power_l3_w",
|
|
56
|
+
name: "Power L3",
|
|
57
|
+
type: "number",
|
|
58
|
+
role: "value.power",
|
|
59
|
+
unit: "W"
|
|
60
|
+
},
|
|
61
|
+
// Voltage
|
|
62
|
+
{
|
|
63
|
+
key: "voltage_v",
|
|
64
|
+
id: "voltage_v",
|
|
65
|
+
name: "Voltage",
|
|
66
|
+
type: "number",
|
|
67
|
+
role: "value.voltage",
|
|
68
|
+
unit: "V"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
key: "voltage_l1_v",
|
|
72
|
+
id: "voltage_l1_v",
|
|
73
|
+
name: "Voltage L1",
|
|
74
|
+
type: "number",
|
|
75
|
+
role: "value.voltage",
|
|
76
|
+
unit: "V"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
key: "voltage_l2_v",
|
|
80
|
+
id: "voltage_l2_v",
|
|
81
|
+
name: "Voltage L2",
|
|
82
|
+
type: "number",
|
|
83
|
+
role: "value.voltage",
|
|
84
|
+
unit: "V"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
key: "voltage_l3_v",
|
|
88
|
+
id: "voltage_l3_v",
|
|
89
|
+
name: "Voltage L3",
|
|
90
|
+
type: "number",
|
|
91
|
+
role: "value.voltage",
|
|
92
|
+
unit: "V"
|
|
93
|
+
},
|
|
94
|
+
// Current
|
|
95
|
+
{
|
|
96
|
+
key: "current_a",
|
|
97
|
+
id: "current_a",
|
|
98
|
+
name: "Current",
|
|
99
|
+
type: "number",
|
|
100
|
+
role: "value.current",
|
|
101
|
+
unit: "A"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
key: "current_l1_a",
|
|
105
|
+
id: "current_l1_a",
|
|
106
|
+
name: "Current L1",
|
|
107
|
+
type: "number",
|
|
108
|
+
role: "value.current",
|
|
109
|
+
unit: "A"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
key: "current_l2_a",
|
|
113
|
+
id: "current_l2_a",
|
|
114
|
+
name: "Current L2",
|
|
115
|
+
type: "number",
|
|
116
|
+
role: "value.current",
|
|
117
|
+
unit: "A"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
key: "current_l3_a",
|
|
121
|
+
id: "current_l3_a",
|
|
122
|
+
name: "Current L3",
|
|
123
|
+
type: "number",
|
|
124
|
+
role: "value.current",
|
|
125
|
+
unit: "A"
|
|
126
|
+
},
|
|
127
|
+
// Frequency
|
|
128
|
+
{
|
|
129
|
+
key: "frequency_hz",
|
|
130
|
+
id: "frequency_hz",
|
|
131
|
+
name: "Frequency",
|
|
132
|
+
type: "number",
|
|
133
|
+
role: "value",
|
|
134
|
+
unit: "Hz"
|
|
135
|
+
},
|
|
136
|
+
// Energy import
|
|
137
|
+
{
|
|
138
|
+
key: "energy_import_kwh",
|
|
139
|
+
id: "energy_import_kwh",
|
|
140
|
+
name: "Energy import total",
|
|
141
|
+
type: "number",
|
|
142
|
+
role: "value.energy",
|
|
143
|
+
unit: "kWh"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
key: "energy_import_t1_kwh",
|
|
147
|
+
id: "energy_import_t1_kwh",
|
|
148
|
+
name: "Energy import T1",
|
|
149
|
+
type: "number",
|
|
150
|
+
role: "value.energy",
|
|
151
|
+
unit: "kWh"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
key: "energy_import_t2_kwh",
|
|
155
|
+
id: "energy_import_t2_kwh",
|
|
156
|
+
name: "Energy import T2",
|
|
157
|
+
type: "number",
|
|
158
|
+
role: "value.energy",
|
|
159
|
+
unit: "kWh"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
key: "energy_import_t3_kwh",
|
|
163
|
+
id: "energy_import_t3_kwh",
|
|
164
|
+
name: "Energy import T3",
|
|
165
|
+
type: "number",
|
|
166
|
+
role: "value.energy",
|
|
167
|
+
unit: "kWh"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
key: "energy_import_t4_kwh",
|
|
171
|
+
id: "energy_import_t4_kwh",
|
|
172
|
+
name: "Energy import T4",
|
|
173
|
+
type: "number",
|
|
174
|
+
role: "value.energy",
|
|
175
|
+
unit: "kWh"
|
|
176
|
+
},
|
|
177
|
+
// Energy export
|
|
178
|
+
{
|
|
179
|
+
key: "energy_export_kwh",
|
|
180
|
+
id: "energy_export_kwh",
|
|
181
|
+
name: "Energy export total",
|
|
182
|
+
type: "number",
|
|
183
|
+
role: "value.energy",
|
|
184
|
+
unit: "kWh"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
key: "energy_export_t1_kwh",
|
|
188
|
+
id: "energy_export_t1_kwh",
|
|
189
|
+
name: "Energy export T1",
|
|
190
|
+
type: "number",
|
|
191
|
+
role: "value.energy",
|
|
192
|
+
unit: "kWh"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
key: "energy_export_t2_kwh",
|
|
196
|
+
id: "energy_export_t2_kwh",
|
|
197
|
+
name: "Energy export T2",
|
|
198
|
+
type: "number",
|
|
199
|
+
role: "value.energy",
|
|
200
|
+
unit: "kWh"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
key: "energy_export_t3_kwh",
|
|
204
|
+
id: "energy_export_t3_kwh",
|
|
205
|
+
name: "Energy export T3",
|
|
206
|
+
type: "number",
|
|
207
|
+
role: "value.energy",
|
|
208
|
+
unit: "kWh"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
key: "energy_export_t4_kwh",
|
|
212
|
+
id: "energy_export_t4_kwh",
|
|
213
|
+
name: "Energy export T4",
|
|
214
|
+
type: "number",
|
|
215
|
+
role: "value.energy",
|
|
216
|
+
unit: "kWh"
|
|
217
|
+
},
|
|
218
|
+
// Tariff
|
|
219
|
+
{
|
|
220
|
+
key: "tariff",
|
|
221
|
+
id: "tariff",
|
|
222
|
+
name: "Active tariff",
|
|
223
|
+
type: "number",
|
|
224
|
+
role: "value"
|
|
225
|
+
},
|
|
226
|
+
// Power quality
|
|
227
|
+
{
|
|
228
|
+
key: "voltage_sag_l1_count",
|
|
229
|
+
id: "quality.voltage_sag_l1_count",
|
|
230
|
+
name: "Voltage sag L1",
|
|
231
|
+
type: "number",
|
|
232
|
+
role: "value"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
key: "voltage_sag_l2_count",
|
|
236
|
+
id: "quality.voltage_sag_l2_count",
|
|
237
|
+
name: "Voltage sag L2",
|
|
238
|
+
type: "number",
|
|
239
|
+
role: "value"
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
key: "voltage_sag_l3_count",
|
|
243
|
+
id: "quality.voltage_sag_l3_count",
|
|
244
|
+
name: "Voltage sag L3",
|
|
245
|
+
type: "number",
|
|
246
|
+
role: "value"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
key: "voltage_swell_l1_count",
|
|
250
|
+
id: "quality.voltage_swell_l1_count",
|
|
251
|
+
name: "Voltage swell L1",
|
|
252
|
+
type: "number",
|
|
253
|
+
role: "value"
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
key: "voltage_swell_l2_count",
|
|
257
|
+
id: "quality.voltage_swell_l2_count",
|
|
258
|
+
name: "Voltage swell L2",
|
|
259
|
+
type: "number",
|
|
260
|
+
role: "value"
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
key: "voltage_swell_l3_count",
|
|
264
|
+
id: "quality.voltage_swell_l3_count",
|
|
265
|
+
name: "Voltage swell L3",
|
|
266
|
+
type: "number",
|
|
267
|
+
role: "value"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
key: "any_power_fail_count",
|
|
271
|
+
id: "quality.power_fail_count",
|
|
272
|
+
name: "Power fail count",
|
|
273
|
+
type: "number",
|
|
274
|
+
role: "value"
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
key: "long_power_fail_count",
|
|
278
|
+
id: "quality.long_power_fail_count",
|
|
279
|
+
name: "Long power fail count",
|
|
280
|
+
type: "number",
|
|
281
|
+
role: "value"
|
|
282
|
+
},
|
|
283
|
+
// Capacity tariff (Belgium)
|
|
284
|
+
{
|
|
285
|
+
key: "average_power_15m_w",
|
|
286
|
+
id: "average_power_15m_w",
|
|
287
|
+
name: "Average power 15min",
|
|
288
|
+
type: "number",
|
|
289
|
+
role: "value.power",
|
|
290
|
+
unit: "W"
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
key: "monthly_power_peak_w",
|
|
294
|
+
id: "monthly_power_peak_w",
|
|
295
|
+
name: "Monthly power peak",
|
|
296
|
+
type: "number",
|
|
297
|
+
role: "value.power",
|
|
298
|
+
unit: "W"
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
key: "monthly_power_peak_timestamp",
|
|
302
|
+
id: "monthly_power_peak_timestamp",
|
|
303
|
+
name: "Monthly power peak time",
|
|
304
|
+
type: "string",
|
|
305
|
+
role: "date"
|
|
306
|
+
},
|
|
307
|
+
// kWh meter specifics
|
|
308
|
+
{
|
|
309
|
+
key: "apparent_current_a",
|
|
310
|
+
id: "apparent_current_a",
|
|
311
|
+
name: "Apparent current",
|
|
312
|
+
type: "number",
|
|
313
|
+
role: "value.current",
|
|
314
|
+
unit: "A"
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
key: "reactive_current_a",
|
|
318
|
+
id: "reactive_current_a",
|
|
319
|
+
name: "Reactive current",
|
|
320
|
+
type: "number",
|
|
321
|
+
role: "value.current",
|
|
322
|
+
unit: "A"
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
key: "apparent_power_va",
|
|
326
|
+
id: "apparent_power_va",
|
|
327
|
+
name: "Apparent power",
|
|
328
|
+
type: "number",
|
|
329
|
+
role: "value.power",
|
|
330
|
+
unit: "VA"
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
key: "reactive_power_var",
|
|
334
|
+
id: "reactive_power_var",
|
|
335
|
+
name: "Reactive power",
|
|
336
|
+
type: "number",
|
|
337
|
+
role: "value.power",
|
|
338
|
+
unit: "var"
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
key: "power_factor",
|
|
342
|
+
id: "power_factor",
|
|
343
|
+
name: "Power factor",
|
|
344
|
+
type: "number",
|
|
345
|
+
role: "value"
|
|
346
|
+
},
|
|
347
|
+
// Battery specifics
|
|
348
|
+
{
|
|
349
|
+
key: "state_of_charge_pct",
|
|
350
|
+
id: "state_of_charge_pct",
|
|
351
|
+
name: "State of charge",
|
|
352
|
+
type: "number",
|
|
353
|
+
role: "value.battery",
|
|
354
|
+
unit: "%"
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
key: "cycles",
|
|
358
|
+
id: "cycles",
|
|
359
|
+
name: "Charge cycles",
|
|
360
|
+
type: "number",
|
|
361
|
+
role: "value"
|
|
362
|
+
},
|
|
363
|
+
// Metadata
|
|
364
|
+
{
|
|
365
|
+
key: "meter_model",
|
|
366
|
+
id: "meter_model",
|
|
367
|
+
name: "Meter model",
|
|
368
|
+
type: "string",
|
|
369
|
+
role: "text"
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
key: "timestamp",
|
|
373
|
+
id: "timestamp",
|
|
374
|
+
name: "Measurement timestamp",
|
|
375
|
+
type: "string",
|
|
376
|
+
role: "date"
|
|
377
|
+
}
|
|
378
|
+
];
|
|
379
|
+
class StateManager {
|
|
380
|
+
adapter;
|
|
381
|
+
/** @param adapter The ioBroker adapter instance */
|
|
382
|
+
constructor(adapter) {
|
|
383
|
+
this.adapter = adapter;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Create device channel and info states
|
|
387
|
+
*
|
|
388
|
+
* @param config Device configuration
|
|
389
|
+
*/
|
|
390
|
+
async createDeviceStates(config) {
|
|
391
|
+
const prefix = this.devicePrefix(config);
|
|
392
|
+
await this.adapter.extendObjectAsync(prefix, {
|
|
393
|
+
type: "device",
|
|
394
|
+
common: { name: config.productName || config.productType },
|
|
395
|
+
native: {}
|
|
396
|
+
});
|
|
397
|
+
await this.adapter.extendObjectAsync(`${prefix}.info`, {
|
|
398
|
+
type: "channel",
|
|
399
|
+
common: { name: "Device Information" },
|
|
400
|
+
native: {}
|
|
401
|
+
});
|
|
402
|
+
await this.createState(
|
|
403
|
+
`${prefix}.info.productName`,
|
|
404
|
+
"Product name",
|
|
405
|
+
"string",
|
|
406
|
+
"text",
|
|
407
|
+
false
|
|
408
|
+
);
|
|
409
|
+
await this.createState(
|
|
410
|
+
`${prefix}.info.productType`,
|
|
411
|
+
"Product type",
|
|
412
|
+
"string",
|
|
413
|
+
"text",
|
|
414
|
+
false
|
|
415
|
+
);
|
|
416
|
+
await this.createState(
|
|
417
|
+
`${prefix}.info.firmware`,
|
|
418
|
+
"Firmware version",
|
|
419
|
+
"string",
|
|
420
|
+
"text",
|
|
421
|
+
false
|
|
422
|
+
);
|
|
423
|
+
await this.createState(
|
|
424
|
+
`${prefix}.info.connected`,
|
|
425
|
+
"Device connected",
|
|
426
|
+
"boolean",
|
|
427
|
+
"indicator.reachable",
|
|
428
|
+
false
|
|
429
|
+
);
|
|
430
|
+
await this.createState(
|
|
431
|
+
`${prefix}.info.wifi_rssi_db`,
|
|
432
|
+
"WiFi signal strength",
|
|
433
|
+
"number",
|
|
434
|
+
"value",
|
|
435
|
+
false,
|
|
436
|
+
"dB"
|
|
437
|
+
);
|
|
438
|
+
await this.createState(
|
|
439
|
+
`${prefix}.info.uptime_s`,
|
|
440
|
+
"Uptime",
|
|
441
|
+
"number",
|
|
442
|
+
"value",
|
|
443
|
+
false,
|
|
444
|
+
"s"
|
|
445
|
+
);
|
|
446
|
+
await this.adapter.setStateAsync(`${prefix}.info.productName`, {
|
|
447
|
+
val: config.productName,
|
|
448
|
+
ack: true
|
|
449
|
+
});
|
|
450
|
+
await this.adapter.setStateAsync(`${prefix}.info.productType`, {
|
|
451
|
+
val: config.productType,
|
|
452
|
+
ack: true
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Update measurement states — only creates states that have values
|
|
457
|
+
*
|
|
458
|
+
* @param config Device configuration
|
|
459
|
+
* @param data Measurement data
|
|
460
|
+
*/
|
|
461
|
+
async updateMeasurement(config, data) {
|
|
462
|
+
var _a;
|
|
463
|
+
const prefix = this.devicePrefix(config);
|
|
464
|
+
const fields = MEASUREMENT_STATE_DEFS;
|
|
465
|
+
for (const def of fields) {
|
|
466
|
+
const rawValue = data[def.key];
|
|
467
|
+
if (rawValue !== void 0 && rawValue !== null && !Array.isArray(rawValue)) {
|
|
468
|
+
await this.ensureAndSet(
|
|
469
|
+
`${prefix}.${def.id}`,
|
|
470
|
+
def.name,
|
|
471
|
+
def.type,
|
|
472
|
+
def.role,
|
|
473
|
+
rawValue,
|
|
474
|
+
def.unit
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
if ((_a = data.external) == null ? void 0 : _a.length) {
|
|
479
|
+
await this.adapter.extendObjectAsync(`${prefix}.external`, {
|
|
480
|
+
type: "channel",
|
|
481
|
+
common: { name: "External Meters" },
|
|
482
|
+
native: {}
|
|
483
|
+
});
|
|
484
|
+
for (const ext of data.external) {
|
|
485
|
+
const extId = `${prefix}.external.${sanitize(ext.type)}_${sanitize(ext.unique_id)}`;
|
|
486
|
+
await this.adapter.extendObjectAsync(extId, {
|
|
487
|
+
type: "channel",
|
|
488
|
+
common: { name: ext.type },
|
|
489
|
+
native: {}
|
|
490
|
+
});
|
|
491
|
+
await this.ensureAndSet(
|
|
492
|
+
`${extId}.value`,
|
|
493
|
+
"Value",
|
|
494
|
+
"number",
|
|
495
|
+
"value",
|
|
496
|
+
ext.value,
|
|
497
|
+
ext.unit
|
|
498
|
+
);
|
|
499
|
+
await this.ensureAndSet(
|
|
500
|
+
`${extId}.unit`,
|
|
501
|
+
"Unit",
|
|
502
|
+
"string",
|
|
503
|
+
"text",
|
|
504
|
+
ext.unit
|
|
505
|
+
);
|
|
506
|
+
await this.ensureAndSet(
|
|
507
|
+
`${extId}.timestamp`,
|
|
508
|
+
"Timestamp",
|
|
509
|
+
"string",
|
|
510
|
+
"date",
|
|
511
|
+
ext.timestamp
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Update system states
|
|
518
|
+
*
|
|
519
|
+
* @param config Device configuration
|
|
520
|
+
* @param system System info data
|
|
521
|
+
*/
|
|
522
|
+
async updateSystem(config, system) {
|
|
523
|
+
const prefix = this.devicePrefix(config);
|
|
524
|
+
await this.ensureAndSet(
|
|
525
|
+
`${prefix}.info.wifi_rssi_db`,
|
|
526
|
+
"WiFi signal strength",
|
|
527
|
+
"number",
|
|
528
|
+
"value",
|
|
529
|
+
system.wifi_rssi_db,
|
|
530
|
+
"dB"
|
|
531
|
+
);
|
|
532
|
+
await this.ensureAndSet(
|
|
533
|
+
`${prefix}.info.uptime_s`,
|
|
534
|
+
"Uptime",
|
|
535
|
+
"number",
|
|
536
|
+
"value",
|
|
537
|
+
system.uptime_s,
|
|
538
|
+
"s"
|
|
539
|
+
);
|
|
540
|
+
await this.adapter.extendObjectAsync(`${prefix}.system`, {
|
|
541
|
+
type: "channel",
|
|
542
|
+
common: { name: "System Settings" },
|
|
543
|
+
native: {}
|
|
544
|
+
});
|
|
545
|
+
await this.ensureAndSet(
|
|
546
|
+
`${prefix}.system.cloud_enabled`,
|
|
547
|
+
"Cloud enabled",
|
|
548
|
+
"boolean",
|
|
549
|
+
"switch",
|
|
550
|
+
system.cloud_enabled,
|
|
551
|
+
void 0,
|
|
552
|
+
true
|
|
553
|
+
);
|
|
554
|
+
await this.ensureAndSet(
|
|
555
|
+
`${prefix}.system.status_led_brightness_pct`,
|
|
556
|
+
"LED brightness",
|
|
557
|
+
"number",
|
|
558
|
+
"level",
|
|
559
|
+
system.status_led_brightness_pct,
|
|
560
|
+
"%",
|
|
561
|
+
true
|
|
562
|
+
);
|
|
563
|
+
if (system.api_v1_enabled !== void 0) {
|
|
564
|
+
await this.ensureAndSet(
|
|
565
|
+
`${prefix}.system.api_v1_enabled`,
|
|
566
|
+
"API v1 enabled",
|
|
567
|
+
"boolean",
|
|
568
|
+
"switch",
|
|
569
|
+
system.api_v1_enabled,
|
|
570
|
+
void 0,
|
|
571
|
+
true
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
await this.createState(
|
|
575
|
+
`${prefix}.system.reboot`,
|
|
576
|
+
"Reboot device",
|
|
577
|
+
"boolean",
|
|
578
|
+
"button",
|
|
579
|
+
true
|
|
580
|
+
);
|
|
581
|
+
await this.createState(
|
|
582
|
+
`${prefix}.system.identify`,
|
|
583
|
+
"Identify (blink LED)",
|
|
584
|
+
"boolean",
|
|
585
|
+
"button",
|
|
586
|
+
true
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Update battery control states
|
|
591
|
+
*
|
|
592
|
+
* @param config Device configuration
|
|
593
|
+
* @param battery Battery control data
|
|
594
|
+
*/
|
|
595
|
+
async updateBattery(config, battery) {
|
|
596
|
+
const prefix = this.devicePrefix(config);
|
|
597
|
+
await this.adapter.extendObjectAsync(`${prefix}.battery`, {
|
|
598
|
+
type: "channel",
|
|
599
|
+
common: { name: "Battery Control" },
|
|
600
|
+
native: {}
|
|
601
|
+
});
|
|
602
|
+
await this.ensureAndSet(
|
|
603
|
+
`${prefix}.battery.mode`,
|
|
604
|
+
"Battery mode",
|
|
605
|
+
"string",
|
|
606
|
+
"text",
|
|
607
|
+
battery.mode,
|
|
608
|
+
void 0,
|
|
609
|
+
true
|
|
610
|
+
);
|
|
611
|
+
if (battery.permissions !== void 0) {
|
|
612
|
+
await this.ensureAndSet(
|
|
613
|
+
`${prefix}.battery.permissions`,
|
|
614
|
+
"Battery permissions",
|
|
615
|
+
"string",
|
|
616
|
+
"json",
|
|
617
|
+
JSON.stringify(battery.permissions),
|
|
618
|
+
void 0,
|
|
619
|
+
true
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
if (battery.battery_count !== void 0) {
|
|
623
|
+
await this.ensureAndSet(
|
|
624
|
+
`${prefix}.battery.battery_count`,
|
|
625
|
+
"Connected batteries",
|
|
626
|
+
"number",
|
|
627
|
+
"value",
|
|
628
|
+
battery.battery_count
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
if (battery.power_w !== void 0) {
|
|
632
|
+
await this.ensureAndSet(
|
|
633
|
+
`${prefix}.battery.power_w`,
|
|
634
|
+
"Battery power",
|
|
635
|
+
"number",
|
|
636
|
+
"value.power",
|
|
637
|
+
battery.power_w,
|
|
638
|
+
"W"
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
if (battery.target_power_w !== void 0) {
|
|
642
|
+
await this.ensureAndSet(
|
|
643
|
+
`${prefix}.battery.target_power_w`,
|
|
644
|
+
"Target power",
|
|
645
|
+
"number",
|
|
646
|
+
"value.power",
|
|
647
|
+
battery.target_power_w,
|
|
648
|
+
"W"
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
if (battery.max_consumption_w !== void 0) {
|
|
652
|
+
await this.ensureAndSet(
|
|
653
|
+
`${prefix}.battery.max_consumption_w`,
|
|
654
|
+
"Max consumption",
|
|
655
|
+
"number",
|
|
656
|
+
"value.power",
|
|
657
|
+
battery.max_consumption_w,
|
|
658
|
+
"W"
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
if (battery.max_production_w !== void 0) {
|
|
662
|
+
await this.ensureAndSet(
|
|
663
|
+
`${prefix}.battery.max_production_w`,
|
|
664
|
+
"Max production",
|
|
665
|
+
"number",
|
|
666
|
+
"value.power",
|
|
667
|
+
battery.max_production_w,
|
|
668
|
+
"W"
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Set device connected state
|
|
674
|
+
*
|
|
675
|
+
* @param config Device configuration
|
|
676
|
+
* @param connected Connection status
|
|
677
|
+
*/
|
|
678
|
+
async setDeviceConnected(config, connected) {
|
|
679
|
+
const prefix = this.devicePrefix(config);
|
|
680
|
+
await this.adapter.setStateAsync(`${prefix}.info.connected`, {
|
|
681
|
+
val: connected,
|
|
682
|
+
ack: true
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* Remove all states for a device
|
|
687
|
+
*
|
|
688
|
+
* @param config Device configuration
|
|
689
|
+
*/
|
|
690
|
+
async removeDevice(config) {
|
|
691
|
+
const prefix = this.devicePrefix(config);
|
|
692
|
+
await this.adapter.delObjectAsync(prefix, { recursive: true });
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Get device object ID prefix
|
|
696
|
+
*
|
|
697
|
+
* @param config Device configuration
|
|
698
|
+
*/
|
|
699
|
+
devicePrefix(config) {
|
|
700
|
+
return `${sanitize(config.productType)}_${sanitize(config.serial)}`;
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Create a state if it doesn't exist
|
|
704
|
+
*
|
|
705
|
+
* @param id State ID
|
|
706
|
+
* @param name State name
|
|
707
|
+
* @param type Value type
|
|
708
|
+
* @param role ioBroker role
|
|
709
|
+
* @param write Whether state is writable
|
|
710
|
+
* @param unit Optional unit
|
|
711
|
+
*/
|
|
712
|
+
async createState(id, name, type, role, write, unit) {
|
|
713
|
+
const common = {
|
|
714
|
+
name,
|
|
715
|
+
type,
|
|
716
|
+
role,
|
|
717
|
+
read: true,
|
|
718
|
+
write
|
|
719
|
+
};
|
|
720
|
+
if (unit) {
|
|
721
|
+
common.unit = unit;
|
|
722
|
+
}
|
|
723
|
+
await this.adapter.extendObjectAsync(id, {
|
|
724
|
+
type: "state",
|
|
725
|
+
common,
|
|
726
|
+
native: {}
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* Ensure state exists and set value
|
|
731
|
+
*
|
|
732
|
+
* @param id State ID
|
|
733
|
+
* @param name State name
|
|
734
|
+
* @param type Value type
|
|
735
|
+
* @param role ioBroker role
|
|
736
|
+
* @param value State value
|
|
737
|
+
* @param unit Optional unit
|
|
738
|
+
* @param write Whether state is writable
|
|
739
|
+
*/
|
|
740
|
+
async ensureAndSet(id, name, type, role, value, unit, write) {
|
|
741
|
+
await this.createState(id, name, type, role, write != null ? write : false, unit);
|
|
742
|
+
await this.adapter.setStateAsync(id, { val: value, ack: true });
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
746
|
+
0 && (module.exports = {
|
|
747
|
+
StateManager
|
|
748
|
+
});
|
|
749
|
+
//# sourceMappingURL=state-manager.js.map
|