homebridge-melcloud-control 3.8.10 → 3.8.11-beta.0

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.
@@ -164,20 +164,12 @@
164
164
  document.getElementById('info').style.color = 'yellow';
165
165
 
166
166
  try {
167
- const accountName = pluginConfig[0].accounts[this.deviceIndex].name;
168
- const user = pluginConfig[0].accounts[this.deviceIndex].user;
169
- const passwd = pluginConfig[0].accounts[this.deviceIndex].passwd;
170
- const language = pluginConfig[0].accounts[this.deviceIndex].language;
171
-
172
- const payload = {
173
- accountName: accountName,
174
- user: user,
175
- passwd: passwd,
176
- language: language
177
- };
167
+ const account = pluginConfig[0].accounts[this.deviceIndex];
168
+ const { name: accountName, user, passwd, language } = account;
169
+
170
+ const payload = { accountName, user, passwd, language };
178
171
  const devicesInMelCloud = await homebridge.request('/connect', payload);
179
172
 
180
- //new found devices
181
173
  const newDevices = {
182
174
  ata: [],
183
175
  ataPresets: [],
@@ -187,36 +179,38 @@
187
179
  ervPresets: [],
188
180
  };
189
181
 
190
- //get devices from melcloud by type
191
182
  const devicesByTypeInMelCloud = {
192
183
  ata: [],
193
184
  atw: [],
194
185
  erv: []
195
186
  };
196
187
 
188
+ // Categorize devices by type
197
189
  for (const deviceInMelcloud of devicesInMelCloud) {
198
- const deviceType = deviceInMelcloud.Type;
199
- const pusDeviceTypeAta = deviceType === 0 ? devicesByTypeInMelCloud.ata.push(deviceInMelcloud) : false;
200
- const pusDeviceTypeAtw = deviceType === 1 ? devicesByTypeInMelCloud.atw.push(deviceInMelcloud) : false;
201
- const pusDeviceTypeErv = deviceType === 3 ? devicesByTypeInMelCloud.erv.push(deviceInMelcloud) : false;
202
- };
203
-
204
- //devices in config
205
- const ataDevicesInConfigExist = pluginConfig[0].accounts[this.deviceIndex].ataDevices ?? false;
206
- const atwDevicesInConfigExist = pluginConfig[0].accounts[this.deviceIndex].atwDevices ?? false;
207
- const ervDevicesInConfigExist = pluginConfig[0].accounts[this.deviceIndex].ervDevices ?? false;
190
+ switch (deviceInMelcloud.Type) {
191
+ case 0: devicesByTypeInMelCloud.ata.push(deviceInMelcloud); break;
192
+ case 1: devicesByTypeInMelCloud.atw.push(deviceInMelcloud); break;
193
+ case 3: devicesByTypeInMelCloud.erv.push(deviceInMelcloud); break;
194
+ }
195
+ }
208
196
 
209
- //check key of devices in config exist
210
- const ataDevicesInConfig = !ataDevicesInConfigExist ? pluginConfig[0].accounts[this.deviceIndex].ataDevices = [] : ataDevicesInConfigExist;
211
- const atwDevicesInConfig = !atwDevicesInConfigExist ? pluginConfig[0].accounts[this.deviceIndex].atwDevices = [] : atwDevicesInConfigExist;
212
- const ervDevicesInConfig = !ervDevicesInConfigExist ? pluginConfig[0].accounts[this.deviceIndex].ervDevices = [] : ervDevicesInConfigExist;
197
+ // Ensure config arrays exist
198
+ const ataDevicesInConfig = account.ataDevices ?? (account.ataDevices = []);
199
+ const atwDevicesInConfig = account.atwDevices ?? (account.atwDevices = []);
200
+ const ervDevicesInConfig = account.ervDevices ?? (account.ervDevices = []);
201
+
202
+ // Helper for updating UI
203
+ const updateInfo = (id, text, color) => {
204
+ const el = document.getElementById(id);
205
+ if (el) {
206
+ el.innerHTML = text;
207
+ el.style.color = color;
208
+ }
209
+ };
213
210
 
214
- //device ata
215
- devicesByTypeInMelCloud.ata.forEach((device, index) => {
216
- const deviceId = device.DeviceID;
217
- const deviceType = device.Type;
218
- const deviceName = device.DeviceName;
219
- const devicePresets = device.Presets ?? [];
211
+ // Handle ATA devices
212
+ devicesByTypeInMelCloud.ata.forEach((device) => {
213
+ const { DeviceID: deviceId, Type: deviceType, DeviceName: deviceName, Presets: devicePresets = [] } = device;
220
214
 
221
215
  const deviceAta = {
222
216
  id: deviceId,
@@ -234,40 +228,29 @@
234
228
  buttonsSensors: []
235
229
  };
236
230
 
237
- const deviceExistsInConfig = ataDevicesInConfig.some(device => device.id === deviceId);
238
- if (!deviceExistsInConfig) {
231
+ if (!ataDevicesInConfig.some(device => device.id === deviceId)) {
239
232
  ataDevicesInConfig.push(deviceAta);
240
233
  newDevices.ata.push(deviceAta);
241
- };
234
+ }
242
235
 
243
- //presets of device in melcloud
244
236
  devicePresets.forEach((preset) => {
245
- const presetId = preset.ID;
246
- const presetName = preset.NumberDescription;
247
-
237
+ const { ID: presetId, NumberDescription: presetName } = preset;
248
238
  preset.id = presetId;
249
239
  preset.name = presetName;
250
- preset.displayType == 0;
240
+ preset.displayType = 0;
251
241
  preset.namePrefix = false;
252
242
 
253
- //find the specific ataDevice to which the preset belongs
254
243
  const ataDevice = ataDevicesInConfig.find((device) => device.id === deviceId);
255
244
  if (ataDevice && !ataDevice.presets.some((p) => p.id === presetId)) {
256
245
  ataDevice.presets.push(preset);
257
246
  newDevices.ataPresets.push(preset);
258
247
  }
259
-
260
248
  });
261
249
  });
262
- const textAta = `ATA: ${newDevices.ata.length}`;
263
- const textAtaPresets = `ATA Presets: ${newDevices.ataPresets.length}`;
264
250
 
265
- //device atw
266
- devicesByTypeInMelCloud.atw.forEach((device, index) => {
267
- const deviceId = device.DeviceID;
268
- const deviceType = device.Type;
269
- const deviceName = device.DeviceName;
270
- const devicePresets = device.Presets ?? [];
251
+ // Handle ATW devices
252
+ devicesByTypeInMelCloud.atw.forEach((device) => {
253
+ const { DeviceID: deviceId, Type: deviceType, DeviceName: deviceName, Presets: devicePresets = [] } = device;
271
254
 
272
255
  const deviceAtw = {
273
256
  id: deviceId,
@@ -286,46 +269,34 @@
286
269
  temperatureSensorReturnWaterTank: false,
287
270
  temperatureSensorFlowZone2: false,
288
271
  temperatureSensorReturnZone2: false,
289
- temperatureSensor: false,
290
272
  temperatureSensorOutdoor: false,
291
273
  presets: [],
292
274
  buttonsSensors: []
293
275
  };
294
276
 
295
- const deviceExistsInConfig = atwDevicesInConfig.some(device => device.id === deviceId);
296
- if (!deviceExistsInConfig) {
277
+ if (!atwDevicesInConfig.some(device => device.id === deviceId)) {
297
278
  atwDevicesInConfig.push(deviceAtw);
298
279
  newDevices.atw.push(deviceAtw);
299
- };
280
+ }
300
281
 
301
- //presets of device in melcloud
302
282
  devicePresets.forEach((preset) => {
303
- const presetId = preset.ID;
304
- const presetName = preset.NumberDescription;
305
-
283
+ const { ID: presetId, NumberDescription: presetName } = preset;
306
284
  preset.id = presetId;
307
285
  preset.name = presetName;
308
- preset.displayType == 0;
286
+ preset.displayType = 0;
309
287
  preset.namePrefix = false;
310
288
 
311
- //find the specific ataDevice to which the preset belongs
312
289
  const atwDevice = atwDevicesInConfig.find((device) => device.id === deviceId);
313
290
  if (atwDevice && !atwDevice.presets.some((p) => p.id === presetId)) {
314
291
  atwDevice.presets.push(preset);
315
292
  newDevices.atwPresets.push(preset);
316
293
  }
317
-
318
294
  });
319
295
  });
320
- const textAtw = `ATW: ${newDevices.atw.length}`;
321
- const textAtwPresets = `ATW Presets: ${newDevices.atwPresets.length}`;
322
296
 
323
- //device erv
324
- devicesByTypeInMelCloud.erv.forEach((device, index) => {
325
- const deviceId = device.DeviceID;
326
- const deviceType = device.Type;
327
- const deviceName = device.DeviceName;
328
- const devicePresets = device.Presets ?? [];
297
+ // Handle ERV devices
298
+ devicesByTypeInMelCloud.erv.forEach((device) => {
299
+ const { DeviceID: deviceId, Type: deviceType, DeviceName: deviceName, Presets: devicePresets = [] } = device;
329
300
 
330
301
  const deviceErv = {
331
302
  id: deviceId,
@@ -337,88 +308,73 @@
337
308
  temperatureSensor: false,
338
309
  temperatureSensorOutdoor: false,
339
310
  temperatureSensorSupply: false,
340
- temperatureSensor: false,
341
- temperatureSensorOutdoor: false,
342
311
  presets: [],
343
312
  buttonsSensors: []
344
313
  };
345
314
 
346
- const deviceExistsInConfig = ervDevicesInConfig.some(device => device.id === deviceId);
347
- if (!deviceExistsInConfig) {
315
+ if (!ervDevicesInConfig.some(device => device.id === deviceId)) {
348
316
  ervDevicesInConfig.push(deviceErv);
349
317
  newDevices.erv.push(deviceErv);
350
- };
318
+ }
351
319
 
352
- //presets of device in melcloud
353
320
  devicePresets.forEach((preset) => {
354
- const presetId = preset.ID;
355
- const presetName = preset.NumberDescription;
356
-
321
+ const { ID: presetId, NumberDescription: presetName } = preset;
357
322
  preset.id = presetId;
358
323
  preset.name = presetName;
359
- preset.displayType == 0;
324
+ preset.displayType = 0;
360
325
  preset.namePrefix = false;
361
326
 
362
- //find the specific ataDevice to which the preset belongs
363
327
  const ervDevice = ervDevicesInConfig.find((device) => device.id === deviceId);
364
328
  if (ervDevice && !ervDevice.presets.some((p) => p.id === presetId)) {
365
329
  ervDevice.presets.push(preset);
366
330
  newDevices.ervPresets.push(preset);
367
331
  }
368
-
369
332
  });
370
333
  });
334
+
335
+ // Display info
336
+ const textAta = `ATA: ${newDevices.ata.length}`;
337
+ const textAtw = `ATW: ${newDevices.atw.length}`;
371
338
  const textErv = `ERV: ${newDevices.erv.length}`;
339
+ const textAtaPresets = `ATA Presets: ${newDevices.ataPresets.length}`;
340
+ const textAtwPresets = `ATW Presets: ${newDevices.atwPresets.length}`;
372
341
  const textErvPresets = `ERV Presets: ${newDevices.ervPresets.length}`;
373
342
 
374
- //display info
375
- const newDevicesCount = newDevices.ata.length + newDevices.atw.length + newDevices.erv.length ?? 0;
376
- const newPresetsCount = newDevices.ataPresets.length + newDevices.atwPresets.length + newDevices.ervPresets.length ?? 0;
377
- if (newDevicesCount === 0 && newPresetsCount === 0) {
378
- document.getElementById('info').innerHTML = 'No new devices found.';
379
- document.getElementById('info').style.color = 'white';
380
- };
343
+ const newDevicesCount = newDevices.ata.length + newDevices.atw.length + newDevices.erv.length;
344
+ const newPresetsCount = newDevices.ataPresets.length + newDevices.atwPresets.length + newDevices.ervPresets.length;
381
345
 
382
- if (newDevicesCount > 0 && newPresetsCount > 0) {
383
- document.getElementById('info').innerHTML = `Found, ${textAta}, ${textAtw}, ${textErv}.`;
384
- document.getElementById('info').style.color = 'green';
385
- document.getElementById('info1').innerHTML = `${textAtaPresets}, ${textAtwPresets}, ${textErvPresets}.`;
386
- document.getElementById('info1').style.color = 'green';
387
- document.getElementById('info2').innerHTML = 'Now You can configure it.';
388
- document.getElementById('info2').style.color = 'green';
389
- };
390
-
391
- if (newDevicesCount > 0 && newPresetsCount === 0) {
392
- document.getElementById('info').innerHTML = `Found, ${textAta}, ${textAtw}, ${textErv}.`;
393
- document.getElementById('info').style.color = 'green';
394
- document.getElementById('info1').innerHTML = 'Now You can configure it.';
395
- document.getElementById('info1').style.color = 'green';
396
- };
397
-
398
- if (newDevicesCount === 0 && newPresetsCount > 0) {
399
- document.getElementById('info').innerHTML = `Found, ${textAtaPresets}, ${textAtwPresets}, ${textErvPresets}.`;
400
- document.getElementById('info').style.color = 'green';
401
- document.getElementById('info1').innerHTML = 'Now You can configure it.';
402
- document.getElementById('info1').style.color = 'green';
346
+ if (newDevicesCount === 0 && newPresetsCount === 0) {
347
+ updateInfo('info', 'No new devices found.', 'white');
348
+ } else {
349
+ if (newDevicesCount > 0) {
350
+ updateInfo('info', `Found, ${textAta}, ${textAtw}, ${textErv}.`, 'green');
351
+ updateInfo('info2', 'Now You can configure it.', 'green');
352
+ }
353
+ if (newPresetsCount > 0) {
354
+ updateInfo('info1', `${textAtaPresets}, ${textAtwPresets}, ${textErvPresets}.`, 'green');
355
+ if (newDevicesCount === 0) {
356
+ updateInfo('info', `Found, ${textAtaPresets}, ${textAtwPresets}, ${textErvPresets}.`, 'green');
357
+ updateInfo('info1', 'Now You can configure it.', 'green');
358
+ }
359
+ }
403
360
  }
404
361
 
405
- //update ans save plugin config
362
+ // Save updated config
406
363
  await homebridge.updatePluginConfig(pluginConfig);
407
364
  await homebridge.savePluginConfig(pluginConfig);
408
365
 
409
- //update button state
410
- document.getElementById(`logIn`).setAttribute("class", "btn btn-secondary");
411
-
366
+ // Update button
367
+ document.getElementById('logIn').setAttribute('class', 'btn btn-secondary');
412
368
  homebridge.hideSpinner();
369
+
413
370
  } catch (error) {
414
- document.getElementById('info').innerHTML = 'Check Your credentials data and try again.';
415
- document.getElementById('info').style.color = 'yellow';
416
- document.getElementById('info1').innerHTML = `Error: ${error}`;
417
- document.getElementById('info1').style.color = 'red';
418
- document.getElementById(`logIn`).setAttribute("class", "btn btn-secondary");
371
+ updateInfo('info', 'Check Your credentials data and try again.', 'yellow');
372
+ updateInfo('info1', `Error: ${error}`, 'red');
373
+ document.getElementById('logIn').setAttribute('class', 'btn btn-secondary');
419
374
  } finally {
420
375
  homebridge.hideSpinner();
421
- };
376
+ }
377
+
422
378
  });
423
379
  })();
424
380
  </script>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "3.8.10",
4
+ "version": "3.8.11-beta.0",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -32,12 +32,12 @@
32
32
  ],
33
33
  "engines": {
34
34
  "homebridge": "^1.9.0 || ^2.0.0 || ^2.0.0-beta.29",
35
- "node": "^18.20.4 || ^20.15.1 || ^22.7.0 || ^23.2.0 || ^24.0.0"
35
+ "node": "^^20.18.0 || ^22.0.0 || ^24.0.0"
36
36
  },
37
37
  "dependencies": {
38
38
  "@homebridge/plugin-ui-utils": "^2.1.0",
39
39
  "async-mqtt": "^2.6.3",
40
- "axios": "^1.9.0",
40
+ "axios": "^1.10.0",
41
41
  "express": "^5.1.0"
42
42
  },
43
43
  "keywords": [