homebridge-melcloud-control 4.1.2-beta.12 → 4.1.2-beta.13
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 +23 -13
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.13",
|
|
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,7 +235,6 @@ 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
|
-
// Funkcja kapitalizująca klucze obiektu
|
|
239
238
|
const capitalizeKeys = obj =>
|
|
240
239
|
Object.fromEntries(
|
|
241
240
|
Object.entries(obj).map(([key, value]) => [
|
|
@@ -244,36 +243,48 @@ class MelCloud extends EventEmitter {
|
|
|
244
243
|
])
|
|
245
244
|
);
|
|
246
245
|
|
|
247
|
-
//
|
|
246
|
+
// Rekurencyjna kapitalizacja kluczy tylko dla wybranych pól
|
|
247
|
+
const capitalizeNestedDeep = obj => {
|
|
248
|
+
if (Array.isArray(obj)) {
|
|
249
|
+
return obj.map(capitalizeNestedDeep);
|
|
250
|
+
} else if (obj && typeof obj === 'object' && obj.constructor === Object) {
|
|
251
|
+
return Object.fromEntries(
|
|
252
|
+
Object.entries(obj).map(([k, v]) => [
|
|
253
|
+
k.charAt(0).toUpperCase() + k.slice(1),
|
|
254
|
+
capitalizeNestedDeep(v)
|
|
255
|
+
])
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
return obj;
|
|
259
|
+
};
|
|
260
|
+
|
|
248
261
|
const capitalizeNestedFields = device => {
|
|
249
262
|
const copy = { ...device };
|
|
250
263
|
|
|
251
|
-
if (copy.frostProtection
|
|
252
|
-
copy.FrostProtection =
|
|
264
|
+
if (copy.frostProtection) {
|
|
265
|
+
copy.FrostProtection = capitalizeNestedDeep(copy.frostProtection);
|
|
253
266
|
delete copy.frostProtection;
|
|
254
267
|
}
|
|
255
268
|
|
|
256
|
-
if (copy.overheatProtection
|
|
257
|
-
copy.OverheatProtection =
|
|
269
|
+
if (copy.overheatProtection) {
|
|
270
|
+
copy.OverheatProtection = capitalizeNestedDeep(copy.overheatProtection);
|
|
258
271
|
delete copy.overheatProtection;
|
|
259
272
|
}
|
|
260
273
|
|
|
261
|
-
if (copy.holidayMode
|
|
262
|
-
copy.HolidayMode =
|
|
274
|
+
if (copy.holidayMode) {
|
|
275
|
+
copy.HolidayMode = capitalizeNestedDeep(copy.holidayMode);
|
|
263
276
|
delete copy.holidayMode;
|
|
264
277
|
}
|
|
265
278
|
|
|
266
279
|
if (Array.isArray(copy.schedule)) {
|
|
267
|
-
copy.Schedule = copy.schedule.map(
|
|
280
|
+
copy.Schedule = copy.schedule.map(capitalizeNestedDeep);
|
|
268
281
|
delete copy.schedule;
|
|
269
282
|
}
|
|
270
283
|
|
|
271
284
|
return copy;
|
|
272
285
|
};
|
|
273
286
|
|
|
274
|
-
// Funkcja tworząca finalny obiekt Device
|
|
275
287
|
const createDevice = (device, type) => {
|
|
276
|
-
// Settings już kapitalizowane w nazwach
|
|
277
288
|
const settingsArray = device.Settings || [];
|
|
278
289
|
|
|
279
290
|
const settingsObject = Object.fromEntries(
|
|
@@ -288,14 +299,12 @@ class MelCloud extends EventEmitter {
|
|
|
288
299
|
})
|
|
289
300
|
);
|
|
290
301
|
|
|
291
|
-
// Scal Capabilities + Settings + DeviceType w Device
|
|
292
302
|
const deviceObject = {
|
|
293
303
|
...capitalizeKeys(device.Capabilities || {}),
|
|
294
304
|
...settingsObject,
|
|
295
305
|
DeviceType: type
|
|
296
306
|
};
|
|
297
307
|
|
|
298
|
-
// Usuń stare pola Settings i Capabilities
|
|
299
308
|
const { Settings, Capabilities, Id, GivenDisplayName, ...rest } = device;
|
|
300
309
|
|
|
301
310
|
return {
|
|
@@ -315,6 +324,7 @@ class MelCloud extends EventEmitter {
|
|
|
315
324
|
];
|
|
316
325
|
});
|
|
317
326
|
|
|
327
|
+
|
|
318
328
|
const devicesCount = devices.length;
|
|
319
329
|
if (devicesCount === 0) {
|
|
320
330
|
devicesList.Info = 'No devices found'
|