homebridge-melcloud-control 4.1.2-beta.13 → 4.1.2-beta.15

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 +22 -28
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.13",
4
+ "version": "4.1.2-beta.15",
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,55 +235,49 @@ 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 capitalizeKeys = obj =>
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
+ // Rekurencyjna kapitalizacja wszystkich kluczy w obiekcie/tablicy
239
+ const capitalizeKeysDeep = obj => {
248
240
  if (Array.isArray(obj)) {
249
- return obj.map(capitalizeNestedDeep);
250
- } else if (obj && typeof obj === 'object' && obj.constructor === Object) {
241
+ return obj.map(capitalizeKeysDeep);
242
+ } else if (obj && typeof obj === 'object') {
251
243
  return Object.fromEntries(
252
- Object.entries(obj).map(([k, v]) => [
253
- k.charAt(0).toUpperCase() + k.slice(1),
254
- capitalizeNestedDeep(v)
244
+ Object.entries(obj).map(([key, value]) => [
245
+ key.charAt(0).toUpperCase() + key.slice(1),
246
+ capitalizeKeysDeep(value)
255
247
  ])
256
248
  );
257
249
  }
258
250
  return obj;
259
251
  };
260
252
 
261
- const capitalizeNestedFields = device => {
262
- const copy = { ...device };
253
+ // Funkcja kapitalizująca tylko wybrane pola w głównym obiekcie
254
+ const capitalizeSelectedFields = obj => {
255
+ const copy = { ...obj };
263
256
 
264
257
  if (copy.frostProtection) {
265
- copy.FrostProtection = capitalizeNestedDeep(copy.frostProtection);
258
+ copy.FrostProtection = capitalizeKeysDeep(copy.frostProtection);
266
259
  delete copy.frostProtection;
267
260
  }
268
261
 
269
262
  if (copy.overheatProtection) {
270
- copy.OverheatProtection = capitalizeNestedDeep(copy.overheatProtection);
263
+ copy.OverheatProtection = capitalizeKeysDeep(copy.overheatProtection);
271
264
  delete copy.overheatProtection;
272
265
  }
273
266
 
274
267
  if (copy.holidayMode) {
275
- copy.HolidayMode = capitalizeNestedDeep(copy.holidayMode);
268
+ copy.HolidayMode = capitalizeKeysDeep(copy.holidayMode);
276
269
  delete copy.holidayMode;
277
270
  }
278
271
 
279
272
  if (Array.isArray(copy.schedule)) {
280
- copy.Schedule = copy.schedule.map(capitalizeNestedDeep);
273
+ copy.Schedule = copy.schedule.map(capitalizeKeysDeep);
281
274
  delete copy.schedule;
282
275
  }
283
276
 
284
277
  return copy;
285
278
  };
286
279
 
280
+ // Funkcja tworząca pojedyncze urządzenie
287
281
  const createDevice = (device, type) => {
288
282
  const settingsArray = device.Settings || [];
289
283
 
@@ -294,13 +288,12 @@ class MelCloud extends EventEmitter {
294
288
  else if (value === "False") parsedValue = false;
295
289
  else if (!isNaN(value) && value !== "") parsedValue = Number(value);
296
290
 
297
- const key = name.charAt(0).toUpperCase() + name.slice(1);
298
- return [key, parsedValue];
291
+ return [name.charAt(0).toUpperCase() + name.slice(1), parsedValue];
299
292
  })
300
293
  );
301
294
 
302
295
  const deviceObject = {
303
- ...capitalizeKeys(device.Capabilities || {}),
296
+ ...capitalizeKeysDeep(device.Capabilities || {}),
304
297
  ...settingsObject,
305
298
  DeviceType: type
306
299
  };
@@ -308,7 +301,7 @@ class MelCloud extends EventEmitter {
308
301
  const { Settings, Capabilities, Id, GivenDisplayName, ...rest } = device;
309
302
 
310
303
  return {
311
- ...capitalizeNestedFields(rest),
304
+ ...capitalizeSelectedFields(rest),
312
305
  Type: type,
313
306
  DeviceID: Id,
314
307
  DeviceName: GivenDisplayName,
@@ -318,13 +311,14 @@ class MelCloud extends EventEmitter {
318
311
  };
319
312
 
320
313
  return [
321
- ...(building.airToAirUnits || []).map(d => createDevice(capitalizeKeys(d), 0)),
322
- ...(building.airToWaterUnits || []).map(d => createDevice(capitalizeKeys(d), 1)),
323
- ...(building.airToVentilationUnits || []).map(d => createDevice(capitalizeKeys(d), 3))
314
+ ...(building.airToAirUnits || []).map(d => createDevice(d, 0)),
315
+ ...(building.airToWaterUnits || []).map(d => createDevice(d, 1)),
316
+ ...(building.airToVentilationUnits || []).map(d => createDevice(d, 3))
324
317
  ];
325
318
  });
326
319
 
327
320
 
321
+
328
322
  const devicesCount = devices.length;
329
323
  if (devicesCount === 0) {
330
324
  devicesList.Info = 'No devices found'