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

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