homebridge-melcloud-control 3.1.4-beta.0 → 3.1.4-beta.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.
@@ -150,7 +150,7 @@
150
150
  const response = await homebridge.request('/connect', payload);
151
151
  const info = response.info ?? '';
152
152
  const status = response.status;
153
- const devices = response.data ?? [];
153
+ const devicesInMelCloud = response.data ?? [];
154
154
 
155
155
  //response status
156
156
  switch (status) {
@@ -165,24 +165,24 @@
165
165
  ervPresets: [],
166
166
  };
167
167
 
168
- const devicesByType = {
168
+ const devicesByTypeInMelCloud = {
169
169
  ata: [],
170
170
  atw: [],
171
171
  erv: []
172
172
  };
173
173
 
174
- //get devices by type
175
- for (const device of devices) {
174
+ //get devices from melcloud by type
175
+ for (const deviceInMelcloud of devicesInMelCloud) {
176
176
  const deviceType = device.Type;
177
- const pusDeviceTypeAta = deviceType === 0 ? devicesByType.ata.push(device) : false;
178
- const pusDeviceTypeAtw = deviceType === 1 ? devicesByType.atw.push(device) : false;
179
- const pusDeviceTypeErv = deviceType === 3 ? devicesByType.erv.push(device) : false;
177
+ const pusDeviceTypeAta = deviceType === 0 ? devicesByTypeInMelCloud.ata.push(deviceInMelcloud) : false;
178
+ const pusDeviceTypeAtw = deviceType === 1 ? devicesByTypeInMelCloud.atw.push(deviceInMelcloud) : false;
179
+ const pusDeviceTypeErv = deviceType === 3 ? devicesByTypeInMelCloud.erv.push(deviceInMelcloud) : false;
180
180
  };
181
181
 
182
- //devices from config
183
- const ataDevices = pluginConfig[0].accounts[this.deviceIndex].ataDevices ?? [];
184
- const atwDevices = pluginConfig[0].accounts[this.deviceIndex].atwDevices ?? [];
185
- const ervDevices = pluginConfig[0].accounts[this.deviceIndex].ervDevices ?? [];
182
+ //devices in config
183
+ const ataDevicesInConfig = pluginConfig[0].accounts[this.deviceIndex].ataDevices ?? [];
184
+ const atwDevicesInConfig = pluginConfig[0].accounts[this.deviceIndex].atwDevices ?? [];
185
+ const ervDevicesInConfig = pluginConfig[0].accounts[this.deviceIndex].ervDevices ?? [];
186
186
 
187
187
  //info text
188
188
  let textAta = 'ATA: 0';
@@ -196,7 +196,7 @@
196
196
  let ervPresetsCount = 0;
197
197
 
198
198
  //device ata
199
- devicesByType.ata.forEach((device, index) => {
199
+ devicesByTypeInMelCloud.ata.forEach((device, index) => {
200
200
  const deviceId = device.DeviceID;
201
201
  const deviceType = device.Type;
202
202
  const deviceName = device.DeviceName;
@@ -217,14 +217,14 @@
217
217
  buttonsSensors: []
218
218
  };
219
219
 
220
- const deviceExistsInConfig = ataDevices.find(device => device.id === deviceId);
220
+ const deviceExistsInConfig = ataDevicesInConfig.some(device => device.id === deviceId);
221
221
  if (!deviceExistsInConfig) {
222
- ataDevices.push(deviceAta);
222
+ ataDevicesInConfig.push(deviceAta);
223
223
  newDevices.ata.push(deviceAta);
224
224
  };
225
225
 
226
- //presets
227
- for (const preset of devicePresets) {
226
+ //presets of device in melcloud
227
+ devicePresets.forEach((preset) => {
228
228
  const presetId = preset.ID;
229
229
  const presetName = preset.NumberDescription;
230
230
 
@@ -233,26 +233,21 @@
233
233
  preset.displayType == 0;
234
234
  preset.namePrefix = false;
235
235
 
236
- let presetExistsInConfig = false;
237
- for (const ataDevice of ataDevices) {
238
- if (ataDevice.presets?.some(preset => preset.id === presetId)) {
239
- presetExistsInConfig = true;
240
- break;
241
- }
236
+ //find the specific ataDevice to which the preset belongs
237
+ const ataDevice = ataDevicesInConfig.find((configDevice) => configDevice.id === deviceId);
238
+ if (ataDevice && !ataDevice.presets.some((p) => p.id === presetId)) {
239
+ ataDevice.presets.push(preset);
240
+ newDevices.ataPresets.push(preset);
242
241
  }
243
242
 
244
- if (!presetExistsInConfig) {
245
- ataDevices[index].presets.push(preset);
246
- newDevices.ataPresets.push(preset);
247
- };
248
- };
243
+ });
249
244
  ataPresetsCount = newDevices.ataPresets.length;
250
245
  textAtaPresets = `ATA Presets: ${ataPresetsCount}`
251
246
  });
252
247
  textAta = `ATA: ${newDevices.ata.length}`
253
248
 
254
249
  //device atw
255
- devicesByType.atw.forEach((device, index) => {
250
+ devicesByTypeInMelCloud.atw.forEach((device, index) => {
256
251
  const deviceId = device.DeviceID;
257
252
  const deviceType = device.Type;
258
253
  const deviceName = device.DeviceName;
@@ -279,14 +274,14 @@
279
274
  buttonsSensors: []
280
275
  };
281
276
 
282
- const deviceExistsInConfig = atwDevices.find(device => device.id === deviceId);
277
+ const deviceExistsInConfig = atwDevicesInConfig.some(device => device.id === deviceId);
283
278
  if (!deviceExistsInConfig) {
284
- atwDevices.push(deviceAtw);
279
+ atwDevicesInConfig.push(deviceAtw);
285
280
  newDevices.atw.push(deviceAtw);
286
281
  };
287
282
 
288
- //presets
289
- for (const preset of devicePresets) {
283
+ //presets of device in melcloud
284
+ devicePresets.forEach((preset) => {
290
285
  const presetId = preset.ID;
291
286
  const presetName = preset.NumberDescription;
292
287
 
@@ -295,26 +290,21 @@
295
290
  preset.displayType == 0;
296
291
  preset.namePrefix = false;
297
292
 
298
- let presetExistsInConfig = false;
299
- for (const atwDevice of atwDevices) {
300
- if (atwDevice.presets?.some(preset => preset.id === presetId)) {
301
- presetExistsInConfig = true;
302
- break;
303
- }
293
+ //find the specific ataDevice to which the preset belongs
294
+ const atwDevice = atwDevicesInConfig.find((configDevice) => configDevice.id === deviceId);
295
+ if (atwDevice && !atwDevice.presets.some((p) => p.id === presetId)) {
296
+ atwDevice.presets.push(preset);
297
+ newDevices.atwPresets.push(preset);
304
298
  }
305
299
 
306
- if (!presetExistsInConfig) {
307
- atwDevices[index].presets.push(preset);
308
- newDevices.atwPresets.push(preset);
309
- };
310
- };
300
+ });
311
301
  atwPresetsCount = newDevices.atwPresets.length;
312
302
  textAtwPresets = `ATW Presets: ${atwPresetsCount}`
313
303
  });
314
304
  textAtw = `ATW: ${newDevices.atw.length}`
315
305
 
316
306
  //device erv
317
- devicesByType.erv.forEach((device, index) => {
307
+ devicesByTypeInMelCloud.erv.forEach((device, index) => {
318
308
  const deviceId = device.DeviceID;
319
309
  const deviceType = device.Type;
320
310
  const deviceName = device.DeviceName;
@@ -335,14 +325,14 @@
335
325
  buttonsSensors: []
336
326
  };
337
327
 
338
- const deviceExistsInConfig = ervDevices.find(device => device.id === deviceId);
328
+ const deviceExistsInConfig = ervDevicesInConfig.some(device => device.id === deviceId);
339
329
  if (!deviceExistsInConfig) {
340
- ervDevices.push(deviceErv);
330
+ ervDevicesInConfig.push(deviceErv);
341
331
  newDevices.erv.push(deviceErv);
342
332
  };
343
333
 
344
- //presets
345
- for (const preset of devicePresets) {
334
+ //presets of device in melcloud
335
+ devicePresets.forEach((preset) => {
346
336
  const presetId = preset.ID;
347
337
  const presetName = preset.NumberDescription;
348
338
 
@@ -351,19 +341,14 @@
351
341
  preset.displayType == 0;
352
342
  preset.namePrefix = false;
353
343
 
354
- let presetExistsInConfig = false;
355
- for (const ervDevice of ervDevices) {
356
- if (ervDevice.presets?.some(preset => preset.id === presetId)) {
357
- presetExistsInConfig = true;
358
- break;
359
- }
344
+ //find the specific ataDevice to which the preset belongs
345
+ const ervDevice = ervDevicesInConfig.find((configDevice) => configDevice.id === deviceId);
346
+ if (ervDevice && !ervDevice.presets.some((p) => p.id === presetId)) {
347
+ ervDevice.presets.push(preset);
348
+ newDevices.ervPresets.push(preset);
360
349
  }
361
350
 
362
- if (!presetExistsInConfig) {
363
- ervDevices[index].presets.push(preset);
364
- newDevices.ervPresets.push(preset);
365
- };
366
- };
351
+ });
367
352
  ervPresetsCount = newDevices.ervPresets.length;
368
353
  textErvPresets = `ERV Presets: ${ervPresetsCount}`
369
354
  });
package/index.js CHANGED
@@ -103,7 +103,7 @@ class MelCloudPlatform {
103
103
  const timers = [{ name: 'checkDevicesList', sampling: refreshInterval }];
104
104
  melCloud.impulseGenerator.start(timers);
105
105
 
106
- //Air Conditioner
106
+ //Air Conditioner 0
107
107
  for (const device of account.ataDevices) {
108
108
  //chack device from config exist on melcloud
109
109
  const deviceExistInMelCloud = devices.some(dev => dev.DeviceID === device.id);
@@ -142,7 +142,7 @@ class MelCloudPlatform {
142
142
  });
143
143
  };
144
144
 
145
- //Heat Pump
145
+ //Heat Pump 1
146
146
  for (const device of account.atwDevices) {
147
147
  //chack device from config exist on melcloud
148
148
  const deviceExistInMelCloud = devices.some(dev => dev.DeviceID === device.id);
@@ -151,9 +151,8 @@ class MelCloudPlatform {
151
151
  };
152
152
 
153
153
  const deviceId = device.id.toString();
154
- const deviceType = device.type ?? 1;
155
154
  const deviceName = device.name;
156
- const deviceTypeText = CONSTANTS.DeviceType[deviceType];
155
+ const deviceTypeText = device.typeString;
157
156
  const deviceInfoFile = `${prefDir}/${accountName}_Device_${deviceId}`;
158
157
  const heatPump = new DeviceAtw(api, account, melCloud, device, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile, deviceRefreshInterval)
159
158
  heatPump.on('publishAccessory', (accessory) => {
@@ -182,7 +181,7 @@ class MelCloudPlatform {
182
181
  });
183
182
  };
184
183
 
185
- //Energy Recovery Ventilation
184
+ //Energy Recovery Ventilation 3
186
185
  for (const device of account.ervDevices) {
187
186
  //chack device from config exist on melcloud
188
187
  const deviceExistInMelCloud = devices.some(dev => dev.DeviceID === device.id);
@@ -191,9 +190,8 @@ class MelCloudPlatform {
191
190
  };
192
191
 
193
192
  const deviceId = device.id.toString();
194
- const deviceType = device.type ?? 3;
195
193
  const deviceName = device.name;
196
- const deviceTypeText = CONSTANTS.DeviceType[deviceType];
194
+ const deviceTypeText = device.typeString;
197
195
  const deviceInfoFile = `${prefDir}/${accountName}_Device_${deviceId}`;
198
196
  const energyRecoveryVentilation = new DeviceErv(api, account, device, melCloud, accountInfo, contextKey, accountName, deviceId, deviceName, deviceTypeText, accountInfoFile, deviceInfoFile, deviceRefreshInterval)
199
197
  energyRecoveryVentilation.on('publishAccessory', (accessory) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "3.1.4-beta.0",
4
+ "version": "3.1.4-beta.1",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "engines": {
31
31
  "homebridge": "^1.6.0 || ^2.0.0-beta.0",
32
- "node": "^18.20.4 || ^20.15.1"
32
+ "node": "^18.20.4 || ^20.15.1, || ^22.7.0"
33
33
  },
34
34
  "dependencies": {
35
35
  "@homebridge/plugin-ui-utils": "^1.0.3",