homebridge-melcloud-control 4.1.2-beta.66 → 4.1.2-beta.68

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.
@@ -276,17 +276,6 @@
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
-
290
279
  // === Create device if missing ===
291
280
  if (!deviceInConfig) {
292
281
  deviceInConfig = {
@@ -304,13 +293,22 @@
304
293
  configDevicesMap.set(deviceId, deviceInConfig);
305
294
  }
306
295
 
296
+ // === Remove placeholder devices (id === '0') if new ones were added ===
297
+ if (devicesInConfig.length > 1 && devicesInConfig.some(d => String(d.id) === '0')) {
298
+ const beforeCount = devicesInConfig.length;
299
+ deviceInConfig = devicesInConfig.filter(d => String(d.id) !== '0');
300
+ const removedCount = beforeCount - deviceInConfig.length;
301
+
302
+ if (removedCount > 0 && removedCount < beforeCount) {
303
+ updateInfo('info1', `Removed ${removedCount} ${typeString} with id === 0 from config`, 'yellow');
304
+ }
305
+ }
306
+
307
307
  // === Process presets/schedules ===
308
308
  const presets = device[typeKey] || [];
309
309
  const presetsInConfig = deviceInConfig[typeKey1] || [];
310
310
  const presetIds = new Set(presetsInConfig.map(p => String(p.id)));
311
311
 
312
- let addedNewPreset = false;
313
-
314
312
  presets.forEach((preset, index) => {
315
313
  const presetId = String(preset[idKey]);
316
314
  if (!presetIds.has(presetId)) {
@@ -323,18 +321,17 @@
323
321
  presetsInConfig.push(presetObj);
324
322
  newPresets.push(presetObj);
325
323
  presetIds.add(presetId);
326
- addedNewPreset = true;
327
324
  }
328
325
  });
329
326
 
330
327
  // === Remove placeholder presets/schedules (id === '0') if new ones were added ===
331
- if (addedNewPreset) {
328
+ if (presetsInConfig.length > 1 && presetsInConfig.some(p => String(p.id) === '0')) {
332
329
  const beforeCount = presetsInConfig.length;
333
330
  deviceInConfig[typeKey1] = presetsInConfig.filter(p => String(p.id) !== '0');
334
331
  const removedCount = beforeCount - deviceInConfig[typeKey1].length;
335
332
 
336
333
  if (removedCount > 0 && removedCount < beforeCount) {
337
- updateInfo('info2', `Removed ${removedCount} placeholder ${typeKey1} from device ${device.DeviceID}`, 'yellow');
334
+ updateInfo('info2', `Removed ${removedCount} ${typeKey1} with id === 0 from ${typeString} id: ${device.DeviceID}`, 'yellow');
338
335
  }
339
336
  }
340
337
  });
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.66",
4
+ "version": "4.1.2-beta.68",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",