homebridge-melcloud-control 4.1.2-beta.80 → 4.1.2-beta.81

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.
@@ -255,9 +255,9 @@
255
255
  if (d.Type === 3) devicesByType.erv.push(d);
256
256
  });
257
257
 
258
- account.ataDevices = (account.ataDevices || []).filter(d => String(d.id) !== '0');
259
- account.atwDevices = (account.atwDevices || []).filter(d => String(d.id) !== '0');
260
- account.ervDevices = (account.ervDevices || []).filter(d => String(d.id) !== '0');
258
+ account.ataDevices ??= [];
259
+ account.atwDevices ??= [];
260
+ account.ervDevices ??= [];
261
261
 
262
262
  const removedAta = removeStaleDevices(account.ataDevices, devicesByType.ata);
263
263
  const removedAtw = removeStaleDevices(account.atwDevices, devicesByType.atw);
@@ -265,7 +265,7 @@
265
265
 
266
266
  const handleDevices = (devicesInMelCloud, devicesInConfig, typeString, newArr, newPresets) => {
267
267
  try {
268
- const configDevicesMap = new Map(devicesInConfig.map(dev => [dev.id, dev]));
268
+ const configDevicesMap = new Map(devicesInConfig.map(dev => [String(dev.id), dev]));
269
269
  const isMelcloud = account.type === 'melcloud';
270
270
 
271
271
  const idKey = isMelcloud ? 'ID' : 'Id';
@@ -276,6 +276,17 @@
276
276
  const deviceId = String(device.DeviceID);
277
277
  let deviceInConfig = configDevicesMap.get(deviceId);
278
278
 
279
+ // === Remove placeholder devices with id '0' before adding new ===
280
+ const beforeDevicesCount = devicesInConfig.length;
281
+ devicesInConfig = devicesInConfig.filter(d => String(d.id) !== '0');
282
+ if (devicesInConfig.length !== beforeDevicesCount) {
283
+ updateInfo('info2', `Removed placeholder devices with id '0'`, 'yellow');
284
+
285
+ // Rebuild map after filtering
286
+ configDevicesMap.clear();
287
+ devicesInConfig.forEach(dev => configDevicesMap.set(String(dev.id), dev));
288
+ }
289
+
279
290
  // === Create device if missing ===
280
291
  if (!deviceInConfig) {
281
292
  deviceInConfig = {
@@ -295,9 +306,11 @@
295
306
 
296
307
  // === Process presets/schedules ===
297
308
  const presets = device[typeKey] || [];
298
- const presetsInConfig = (deviceInConfig[typeKey1] || []).filter(p => String(p.id) !== '0');
309
+ const presetsInConfig = deviceInConfig[typeKey1] || [];
299
310
  const presetIds = new Set(presetsInConfig.map(p => String(p.id)));
300
311
 
312
+ let addedNewPreset = false;
313
+
301
314
  presets.forEach((preset, index) => {
302
315
  const presetId = String(preset[idKey]);
303
316
  if (!presetIds.has(presetId)) {
@@ -310,8 +323,20 @@
310
323
  presetsInConfig.push(presetObj);
311
324
  newPresets.push(presetObj);
312
325
  presetIds.add(presetId);
326
+ addedNewPreset = true;
313
327
  }
314
328
  });
329
+
330
+ // === Remove placeholder presets/schedules (id === '0') if new ones were added ===
331
+ if (addedNewPreset) {
332
+ const beforeCount = presetsInConfig.length;
333
+ deviceInConfig[typeKey1] = presetsInConfig.filter(p => String(p.id) !== '0');
334
+ const removedCount = beforeCount - deviceInConfig[typeKey1].length;
335
+
336
+ if (removedCount > 0 && removedCount < beforeCount) {
337
+ updateInfo('info2', `Removed ${removedCount} placeholder ${typeKey1} from device ${device.DeviceID}`, 'yellow');
338
+ }
339
+ }
315
340
  });
316
341
 
317
342
  // Return filtered devicesInConfig to make sure upstream code uses it
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.80",
4
+ "version": "4.1.2-beta.81",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",