homebridge-melcloud-control 4.4.1-beta.43 → 4.4.1-beta.44

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.
@@ -204,7 +204,6 @@
204
204
  }
205
205
  });
206
206
 
207
- // Generic remove function
208
207
  // Generic remove function
209
208
  function removeStaleEntities(configEntities, MelcloudEntities, getConfigId, getMelcloudId) {
210
209
  const serverIds = new Set((MelcloudEntities ?? []).map(item => String(getMelcloudId(item))));
@@ -223,6 +222,14 @@
223
222
  return removedEntities;
224
223
  }
225
224
 
225
+ function getScenesForDevice(unitId, scenesInMelCloud) {
226
+ return (scenesInMelCloud ?? []).filter(scene => {
227
+ const allSettings = [...(scene.AtaSceneSettings ?? []), ...(scene.AtwSceneSettings ?? []), ...(scene.ErvSceneSettings ?? [])];
228
+ return allSettings.some(s => String(s.UnitId) === String(unitId));
229
+ });
230
+ }
231
+
232
+
226
233
  // Update info on page
227
234
  function updateInfo(id, text, color) {
228
235
  const el = document.getElementById(id);
@@ -232,22 +239,6 @@
232
239
  }
233
240
  }
234
241
 
235
- // Map UnitId → Scenes for quick lookup
236
- function mapUnitIdToScenes(scenesInMelCloud) {
237
- const map = new Map();
238
-
239
- (scenesInMelCloud ?? []).forEach(scene => {
240
- const allSceneSettings = [...(scene.AtaSceneSettings ?? []), ...(scene.AtwSceneSettings ?? []), ...(scene.ErvSceneSettings ?? [])];
241
- allSceneSettings.forEach(setting => {
242
- const unitId = String(setting.UnitId);
243
- if (!map.has(unitId)) map.set(unitId, []);
244
- map.get(unitId).push(scene);
245
- });
246
- });
247
-
248
- return map;
249
- }
250
-
251
242
  // Login & Sync Logic
252
243
  document.getElementById('logIn').addEventListener('click', async () => {
253
244
  homebridge.showSpinner();
@@ -286,10 +277,8 @@
286
277
  const removedFromConfigAta = removeStaleEntities(account.ataDevices, devicesInMelCloudByType.ata, d => d.id, d => d.DeviceID);
287
278
  const removedFromConfigAtw = removeStaleEntities(account.atwDevices, devicesInMelCloudByType.atw, d => d.id, d => d.DeviceID);
288
279
  const removedFromConfigErv = removeStaleEntities(account.ervDevices, devicesInMelCloudByType.erv, d => d.id, d => d.DeviceID);
289
- const removedFromConfig = { ataPresets: [], atwPresets: [], ervPresets: [], ataSchedules: [], atwSchedules: [], ervSchedules: [], scenes: [] };
290
280
 
291
- // Map UnitId Scenes
292
- const unitIdToScenes = mapUnitIdToScenes(scenesInMelCloud);
281
+ const removedFromConfig = { ataPresets: [], atwPresets: [], ervPresets: [], ataSchedules: [], atwSchedules: [], ervSchedules: [], scenes: [] };
293
282
 
294
283
  // Generic device handler (obsługuje urządzenia, presety, harmonogramy i sceny)
295
284
  const handleDevices = (devicesInMelCloud, devicesInConfig, deviceTypeString, newDevices, newPresets, newSchedules, newScenes) => {
@@ -348,13 +337,26 @@
348
337
  }
349
338
  });
350
339
 
351
- // SCENES
352
340
  // SCENES
353
341
  deviceInConfig.scenes = deviceInConfig.scenes ?? [];
354
- const scenesForDevice = unitIdToScenes.get(deviceId) ?? [];
355
- removedFromConfig.scenes.push(...removeStaleEntities(deviceInConfig.scenes, scenesForDevice, s => s.id, s => s.Id));
342
+
343
+ // tylko sceny MELCloud należące do tego urządzenia
344
+ const scenesInMelCloudForDevice = getScenesForDevice(deviceId, scenesInMelCloud);
345
+
346
+ // USUWANIE: scena istnieje globalnie, ale nie należy już do tego urządzenia
347
+ removedFromConfig.scenes.push(
348
+ ...removeStaleEntities(
349
+ deviceInConfig.scenes,
350
+ scenesInMelCloudForDevice,
351
+ s => s.id,
352
+ s => s.Id
353
+ )
354
+ );
355
+
356
+ // DODAWANIE: brakujące sceny dla urządzenia
356
357
  const existingSceneIds = new Set(deviceInConfig.scenes.map(s => String(s.id)));
357
- scenesForDevice.forEach((scene, index) => {
358
+
359
+ scenesInMelCloudForDevice.forEach((scene, index) => {
358
360
  const sceneId = String(scene.Id);
359
361
  if (!existingSceneIds.has(sceneId)) {
360
362
  const sceneObj = {
@@ -367,6 +369,7 @@
367
369
  newScenes.push(sceneObj);
368
370
  }
369
371
  });
372
+
370
373
  }
371
374
  });
372
375
 
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.43",
4
+ "version": "4.4.1-beta.44",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",