iobroker.anker-solix 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +351 -0
  3. package/admin/anker-solix.png +0 -0
  4. package/admin/i18n/de.json +76 -0
  5. package/admin/i18n/en.json +76 -0
  6. package/admin/i18n/es.json +3 -0
  7. package/admin/i18n/fr.json +3 -0
  8. package/admin/i18n/it.json +3 -0
  9. package/admin/i18n/nl.json +3 -0
  10. package/admin/i18n/pl.json +3 -0
  11. package/admin/i18n/pt.json +3 -0
  12. package/admin/i18n/ru.json +3 -0
  13. package/admin/i18n/uk.json +3 -0
  14. package/admin/i18n/zh-cn.json +3 -0
  15. package/admin/jsonConfig.json +421 -0
  16. package/build/lib/bridgeDaemon.js +204 -0
  17. package/build/lib/bridgeDaemon.js.map +7 -0
  18. package/build/lib/configHelpers.js +37 -0
  19. package/build/lib/configHelpers.js.map +7 -0
  20. package/build/lib/controlQueue.js +80 -0
  21. package/build/lib/controlQueue.js.map +7 -0
  22. package/build/lib/ensurePython.js +82 -0
  23. package/build/lib/ensurePython.js.map +7 -0
  24. package/build/lib/entities.js +238 -0
  25. package/build/lib/entities.js.map +7 -0
  26. package/build/lib/entityGroups.js +244 -0
  27. package/build/lib/entityGroups.js.map +7 -0
  28. package/build/lib/pythonBridge.js +165 -0
  29. package/build/lib/pythonBridge.js.map +7 -0
  30. package/build/lib/pythonPaths.js +93 -0
  31. package/build/lib/pythonPaths.js.map +7 -0
  32. package/build/lib/services.js +135 -0
  33. package/build/lib/services.js.map +7 -0
  34. package/build/lib/spawnEnv.js +48 -0
  35. package/build/lib/spawnEnv.js.map +7 -0
  36. package/build/lib/stateSync.js +213 -0
  37. package/build/lib/stateSync.js.map +7 -0
  38. package/build/lib/types.js +17 -0
  39. package/build/lib/types.js.map +7 -0
  40. package/build/main.js +458 -0
  41. package/build/main.js.map +7 -0
  42. package/io-package.json +232 -0
  43. package/package.json +80 -0
  44. package/python/__pycache__/bridge.cpython-314.pyc +0 -0
  45. package/python/__pycache__/entities.cpython-314.pyc +0 -0
  46. package/python/__pycache__/entity_groups.cpython-314.pyc +0 -0
  47. package/python/__pycache__/extended_entities.cpython-314.pyc +0 -0
  48. package/python/__pycache__/ha_api_client.cpython-314.pyc +0 -0
  49. package/python/auth_helpers.py +84 -0
  50. package/python/bridge.py +907 -0
  51. package/python/bridge_runtime.py +95 -0
  52. package/python/energy_entities.py +181 -0
  53. package/python/entities.py +580 -0
  54. package/python/entity_groups.py +172 -0
  55. package/python/extended_entities.py +545 -0
  56. package/python/ha_api_client.py +227 -0
  57. package/python/requirements.txt +4 -0
  58. package/python/solixapi/__init__.py +1 -0
  59. package/python/solixapi/__pycache__/__init__.cpython-314.pyc +0 -0
  60. package/python/solixapi/__pycache__/api.cpython-314.pyc +0 -0
  61. package/python/solixapi/__pycache__/apibase.cpython-314.pyc +0 -0
  62. package/python/solixapi/__pycache__/apitypes.cpython-314.pyc +0 -0
  63. package/python/solixapi/__pycache__/energy.cpython-314.pyc +0 -0
  64. package/python/solixapi/__pycache__/errors.cpython-314.pyc +0 -0
  65. package/python/solixapi/__pycache__/export.cpython-314.pyc +0 -0
  66. package/python/solixapi/__pycache__/helpers.cpython-314.pyc +0 -0
  67. package/python/solixapi/__pycache__/hesapi.cpython-314.pyc +0 -0
  68. package/python/solixapi/__pycache__/mqtt.cpython-314.pyc +0 -0
  69. package/python/solixapi/__pycache__/mqtt_charger.cpython-314.pyc +0 -0
  70. package/python/solixapi/__pycache__/mqtt_device.cpython-314.pyc +0 -0
  71. package/python/solixapi/__pycache__/mqtt_factory.cpython-314.pyc +0 -0
  72. package/python/solixapi/__pycache__/mqtt_generator.cpython-314.pyc +0 -0
  73. package/python/solixapi/__pycache__/mqtt_pps.cpython-314.pyc +0 -0
  74. package/python/solixapi/__pycache__/mqtt_solarbank.cpython-314.pyc +0 -0
  75. package/python/solixapi/__pycache__/mqtt_various.cpython-314.pyc +0 -0
  76. package/python/solixapi/__pycache__/mqttcmdmap.cpython-314.pyc +0 -0
  77. package/python/solixapi/__pycache__/mqttmap.cpython-314.pyc +0 -0
  78. package/python/solixapi/__pycache__/mqtttypes.cpython-314.pyc +0 -0
  79. package/python/solixapi/__pycache__/poller.cpython-314.pyc +0 -0
  80. package/python/solixapi/__pycache__/powerpanel.cpython-314.pyc +0 -0
  81. package/python/solixapi/__pycache__/schedule.cpython-314.pyc +0 -0
  82. package/python/solixapi/__pycache__/session.cpython-314.pyc +0 -0
  83. package/python/solixapi/__pycache__/vehicle.cpython-314.pyc +0 -0
  84. package/python/solixapi/api.py +2444 -0
  85. package/python/solixapi/apibase.py +2242 -0
  86. package/python/solixapi/apitypes.py +2149 -0
  87. package/python/solixapi/energy.py +1597 -0
  88. package/python/solixapi/errors.py +137 -0
  89. package/python/solixapi/export.py +2247 -0
  90. package/python/solixapi/helpers.py +147 -0
  91. package/python/solixapi/hesapi.py +1861 -0
  92. package/python/solixapi/mqtt.py +1125 -0
  93. package/python/solixapi/mqtt_charger.py +241 -0
  94. package/python/solixapi/mqtt_device.py +936 -0
  95. package/python/solixapi/mqtt_factory.py +83 -0
  96. package/python/solixapi/mqtt_generator.py +39 -0
  97. package/python/solixapi/mqtt_pps.py +556 -0
  98. package/python/solixapi/mqtt_solarbank.py +116 -0
  99. package/python/solixapi/mqtt_various.py +86 -0
  100. package/python/solixapi/mqttcmdmap.py +1418 -0
  101. package/python/solixapi/mqttmap.py +5944 -0
  102. package/python/solixapi/mqtttypes.py +1633 -0
  103. package/python/solixapi/poller.py +1662 -0
  104. package/python/solixapi/powerpanel.py +1574 -0
  105. package/python/solixapi/schedule.py +3021 -0
  106. package/python/solixapi/session.py +1108 -0
  107. package/python/solixapi/vehicle.py +846 -0
  108. package/tools/install-python.js +225 -0
@@ -0,0 +1,421 @@
1
+ {
2
+ "i18n": true,
3
+ "type": "tabs",
4
+ "items": {
5
+ "_tab_account": {
6
+ "type": "panel",
7
+ "label": "Account",
8
+ "items": {
9
+ "username": {
10
+ "type": "text",
11
+ "label": "username",
12
+ "xs": 12,
13
+ "sm": 6,
14
+ "md": 4,
15
+ "lg": 4,
16
+ "xl": 4
17
+ },
18
+ "password": {
19
+ "type": "password",
20
+ "label": "password",
21
+ "xs": 12,
22
+ "sm": 6,
23
+ "md": 4,
24
+ "lg": 4,
25
+ "xl": 4
26
+ },
27
+ "country": {
28
+ "type": "text",
29
+ "label": "country",
30
+ "default": "DE",
31
+ "xs": 12,
32
+ "sm": 6,
33
+ "md": 4,
34
+ "lg": 4,
35
+ "xl": 4
36
+ }
37
+ }
38
+ },
39
+ "_tab_devices": {
40
+ "type": "panel",
41
+ "label": "Devices",
42
+ "items": {
43
+ "_devices_hint": {
44
+ "type": "staticText",
45
+ "text": "devices_hint",
46
+ "xs": 12,
47
+ "sm": 12,
48
+ "md": 12,
49
+ "lg": 12,
50
+ "xl": 12
51
+ },
52
+ "loadDevices": {
53
+ "type": "sendTo",
54
+ "label": "loadDevices",
55
+ "command": "loadDevices",
56
+ "variant": "contained",
57
+ "showProcess": true,
58
+ "xs": 12,
59
+ "sm": 6,
60
+ "md": 4,
61
+ "lg": 4,
62
+ "xl": 4
63
+ },
64
+ "installPython": {
65
+ "type": "sendTo",
66
+ "label": "installPython",
67
+ "command": "installPython",
68
+ "variant": "outlined",
69
+ "showProcess": true,
70
+ "xs": 12,
71
+ "sm": 6,
72
+ "md": 4,
73
+ "lg": 4,
74
+ "xl": 4
75
+ },
76
+ "_clearAuthCache_warn": {
77
+ "type": "staticText",
78
+ "text": "clearAuthCache_warn",
79
+ "style": {
80
+ "fontSize": "0.9em",
81
+ "color": "#b45309"
82
+ },
83
+ "xs": 12,
84
+ "sm": 12,
85
+ "md": 12,
86
+ "lg": 12,
87
+ "xl": 12
88
+ },
89
+ "clearAuthCache": {
90
+ "type": "sendTo",
91
+ "label": "clearAuthCache",
92
+ "command": "clearAuthCache",
93
+ "variant": "outlined",
94
+ "showProcess": true,
95
+ "xs": 12,
96
+ "sm": 6,
97
+ "md": 4,
98
+ "lg": 4,
99
+ "xl": 4
100
+ },
101
+ "enableAllDevices": {
102
+ "type": "checkbox",
103
+ "label": "enableAllDevices",
104
+ "default": true,
105
+ "xs": 12,
106
+ "sm": 6,
107
+ "md": 4
108
+ },
109
+ "selectedSiteId": {
110
+ "type": "text",
111
+ "label": "selectedSiteId",
112
+ "xs": 12,
113
+ "sm": 6,
114
+ "md": 4
115
+ },
116
+ "selectedDeviceIds": {
117
+ "type": "text",
118
+ "label": "selectedDeviceIds",
119
+ "xs": 12,
120
+ "sm": 12,
121
+ "md": 8
122
+ },
123
+ "deviceListJson": {
124
+ "type": "text",
125
+ "label": "deviceListJson",
126
+ "readOnly": true,
127
+ "disabled": "true",
128
+ "xs": 12,
129
+ "sm": 12,
130
+ "md": 12,
131
+ "lg": 12,
132
+ "xl": 12
133
+ }
134
+ }
135
+ },
136
+ "_tab_options": {
137
+ "type": "panel",
138
+ "label": "Options",
139
+ "items": {
140
+ "scanInterval": {
141
+ "type": "number",
142
+ "label": "scanInterval",
143
+ "min": 30,
144
+ "max": 600,
145
+ "default": 60,
146
+ "xs": 12,
147
+ "sm": 6,
148
+ "md": 4
149
+ },
150
+ "deviceDetailMultiplier": {
151
+ "type": "number",
152
+ "label": "deviceDetailMultiplier",
153
+ "min": 1,
154
+ "max": 30,
155
+ "default": 10,
156
+ "xs": 12,
157
+ "sm": 6,
158
+ "md": 4
159
+ },
160
+ "requestDelay": {
161
+ "type": "number",
162
+ "label": "requestDelay",
163
+ "min": 0,
164
+ "max": 10,
165
+ "step": 0.1,
166
+ "default": 0.3,
167
+ "xs": 12,
168
+ "sm": 6,
169
+ "md": 4
170
+ },
171
+ "endpointLimit": {
172
+ "type": "number",
173
+ "label": "endpointLimit",
174
+ "min": 0,
175
+ "max": 60,
176
+ "default": 10,
177
+ "xs": 12,
178
+ "sm": 6,
179
+ "md": 4
180
+ },
181
+ "mqttUsage": {
182
+ "type": "checkbox",
183
+ "label": "mqttUsage",
184
+ "default": true,
185
+ "xs": 12,
186
+ "sm": 6,
187
+ "md": 4
188
+ },
189
+ "autoInstallPython": {
190
+ "type": "checkbox",
191
+ "label": "autoInstallPython",
192
+ "default": true,
193
+ "xs": 12,
194
+ "sm": 6,
195
+ "md": 4
196
+ },
197
+ "pythonPath": {
198
+ "type": "text",
199
+ "label": "pythonPath",
200
+ "xs": 12,
201
+ "sm": 6,
202
+ "md": 4
203
+ }
204
+ }
205
+ },
206
+ "_tab_entities": {
207
+ "type": "panel",
208
+ "label": "Entities",
209
+ "items": {
210
+ "_entities_hint": {
211
+ "type": "staticText",
212
+ "text": "entities_hint",
213
+ "xs": 12
214
+ },
215
+ "enableCoreEntities": {
216
+ "type": "checkbox",
217
+ "label": "enableCoreEntities",
218
+ "default": true,
219
+ "xs": 12,
220
+ "sm": 6,
221
+ "md": 4
222
+ },
223
+ "_grp_energy": {
224
+ "type": "header",
225
+ "text": "grp_energy",
226
+ "xs": 12,
227
+ "sm": 12,
228
+ "md": 12,
229
+ "lg": 12,
230
+ "xl": 12
231
+ },
232
+ "enableEnergyStatistics": {
233
+ "type": "checkbox",
234
+ "label": "enableEnergyStatistics",
235
+ "default": false,
236
+ "xs": 12,
237
+ "sm": 6,
238
+ "md": 4
239
+ },
240
+ "enableEnergyDetail": {
241
+ "type": "checkbox",
242
+ "label": "enableEnergyDetail",
243
+ "default": false,
244
+ "xs": 12,
245
+ "sm": 6,
246
+ "md": 4
247
+ },
248
+ "_grp_solarbank": {
249
+ "type": "header",
250
+ "text": "grp_solarbank",
251
+ "xs": 12,
252
+ "sm": 12,
253
+ "md": 12,
254
+ "lg": 12,
255
+ "xl": 12
256
+ },
257
+ "enablePowerFlows": {
258
+ "type": "checkbox",
259
+ "label": "enablePowerFlows",
260
+ "default": false,
261
+ "xs": 12,
262
+ "sm": 6,
263
+ "md": 4
264
+ },
265
+ "enableDiagnostics": {
266
+ "type": "checkbox",
267
+ "label": "enableDiagnostics",
268
+ "default": false,
269
+ "xs": 12,
270
+ "sm": 6,
271
+ "md": 4
272
+ },
273
+ "enableBinaryIndicators": {
274
+ "type": "checkbox",
275
+ "label": "enableBinaryIndicators",
276
+ "default": false,
277
+ "xs": 12,
278
+ "sm": 6,
279
+ "md": 4
280
+ },
281
+ "enableAdvancedControls": {
282
+ "type": "checkbox",
283
+ "label": "enableAdvancedControls",
284
+ "default": false,
285
+ "xs": 12,
286
+ "sm": 6,
287
+ "md": 4
288
+ },
289
+ "enableSolarbankMeta": {
290
+ "type": "checkbox",
291
+ "label": "enableSolarbankMeta",
292
+ "default": false,
293
+ "xs": 12,
294
+ "sm": 6,
295
+ "md": 4
296
+ },
297
+ "enableSystemOverview": {
298
+ "type": "checkbox",
299
+ "label": "enableSystemOverview",
300
+ "default": false,
301
+ "xs": 12,
302
+ "sm": 6,
303
+ "md": 4
304
+ },
305
+ "enableSitePrice": {
306
+ "type": "checkbox",
307
+ "label": "enableSitePrice",
308
+ "default": false,
309
+ "xs": 12,
310
+ "sm": 6,
311
+ "md": 4
312
+ },
313
+ "enableAccountInfo": {
314
+ "type": "checkbox",
315
+ "label": "enableAccountInfo",
316
+ "default": false,
317
+ "xs": 12,
318
+ "sm": 6,
319
+ "md": 4
320
+ },
321
+ "_grp_devices": {
322
+ "type": "header",
323
+ "text": "grp_devices",
324
+ "xs": 12,
325
+ "sm": 12,
326
+ "md": 12,
327
+ "lg": 12,
328
+ "xl": 12
329
+ },
330
+ "enableSmartplug": {
331
+ "type": "checkbox",
332
+ "label": "enableSmartplug",
333
+ "default": false,
334
+ "xs": 12,
335
+ "sm": 6,
336
+ "md": 4
337
+ },
338
+ "enablePps": {
339
+ "type": "checkbox",
340
+ "label": "enablePps",
341
+ "default": false,
342
+ "xs": 12,
343
+ "sm": 6,
344
+ "md": 4
345
+ },
346
+ "enableEvCharger": {
347
+ "type": "checkbox",
348
+ "label": "enableEvCharger",
349
+ "default": false,
350
+ "xs": 12,
351
+ "sm": 6,
352
+ "md": 4
353
+ },
354
+ "enableVehicle": {
355
+ "type": "checkbox",
356
+ "label": "enableVehicle",
357
+ "default": false,
358
+ "xs": 12,
359
+ "sm": 6,
360
+ "md": 4
361
+ },
362
+ "enableHes": {
363
+ "type": "checkbox",
364
+ "label": "enableHes",
365
+ "default": false,
366
+ "xs": 12,
367
+ "sm": 6,
368
+ "md": 4
369
+ },
370
+ "enablePowerPanel": {
371
+ "type": "checkbox",
372
+ "label": "enablePowerPanel",
373
+ "default": false,
374
+ "xs": 12,
375
+ "sm": 6,
376
+ "md": 4
377
+ },
378
+ "enableInverter": {
379
+ "type": "checkbox",
380
+ "label": "enableInverter",
381
+ "default": false,
382
+ "xs": 12,
383
+ "sm": 6,
384
+ "md": 4
385
+ }
386
+ }
387
+ },
388
+ "_tab_services": {
389
+ "type": "panel",
390
+ "label": "Services",
391
+ "items": {
392
+ "_services_hint": {
393
+ "type": "staticText",
394
+ "text": "services_hint",
395
+ "xs": 12
396
+ },
397
+ "_service_note": {
398
+ "type": "staticText",
399
+ "text": "services_note",
400
+ "xs": 12
401
+ }
402
+ }
403
+ },
404
+ "_tab_terms": {
405
+ "type": "panel",
406
+ "label": "Terms",
407
+ "items": {
408
+ "acceptTerms": {
409
+ "type": "checkbox",
410
+ "label": "acceptTerms",
411
+ "xs": 12
412
+ },
413
+ "_terms_hint": {
414
+ "type": "staticText",
415
+ "text": "terms_hint",
416
+ "xs": 12
417
+ }
418
+ }
419
+ }
420
+ }
421
+ }
@@ -0,0 +1,204 @@
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 bridgeDaemon_exports = {};
30
+ __export(bridgeDaemon_exports, {
31
+ BridgeDaemon: () => BridgeDaemon,
32
+ getBridgeDaemon: () => getBridgeDaemon,
33
+ stopBridgeDaemon: () => stopBridgeDaemon
34
+ });
35
+ module.exports = __toCommonJS(bridgeDaemon_exports);
36
+ var import_node_child_process = require("node:child_process");
37
+ var readline = __toESM(require("node:readline"));
38
+ var fs = __toESM(require("node:fs"));
39
+ var import_pythonPaths = require("./pythonPaths");
40
+ function bridgeScriptPath() {
41
+ return `${__dirname}/../../python/bridge.py`;
42
+ }
43
+ class BridgeDaemon {
44
+ constructor(pythonPath, log) {
45
+ this.pythonPath = pythonPath;
46
+ this.log = log;
47
+ }
48
+ proc;
49
+ pending = /* @__PURE__ */ new Map();
50
+ reqCounter = 0;
51
+ readyPromise;
52
+ configured = false;
53
+ queue = Promise.resolve();
54
+ get isRunning() {
55
+ return Boolean(this.proc && !this.proc.killed);
56
+ }
57
+ async start(config) {
58
+ var _a;
59
+ if (this.isRunning) {
60
+ await this.request("configure", config);
61
+ return;
62
+ }
63
+ const script = bridgeScriptPath();
64
+ if (!fs.existsSync(script)) {
65
+ throw new Error(`Python bridge not found: ${script}`);
66
+ }
67
+ const python = (0, import_pythonPaths.resolvePythonExecutable)(this.pythonPath);
68
+ const args = (0, import_pythonPaths.isPyLauncher)(python) ? ["-3", script, "serve"] : [script, "serve"];
69
+ this.readyPromise = new Promise((resolveReady, rejectReady) => {
70
+ var _a2;
71
+ const proc = (0, import_node_child_process.spawn)(python, args, {
72
+ windowsHide: true,
73
+ env: (0, import_pythonPaths.buildPythonEnv)(),
74
+ stdio: ["pipe", "pipe", "pipe"]
75
+ });
76
+ this.proc = proc;
77
+ let readyResolved = false;
78
+ const failStart = (err) => {
79
+ if (!readyResolved) {
80
+ readyResolved = true;
81
+ rejectReady(err);
82
+ }
83
+ };
84
+ proc.on("error", failStart);
85
+ (_a2 = proc.stderr) == null ? void 0 : _a2.on("data", (chunk) => {
86
+ var _a3, _b;
87
+ const text = chunk.toString("utf8").trim();
88
+ if (text) {
89
+ (_b = (_a3 = this.log) == null ? void 0 : _a3.debug) == null ? void 0 : _b.call(_a3, `Bridge daemon stderr: ${text}`);
90
+ }
91
+ });
92
+ proc.on("close", (code) => {
93
+ this.proc = void 0;
94
+ this.configured = false;
95
+ const err = new Error(`Bridge daemon exited (code ${code != null ? code : "unknown"})`);
96
+ for (const pending of this.pending.values()) {
97
+ pending.reject(err);
98
+ }
99
+ this.pending.clear();
100
+ failStart(err);
101
+ });
102
+ if (!proc.stdout) {
103
+ failStart(new Error("Bridge daemon has no stdout"));
104
+ return;
105
+ }
106
+ const rl = readline.createInterface({ input: proc.stdout });
107
+ rl.on("line", (line) => {
108
+ this.onLine(line);
109
+ if (!readyResolved && line.includes('"ready"')) {
110
+ readyResolved = true;
111
+ resolveReady();
112
+ }
113
+ });
114
+ });
115
+ await this.readyPromise;
116
+ await this.request("configure", config);
117
+ this.configured = true;
118
+ (_a = this.log) == null ? void 0 : _a.info("Anker Solix bridge daemon running (persistent API/MQTT session like HA)");
119
+ }
120
+ onLine(line) {
121
+ var _a;
122
+ const trimmed = line.trim();
123
+ if (!trimmed) {
124
+ return;
125
+ }
126
+ try {
127
+ const parsed = JSON.parse(trimmed);
128
+ const id = parsed.id;
129
+ if (!id) {
130
+ return;
131
+ }
132
+ const pending = this.pending.get(id);
133
+ if (!pending) {
134
+ return;
135
+ }
136
+ this.pending.delete(id);
137
+ if (!parsed.ok) {
138
+ pending.reject(new Error(parsed.error || "Bridge daemon error"));
139
+ return;
140
+ }
141
+ pending.resolve(parsed);
142
+ } catch (error) {
143
+ (_a = this.log) == null ? void 0 : _a.warn(`Invalid daemon response: ${trimmed} (${error.message})`);
144
+ }
145
+ }
146
+ async request(action, config) {
147
+ const run = this.queue.then(() => this._requestOnce(action, config));
148
+ this.queue = run.then(
149
+ () => void 0,
150
+ () => void 0
151
+ );
152
+ return run;
153
+ }
154
+ _requestOnce(action, config) {
155
+ if (!this.isRunning) {
156
+ return Promise.reject(new Error("Bridge daemon is not running"));
157
+ }
158
+ return new Promise((resolve, reject) => {
159
+ var _a, _b;
160
+ const id = String(++this.reqCounter);
161
+ this.pending.set(id, { resolve, reject });
162
+ const payload = `${JSON.stringify({ id, action, config })}
163
+ `;
164
+ const ok = (_b = (_a = this.proc) == null ? void 0 : _a.stdin) == null ? void 0 : _b.write(payload);
165
+ if (!ok) {
166
+ this.pending.delete(id);
167
+ reject(new Error("Bridge daemon stdin write failed"));
168
+ }
169
+ });
170
+ }
171
+ async stop() {
172
+ var _a;
173
+ if (!this.isRunning) {
174
+ return;
175
+ }
176
+ try {
177
+ await this.request("shutdown");
178
+ } catch {
179
+ }
180
+ (_a = this.proc) == null ? void 0 : _a.kill();
181
+ this.proc = void 0;
182
+ this.configured = false;
183
+ }
184
+ }
185
+ let sharedDaemon;
186
+ function getBridgeDaemon(pythonPath, log) {
187
+ if (!sharedDaemon) {
188
+ sharedDaemon = new BridgeDaemon(pythonPath, log);
189
+ }
190
+ return sharedDaemon;
191
+ }
192
+ async function stopBridgeDaemon() {
193
+ if (sharedDaemon) {
194
+ await sharedDaemon.stop();
195
+ sharedDaemon = void 0;
196
+ }
197
+ }
198
+ // Annotate the CommonJS export names for ESM import in node:
199
+ 0 && (module.exports = {
200
+ BridgeDaemon,
201
+ getBridgeDaemon,
202
+ stopBridgeDaemon
203
+ });
204
+ //# sourceMappingURL=bridgeDaemon.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/lib/bridgeDaemon.ts"],
4
+ "sourcesContent": ["import { type ChildProcess, spawn } from \"node:child_process\";\nimport * as readline from \"node:readline\";\nimport * as fs from \"node:fs\";\n\nimport { buildPythonEnv, isPyLauncher, resolvePythonExecutable } from \"./pythonPaths\";\nimport type { BridgeConfig, BridgePollResult, BridgeServiceConfig, BridgeSetConfig } from \"./types\";\n\nfunction bridgeScriptPath(): string {\n\treturn `${__dirname}/../../python/bridge.py`;\n}\n\ntype BridgeAction = \"configure\" | \"poll\" | \"login\" | \"set\" | \"list_devices\" | \"service\" | \"shutdown\";\n\ntype DaemonConfig = BridgeConfig | BridgeSetConfig | BridgeServiceConfig;\n\ninterface DaemonResponse extends BridgePollResult {\n\tid?: string;\n\tready?: boolean;\n\tpersistent?: boolean;\n}\n\nexport class BridgeDaemon {\n\tprivate proc: ChildProcess | undefined;\n\tprivate readonly pending = new Map<\n\t\tstring,\n\t\t{ resolve: (value: BridgePollResult) => void; reject: (error: Error) => void }\n\t>();\n\tprivate reqCounter = 0;\n\tprivate readyPromise: Promise<void> | undefined;\n\tprivate configured = false;\n\tprivate queue: Promise<void> = Promise.resolve();\n\n\tconstructor(\n\t\tprivate readonly pythonPath: string,\n\t\tprivate readonly log?: ioBroker.Logger,\n\t) {}\n\n\tget isRunning(): boolean {\n\t\treturn Boolean(this.proc && !this.proc.killed);\n\t}\n\n\tasync start(config: BridgeConfig): Promise<void> {\n\t\tif (this.isRunning) {\n\t\t\tawait this.request(\"configure\", config);\n\t\t\treturn;\n\t\t}\n\n\t\tconst script = bridgeScriptPath();\n\t\tif (!fs.existsSync(script)) {\n\t\t\tthrow new Error(`Python bridge not found: ${script}`);\n\t\t}\n\n\t\tconst python = resolvePythonExecutable(this.pythonPath);\n\t\tconst args = isPyLauncher(python) ? [\"-3\", script, \"serve\"] : [script, \"serve\"];\n\n\t\tthis.readyPromise = new Promise<void>((resolveReady, rejectReady) => {\n\t\t\tconst proc = spawn(python, args, {\n\t\t\t\twindowsHide: true,\n\t\t\t\tenv: buildPythonEnv(),\n\t\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\t});\n\t\t\tthis.proc = proc;\n\n\t\t\tlet readyResolved = false;\n\t\t\tconst failStart = (err: Error): void => {\n\t\t\t\tif (!readyResolved) {\n\t\t\t\t\treadyResolved = true;\n\t\t\t\t\trejectReady(err);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tproc.on(\"error\", failStart);\n\t\t\tproc.stderr?.on(\"data\", (chunk: Buffer) => {\n\t\t\t\tconst text = chunk.toString(\"utf8\").trim();\n\t\t\t\tif (text) {\n\t\t\t\t\tthis.log?.debug?.(`Bridge daemon stderr: ${text}`);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tproc.on(\"close\", code => {\n\t\t\t\tthis.proc = undefined;\n\t\t\t\tthis.configured = false;\n\t\t\t\tconst err = new Error(`Bridge daemon exited (code ${code ?? \"unknown\"})`);\n\t\t\t\tfor (const pending of this.pending.values()) {\n\t\t\t\t\tpending.reject(err);\n\t\t\t\t}\n\t\t\t\tthis.pending.clear();\n\t\t\t\tfailStart(err);\n\t\t\t});\n\n\t\t\tif (!proc.stdout) {\n\t\t\t\tfailStart(new Error(\"Bridge daemon has no stdout\"));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst rl = readline.createInterface({ input: proc.stdout });\n\t\t\trl.on(\"line\", line => {\n\t\t\t\tthis.onLine(line);\n\t\t\t\tif (!readyResolved && line.includes('\"ready\"')) {\n\t\t\t\t\treadyResolved = true;\n\t\t\t\t\tresolveReady();\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\tawait this.readyPromise;\n\t\tawait this.request(\"configure\", config);\n\t\tthis.configured = true;\n\t\tthis.log?.info(\"Anker Solix bridge daemon running (persistent API/MQTT session like HA)\");\n\t}\n\n\tprivate onLine(line: string): void {\n\t\tconst trimmed = line.trim();\n\t\tif (!trimmed) {\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(trimmed) as DaemonResponse;\n\t\t\tconst id = parsed.id;\n\t\t\tif (!id) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst pending = this.pending.get(id);\n\t\t\tif (!pending) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.pending.delete(id);\n\t\t\tif (!parsed.ok) {\n\t\t\t\tpending.reject(new Error(parsed.error || \"Bridge daemon error\"));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpending.resolve(parsed);\n\t\t} catch (error) {\n\t\t\tthis.log?.warn(`Invalid daemon response: ${trimmed} (${(error as Error).message})`);\n\t\t}\n\t}\n\n\tasync request(action: BridgeAction, config?: DaemonConfig): Promise<BridgePollResult> {\n\t\tconst run = this.queue.then(() => this._requestOnce(action, config));\n\t\tthis.queue = run.then(\n\t\t\t() => undefined,\n\t\t\t() => undefined,\n\t\t);\n\t\treturn run;\n\t}\n\n\tprivate _requestOnce(action: BridgeAction, config?: DaemonConfig): Promise<BridgePollResult> {\n\t\tif (!this.isRunning) {\n\t\t\treturn Promise.reject(new Error(\"Bridge daemon is not running\"));\n\t\t}\n\t\treturn new Promise<BridgePollResult>((resolve, reject) => {\n\t\t\tconst id = String(++this.reqCounter);\n\t\t\tthis.pending.set(id, { resolve, reject });\n\t\t\tconst payload = `${JSON.stringify({ id, action, config })}\\n`;\n\t\t\tconst ok = this.proc?.stdin?.write(payload);\n\t\t\tif (!ok) {\n\t\t\t\tthis.pending.delete(id);\n\t\t\t\treject(new Error(\"Bridge daemon stdin write failed\"));\n\t\t\t}\n\t\t});\n\t}\n\n\tasync stop(): Promise<void> {\n\t\tif (!this.isRunning) {\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tawait this.request(\"shutdown\");\n\t\t} catch {\n\t\t\t// daemon may already be gone\n\t\t}\n\t\tthis.proc?.kill();\n\t\tthis.proc = undefined;\n\t\tthis.configured = false;\n\t}\n}\n\nlet sharedDaemon: BridgeDaemon | undefined;\n\nexport function getBridgeDaemon(pythonPath: string, log?: ioBroker.Logger): BridgeDaemon {\n\tif (!sharedDaemon) {\n\t\tsharedDaemon = new BridgeDaemon(pythonPath, log);\n\t}\n\treturn sharedDaemon;\n}\n\nexport async function stopBridgeDaemon(): Promise<void> {\n\tif (sharedDaemon) {\n\t\tawait sharedDaemon.stop();\n\t\tsharedDaemon = undefined;\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAAyC;AACzC,eAA0B;AAC1B,SAAoB;AAEpB,yBAAsE;AAGtE,SAAS,mBAA2B;AACnC,SAAO,GAAG,SAAS;AACpB;AAYO,MAAM,aAAa;AAAA,EAWzB,YACkB,YACA,KAChB;AAFgB;AACA;AAAA,EACf;AAAA,EAbK;AAAA,EACS,UAAU,oBAAI,IAG7B;AAAA,EACM,aAAa;AAAA,EACb;AAAA,EACA,aAAa;AAAA,EACb,QAAuB,QAAQ,QAAQ;AAAA,EAO/C,IAAI,YAAqB;AACxB,WAAO,QAAQ,KAAK,QAAQ,CAAC,KAAK,KAAK,MAAM;AAAA,EAC9C;AAAA,EAEA,MAAM,MAAM,QAAqC;AAzClD;AA0CE,QAAI,KAAK,WAAW;AACnB,YAAM,KAAK,QAAQ,aAAa,MAAM;AACtC;AAAA,IACD;AAEA,UAAM,SAAS,iBAAiB;AAChC,QAAI,CAAC,GAAG,WAAW,MAAM,GAAG;AAC3B,YAAM,IAAI,MAAM,4BAA4B,MAAM,EAAE;AAAA,IACrD;AAEA,UAAM,aAAS,4CAAwB,KAAK,UAAU;A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AACnC,WAAK,QAAQ,IAAI,IAAI,EAAE,SAAS,OAAO,CAAC;AACxC,YAAM,UAAU,GAAG,KAAK,UAAU,EAAE,IAAI,QAAQ,OAAO,CAAC,CAAC;AAAA;AACzD,YAAM,MAAK,gBAAK,SAAL,mBAAW,UAAX,mBAAkB,MAAM;AACnC,UAAI,CAAC,IAAI;AACR,aAAK,QAAQ,OAAO,EAAE;AACtB,eAAO,IAAI,MAAM,kCAAkC,CAAC;AAAA,MACrD;AAAA,IACD,CAAC;AAAA,EACF;AAAA,EAEA,MAAM,OAAsB;AAlK7B;AAmKE,QAAI,CAAC,KAAK,WAAW;AACpB;AAAA,IACD;AACA,QAAI;AACH,YAAM,KAAK,QAAQ,UAAU;AAAA,IAC9B,QAAQ;AAAA,IAER;AACA,eAAK,SAAL,mBAAW;AACX,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACnB;AACD;AAEA,IAAI;AAEG,SAAS,gBAAgB,YAAoB,KAAqC;AACxF,MAAI,CAAC,cAAc;AAClB,mBAAe,IAAI,aAAa,YAAY,GAAG;AAAA,EAChD;AACA,SAAO;AACR;AAEA,eAAsB,mBAAkC;AACvD,MAAI,cAAc;AACjB,UAAM,aAAa,KAAK;AACxB,mBAAe;AAAA,EAChB;AACD;",
6
+ "names": ["_a"]
7
+ }
@@ -0,0 +1,37 @@
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 configHelpers_exports = {};
20
+ __export(configHelpers_exports, {
21
+ parseSelectedDeviceIds: () => parseSelectedDeviceIds
22
+ });
23
+ module.exports = __toCommonJS(configHelpers_exports);
24
+ function parseSelectedDeviceIds(value) {
25
+ if (Array.isArray(value)) {
26
+ return value.map((id) => String(id).trim()).filter(Boolean);
27
+ }
28
+ if (!value || typeof value !== "string") {
29
+ return [];
30
+ }
31
+ return value.split(/[,;\s]+/).map((id) => id.trim()).filter(Boolean);
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ parseSelectedDeviceIds
36
+ });
37
+ //# sourceMappingURL=configHelpers.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/lib/configHelpers.ts"],
4
+ "sourcesContent": ["/** Parse selectedDeviceIds from admin text (comma/semicolon/space) or array. */\nexport function parseSelectedDeviceIds(value: string | string[] | undefined): string[] {\n\tif (Array.isArray(value)) {\n\t\treturn value.map(id => String(id).trim()).filter(Boolean);\n\t}\n\tif (!value || typeof value !== \"string\") {\n\t\treturn [];\n\t}\n\treturn value\n\t\t.split(/[,;\\s]+/)\n\t\t.map(id => id.trim())\n\t\t.filter(Boolean);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACO,SAAS,uBAAuB,OAAgD;AACtF,MAAI,MAAM,QAAQ,KAAK,GAAG;AACzB,WAAO,MAAM,IAAI,QAAM,OAAO,EAAE,EAAE,KAAK,CAAC,EAAE,OAAO,OAAO;AAAA,EACzD;AACA,MAAI,CAAC,SAAS,OAAO,UAAU,UAAU;AACxC,WAAO,CAAC;AAAA,EACT;AACA,SAAO,MACL,MAAM,SAAS,EACf,IAAI,QAAM,GAAG,KAAK,CAAC,EACnB,OAAO,OAAO;AACjB;",
6
+ "names": []
7
+ }