homebridge-melcloud-control 4.0.0-beta.83 → 4.0.0-beta.85

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.
@@ -146,8 +146,8 @@
146
146
 
147
147
  document.getElementById('logIn').disabled = !(acc.name && acc.user && acc.passwd && acc.languaged && acc.displayType);
148
148
 
149
- await homebridge.updatePluginConfig(acc);
150
- await homebridge.savePluginConfig(acc);
149
+ await homebridge.updatePluginConfig(pluginConfig);
150
+ await homebridge.savePluginConfig(pluginConfig);
151
151
  });
152
152
 
153
153
  // --- Config Button Toggle ---
@@ -224,33 +224,52 @@
224
224
  const removedErv = removeStaleDevices(acc.ervDevices, devicesByType.erv);
225
225
 
226
226
  // Function to handle device & presets
227
+ // Function to handle devices & presets safely (deep cloning)
227
228
  const handleDevices = (devicesInCloud, devicesInConfig, typeString, newArr, newPresets) => {
228
229
  devicesInCloud.forEach(device => {
229
230
  const { DeviceID: id, Type: type, DeviceName: name, Presets: presets = [] } = device;
230
- const devObj = { id, type, typeString, name, displayMode: 1, presets: [], buttonsSensors: [] };
231
+
232
+ // Create a cloned device object
233
+ const devObj = structuredClone({
234
+ id,
235
+ type,
236
+ typeString,
237
+ name,
238
+ displayMode: 1,
239
+ presets: [],
240
+ buttonsSensors: []
241
+ });
242
+
243
+ // Add device if not exists
231
244
  if (!devicesInConfig.some(d => d.id === id)) {
232
245
  devicesInConfig.push(devObj);
233
- newArr.push(devObj);
246
+ newArr.push(structuredClone(devObj)); // also clone into new devices list
234
247
  }
235
- presets.forEach(p => {
236
- p.id = p.ID;
237
- p.name = p.NumberDescription;
238
- p.displayType = 0;
239
- p.namePrefix = false;
248
+
249
+ // Add presets safely
250
+ presets.forEach(preset => {
251
+ const p = structuredClone({
252
+ id: preset.ID,
253
+ name: preset.NumberDescription,
254
+ displayType: 0,
255
+ namePrefix: false
256
+ });
257
+
240
258
  const devConfig = devicesInConfig.find(d => d.id === id);
241
- if (devConfig && !devConfig.presets.some(x => x.id === p.ID)) {
259
+ if (devConfig && !devConfig.presets.some(x => x.id === p.id)) {
242
260
  devConfig.presets.push(p);
243
- newPresets.push(p);
261
+ newPresets.push(structuredClone(p));
244
262
  }
245
263
  });
246
264
  });
247
265
  };
248
266
 
267
+ // Call for each device type
249
268
  handleDevices(devicesByType.ata, acc.ataDevices, "Air Conditioner", newDevices.ata, newDevices.ataPresets);
250
269
  handleDevices(devicesByType.atw, acc.atwDevices, "Heat Pump", newDevices.atw, newDevices.atwPresets);
251
- handleDevices(devicesByType.erv, acc.ervDevices, "Energy Recovery ventiltion", newDevices.erv, newDevices.ervPresets);
270
+ handleDevices(devicesByType.erv, acc.ervDevices, "Energy Recovery Ventilation", newDevices.erv, newDevices.ervPresets);
252
271
 
253
- // Display summary
272
+ // Summary info
254
273
  const newDevicesCount = newDevices.ata.length + newDevices.atw.length + newDevices.erv.length;
255
274
  const newPresetsCount = newDevices.ataPresets.length + newDevices.atwPresets.length + newDevices.ervPresets.length;
256
275
  const removedDevicesCount = removedAta.length + removedAtw.length + removedErv.length;
@@ -258,15 +277,24 @@
258
277
  if (!newDevicesCount && !newPresetsCount && !removedDevicesCount) {
259
278
  updateInfo('info', 'No changes detected.', 'white');
260
279
  } else {
261
- if (newDevicesCount) updateInfo('info', `Found new devices: ATA: ${newDevices.ata.length}, ATW: ${newDevices.atw.length}, ERV: ${newDevices.erv.length}.`, 'green');
262
- if (newPresetsCount) updateInfo('info1', `Found new presets: ATA: ${newDevices.ataPresets.length}, ATW: ${newDevices.atwPresets.length}, ERV: ${newDevices.ervPresets.length}.`, 'green');
263
- if (removedDevicesCount) updateInfo('info2', `Removed devices: ATA: ${removedAta.length}, ATW: ${removedAtw.length}, ERV: ${removedErv.length}.`, 'orange');
280
+ if (newDevicesCount)
281
+ updateInfo('info', `Found new devices: ATA: ${newDevices.ata.length}, ATW: ${newDevices.atw.length}, ERV: ${newDevices.erv.length}.`, 'green');
282
+ if (newPresetsCount)
283
+ updateInfo('info1', `Found new presets: ATA: ${newDevices.ataPresets.length}, ATW: ${newDevices.atwPresets.length}, ERV: ${newDevices.ervPresets.length}.`, 'green');
284
+ if (removedDevicesCount)
285
+ updateInfo('info2', `Removed devices: ATA: ${removedAta.length}, ATW: ${removedAtw.length}, ERV: ${removedErv.length}.`, 'orange');
264
286
  }
265
287
 
266
- await homebridge.updatePluginConfig(acc);
267
- await homebridge.savePluginConfig(acc);
288
+ console.log('Account 0:', pluginConfig[0].accounts[0].ataDevices);
289
+ console.log('Account 1:', pluginConfig[0].accounts[1].ataDevices);
290
+ console.log('Same ref?', pluginConfig[0].accounts[0].ataDevices === pluginConfig[0].accounts[1].ataDevices);
291
+
292
+ // Correct save (must be array)
293
+ await homebridge.updatePluginConfig(pluginConfig);
294
+ await homebridge.savePluginConfig(pluginConfig);
268
295
  document.getElementById('logIn').className = "btn btn-secondary";
269
296
 
297
+
270
298
  } catch (error) {
271
299
  updateInfo('info', 'Check Your credentials data and try again.', 'yellow');
272
300
  updateInfo('info1', `Error: ${JSON.stringify(error)}`, 'red');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.0.0-beta.83",
4
+ "version": "4.0.0-beta.85",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",