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