iobroker.acinfinity 0.7.1 → 0.7.2
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/io-package.json +14 -1
- package/lib/client.js +84 -54
- package/lib/constants.js +96 -108
- package/lib/creators/deviceCreator.js +97 -91
- package/lib/creators/portCreator.js +238 -225
- package/lib/creators/stateCreator.js +27 -21
- package/lib/dataModels.js +25 -20
- package/lib/handlers/deviceSettingsHandler.js +55 -38
- package/lib/handlers/portModeHandler.js +72 -71
- package/lib/handlers/portSettingsHandler.js +95 -68
- package/lib/stateManager.js +62 -42
- package/lib/updaters/deviceUpdater.js +133 -96
- package/lib/updaters/portUpdater.js +256 -207
- package/main.js +102 -77
- package/package.json +4 -4
package/lib/stateManager.js
CHANGED
|
@@ -3,25 +3,26 @@
|
|
|
3
3
|
* Zentrale Klasse zum Verwalten von Zuständen für AC Infinity-Geräte
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
'use strict';
|
|
7
7
|
|
|
8
8
|
// Importiere Handler-Module
|
|
9
|
-
const DeviceSettingsHandler = require(
|
|
10
|
-
const PortSettingsHandler = require(
|
|
11
|
-
const PortModeHandler = require(
|
|
9
|
+
const DeviceSettingsHandler = require('./handlers/deviceSettingsHandler');
|
|
10
|
+
const PortSettingsHandler = require('./handlers/portSettingsHandler');
|
|
11
|
+
const PortModeHandler = require('./handlers/portModeHandler');
|
|
12
12
|
|
|
13
13
|
// Importiere Creator-Module
|
|
14
|
-
const StateCreator = require(
|
|
15
|
-
const DeviceCreator = require(
|
|
16
|
-
const PortCreator = require(
|
|
14
|
+
const StateCreator = require('./creators/stateCreator');
|
|
15
|
+
const DeviceCreator = require('./creators/deviceCreator');
|
|
16
|
+
const PortCreator = require('./creators/portCreator');
|
|
17
17
|
|
|
18
18
|
// Importiere Updater-Module
|
|
19
|
-
const DeviceUpdater = require(
|
|
20
|
-
const PortUpdater = require(
|
|
19
|
+
const DeviceUpdater = require('./updaters/deviceUpdater');
|
|
20
|
+
const PortUpdater = require('./updaters/portUpdater');
|
|
21
21
|
|
|
22
22
|
class StateManager {
|
|
23
23
|
/**
|
|
24
24
|
* Erstellt einen neuen StateManager
|
|
25
|
+
*
|
|
25
26
|
* @param {object} adapter - ioBroker-Adapter-Instanz
|
|
26
27
|
*/
|
|
27
28
|
constructor(adapter) {
|
|
@@ -48,37 +49,39 @@ class StateManager {
|
|
|
48
49
|
|
|
49
50
|
/**
|
|
50
51
|
* Setzt den API-Client und gibt ihn an die Handler weiter
|
|
52
|
+
*
|
|
51
53
|
* @param {object} client - AC Infinity API-Client
|
|
52
54
|
*/
|
|
53
55
|
setClient(client) {
|
|
54
56
|
this.client = client;
|
|
55
|
-
|
|
57
|
+
|
|
56
58
|
// Gib den Client an alle Handler weiter
|
|
57
59
|
this.deviceSettingsHandler.setClient(client);
|
|
58
60
|
this.portSettingsHandler.setClient(client);
|
|
59
61
|
this.portModeHandler.setClient(client);
|
|
60
62
|
|
|
61
|
-
this.adapter.log.debug(
|
|
63
|
+
this.adapter.log.debug('API client successfully passed to StateManager and handlers');
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
/**
|
|
65
67
|
* Initialisiert Zustände für alle Geräte
|
|
68
|
+
*
|
|
66
69
|
* @param {Array} devices - Array mit Geräteobjekten
|
|
67
70
|
*/
|
|
68
71
|
async initializeDevices(devices) {
|
|
69
72
|
for (const device of devices) {
|
|
70
73
|
const deviceId = device.devId;
|
|
71
74
|
this.adapter.log.info(`Initializing device: ${device.devName} (ID: ${deviceId})`);
|
|
72
|
-
|
|
75
|
+
|
|
73
76
|
// Erstelle Geräteobjekt
|
|
74
77
|
await this.deviceCreator.createDeviceObject(deviceId, device.devName);
|
|
75
|
-
|
|
78
|
+
|
|
76
79
|
// Erstelle Controller-Info-Kanal
|
|
77
80
|
await this.deviceCreator.createInfoChannel(deviceId);
|
|
78
|
-
|
|
81
|
+
|
|
79
82
|
// Erstelle Controller-Sensor-Zustände
|
|
80
83
|
await this.deviceCreator.createSensorChannel(deviceId);
|
|
81
|
-
|
|
84
|
+
|
|
82
85
|
// Erstelle Ports
|
|
83
86
|
const ports = device.deviceInfo.ports;
|
|
84
87
|
if (Array.isArray(ports)) {
|
|
@@ -94,15 +97,16 @@ class StateManager {
|
|
|
94
97
|
|
|
95
98
|
/**
|
|
96
99
|
* Aktualisiere Gerätedaten mit neuesten Werten
|
|
100
|
+
*
|
|
97
101
|
* @param {object} device - Geräteobjekt
|
|
98
102
|
*/
|
|
99
103
|
async updateDeviceData(device) {
|
|
100
104
|
const deviceId = device.devId;
|
|
101
105
|
this.adapter.log.debug(`Updating device data for ${deviceId}`);
|
|
102
|
-
|
|
106
|
+
|
|
103
107
|
// Aktualisiere Gerätedaten über den DeviceUpdater
|
|
104
108
|
await this.deviceUpdater.updateDeviceData(deviceId, device);
|
|
105
|
-
|
|
109
|
+
|
|
106
110
|
// Aktualisiere Port-Zustände
|
|
107
111
|
if (device.deviceInfo && Array.isArray(device.deviceInfo.ports)) {
|
|
108
112
|
for (const port of device.deviceInfo.ports) {
|
|
@@ -113,9 +117,10 @@ class StateManager {
|
|
|
113
117
|
this.adapter.log.warn(`No ports found in device data for ${deviceId}`);
|
|
114
118
|
}
|
|
115
119
|
}
|
|
116
|
-
|
|
120
|
+
|
|
117
121
|
/**
|
|
118
122
|
* Aktualisiere Port-Einstellungen
|
|
123
|
+
*
|
|
119
124
|
* @param {string|number} deviceId - Geräte-ID
|
|
120
125
|
* @param {number} portId - Port-ID
|
|
121
126
|
* @param {object} settings - Einstellungsobjekt
|
|
@@ -126,6 +131,7 @@ class StateManager {
|
|
|
126
131
|
|
|
127
132
|
/**
|
|
128
133
|
* Aktualisiere erweiterte Einstellungen
|
|
134
|
+
*
|
|
129
135
|
* @param {string|number} deviceId - Geräte-ID
|
|
130
136
|
* @param {number} portId - Port-ID (0 für Controller-Einstellungen)
|
|
131
137
|
* @param {object} settings - Einstellungsobjekt
|
|
@@ -142,6 +148,7 @@ class StateManager {
|
|
|
142
148
|
|
|
143
149
|
/**
|
|
144
150
|
* Verarbeitet eine vom Benutzer initiierte Zustandsänderung
|
|
151
|
+
*
|
|
145
152
|
* @param {string} id - Zustands-ID
|
|
146
153
|
* @param {object} state - Zustandsobjekt
|
|
147
154
|
*/
|
|
@@ -156,12 +163,12 @@ class StateManager {
|
|
|
156
163
|
try {
|
|
157
164
|
// Überprüfen, ob der Client gesetzt ist
|
|
158
165
|
if (!this.client) {
|
|
159
|
-
throw new Error(
|
|
166
|
+
throw new Error('API client not set. Cannot process state change.');
|
|
160
167
|
}
|
|
161
168
|
|
|
162
169
|
// Parse ID, um Geräte-, Port- und Parameterinformationen zu erhalten
|
|
163
|
-
const idParts = id.split(
|
|
164
|
-
|
|
170
|
+
const idParts = id.split('.');
|
|
171
|
+
|
|
165
172
|
// Entferne Adaptername und Instanz vom Pfad
|
|
166
173
|
let path;
|
|
167
174
|
if (idParts[0] === this.adapter.name && idParts[1].match(/^\d+$/)) {
|
|
@@ -171,40 +178,49 @@ class StateManager {
|
|
|
171
178
|
// ID ist bereits ohne Präfix (z.B. "devices.1234")
|
|
172
179
|
path = idParts;
|
|
173
180
|
}
|
|
174
|
-
|
|
181
|
+
|
|
175
182
|
this.adapter.log.debug(`Processing path parts: ${JSON.stringify(path)}`);
|
|
176
183
|
|
|
177
|
-
if (path[0] !==
|
|
184
|
+
if (path[0] !== 'devices' || path.length < 4) {
|
|
178
185
|
this.adapter.log.warn(`Received state change with invalid path: ${id}`);
|
|
179
186
|
return;
|
|
180
187
|
}
|
|
181
|
-
|
|
188
|
+
|
|
182
189
|
const deviceId = path[1];
|
|
183
|
-
|
|
190
|
+
|
|
184
191
|
// Verarbeite Geräteebenen-Einstellungen
|
|
185
|
-
if (path[2] ===
|
|
192
|
+
if (path[2] === 'settings') {
|
|
186
193
|
await this.deviceSettingsHandler.handleDeviceSettingsChange(deviceId, path.slice(3), state.val);
|
|
187
194
|
return;
|
|
188
195
|
}
|
|
189
|
-
|
|
196
|
+
|
|
190
197
|
// Verarbeite Port-Ebenen-Einstellungen
|
|
191
|
-
if (path[2] ===
|
|
198
|
+
if (path[2] === 'ports' && path.length >= 5) {
|
|
192
199
|
const portId = parseInt(path[3]);
|
|
193
200
|
const subPath = path.slice(4);
|
|
194
|
-
|
|
201
|
+
|
|
195
202
|
// Leite die Änderung an den richtigen Handler weiter
|
|
196
|
-
if (subPath[0] ===
|
|
197
|
-
this.adapter.log.info(
|
|
203
|
+
if (subPath[0] === 'mode') {
|
|
204
|
+
this.adapter.log.info(
|
|
205
|
+
`Processing mode change: Device ${deviceId}, Port ${portId}, Path ${subPath.join('.')}, Value ${state.val}`,
|
|
206
|
+
);
|
|
198
207
|
await this.portModeHandler.handlePortModeChange(deviceId, portId, subPath.slice(1), state.val);
|
|
199
|
-
} else if (subPath[0] ===
|
|
200
|
-
this.adapter.log.info(
|
|
201
|
-
|
|
208
|
+
} else if (subPath[0] === 'settings') {
|
|
209
|
+
this.adapter.log.info(
|
|
210
|
+
`Processing settings change: Device ${deviceId}, Port ${portId}, Path ${subPath.join('.')}, Value ${state.val}`,
|
|
211
|
+
);
|
|
212
|
+
await this.portSettingsHandler.handlePortAdvancedSettingsChange(
|
|
213
|
+
deviceId,
|
|
214
|
+
portId,
|
|
215
|
+
subPath.slice(1),
|
|
216
|
+
state.val,
|
|
217
|
+
);
|
|
202
218
|
} else {
|
|
203
219
|
this.adapter.log.warn(`Unknown port settings category: ${subPath[0]}`);
|
|
204
220
|
}
|
|
205
221
|
return;
|
|
206
222
|
}
|
|
207
|
-
|
|
223
|
+
|
|
208
224
|
this.adapter.log.warn(`Unprocessed state change: ${id}`);
|
|
209
225
|
} catch (error) {
|
|
210
226
|
this.adapter.log.error(`Error processing state change: ${error.message}`);
|
|
@@ -217,6 +233,7 @@ class StateManager {
|
|
|
217
233
|
/**
|
|
218
234
|
* Helfermethode zum Erstellen eines Zustands
|
|
219
235
|
* Wird vom StateCreator verwendet
|
|
236
|
+
*
|
|
220
237
|
* @param {string} id - Zustands-ID
|
|
221
238
|
* @param {string} name - Zustandsname
|
|
222
239
|
* @param {string} type - Zustandstyp
|
|
@@ -232,6 +249,7 @@ class StateManager {
|
|
|
232
249
|
|
|
233
250
|
/**
|
|
234
251
|
* Aktualisiere einen Zustandswert
|
|
252
|
+
*
|
|
235
253
|
* @param {string} id - Zustands-ID
|
|
236
254
|
* @param {any} value - Zustandswert
|
|
237
255
|
*/
|
|
@@ -241,10 +259,10 @@ class StateManager {
|
|
|
241
259
|
if (value === null || value === undefined) {
|
|
242
260
|
return;
|
|
243
261
|
}
|
|
244
|
-
|
|
262
|
+
|
|
245
263
|
// Für Debug-Zwecke
|
|
246
264
|
this.adapter.log.debug(`Updating state ${id} with value ${value}`);
|
|
247
|
-
|
|
265
|
+
|
|
248
266
|
await this.adapter.setStateAsync(id, { val: value, ack: true });
|
|
249
267
|
} catch (error) {
|
|
250
268
|
this.adapter.log.error(`Error updating state ${id}: ${error.message}`);
|
|
@@ -254,6 +272,7 @@ class StateManager {
|
|
|
254
272
|
/**
|
|
255
273
|
* Hilfsmethode, um Änderungen im UI temporär zu aktualisieren, bevor die tatsächliche Aktualisierung stattfindet
|
|
256
274
|
* Dies verhindert, dass das UI zurückspringt, solange die API-Anfrage bearbeitet wird
|
|
275
|
+
*
|
|
257
276
|
* @param {string} id - Zustands-ID
|
|
258
277
|
* @param {any} value - Zustandswert
|
|
259
278
|
*/
|
|
@@ -268,6 +287,7 @@ class StateManager {
|
|
|
268
287
|
|
|
269
288
|
/**
|
|
270
289
|
* Verzögert die Ausführung einer Funktion
|
|
290
|
+
*
|
|
271
291
|
* @param {number} ms - Verzögerung in Millisekunden
|
|
272
292
|
* @returns {Promise} - Promise, das nach der Verzögerung aufgelöst wird
|
|
273
293
|
*/
|
|
@@ -281,16 +301,16 @@ class StateManager {
|
|
|
281
301
|
*/
|
|
282
302
|
async refreshWithThrottle() {
|
|
283
303
|
if (this._refreshPending) {
|
|
284
|
-
this.adapter.log.debug(
|
|
304
|
+
this.adapter.log.debug('Update already in progress, skipping');
|
|
285
305
|
return;
|
|
286
306
|
}
|
|
287
|
-
|
|
307
|
+
|
|
288
308
|
// Falls noch ein ausstehender Timer existiert, diesen löschen
|
|
289
309
|
if (this._refreshTimer) {
|
|
290
310
|
clearTimeout(this._refreshTimer);
|
|
291
311
|
this._refreshTimer = null;
|
|
292
312
|
}
|
|
293
|
-
|
|
313
|
+
|
|
294
314
|
this._refreshPending = true;
|
|
295
315
|
try {
|
|
296
316
|
// Warte einen Moment, um die API nicht zu überlasten
|
|
@@ -304,10 +324,10 @@ class StateManager {
|
|
|
304
324
|
this._refreshTimer = setTimeout(() => {
|
|
305
325
|
this._refreshPending = false;
|
|
306
326
|
this._refreshTimer = null;
|
|
307
|
-
this.adapter.log.debug(
|
|
327
|
+
this.adapter.log.debug('Update lock released');
|
|
308
328
|
}, 3000); // Wartezeit, um übermäßige Aufrufe zu verhindern
|
|
309
329
|
}
|
|
310
330
|
}
|
|
311
331
|
}
|
|
312
332
|
|
|
313
|
-
module.exports = StateManager;
|
|
333
|
+
module.exports = StateManager;
|
|
@@ -3,16 +3,14 @@
|
|
|
3
3
|
* Verantwortlich für das Aktualisieren von Gerätedaten in ioBroker
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
'use strict';
|
|
7
7
|
|
|
8
|
-
const {
|
|
9
|
-
OUTSIDE_CLIMATE_OPTIONS,
|
|
10
|
-
ADVANCED_SETTINGS_KEY
|
|
11
|
-
} = require("../constants");
|
|
8
|
+
const { OUTSIDE_CLIMATE_OPTIONS, ADVANCED_SETTINGS_KEY } = require('../constants');
|
|
12
9
|
|
|
13
10
|
class DeviceUpdater {
|
|
14
11
|
/**
|
|
15
12
|
* Erstellt einen neuen DeviceUpdater
|
|
13
|
+
*
|
|
16
14
|
* @param {object} stateManager - Referenz zum StateManager
|
|
17
15
|
*/
|
|
18
16
|
constructor(stateManager) {
|
|
@@ -22,34 +20,38 @@ class DeviceUpdater {
|
|
|
22
20
|
|
|
23
21
|
/**
|
|
24
22
|
* Wandelt einen numerischen Gerätetyp in einen benutzerfreundlichen Namen um
|
|
23
|
+
*
|
|
25
24
|
* @param {number} deviceType - Numerischer Gerätetyp
|
|
26
25
|
* @returns {string} - Benutzerfreundlicher Name des Gerätetyps
|
|
27
26
|
*/
|
|
28
27
|
getDeviceModelByType(deviceType) {
|
|
29
28
|
const models = {
|
|
30
|
-
1:
|
|
31
|
-
11:
|
|
32
|
-
18:
|
|
33
|
-
20:
|
|
34
|
-
22:
|
|
35
|
-
24:
|
|
29
|
+
1: 'UIS Controller 69 WiFi (CTR69W)',
|
|
30
|
+
11: 'UIS Controller 69 Pro (CTR69P)',
|
|
31
|
+
18: 'UIS Controller 69 Pro+ (CTR69Q)',
|
|
32
|
+
20: 'UIS Controller AI+ (CTR89Q)',
|
|
33
|
+
22: 'UIS Controller Outlet AI (AC-ADA4)',
|
|
34
|
+
24: 'UIS Controller Outlet AI+ (AC-ADA8)',
|
|
36
35
|
};
|
|
37
36
|
return models[deviceType] || `UIS Controller (Typ ${deviceType})`;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
/**
|
|
41
40
|
* Aktualisiert Gerätedaten mit den neuesten Werten
|
|
41
|
+
*
|
|
42
42
|
* @param {string} deviceId - Geräte-ID
|
|
43
43
|
* @param {object} device - Geräteobjekt mit den neuen Daten
|
|
44
44
|
* @returns {Promise<void>}
|
|
45
45
|
*/
|
|
46
46
|
async updateDeviceData(deviceId, device) {
|
|
47
47
|
try {
|
|
48
|
-
this.adapter.log.debug(
|
|
49
|
-
|
|
48
|
+
this.adapter.log.debug(
|
|
49
|
+
`Aktualisiere Gerätedaten für ${deviceId}: ${JSON.stringify(device).substring(0, 500)}...`,
|
|
50
|
+
);
|
|
51
|
+
|
|
50
52
|
// Aktualisiere Info-Zustände
|
|
51
53
|
await this.updateInfoStates(deviceId, device);
|
|
52
|
-
|
|
54
|
+
|
|
53
55
|
// Aktualisiere Sensor-Zustände
|
|
54
56
|
await this.updateSensorStates(deviceId, device);
|
|
55
57
|
} catch (error) {
|
|
@@ -59,6 +61,7 @@ class DeviceUpdater {
|
|
|
59
61
|
|
|
60
62
|
/**
|
|
61
63
|
* Aktualisiert die Info-Zustände des Geräts
|
|
64
|
+
*
|
|
62
65
|
* @param {string} deviceId - Geräte-ID
|
|
63
66
|
* @param {object} device - Geräteobjekt
|
|
64
67
|
* @returns {Promise<void>}
|
|
@@ -67,50 +70,54 @@ class DeviceUpdater {
|
|
|
67
70
|
await this.stateManager.updateState(`devices.${deviceId}.info.name`, device.devName);
|
|
68
71
|
await this.stateManager.updateState(`devices.${deviceId}.info.online`, device.online === 1);
|
|
69
72
|
await this.stateManager.updateState(`devices.${deviceId}.info.mac`, device.devMacAddr);
|
|
70
|
-
|
|
73
|
+
|
|
71
74
|
// Ermittle die numerische Gerätetypnummer
|
|
72
75
|
let deviceTypeNum = 0;
|
|
73
|
-
if (typeof device.devType ===
|
|
76
|
+
if (typeof device.devType === 'number') {
|
|
74
77
|
deviceTypeNum = device.devType;
|
|
75
|
-
} else if (typeof device.devType ===
|
|
78
|
+
} else if (typeof device.devType === 'string') {
|
|
76
79
|
// Versuche, die Zahl zu extrahieren
|
|
77
80
|
const match = device.devType.match(/\d+/);
|
|
78
81
|
if (match) {
|
|
79
82
|
deviceTypeNum = parseInt(match[0], 10);
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
|
-
|
|
85
|
+
|
|
83
86
|
// Verwende zusätzlich den beschreibenden Namen als Text-Beschreibung
|
|
84
87
|
const deviceTypeStr = this.getDeviceModelByType(deviceTypeNum);
|
|
85
|
-
|
|
88
|
+
|
|
86
89
|
// Setze den numerischen Gerätetyp
|
|
87
90
|
await this.stateManager.updateState(`devices.${deviceId}.info.deviceType`, deviceTypeNum);
|
|
88
|
-
|
|
91
|
+
|
|
89
92
|
// Optional: Füge eine zusätzliche Beschreibung hinzu
|
|
90
93
|
if (deviceTypeStr !== `UIS Controller Typ ${deviceTypeNum}`) {
|
|
91
94
|
await this.adapter.setObjectNotExistsAsync(`devices.${deviceId}.info.deviceTypeDescription`, {
|
|
92
|
-
type:
|
|
95
|
+
type: 'state',
|
|
93
96
|
common: {
|
|
94
|
-
name:
|
|
95
|
-
type:
|
|
96
|
-
role:
|
|
97
|
+
name: 'Device Type Description',
|
|
98
|
+
type: 'string',
|
|
99
|
+
role: 'text',
|
|
97
100
|
read: true,
|
|
98
|
-
write: false
|
|
101
|
+
write: false,
|
|
99
102
|
},
|
|
100
|
-
native: {}
|
|
103
|
+
native: {},
|
|
101
104
|
});
|
|
102
105
|
await this.stateManager.updateState(`devices.${deviceId}.info.deviceTypeDescription`, deviceTypeStr);
|
|
103
106
|
}
|
|
104
|
-
|
|
107
|
+
|
|
105
108
|
// Prüfen, wo die Firmware- und Hardwaredaten zu finden sind
|
|
106
109
|
if (device.deviceInfo) {
|
|
107
110
|
// Prüfen der verschiedenen möglichen Orte für die Versionsinformationen
|
|
108
|
-
const firmwareVersion =
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
const firmwareVersion =
|
|
112
|
+
device.deviceInfo.firmwareVersion ||
|
|
113
|
+
device.firmwareVersion ||
|
|
114
|
+
(device.deviceInfo.versions ? device.deviceInfo.versions.firmware : null);
|
|
115
|
+
|
|
116
|
+
const hardwareVersion =
|
|
117
|
+
device.deviceInfo.hardwareVersion ||
|
|
118
|
+
device.hardwareVersion ||
|
|
119
|
+
(device.deviceInfo.versions ? device.deviceInfo.versions.hardware : null);
|
|
120
|
+
|
|
114
121
|
await this.stateManager.updateState(`devices.${deviceId}.info.firmware`, firmwareVersion);
|
|
115
122
|
await this.stateManager.updateState(`devices.${deviceId}.info.hardware`, hardwareVersion);
|
|
116
123
|
} else {
|
|
@@ -118,59 +125,70 @@ class DeviceUpdater {
|
|
|
118
125
|
await this.stateManager.updateState(`devices.${deviceId}.info.firmware`, device.firmwareVersion);
|
|
119
126
|
await this.stateManager.updateState(`devices.${deviceId}.info.hardware`, device.hardwareVersion);
|
|
120
127
|
}
|
|
121
|
-
|
|
128
|
+
|
|
122
129
|
// Füge zusätzliches Debug-Logging hinzu, um die aktuelle Datenstruktur zu verstehen
|
|
123
130
|
this.adapter.log.debug(`Device info structure for ${deviceId}: ${JSON.stringify(device)}`);
|
|
124
131
|
}
|
|
125
132
|
|
|
126
133
|
/**
|
|
127
134
|
* Aktualisiert die Sensor-Zustände des Geräts
|
|
135
|
+
*
|
|
128
136
|
* @param {string} deviceId - Geräte-ID
|
|
129
137
|
* @param {object} device - Geräteobjekt
|
|
130
138
|
* @returns {Promise<void>}
|
|
131
139
|
*/
|
|
132
140
|
async updateSensorStates(deviceId, device) {
|
|
133
141
|
// Temperatur und Feuchtigkeit können entweder direkt im Gerät oder in deviceInfo sein
|
|
134
|
-
const temperature =
|
|
135
|
-
|
|
136
|
-
const humidity =
|
|
137
|
-
|
|
138
|
-
const vpd = device.vpdnums !== undefined ? device.vpdnums :
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
const temperature =
|
|
143
|
+
device.temperature !== undefined ? device.temperature : device.deviceInfo && device.deviceInfo.temperature;
|
|
144
|
+
const humidity =
|
|
145
|
+
device.humidity !== undefined ? device.humidity : device.deviceInfo && device.deviceInfo.humidity;
|
|
146
|
+
const vpd = device.vpdnums !== undefined ? device.vpdnums : device.deviceInfo && device.deviceInfo.vpdnums;
|
|
147
|
+
|
|
148
|
+
this.adapter.log.debug(
|
|
149
|
+
`Sensorwerte für Gerät ${deviceId}: temperature=${temperature}, humidity=${humidity}, vpd=${vpd}`,
|
|
150
|
+
);
|
|
151
|
+
|
|
143
152
|
// Aktualisiere Sensorwerte mit sorgfältiger Prüfung
|
|
144
|
-
if (typeof temperature ===
|
|
145
|
-
await this.stateManager.updateState(
|
|
153
|
+
if (typeof temperature === 'number') {
|
|
154
|
+
await this.stateManager.updateState(
|
|
155
|
+
`devices.${deviceId}.sensors.temperature`,
|
|
156
|
+
parseFloat((temperature / 100).toFixed(2)),
|
|
157
|
+
);
|
|
146
158
|
}
|
|
147
|
-
|
|
148
|
-
if (typeof humidity ===
|
|
149
|
-
await this.stateManager.updateState(
|
|
159
|
+
|
|
160
|
+
if (typeof humidity === 'number') {
|
|
161
|
+
await this.stateManager.updateState(
|
|
162
|
+
`devices.${deviceId}.sensors.humidity`,
|
|
163
|
+
parseFloat((humidity / 100).toFixed(2)),
|
|
164
|
+
);
|
|
150
165
|
}
|
|
151
|
-
|
|
152
|
-
if (typeof vpd ===
|
|
166
|
+
|
|
167
|
+
if (typeof vpd === 'number') {
|
|
153
168
|
await this.stateManager.updateState(`devices.${deviceId}.sensors.vpd`, parseFloat((vpd / 100).toFixed(2)));
|
|
154
169
|
}
|
|
155
170
|
|
|
156
171
|
// Optional sensors — present only when external sensors are connected
|
|
157
172
|
// The API field names follow the pattern used by the AC Infinity UIS sensor protocol
|
|
158
|
-
const co2 = device.co2 !== undefined ? device.co2 :
|
|
159
|
-
|
|
160
|
-
if (typeof co2 === "number" && co2 > 0) {
|
|
173
|
+
const co2 = device.co2 !== undefined ? device.co2 : device.deviceInfo && device.deviceInfo.co2;
|
|
174
|
+
if (typeof co2 === 'number' && co2 > 0) {
|
|
161
175
|
await this.stateManager.updateState(`devices.${deviceId}.sensors.co2`, co2);
|
|
162
176
|
}
|
|
163
177
|
|
|
164
|
-
const soilMoisture =
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
178
|
+
const soilMoisture =
|
|
179
|
+
device.soilMoisture !== undefined
|
|
180
|
+
? device.soilMoisture
|
|
181
|
+
: device.deviceInfo && device.deviceInfo.soilMoisture;
|
|
182
|
+
if (typeof soilMoisture === 'number') {
|
|
183
|
+
await this.stateManager.updateState(
|
|
184
|
+
`devices.${deviceId}.sensors.soilMoisture`,
|
|
185
|
+
parseFloat((soilMoisture / 100).toFixed(1)),
|
|
186
|
+
);
|
|
169
187
|
}
|
|
170
188
|
|
|
171
|
-
const waterLevel =
|
|
172
|
-
|
|
173
|
-
if (typeof waterLevel ===
|
|
189
|
+
const waterLevel =
|
|
190
|
+
device.waterLevel !== undefined ? device.waterLevel : device.deviceInfo && device.deviceInfo.waterLevel;
|
|
191
|
+
if (typeof waterLevel === 'number') {
|
|
174
192
|
await this.stateManager.updateState(`devices.${deviceId}.sensors.waterLevel`, waterLevel);
|
|
175
193
|
}
|
|
176
194
|
|
|
@@ -180,6 +198,7 @@ class DeviceUpdater {
|
|
|
180
198
|
|
|
181
199
|
/**
|
|
182
200
|
* Aktualisiert die erweiterten Geräteeinstellungen
|
|
201
|
+
*
|
|
183
202
|
* @param {string} deviceId - Geräte-ID
|
|
184
203
|
* @param {object} settings - Einstellungsobjekt
|
|
185
204
|
* @returns {Promise<void>}
|
|
@@ -189,64 +208,82 @@ class DeviceUpdater {
|
|
|
189
208
|
this.adapter.log.warn(`Erhielt leere erweiterte Einstellungen für ${deviceId}`);
|
|
190
209
|
return;
|
|
191
210
|
}
|
|
192
|
-
|
|
193
|
-
this.adapter.log.debug(
|
|
194
|
-
|
|
211
|
+
|
|
212
|
+
this.adapter.log.debug(
|
|
213
|
+
`Aktualisiere erweiterte Einstellungen für ${deviceId}: ${JSON.stringify(settings).substring(0, 500)}...`,
|
|
214
|
+
);
|
|
215
|
+
|
|
195
216
|
try {
|
|
196
217
|
// Temperatureinheit (1 = Celsius, 0 = Fahrenheit)
|
|
197
|
-
if (typeof settings[ADVANCED_SETTINGS_KEY.TEMP_UNIT] ===
|
|
198
|
-
await this.stateManager.updateState(
|
|
199
|
-
settings
|
|
218
|
+
if (typeof settings[ADVANCED_SETTINGS_KEY.TEMP_UNIT] === 'number') {
|
|
219
|
+
await this.stateManager.updateState(
|
|
220
|
+
`devices.${deviceId}.settings.temperatureUnit`,
|
|
221
|
+
settings[ADVANCED_SETTINGS_KEY.TEMP_UNIT] > 0 ? 'C' : 'F',
|
|
222
|
+
);
|
|
200
223
|
}
|
|
201
|
-
|
|
224
|
+
|
|
202
225
|
// Verwende je nach Temperatureinheit den passenden Kalibrierungswert
|
|
203
226
|
const tempUnit = settings[ADVANCED_SETTINGS_KEY.TEMP_UNIT];
|
|
204
|
-
|
|
227
|
+
|
|
205
228
|
if (tempUnit !== undefined) {
|
|
206
|
-
const tempCalibration =
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
229
|
+
const tempCalibration =
|
|
230
|
+
tempUnit > 0
|
|
231
|
+
? settings[ADVANCED_SETTINGS_KEY.CALIBRATE_TEMP]
|
|
232
|
+
: settings[ADVANCED_SETTINGS_KEY.CALIBRATE_TEMP_F];
|
|
233
|
+
|
|
210
234
|
if (tempCalibration !== undefined) {
|
|
211
|
-
await this.stateManager.updateState(
|
|
212
|
-
|
|
235
|
+
await this.stateManager.updateState(
|
|
236
|
+
`devices.${deviceId}.settings.temperatureCalibration`,
|
|
237
|
+
tempCalibration,
|
|
238
|
+
);
|
|
213
239
|
}
|
|
214
240
|
}
|
|
215
|
-
|
|
241
|
+
|
|
216
242
|
// Feuchtigkeitskalibrierung
|
|
217
|
-
if (typeof settings[ADVANCED_SETTINGS_KEY.CALIBRATE_HUMIDITY] ===
|
|
218
|
-
await this.stateManager.updateState(
|
|
219
|
-
settings
|
|
243
|
+
if (typeof settings[ADVANCED_SETTINGS_KEY.CALIBRATE_HUMIDITY] === 'number') {
|
|
244
|
+
await this.stateManager.updateState(
|
|
245
|
+
`devices.${deviceId}.settings.humidityCalibration`,
|
|
246
|
+
settings[ADVANCED_SETTINGS_KEY.CALIBRATE_HUMIDITY],
|
|
247
|
+
);
|
|
220
248
|
}
|
|
221
|
-
|
|
249
|
+
|
|
222
250
|
// VPD-Blatttemperatur-Offset
|
|
223
251
|
if (tempUnit !== undefined) {
|
|
224
|
-
const vpdLeafOffset =
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
252
|
+
const vpdLeafOffset =
|
|
253
|
+
tempUnit > 0
|
|
254
|
+
? settings[ADVANCED_SETTINGS_KEY.VPD_LEAF_TEMP_OFFSET]
|
|
255
|
+
: settings[ADVANCED_SETTINGS_KEY.VPD_LEAF_TEMP_OFFSET_F];
|
|
256
|
+
|
|
228
257
|
if (vpdLeafOffset !== undefined) {
|
|
229
|
-
await this.stateManager.updateState(
|
|
230
|
-
|
|
258
|
+
await this.stateManager.updateState(
|
|
259
|
+
`devices.${deviceId}.settings.vpdLeafTemperatureOffset`,
|
|
260
|
+
vpdLeafOffset,
|
|
261
|
+
);
|
|
231
262
|
}
|
|
232
263
|
}
|
|
233
|
-
|
|
264
|
+
|
|
234
265
|
// Außenklima-Einstellungen
|
|
235
266
|
const outsideTempCompare = settings[ADVANCED_SETTINGS_KEY.OUTSIDE_TEMP_COMPARE];
|
|
236
|
-
if (typeof outsideTempCompare ===
|
|
237
|
-
await this.stateManager.updateState(
|
|
238
|
-
|
|
267
|
+
if (typeof outsideTempCompare === 'number' && outsideTempCompare < OUTSIDE_CLIMATE_OPTIONS.length) {
|
|
268
|
+
await this.stateManager.updateState(
|
|
269
|
+
`devices.${deviceId}.settings.outsideTemperature`,
|
|
270
|
+
OUTSIDE_CLIMATE_OPTIONS[outsideTempCompare],
|
|
271
|
+
);
|
|
239
272
|
}
|
|
240
|
-
|
|
273
|
+
|
|
241
274
|
const outsideHumidityCompare = settings[ADVANCED_SETTINGS_KEY.OUTSIDE_HUMIDITY_COMPARE];
|
|
242
|
-
if (typeof outsideHumidityCompare ===
|
|
243
|
-
await this.stateManager.updateState(
|
|
244
|
-
|
|
275
|
+
if (typeof outsideHumidityCompare === 'number' && outsideHumidityCompare < OUTSIDE_CLIMATE_OPTIONS.length) {
|
|
276
|
+
await this.stateManager.updateState(
|
|
277
|
+
`devices.${deviceId}.settings.outsideHumidity`,
|
|
278
|
+
OUTSIDE_CLIMATE_OPTIONS[outsideHumidityCompare],
|
|
279
|
+
);
|
|
245
280
|
}
|
|
246
281
|
} catch (error) {
|
|
247
|
-
this.adapter.log.error(
|
|
282
|
+
this.adapter.log.error(
|
|
283
|
+
`Fehler beim Aktualisieren erweiterter Geräteeinstellungen für ${deviceId}: ${error.message}`,
|
|
284
|
+
);
|
|
248
285
|
}
|
|
249
286
|
}
|
|
250
287
|
}
|
|
251
288
|
|
|
252
|
-
module.exports = DeviceUpdater;
|
|
289
|
+
module.exports = DeviceUpdater;
|