iobroker.acinfinity 0.3.1
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 +86 -0
- package/admin/acinfinity.png +0 -0
- package/admin/index_m.html +151 -0
- package/admin/jsonConfig.json +77 -0
- package/admin/words.js +54 -0
- package/io-package.json +97 -0
- package/lib/client.js +625 -0
- package/lib/constants.js +173 -0
- package/lib/creators/deviceCreator.js +202 -0
- package/lib/creators/portCreator.js +536 -0
- package/lib/creators/stateCreator.js +177 -0
- package/lib/dataModels.js +135 -0
- package/lib/handlers/deviceSettingsHandler.js +163 -0
- package/lib/handlers/portModeHandler.js +630 -0
- package/lib/handlers/portSettingsHandler.js +212 -0
- package/lib/stateManager.js +313 -0
- package/lib/updaters/deviceUpdater.js +202 -0
- package/lib/updaters/portUpdater.js +527 -0
- package/main.js +325 -0
- package/package.json +62 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DeviceUpdater für AC Infinity Adapter
|
|
3
|
+
* Verantwortlich für das Aktualisieren von Gerätedaten in ioBroker
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
OUTSIDE_CLIMATE_OPTIONS,
|
|
10
|
+
ADVANCED_SETTINGS_KEY
|
|
11
|
+
} = require('../constants');
|
|
12
|
+
|
|
13
|
+
class DeviceUpdater {
|
|
14
|
+
/**
|
|
15
|
+
* Erstellt einen neuen DeviceUpdater
|
|
16
|
+
* @param {object} stateManager - Referenz zum StateManager
|
|
17
|
+
*/
|
|
18
|
+
constructor(stateManager) {
|
|
19
|
+
this.stateManager = stateManager;
|
|
20
|
+
this.adapter = stateManager.adapter;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Wandelt einen numerischen Gerätetyp in einen benutzerfreundlichen Namen um
|
|
25
|
+
* @param {number} deviceType - Numerischer Gerätetyp
|
|
26
|
+
* @returns {string} - Benutzerfreundlicher Name des Gerätetyps
|
|
27
|
+
*/
|
|
28
|
+
getDeviceModelByType(deviceType) {
|
|
29
|
+
switch (deviceType) {
|
|
30
|
+
case 11:
|
|
31
|
+
return "UIS Controller 69 Pro (CTR69P)";
|
|
32
|
+
case 18:
|
|
33
|
+
return "UIS CONTROLLER 69 Pro+ (CTR69Q)";
|
|
34
|
+
default:
|
|
35
|
+
return `UIS Controller Typ ${deviceType}`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Aktualisiert Gerätedaten mit den neuesten Werten
|
|
41
|
+
* @param {string} deviceId - Geräte-ID
|
|
42
|
+
* @param {object} device - Geräteobjekt mit den neuen Daten
|
|
43
|
+
* @returns {Promise<void>}
|
|
44
|
+
*/
|
|
45
|
+
async updateDeviceData(deviceId, device) {
|
|
46
|
+
try {
|
|
47
|
+
this.adapter.log.debug(`Aktualisiere Gerätedaten für ${deviceId}: ${JSON.stringify(device).substring(0, 500)}...`);
|
|
48
|
+
|
|
49
|
+
// Aktualisiere Info-Zustände
|
|
50
|
+
await this.updateInfoStates(deviceId, device);
|
|
51
|
+
|
|
52
|
+
// Aktualisiere Sensor-Zustände
|
|
53
|
+
await this.updateSensorStates(deviceId, device);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
this.adapter.log.error(`Fehler beim Aktualisieren der Gerätedaten für ${deviceId}: ${error.message}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Aktualisiert die Info-Zustände des Geräts
|
|
61
|
+
* @param {string} deviceId - Geräte-ID
|
|
62
|
+
* @param {object} device - Geräteobjekt
|
|
63
|
+
* @returns {Promise<void>}
|
|
64
|
+
*/
|
|
65
|
+
async updateInfoStates(deviceId, device) {
|
|
66
|
+
await this.stateManager.updateState(`devices.${deviceId}.info.name`, device.devName);
|
|
67
|
+
await this.stateManager.updateState(`devices.${deviceId}.info.online`, device.online === 1);
|
|
68
|
+
await this.stateManager.updateState(`devices.${deviceId}.info.mac`, device.devMacAddr);
|
|
69
|
+
|
|
70
|
+
// Wandle den numerischen Gerätetyp in einen benutzerfreundlichen Namen um
|
|
71
|
+
if (typeof device.devType === 'number') {
|
|
72
|
+
const deviceTypeStr = this.getDeviceModelByType(device.devType);
|
|
73
|
+
await this.stateManager.updateState(`devices.${deviceId}.info.deviceType`, deviceTypeStr);
|
|
74
|
+
} else {
|
|
75
|
+
// Fallback, falls devType nicht als Zahl vorliegt
|
|
76
|
+
await this.stateManager.updateState(`devices.${deviceId}.info.deviceType`, device.devType);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Prüfen, wo die Firmware- und Hardwaredaten zu finden sind
|
|
80
|
+
if (device.deviceInfo) {
|
|
81
|
+
// Prüfen der verschiedenen möglichen Orte für die Versionsinformationen
|
|
82
|
+
const firmwareVersion = device.deviceInfo.firmwareVersion || device.firmwareVersion ||
|
|
83
|
+
(device.deviceInfo.versions ? device.deviceInfo.versions.firmware : null);
|
|
84
|
+
|
|
85
|
+
const hardwareVersion = device.deviceInfo.hardwareVersion || device.hardwareVersion ||
|
|
86
|
+
(device.deviceInfo.versions ? device.deviceInfo.versions.hardware : null);
|
|
87
|
+
|
|
88
|
+
await this.stateManager.updateState(`devices.${deviceId}.info.firmware`, firmwareVersion);
|
|
89
|
+
await this.stateManager.updateState(`devices.${deviceId}.info.hardware`, hardwareVersion);
|
|
90
|
+
} else {
|
|
91
|
+
// Alternativ, falls deviceInfo nicht existiert, versuche direkt auf die Eigenschaften zuzugreifen
|
|
92
|
+
await this.stateManager.updateState(`devices.${deviceId}.info.firmware`, device.firmwareVersion);
|
|
93
|
+
await this.stateManager.updateState(`devices.${deviceId}.info.hardware`, device.hardwareVersion);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Füge zusätzliches Debug-Logging hinzu, um die aktuelle Datenstruktur zu verstehen
|
|
97
|
+
this.adapter.log.debug(`Device info structure for ${deviceId}: ${JSON.stringify(device)}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Aktualisiert die Sensor-Zustände des Geräts
|
|
102
|
+
* @param {string} deviceId - Geräte-ID
|
|
103
|
+
* @param {object} device - Geräteobjekt
|
|
104
|
+
* @returns {Promise<void>}
|
|
105
|
+
*/
|
|
106
|
+
async updateSensorStates(deviceId, device) {
|
|
107
|
+
// Temperatur und Feuchtigkeit können entweder direkt im Gerät oder in deviceInfo sein
|
|
108
|
+
const temperature = device.temperature !== undefined ? device.temperature :
|
|
109
|
+
(device.deviceInfo && device.deviceInfo.temperature);
|
|
110
|
+
const humidity = device.humidity !== undefined ? device.humidity :
|
|
111
|
+
(device.deviceInfo && device.deviceInfo.humidity);
|
|
112
|
+
const vpd = device.vpdnums !== undefined ? device.vpdnums :
|
|
113
|
+
(device.deviceInfo && device.deviceInfo.vpdnums);
|
|
114
|
+
|
|
115
|
+
this.adapter.log.debug(`Sensorwerte für Gerät ${deviceId}: temperature=${temperature}, humidity=${humidity}, vpd=${vpd}`);
|
|
116
|
+
|
|
117
|
+
// Aktualisiere Sensorwerte mit sorgfältiger Prüfung
|
|
118
|
+
if (typeof temperature === 'number') {
|
|
119
|
+
await this.stateManager.updateState(`devices.${deviceId}.sensors.temperature`, parseFloat((temperature / 100).toFixed(2)));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (typeof humidity === 'number') {
|
|
123
|
+
await this.stateManager.updateState(`devices.${deviceId}.sensors.humidity`, parseFloat((humidity / 100).toFixed(2)));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (typeof vpd === 'number') {
|
|
127
|
+
await this.stateManager.updateState(`devices.${deviceId}.sensors.vpd`, parseFloat((vpd / 100).toFixed(2)));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Aktualisiert die erweiterten Geräteeinstellungen
|
|
133
|
+
* @param {string} deviceId - Geräte-ID
|
|
134
|
+
* @param {object} settings - Einstellungsobjekt
|
|
135
|
+
* @returns {Promise<void>}
|
|
136
|
+
*/
|
|
137
|
+
async updateAdvancedSettings(deviceId, settings) {
|
|
138
|
+
if (!settings) {
|
|
139
|
+
this.adapter.log.warn(`Erhielt leere erweiterte Einstellungen für ${deviceId}`);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
this.adapter.log.debug(`Aktualisiere erweiterte Einstellungen für ${deviceId}: ${JSON.stringify(settings).substring(0, 500)}...`);
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
// Temperatureinheit (1 = Celsius, 0 = Fahrenheit)
|
|
147
|
+
if (typeof settings[ADVANCED_SETTINGS_KEY.TEMP_UNIT] === 'number') {
|
|
148
|
+
await this.stateManager.updateState(`devices.${deviceId}.settings.temperatureUnit`,
|
|
149
|
+
settings[ADVANCED_SETTINGS_KEY.TEMP_UNIT] > 0 ? "C" : "F");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Verwende je nach Temperatureinheit den passenden Kalibrierungswert
|
|
153
|
+
const tempUnit = settings[ADVANCED_SETTINGS_KEY.TEMP_UNIT];
|
|
154
|
+
|
|
155
|
+
if (tempUnit !== undefined) {
|
|
156
|
+
const tempCalibration = tempUnit > 0
|
|
157
|
+
? settings[ADVANCED_SETTINGS_KEY.CALIBRATE_TEMP]
|
|
158
|
+
: settings[ADVANCED_SETTINGS_KEY.CALIBRATE_TEMP_F];
|
|
159
|
+
|
|
160
|
+
if (tempCalibration !== undefined) {
|
|
161
|
+
await this.stateManager.updateState(`devices.${deviceId}.settings.temperatureCalibration`,
|
|
162
|
+
tempCalibration);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Feuchtigkeitskalibrierung
|
|
167
|
+
if (typeof settings[ADVANCED_SETTINGS_KEY.CALIBRATE_HUMIDITY] === 'number') {
|
|
168
|
+
await this.stateManager.updateState(`devices.${deviceId}.settings.humidityCalibration`,
|
|
169
|
+
settings[ADVANCED_SETTINGS_KEY.CALIBRATE_HUMIDITY]);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// VPD-Blatttemperatur-Offset
|
|
173
|
+
if (tempUnit !== undefined) {
|
|
174
|
+
const vpdLeafOffset = tempUnit > 0
|
|
175
|
+
? settings[ADVANCED_SETTINGS_KEY.VPD_LEAF_TEMP_OFFSET]
|
|
176
|
+
: settings[ADVANCED_SETTINGS_KEY.VPD_LEAF_TEMP_OFFSET_F];
|
|
177
|
+
|
|
178
|
+
if (vpdLeafOffset !== undefined) {
|
|
179
|
+
await this.stateManager.updateState(`devices.${deviceId}.settings.vpdLeafTemperatureOffset`,
|
|
180
|
+
vpdLeafOffset);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Außenklima-Einstellungen
|
|
185
|
+
const outsideTempCompare = settings[ADVANCED_SETTINGS_KEY.OUTSIDE_TEMP_COMPARE];
|
|
186
|
+
if (typeof outsideTempCompare === 'number' && outsideTempCompare < OUTSIDE_CLIMATE_OPTIONS.length) {
|
|
187
|
+
await this.stateManager.updateState(`devices.${deviceId}.settings.outsideTemperature`,
|
|
188
|
+
OUTSIDE_CLIMATE_OPTIONS[outsideTempCompare]);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const outsideHumidityCompare = settings[ADVANCED_SETTINGS_KEY.OUTSIDE_HUMIDITY_COMPARE];
|
|
192
|
+
if (typeof outsideHumidityCompare === 'number' && outsideHumidityCompare < OUTSIDE_CLIMATE_OPTIONS.length) {
|
|
193
|
+
await this.stateManager.updateState(`devices.${deviceId}.settings.outsideHumidity`,
|
|
194
|
+
OUTSIDE_CLIMATE_OPTIONS[outsideHumidityCompare]);
|
|
195
|
+
}
|
|
196
|
+
} catch (error) {
|
|
197
|
+
this.adapter.log.error(`Fehler beim Aktualisieren erweiterter Geräteeinstellungen für ${deviceId}: ${error.message}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
module.exports = DeviceUpdater;
|