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.
@@ -3,11 +3,12 @@
3
3
  * Verantwortlich für das Erstellen einzelner States in ioBroker
4
4
  */
5
5
 
6
- "use strict";
6
+ 'use strict';
7
7
 
8
8
  class StateCreator {
9
9
  /**
10
10
  * Erstellt einen neuen StateCreator
11
+ *
11
12
  * @param {object} stateManager - Referenz zum StateManager
12
13
  */
13
14
  constructor(stateManager) {
@@ -17,6 +18,7 @@ class StateCreator {
17
18
 
18
19
  /**
19
20
  * Erstellt einen einzelnen State
21
+ *
20
22
  * @param {string} id - Zustands-ID
21
23
  * @param {string} name - Zustandsname
22
24
  * @param {string} type - Zustandstyp
@@ -32,10 +34,10 @@ class StateCreator {
32
34
  if (this.stateManager.deviceStates.has(id)) {
33
35
  return;
34
36
  }
35
-
37
+
36
38
  // Erstelle State-Objekt
37
39
  const obj = {
38
- type: "state",
40
+ type: 'state',
39
41
  common: {
40
42
  name: name,
41
43
  type: type,
@@ -45,12 +47,12 @@ class StateCreator {
45
47
  },
46
48
  native: {},
47
49
  };
48
-
50
+
49
51
  // Füge optionale Eigenschaften hinzu
50
52
  if (unit !== null) {
51
53
  obj.common.unit = unit;
52
54
  }
53
-
55
+
54
56
  // Behandle States für Dropdown-Menüs
55
57
  if (states !== null) {
56
58
  if (Array.isArray(states)) {
@@ -65,28 +67,29 @@ class StateCreator {
65
67
  obj.common.states = states;
66
68
  }
67
69
  }
68
-
70
+
69
71
  // Füge zusätzliche Common-Eigenschaften hinzu
70
72
  if (common !== null) {
71
73
  Object.assign(obj.common, common);
72
74
  }
73
-
75
+
74
76
  // Erstelle State in ioBroker
75
77
  try {
76
78
  await this.adapter.setObjectNotExistsAsync(id, obj);
77
-
79
+
78
80
  // Füge zum Tracking hinzu
79
81
  this.stateManager.deviceStates.set(id, true);
80
-
82
+
81
83
  // Debug-Logging
82
84
  this.adapter.log.debug(`State erstellt: ${id}`);
83
85
  } catch (error) {
84
86
  this.adapter.log.error(`Fehler beim Erstellen von State ${id}: ${error.message}`);
85
87
  }
86
88
  }
87
-
89
+
88
90
  /**
89
91
  * Erstellt mehrere States auf einmal
92
+ *
90
93
  * @param {Array<object>} stateDefinitions - Array mit State-Definitionen
91
94
  * @returns {Promise<void>}
92
95
  */
@@ -100,13 +103,14 @@ class StateCreator {
100
103
  def.unit || null,
101
104
  def.write || false,
102
105
  def.states || null,
103
- def.common || null
106
+ def.common || null,
104
107
  );
105
108
  }
106
109
  }
107
-
110
+
108
111
  /**
109
112
  * Erstellt einen Kanal (Channel) in ioBroker
113
+ *
110
114
  * @param {string} id - Kanal-ID
111
115
  * @param {string} name - Kanalname
112
116
  * @param {object|null} native - Native-Eigenschaften
@@ -115,21 +119,22 @@ class StateCreator {
115
119
  async createChannel(id, name, native = {}) {
116
120
  try {
117
121
  await this.adapter.setObjectNotExistsAsync(id, {
118
- type: "channel",
122
+ type: 'channel',
119
123
  common: {
120
124
  name: name,
121
125
  },
122
126
  native: native || {},
123
127
  });
124
-
128
+
125
129
  this.adapter.log.debug(`Kanal erstellt: ${id}`);
126
130
  } catch (error) {
127
131
  this.adapter.log.error(`Fehler beim Erstellen von Kanal ${id}: ${error.message}`);
128
132
  }
129
133
  }
130
-
134
+
131
135
  /**
132
136
  * Erstellt einen Ordner (Folder) in ioBroker
137
+ *
133
138
  * @param {string} id - Ordner-ID
134
139
  * @param {string} name - Ordnername
135
140
  * @returns {Promise<void>}
@@ -137,21 +142,22 @@ class StateCreator {
137
142
  async createFolder(id, name) {
138
143
  try {
139
144
  await this.adapter.setObjectNotExistsAsync(id, {
140
- type: "folder",
145
+ type: 'folder',
141
146
  common: {
142
147
  name: name,
143
148
  },
144
149
  native: {},
145
150
  });
146
-
151
+
147
152
  this.adapter.log.debug(`Ordner erstellt: ${id}`);
148
153
  } catch (error) {
149
154
  this.adapter.log.error(`Fehler beim Erstellen von Ordner ${id}: ${error.message}`);
150
155
  }
151
156
  }
152
-
157
+
153
158
  /**
154
159
  * Erstellt ein Gerät (Device) in ioBroker
160
+ *
155
161
  * @param {string} id - Geräte-ID
156
162
  * @param {string} name - Gerätename
157
163
  * @param {object|null} native - Native-Eigenschaften
@@ -160,13 +166,13 @@ class StateCreator {
160
166
  async createDevice(id, name, native = {}) {
161
167
  try {
162
168
  await this.adapter.setObjectNotExistsAsync(id, {
163
- type: "device",
169
+ type: 'device',
164
170
  common: {
165
171
  name: name,
166
172
  },
167
173
  native: native || {},
168
174
  });
169
-
175
+
170
176
  this.adapter.log.debug(`Gerät erstellt: ${id}`);
171
177
  } catch (error) {
172
178
  this.adapter.log.error(`Fehler beim Erstellen von Gerät ${id}: ${error.message}`);
@@ -174,4 +180,4 @@ class StateCreator {
174
180
  }
175
181
  }
176
182
 
177
- module.exports = StateCreator;
183
+ module.exports = StateCreator;
package/lib/dataModels.js CHANGED
@@ -3,9 +3,9 @@
3
3
  * Provides helper classes to work with AC Infinity data structures
4
4
  */
5
5
 
6
- "use strict";
6
+ 'use strict';
7
7
 
8
- const { DEVICE_LOAD_TYPE_OPTIONS } = require("./constants");
8
+ const { DEVICE_LOAD_TYPE_OPTIONS } = require('./constants');
9
9
 
10
10
  /**
11
11
  * Represents an AC Infinity controller device
@@ -13,6 +13,7 @@ const { DEVICE_LOAD_TYPE_OPTIONS } = require("./constants");
13
13
  class ACInfinityController {
14
14
  /**
15
15
  * Create a new ACInfinityController
16
+ *
16
17
  * @param {object} data - Raw device data from API
17
18
  */
18
19
  constructor(data) {
@@ -23,12 +24,12 @@ class ACInfinityController {
23
24
  this.hardwareVersion = data.deviceInfo.hardwareVersion;
24
25
  this.firmwareVersion = data.deviceInfo.firmwareVersion;
25
26
  this.deviceType = data.deviceType;
26
-
27
+
27
28
  // Sensor values (stored as integers representing floating point with 2 decimal places)
28
29
  this.temperature = data.temperature / 100;
29
30
  this.humidity = data.humidity / 100;
30
31
  this.vpd = data.vpdnums / 100;
31
-
32
+
32
33
  // Process ports
33
34
  this.ports = [];
34
35
  if (data.deviceInfo && Array.isArray(data.deviceInfo.ports)) {
@@ -43,6 +44,7 @@ class ACInfinityController {
43
44
  class ACInfinityPort {
44
45
  /**
45
46
  * Create a new ACInfinityPort
47
+ *
46
48
  * @param {ACInfinityController} controller - Parent controller
47
49
  * @param {object} data - Raw port data from API
48
50
  */
@@ -54,14 +56,14 @@ class ACInfinityPort {
54
56
  this.power = data.speak;
55
57
  this.state = data.loadState === 1;
56
58
  this.remainingTime = data.remainTime;
57
-
59
+
58
60
  // Determine next state change time
59
61
  this.nextStateChange = null;
60
62
  if (this.remainingTime > 0) {
61
63
  const now = new Date();
62
64
  this.nextStateChange = new Date(now.getTime() + this.remainingTime * 1000);
63
65
  }
64
-
66
+
65
67
  // Device type
66
68
  this.deviceType = null;
67
69
  if (data.loadType in DEVICE_LOAD_TYPE_OPTIONS) {
@@ -76,6 +78,7 @@ class ACInfinityPort {
76
78
  const DataHelper = {
77
79
  /**
78
80
  * Convert minutes from midnight to a time string
81
+ *
79
82
  * @param {number} minutes - Minutes from midnight
80
83
  * @returns {string|null} - Time in HH:MM format or null if invalid
81
84
  */
@@ -83,53 +86,55 @@ const DataHelper = {
83
86
  if (minutes === undefined || minutes === null || minutes > 1439) {
84
87
  return null;
85
88
  }
86
-
89
+
87
90
  const hours = Math.floor(minutes / 60);
88
91
  const mins = minutes % 60;
89
- return `${hours.toString().padStart(2, "0")}:${mins.toString().padStart(2, "0")}`;
92
+ return `${hours.toString().padStart(2, '0')}:${mins.toString().padStart(2, '0')}`;
90
93
  },
91
-
94
+
92
95
  /**
93
96
  * Convert a time string to minutes from midnight
97
+ *
94
98
  * @param {string} timeString - Time in HH:MM format
95
99
  * @returns {number|null} - Minutes from midnight or null if invalid
96
100
  */
97
101
  timeStringToMinutes(timeString) {
98
- if (!timeString || typeof timeString !== "string") {
102
+ if (!timeString || typeof timeString !== 'string') {
99
103
  return null;
100
104
  }
101
-
102
- const parts = timeString.split(":");
105
+
106
+ const parts = timeString.split(':');
103
107
  if (parts.length !== 2) {
104
108
  return null;
105
109
  }
106
-
110
+
107
111
  const hours = parseInt(parts[0]);
108
112
  const minutes = parseInt(parts[1]);
109
-
113
+
110
114
  if (isNaN(hours) || isNaN(minutes) || hours < 0 || hours > 23 || minutes < 0 || minutes > 59) {
111
115
  return null;
112
116
  }
113
-
117
+
114
118
  return hours * 60 + minutes;
115
119
  },
116
-
120
+
117
121
  /**
118
122
  * Clean value for display
123
+ *
119
124
  * @param {any} value - Value to clean
120
125
  * @returns {any} - Cleaned value
121
126
  */
122
127
  cleanValue(value) {
123
- if (typeof value === "number") {
128
+ if (typeof value === 'number') {
124
129
  // Round to 2 decimal places
125
130
  return Math.round(value * 100) / 100;
126
131
  }
127
132
  return value;
128
- }
133
+ },
129
134
  };
130
135
 
131
136
  module.exports = {
132
137
  ACInfinityController,
133
138
  ACInfinityPort,
134
- DataHelper
135
- };
139
+ DataHelper,
140
+ };
@@ -3,16 +3,14 @@
3
3
  * Verarbeitet Änderungen an den Geräteeinstellungen
4
4
  */
5
5
 
6
- "use strict";
6
+ 'use strict';
7
7
 
8
- const {
9
- ADVANCED_SETTINGS_KEY,
10
- OUTSIDE_CLIMATE_OPTIONS
11
- } = require("../constants");
8
+ const { ADVANCED_SETTINGS_KEY, OUTSIDE_CLIMATE_OPTIONS } = require('../constants');
12
9
 
13
10
  class DeviceSettingsHandler {
14
11
  /**
15
12
  * Erstellt einen neuen DeviceSettingsHandler
13
+ *
16
14
  * @param {object} stateManager - Referenz zum StateManager
17
15
  */
18
16
  constructor(stateManager) {
@@ -23,42 +21,47 @@ class DeviceSettingsHandler {
23
21
 
24
22
  /**
25
23
  * Setzt den API-Client für diesen Handler
24
+ *
26
25
  * @param {object} client - AC Infinity API-Client
27
26
  */
28
27
  setClient(client) {
29
28
  this.client = client;
30
- this.adapter.log.debug("API-Client erfolgreich an DeviceSettingsHandler übergeben");
29
+ this.adapter.log.debug('API-Client erfolgreich an DeviceSettingsHandler übergeben');
31
30
  }
32
31
 
33
32
  /**
34
33
  * Verarbeitet Änderungen an Geräteeinstellungen
34
+ *
35
35
  * @param {string} deviceId - Geräte-ID
36
36
  * @param {Array} path - Pfadkomponenten
37
37
  * @param {any} value - Neuer Wert
38
38
  */
39
39
  async handleDeviceSettingsChange(deviceId, path, value) {
40
40
  const settingName = path[0];
41
-
41
+
42
42
  try {
43
43
  // Prüfen, ob der Client gesetzt ist
44
44
  if (!this.client) {
45
- throw new Error("API-Client nicht gesetzt. Kann Geräteeinstellungen nicht aktualisieren.");
45
+ throw new Error('API-Client nicht gesetzt. Kann Geräteeinstellungen nicht aktualisieren.');
46
46
  }
47
47
 
48
48
  // Hole den Gerätenamen für den Aktualisierungsaufruf
49
49
  let deviceName = await this.adapter.getStateAsync(`devices.${deviceId}.info.name`);
50
50
  deviceName = deviceName && deviceName.val ? deviceName.val : `Gerät ${deviceId}`;
51
-
51
+
52
52
  switch (settingName) {
53
- case "temperatureCalibration":
53
+ case 'temperatureCalibration':
54
54
  // UI sofort aktualisieren, um Flackern zu vermeiden
55
- await this.stateManager.updateUIState(`devices.${deviceId}.settings.temperatureCalibration`, parseInt(value));
56
-
55
+ await this.stateManager.updateUIState(
56
+ `devices.${deviceId}.settings.temperatureCalibration`,
57
+ parseInt(value),
58
+ );
59
+
57
60
  this.adapter.log.debug(`Sende Temperaturkalibrierung an API: deviceId=${deviceId}, value=${value}`);
58
61
  try {
59
62
  await this.client.updateAdvancedSettings(deviceId, 0, deviceName, [
60
63
  [ADVANCED_SETTINGS_KEY.CALIBRATE_TEMP, parseInt(value)],
61
- [ADVANCED_SETTINGS_KEY.CALIBRATE_TEMP_F, parseInt(value)]
64
+ [ADVANCED_SETTINGS_KEY.CALIBRATE_TEMP_F, parseInt(value)],
62
65
  ]);
63
66
  this.adapter.log.debug(`API-Antwort für Temperaturkalibrierung erfolgreich`);
64
67
  } catch (error) {
@@ -68,14 +71,19 @@ class DeviceSettingsHandler {
68
71
  }
69
72
  }
70
73
  break;
71
-
72
- case "humidityCalibration":
73
- await this.stateManager.updateUIState(`devices.${deviceId}.settings.humidityCalibration`, parseInt(value));
74
-
75
- this.adapter.log.debug(`Sende Feuchtigkeitskalibrierung an API: deviceId=${deviceId}, value=${value}`);
74
+
75
+ case 'humidityCalibration':
76
+ await this.stateManager.updateUIState(
77
+ `devices.${deviceId}.settings.humidityCalibration`,
78
+ parseInt(value),
79
+ );
80
+
81
+ this.adapter.log.debug(
82
+ `Sende Feuchtigkeitskalibrierung an API: deviceId=${deviceId}, value=${value}`,
83
+ );
76
84
  try {
77
85
  await this.client.updateAdvancedSettings(deviceId, 0, deviceName, [
78
- [ADVANCED_SETTINGS_KEY.CALIBRATE_HUMIDITY, parseInt(value)]
86
+ [ADVANCED_SETTINGS_KEY.CALIBRATE_HUMIDITY, parseInt(value)],
79
87
  ]);
80
88
  this.adapter.log.debug(`API-Antwort für Feuchtigkeitskalibrierung erfolgreich`);
81
89
  } catch (error) {
@@ -85,15 +93,20 @@ class DeviceSettingsHandler {
85
93
  }
86
94
  }
87
95
  break;
88
-
89
- case "vpdLeafTemperatureOffset":
90
- await this.stateManager.updateUIState(`devices.${deviceId}.settings.vpdLeafTemperatureOffset`, parseInt(value));
91
-
92
- this.adapter.log.debug(`Sende VPD-Blatttemperaturversatz an API: deviceId=${deviceId}, value=${value}`);
96
+
97
+ case 'vpdLeafTemperatureOffset':
98
+ await this.stateManager.updateUIState(
99
+ `devices.${deviceId}.settings.vpdLeafTemperatureOffset`,
100
+ parseInt(value),
101
+ );
102
+
103
+ this.adapter.log.debug(
104
+ `Sende VPD-Blatttemperaturversatz an API: deviceId=${deviceId}, value=${value}`,
105
+ );
93
106
  try {
94
107
  await this.client.updateAdvancedSettings(deviceId, 0, deviceName, [
95
108
  [ADVANCED_SETTINGS_KEY.VPD_LEAF_TEMP_OFFSET, parseInt(value)],
96
- [ADVANCED_SETTINGS_KEY.VPD_LEAF_TEMP_OFFSET_F, parseInt(value)]
109
+ [ADVANCED_SETTINGS_KEY.VPD_LEAF_TEMP_OFFSET_F, parseInt(value)],
97
110
  ]);
98
111
  this.adapter.log.debug(`API-Antwort für VPD-Blatttemperaturversatz erfolgreich`);
99
112
  } catch (error) {
@@ -103,16 +116,18 @@ class DeviceSettingsHandler {
103
116
  }
104
117
  }
105
118
  break;
106
-
107
- case "outsideTemperature": {
119
+
120
+ case 'outsideTemperature': {
108
121
  await this.stateManager.updateUIState(`devices.${deviceId}.settings.outsideTemperature`, value);
109
-
122
+
110
123
  const tempCompareIndex = OUTSIDE_CLIMATE_OPTIONS.indexOf(value);
111
124
  if (tempCompareIndex >= 0) {
112
- this.adapter.log.debug(`Sende Außentemperatureinstellung an API: deviceId=${deviceId}, value=${value}, index=${tempCompareIndex}`);
125
+ this.adapter.log.debug(
126
+ `Sende Außentemperatureinstellung an API: deviceId=${deviceId}, value=${value}, index=${tempCompareIndex}`,
127
+ );
113
128
  try {
114
129
  await this.client.updateAdvancedSettings(deviceId, 0, deviceName, [
115
- [ADVANCED_SETTINGS_KEY.OUTSIDE_TEMP_COMPARE, tempCompareIndex]
130
+ [ADVANCED_SETTINGS_KEY.OUTSIDE_TEMP_COMPARE, tempCompareIndex],
116
131
  ]);
117
132
  this.adapter.log.debug(`API-Antwort für Außentemperatureinstellung erfolgreich`);
118
133
  } catch (error) {
@@ -126,16 +141,18 @@ class DeviceSettingsHandler {
126
141
  }
127
142
  break;
128
143
  }
129
-
130
- case "outsideHumidity": {
144
+
145
+ case 'outsideHumidity': {
131
146
  await this.stateManager.updateUIState(`devices.${deviceId}.settings.outsideHumidity`, value);
132
-
147
+
133
148
  const humidityCompareIndex = OUTSIDE_CLIMATE_OPTIONS.indexOf(value);
134
149
  if (humidityCompareIndex >= 0) {
135
- this.adapter.log.debug(`Sende Außenfeuchtigkeitseinstellung an API: deviceId=${deviceId}, value=${value}, index=${humidityCompareIndex}`);
150
+ this.adapter.log.debug(
151
+ `Sende Außenfeuchtigkeitseinstellung an API: deviceId=${deviceId}, value=${value}, index=${humidityCompareIndex}`,
152
+ );
136
153
  try {
137
154
  await this.client.updateAdvancedSettings(deviceId, 0, deviceName, [
138
- [ADVANCED_SETTINGS_KEY.OUTSIDE_HUMIDITY_COMPARE, humidityCompareIndex]
155
+ [ADVANCED_SETTINGS_KEY.OUTSIDE_HUMIDITY_COMPARE, humidityCompareIndex],
139
156
  ]);
140
157
  this.adapter.log.debug(`API-Antwort für Außenfeuchtigkeitseinstellung erfolgreich`);
141
158
  } catch (error) {
@@ -149,11 +166,11 @@ class DeviceSettingsHandler {
149
166
  }
150
167
  break;
151
168
  }
152
-
169
+
153
170
  default:
154
171
  this.adapter.log.warn(`Unbekannte Geräteeinstellung: ${settingName}`);
155
172
  }
156
-
173
+
157
174
  // Aktualisierung der Daten auslösen, um die Zustände zu aktualisieren
158
175
  await this.stateManager.refreshWithThrottle();
159
176
  } catch (error) {
@@ -162,4 +179,4 @@ class DeviceSettingsHandler {
162
179
  }
163
180
  }
164
181
 
165
- module.exports = DeviceSettingsHandler;
182
+ module.exports = DeviceSettingsHandler;