homebridge-melcloud-control 4.1.2-beta.10 → 4.1.2-beta.12
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/package.json +1 -1
- package/src/melcloud.js +43 -26
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.12",
|
|
5
5
|
"description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "grzegorz914",
|
package/src/melcloud.js
CHANGED
|
@@ -235,26 +235,45 @@ class MelCloud extends EventEmitter {
|
|
|
235
235
|
if (this.logDebug) this.emit('debug', `Buildings list saved`);
|
|
236
236
|
|
|
237
237
|
const devices = buildingsList.flatMap(building => {
|
|
238
|
-
//
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
238
|
+
// Funkcja kapitalizująca klucze obiektu
|
|
239
|
+
const capitalizeKeys = obj =>
|
|
240
|
+
Object.fromEntries(
|
|
241
|
+
Object.entries(obj).map(([key, value]) => [
|
|
242
|
+
key.charAt(0).toUpperCase() + key.slice(1),
|
|
243
|
+
value
|
|
244
|
+
])
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
// Funkcja kapitalizująca tylko wybrane zagnieżdżone obiekty/tablice
|
|
248
|
+
const capitalizeNestedFields = device => {
|
|
249
|
+
const copy = { ...device };
|
|
250
|
+
|
|
251
|
+
if (copy.frostProtection && typeof copy.frostProtection === 'object') {
|
|
252
|
+
copy.FrostProtection = capitalizeKeys(copy.frostProtection);
|
|
253
|
+
delete copy.frostProtection;
|
|
252
254
|
}
|
|
253
|
-
|
|
255
|
+
|
|
256
|
+
if (copy.overheatProtection && typeof copy.overheatProtection === 'object') {
|
|
257
|
+
copy.OverheatProtection = capitalizeKeys(copy.overheatProtection);
|
|
258
|
+
delete copy.overheatProtection;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (copy.holidayMode && typeof copy.holidayMode === 'object') {
|
|
262
|
+
copy.HolidayMode = capitalizeKeys(copy.holidayMode);
|
|
263
|
+
delete copy.holidayMode;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (Array.isArray(copy.schedule)) {
|
|
267
|
+
copy.Schedule = copy.schedule.map(item => capitalizeKeys(item));
|
|
268
|
+
delete copy.schedule;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return copy;
|
|
254
272
|
};
|
|
255
273
|
|
|
256
274
|
// Funkcja tworząca finalny obiekt Device
|
|
257
275
|
const createDevice = (device, type) => {
|
|
276
|
+
// Settings już kapitalizowane w nazwach
|
|
258
277
|
const settingsArray = device.Settings || [];
|
|
259
278
|
|
|
260
279
|
const settingsObject = Object.fromEntries(
|
|
@@ -266,22 +285,21 @@ class MelCloud extends EventEmitter {
|
|
|
266
285
|
|
|
267
286
|
const key = name.charAt(0).toUpperCase() + name.slice(1);
|
|
268
287
|
return [key, parsedValue];
|
|
269
|
-
})
|
|
270
|
-
|
|
288
|
+
})
|
|
289
|
+
);
|
|
271
290
|
|
|
272
|
-
//
|
|
291
|
+
// Scal Capabilities + Settings + DeviceType w Device
|
|
273
292
|
const deviceObject = {
|
|
274
|
-
...
|
|
293
|
+
...capitalizeKeys(device.Capabilities || {}),
|
|
275
294
|
...settingsObject,
|
|
276
295
|
DeviceType: type
|
|
277
296
|
};
|
|
278
297
|
|
|
279
|
-
// Usuń pola
|
|
298
|
+
// Usuń stare pola Settings i Capabilities
|
|
280
299
|
const { Settings, Capabilities, Id, GivenDisplayName, ...rest } = device;
|
|
281
300
|
|
|
282
|
-
// Zwróć gotowy obiekt urządzenia
|
|
283
301
|
return {
|
|
284
|
-
...
|
|
302
|
+
...capitalizeNestedFields(rest),
|
|
285
303
|
Type: type,
|
|
286
304
|
DeviceID: Id,
|
|
287
305
|
DeviceName: GivenDisplayName,
|
|
@@ -290,11 +308,10 @@ class MelCloud extends EventEmitter {
|
|
|
290
308
|
};
|
|
291
309
|
};
|
|
292
310
|
|
|
293
|
-
// Mapowanie urządzeń w budynku
|
|
294
311
|
return [
|
|
295
|
-
...(building.airToAirUnits || []).map(d => createDevice(
|
|
296
|
-
...(building.airToWaterUnits || []).map(d => createDevice(
|
|
297
|
-
...(building.airToVentilationUnits || []).map(d => createDevice(
|
|
312
|
+
...(building.airToAirUnits || []).map(d => createDevice(capitalizeKeys(d), 0)),
|
|
313
|
+
...(building.airToWaterUnits || []).map(d => createDevice(capitalizeKeys(d), 1)),
|
|
314
|
+
...(building.airToVentilationUnits || []).map(d => createDevice(capitalizeKeys(d), 3))
|
|
298
315
|
];
|
|
299
316
|
});
|
|
300
317
|
|