homebridge-melcloud-control 4.1.2-beta.44 → 4.1.2-beta.45

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.
@@ -256,11 +256,17 @@
256
256
  const handleDevices = (devicesInMelCloud, devicesInConfig, typeString, newArr, newPresets) => {
257
257
  try {
258
258
  const configDevicesMap = new Map(devicesInConfig.map(dev => [String(dev.id), dev]));
259
+ const isMelcloud = account.type === 'melcloud';
260
+
261
+ const idKey = isMelcloud ? 'ID' : 'Id';
262
+ const typeKey = isMelcloud ? 'Presets' : 'Schedule';
263
+ const typeKey1 = isMelcloud ? 'presets' : 'schedules';
259
264
 
260
265
  devicesInMelCloud.forEach(device => {
261
266
  const deviceId = String(device.DeviceID);
262
267
  let deviceInConfig = configDevicesMap.get(deviceId);
263
268
 
269
+ // === Create device if missing ===
264
270
  if (!deviceInConfig) {
265
271
  deviceInConfig = {
266
272
  id: device.DeviceID,
@@ -277,14 +283,13 @@
277
283
  configDevicesMap.set(deviceId, deviceInConfig);
278
284
  }
279
285
 
280
- const idKey = account.type === 'melcloud' ? 'ID' : 'Id';
281
- const typeKey = account.type === 'melcloud' ? 'Presets' : 'Schedule';
282
- const typeKey1 = account.type === 'melcloud' ? 'presets' : 'schedules';
286
+ // === Process presets/schedules ===
283
287
  const presets = device[typeKey] || [];
284
-
285
288
  const presetsInConfig = deviceInConfig[typeKey1] || [];
286
289
  const presetIds = new Set(presetsInConfig.map(p => String(p.id)));
287
290
 
291
+ let addedNewPreset = false;
292
+
288
293
  presets.forEach((preset, index) => {
289
294
  const presetId = String(preset[idKey]);
290
295
  if (!presetIds.has(presetId)) {
@@ -297,14 +302,27 @@
297
302
  presetsInConfig.push(presetObj);
298
303
  newPresets.push(presetObj);
299
304
  presetIds.add(presetId);
305
+ addedNewPreset = true;
300
306
  }
301
307
  });
308
+
309
+ // === Remove placeholder presets/schedules (id === '0') if new ones were added ===
310
+ if (addedNewPreset) {
311
+ const beforeCount = presetsInConfig.length;
312
+ deviceInConfig[typeKey1] = presetsInConfig.filter(p => String(p.id) !== '0');
313
+ const removedCount = beforeCount - deviceInConfig[typeKey1].length;
314
+
315
+ if (removedCount > 0 && removedCount < beforeCount) {
316
+ updateInfo('info', `Removed ${removedCount} placeholder ${typeKey1} from device ${device.DeviceID}`, 'yellow');
317
+ }
318
+ }
302
319
  });
303
320
  } catch (error) {
304
- updateInfo('info1', `Error while processing device: ${error.message || error}`, 'red');
321
+ updateInfo('info', `Error while processing device: ${error.message || error}`, 'red');
305
322
  }
306
323
  };
307
324
 
325
+
308
326
  handleDevices(devicesByType.ata, account.ataDevices, "Air Conditioner", newDevices.ata, newDevices.ataPresets);
309
327
  handleDevices(devicesByType.atw, account.atwDevices, "Heat Pump", newDevices.atw, newDevices.atwPresets);
310
328
  handleDevices(devicesByType.erv, account.ervDevices, "Energy Recovery Ventilation", newDevices.erv, newDevices.ervPresets);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.1.2-beta.44",
4
+ "version": "4.1.2-beta.45",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",