homebridge-melcloud-control 4.4.1-beta.41 → 4.4.1-beta.42

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.
@@ -205,13 +205,13 @@
205
205
  });
206
206
 
207
207
  // Generic remove function
208
- // Generic remove function
209
- function removeStaleEntities(configEntities, MelcloudEntities, getConfigId, getMelcloudId) {
208
+ function removeStaleEntities(configEntities, MelcloudEntities, getConfigId, getMelcloudId, filterFn) {
210
209
  const serverIds = new Set((MelcloudEntities ?? []).map(item => String(getMelcloudId(item))));
211
210
  const removedEntities = [];
212
211
 
213
212
  for (let i = configEntities.length - 1; i >= 0; i--) {
214
213
  const entity = configEntities[i];
214
+ if (filterFn && !filterFn(entity)) continue; // jeśli nie dotyczy tego urządzenia, pomiń
215
215
  const entityId = String(getConfigId(entity));
216
216
 
217
217
  if (!serverIds.has(entityId)) {
@@ -223,6 +223,7 @@
223
223
  return removedEntities;
224
224
  }
225
225
 
226
+
226
227
  // Update info on page
227
228
  function updateInfo(id, text, color) {
228
229
  const el = document.getElementById(id);
@@ -272,7 +273,7 @@
272
273
  const scenesInMelCloud = response.Scenes ?? [];
273
274
 
274
275
  // Split devices by type
275
- (response.Devices ?? []).forEach(device => {
276
+ response.Devices ?? [].forEach(device => {
276
277
  if (device.Type === 0) devicesInMelCloudByType.ata.push(device);
277
278
  if (device.Type === 1) devicesInMelCloudByType.atw.push(device);
278
279
  if (device.Type === 3) devicesInMelCloudByType.erv.push(device);
@@ -286,7 +287,6 @@
286
287
  const removedFromConfigAta = removeStaleEntities(account.ataDevices, devicesInMelCloudByType.ata, d => d.id, d => d.DeviceID);
287
288
  const removedFromConfigAtw = removeStaleEntities(account.atwDevices, devicesInMelCloudByType.atw, d => d.id, d => d.DeviceID);
288
289
  const removedFromConfigErv = removeStaleEntities(account.ervDevices, devicesInMelCloudByType.erv, d => d.id, d => d.DeviceID);
289
-
290
290
  const removedFromConfig = { ataPresets: [], atwPresets: [], ervPresets: [], ataSchedules: [], atwSchedules: [], ervSchedules: [], scenes: [] };
291
291
 
292
292
  // Map UnitId → Scenes
@@ -296,7 +296,7 @@
296
296
  const handleDevices = (devicesInMelCloud, devicesInConfig, deviceTypeString, newDevices, newPresets, newSchedules, newScenes) => {
297
297
  const configDevicesMap = new Map(devicesInConfig.map(dev => [String(dev.id), dev]));
298
298
 
299
- (devicesInMelCloud ?? []).forEach(device => {
299
+ devicesInMelCloud.forEach(device => {
300
300
  const deviceId = String(device.DeviceID);
301
301
  let deviceInConfig = configDevicesMap.get(deviceId);
302
302
 
@@ -351,13 +351,16 @@
351
351
 
352
352
  // SCENES
353
353
  deviceInConfig.scenes = deviceInConfig.scenes ?? [];
354
- removedFromConfig.scenes.push(...removeStaleEntities(deviceInConfig.scenes, scenesInMelCloud, s => s.id, s => s.Id));
355
- const sceneIds = new Set(deviceInConfig.scenes.map(s => String(s.id)));
356
354
  const scenesForDevice = unitIdToScenes.get(deviceId) ?? [];
357
355
 
356
+ // Usuń stare sceny tylko dla tego urządzenia
357
+ removedFromConfig.scenes.push(...removeStaleEntities(deviceInConfig.scenes, scenesForDevice, s => s.id, s => s.Id));
358
+
359
+ // Dodaj nowe sceny dla tego urządzenia
360
+ const existingSceneIds = new Set(deviceInConfig.scenes.map(s => String(s.id)));
358
361
  scenesForDevice.forEach((scene, index) => {
359
362
  const sceneId = String(scene.Id);
360
- if (!sceneIds.has(sceneId)) {
363
+ if (!existingSceneIds.has(sceneId)) {
361
364
  const sceneObj = {
362
365
  id: sceneId,
363
366
  displayType: 0,
@@ -368,6 +371,7 @@
368
371
  newScenes.push(sceneObj);
369
372
  }
370
373
  });
374
+
371
375
  }
372
376
  });
373
377
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.4.1-beta.41",
4
+ "version": "4.4.1-beta.42",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",