homebridge-melcloud-control 4.1.2-beta.44 → 4.1.2-beta.46
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,28 @@
|
|
|
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
|
+
// === Remove placeholder devices with id '0' before adding new ===
|
|
270
|
+
const beforeDevicesCount = devicesInConfig.length;
|
|
271
|
+
devicesInConfig = devicesInConfig.filter(d => String(d.id) !== '0');
|
|
272
|
+
if (devicesInConfig.length !== beforeDevicesCount) {
|
|
273
|
+
updateInfo('info2', `Removed placeholder devices with id '0'`, 'yellow');
|
|
274
|
+
|
|
275
|
+
// Rebuild map after filtering
|
|
276
|
+
configDevicesMap.clear();
|
|
277
|
+
devicesInConfig.forEach(dev => configDevicesMap.set(String(dev.id), dev));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// === Create device if missing ===
|
|
264
281
|
if (!deviceInConfig) {
|
|
265
282
|
deviceInConfig = {
|
|
266
283
|
id: device.DeviceID,
|
|
@@ -277,14 +294,13 @@
|
|
|
277
294
|
configDevicesMap.set(deviceId, deviceInConfig);
|
|
278
295
|
}
|
|
279
296
|
|
|
280
|
-
|
|
281
|
-
const typeKey = account.type === 'melcloud' ? 'Presets' : 'Schedule';
|
|
282
|
-
const typeKey1 = account.type === 'melcloud' ? 'presets' : 'schedules';
|
|
297
|
+
// === Process presets/schedules ===
|
|
283
298
|
const presets = device[typeKey] || [];
|
|
284
|
-
|
|
285
299
|
const presetsInConfig = deviceInConfig[typeKey1] || [];
|
|
286
300
|
const presetIds = new Set(presetsInConfig.map(p => String(p.id)));
|
|
287
301
|
|
|
302
|
+
let addedNewPreset = false;
|
|
303
|
+
|
|
288
304
|
presets.forEach((preset, index) => {
|
|
289
305
|
const presetId = String(preset[idKey]);
|
|
290
306
|
if (!presetIds.has(presetId)) {
|
|
@@ -297,11 +313,27 @@
|
|
|
297
313
|
presetsInConfig.push(presetObj);
|
|
298
314
|
newPresets.push(presetObj);
|
|
299
315
|
presetIds.add(presetId);
|
|
316
|
+
addedNewPreset = true;
|
|
300
317
|
}
|
|
301
318
|
});
|
|
319
|
+
|
|
320
|
+
// === Remove placeholder presets/schedules (id === '0') if new ones were added ===
|
|
321
|
+
if (addedNewPreset) {
|
|
322
|
+
const beforeCount = presetsInConfig.length;
|
|
323
|
+
deviceInConfig[typeKey1] = presetsInConfig.filter(p => String(p.id) !== '0');
|
|
324
|
+
const removedCount = beforeCount - deviceInConfig[typeKey1].length;
|
|
325
|
+
|
|
326
|
+
if (removedCount > 0 && removedCount < beforeCount) {
|
|
327
|
+
updateInfo('info2', `Removed ${removedCount} placeholder ${typeKey1} from device ${device.DeviceID}`, 'yellow');
|
|
328
|
+
}
|
|
329
|
+
}
|
|
302
330
|
});
|
|
331
|
+
|
|
332
|
+
// Return filtered devicesInConfig to make sure upstream code uses it
|
|
333
|
+
return devicesInConfig;
|
|
334
|
+
|
|
303
335
|
} catch (error) {
|
|
304
|
-
updateInfo('
|
|
336
|
+
updateInfo('info', `Error while processing device: ${JSON.stringify(error)}`, 'red');
|
|
305
337
|
}
|
|
306
338
|
};
|
|
307
339
|
|
|
@@ -329,8 +361,7 @@
|
|
|
329
361
|
document.getElementById('logIn').className = "btn btn-secondary";
|
|
330
362
|
|
|
331
363
|
} catch (error) {
|
|
332
|
-
updateInfo('info',
|
|
333
|
-
updateInfo('info1', `${JSON.stringify(error)}`, 'red');
|
|
364
|
+
updateInfo('info', `Connect error ${JSON.stringify(error)}`, 'red');
|
|
334
365
|
document.getElementById('logIn').className = "btn btn-secondary";
|
|
335
366
|
} finally {
|
|
336
367
|
homebridge.hideSpinner();
|
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.
|
|
4
|
+
"version": "4.1.2-beta.46",
|
|
5
5
|
"description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|