homebridge-melcloud-control 4.1.2-beta.16 → 4.1.2-beta.18

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/melcloud.js +39 -1
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.16",
4
+ "version": "4.1.2-beta.18",
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
@@ -244,6 +244,20 @@ class MelCloud extends EventEmitter {
244
244
  ])
245
245
  );
246
246
 
247
+ // Rekurencyjna kapitalizacja kluczy w obiekcie lub tablicy
248
+ const capitalizeKeysDeep = obj => {
249
+ if (Array.isArray(obj)) return obj.map(capitalizeKeysDeep);
250
+ if (obj && typeof obj === 'object') {
251
+ return Object.fromEntries(
252
+ Object.entries(obj).map(([key, value]) => [
253
+ key.charAt(0).toUpperCase() + key.slice(1),
254
+ capitalizeKeysDeep(value)
255
+ ])
256
+ );
257
+ }
258
+ return obj;
259
+ };
260
+
247
261
  // Funkcja tworząca finalny obiekt Device
248
262
  const createDevice = (device, type) => {
249
263
  // Settings już kapitalizowane w nazwach
@@ -271,8 +285,31 @@ class MelCloud extends EventEmitter {
271
285
  // Usuń stare pola Settings i Capabilities
272
286
  const { Settings, Capabilities, Id, GivenDisplayName, ...rest } = device;
273
287
 
288
+ // Kapitalizacja brakujących obiektów/tablic
289
+ const capitalizedRest = { ...rest };
290
+
291
+ if (capitalizedRest.frostProtection) {
292
+ capitalizedRest.FrostProtection = { ...capitalizeKeys(device.frostProtection || {}) };
293
+ delete capitalizedRest.frostProtection;
294
+ }
295
+
296
+ if (capitalizedRest.overheatProtection) {
297
+ capitalizedRest.OverheatProtection = { ...capitalizeKeys(device.overheatProtection || {}) };
298
+ delete capitalizedRest.overheatProtection;
299
+ }
300
+
301
+ if (capitalizedRest.holidayMode) {
302
+ capitalizedRest.HolidayMode = { ...capitalizeKeys(device.HolidayMode || {}) };
303
+ delete capitalizedRest.holidayMode;
304
+ }
305
+
306
+ if (Array.isArray(capitalizedRest.schedule)) {
307
+ capitalizedRest.Schedule = capitalizedRest.schedule.map(capitalizeKeysDeep);
308
+ delete capitalizedRest.schedule;
309
+ }
310
+
274
311
  return {
275
- ...rest,
312
+ ...capitalizedRest,
276
313
  Type: type,
277
314
  DeviceID: Id,
278
315
  DeviceName: GivenDisplayName,
@@ -288,6 +325,7 @@ class MelCloud extends EventEmitter {
288
325
  ];
289
326
  });
290
327
 
328
+
291
329
  const devicesCount = devices.length;
292
330
  if (devicesCount === 0) {
293
331
  devicesList.Info = 'No devices found'