homebridge-melcloud-control 4.4.1-beta.44 → 4.4.1-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.
- package/homebridge-ui/public/index.html +27 -30
- package/package.json +1 -1
|
@@ -204,6 +204,7 @@
|
|
|
204
204
|
}
|
|
205
205
|
});
|
|
206
206
|
|
|
207
|
+
// Generic remove function
|
|
207
208
|
// Generic remove function
|
|
208
209
|
function removeStaleEntities(configEntities, MelcloudEntities, getConfigId, getMelcloudId) {
|
|
209
210
|
const serverIds = new Set((MelcloudEntities ?? []).map(item => String(getMelcloudId(item))));
|
|
@@ -222,14 +223,6 @@
|
|
|
222
223
|
return removedEntities;
|
|
223
224
|
}
|
|
224
225
|
|
|
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
|
-
|
|
233
226
|
// Update info on page
|
|
234
227
|
function updateInfo(id, text, color) {
|
|
235
228
|
const el = document.getElementById(id);
|
|
@@ -239,6 +232,22 @@
|
|
|
239
232
|
}
|
|
240
233
|
}
|
|
241
234
|
|
|
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
|
+
|
|
242
251
|
// Login & Sync Logic
|
|
243
252
|
document.getElementById('logIn').addEventListener('click', async () => {
|
|
244
253
|
homebridge.showSpinner();
|
|
@@ -263,7 +272,7 @@
|
|
|
263
272
|
const scenesInMelCloud = response.Scenes ?? [];
|
|
264
273
|
|
|
265
274
|
// Split devices by type
|
|
266
|
-
response.Devices ?? [].forEach(device => {
|
|
275
|
+
(response.Devices ?? []).forEach(device => {
|
|
267
276
|
if (device.Type === 0) devicesInMelCloudByType.ata.push(device);
|
|
268
277
|
if (device.Type === 1) devicesInMelCloudByType.atw.push(device);
|
|
269
278
|
if (device.Type === 3) devicesInMelCloudByType.erv.push(device);
|
|
@@ -280,11 +289,14 @@
|
|
|
280
289
|
|
|
281
290
|
const removedFromConfig = { ataPresets: [], atwPresets: [], ervPresets: [], ataSchedules: [], atwSchedules: [], ervSchedules: [], scenes: [] };
|
|
282
291
|
|
|
292
|
+
// Map UnitId → Scenes
|
|
293
|
+
const unitIdToScenes = mapUnitIdToScenes(scenesInMelCloud);
|
|
294
|
+
|
|
283
295
|
// Generic device handler (obsługuje urządzenia, presety, harmonogramy i sceny)
|
|
284
296
|
const handleDevices = (devicesInMelCloud, devicesInConfig, deviceTypeString, newDevices, newPresets, newSchedules, newScenes) => {
|
|
285
297
|
const configDevicesMap = new Map(devicesInConfig.map(dev => [String(dev.id), dev]));
|
|
286
298
|
|
|
287
|
-
devicesInMelCloud.forEach(device => {
|
|
299
|
+
(devicesInMelCloud ?? []).forEach(device => {
|
|
288
300
|
const deviceId = String(device.DeviceID);
|
|
289
301
|
let deviceInConfig = configDevicesMap.get(deviceId);
|
|
290
302
|
|
|
@@ -339,26 +351,12 @@
|
|
|
339
351
|
|
|
340
352
|
// SCENES
|
|
341
353
|
deviceInConfig.scenes = deviceInConfig.scenes ?? [];
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const
|
|
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
|
|
357
|
-
const existingSceneIds = new Set(deviceInConfig.scenes.map(s => String(s.id)));
|
|
358
|
-
|
|
359
|
-
scenesInMelCloudForDevice.forEach((scene, index) => {
|
|
354
|
+
const scenesForDevice = unitIdToScenes.get(deviceId) ?? [];
|
|
355
|
+
removedFromConfig.scenes.push(...removeStaleEntities(deviceInConfig.scenes, scenesForDevice, s => s.id, s => s.Id));
|
|
356
|
+
const sceneIds = new Set(deviceInConfig.scenes.map(s => String(s.id)));
|
|
357
|
+
scenesForDevice.forEach((scene, index) => {
|
|
360
358
|
const sceneId = String(scene.Id);
|
|
361
|
-
if (!
|
|
359
|
+
if (!sceneIds.has(sceneId)) {
|
|
362
360
|
const sceneObj = {
|
|
363
361
|
id: sceneId,
|
|
364
362
|
displayType: 0,
|
|
@@ -369,7 +367,6 @@
|
|
|
369
367
|
newScenes.push(sceneObj);
|
|
370
368
|
}
|
|
371
369
|
});
|
|
372
|
-
|
|
373
370
|
}
|
|
374
371
|
});
|
|
375
372
|
|
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.
|
|
4
|
+
"version": "4.4.1-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",
|