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

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 +14 -41
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.14",
4
+ "version": "4.1.2-beta.16",
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,20 +235,16 @@ 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 capitalizeKeysDeep = obj => {
239
- if (Array.isArray(obj)) {
240
- return obj.map(capitalizeKeysDeep);
241
- } else if (obj && typeof obj === 'object') {
242
- return Object.fromEntries(
243
- Object.entries(obj).map(([key, value]) => [
244
- key.charAt(0).toUpperCase() + key.slice(1),
245
- capitalizeKeysDeep(value)
246
- ])
247
- );
248
- }
249
- return obj;
250
- };
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
+ );
251
246
 
247
+ // Funkcja tworząca finalny obiekt Device
252
248
  const createDevice = (device, type) => {
253
249
  // Settings już kapitalizowane w nazwach
254
250
  const settingsArray = device.Settings || [];
@@ -267,7 +263,7 @@ class MelCloud extends EventEmitter {
267
263
 
268
264
  // Scal Capabilities + Settings + DeviceType w Device
269
265
  const deviceObject = {
270
- ...capitalizeKeysDeep(device.Capabilities || {}),
266
+ ...capitalizeKeys(device.Capabilities || {}),
271
267
  ...settingsObject,
272
268
  DeviceType: type
273
269
  };
@@ -275,31 +271,8 @@ class MelCloud extends EventEmitter {
275
271
  // Usuń stare pola Settings i Capabilities
276
272
  const { Settings, Capabilities, Id, GivenDisplayName, ...rest } = device;
277
273
 
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
-
301
274
  return {
302
- ...capitalizedNested,
275
+ ...rest,
303
276
  Type: type,
304
277
  DeviceID: Id,
305
278
  DeviceName: GivenDisplayName,
@@ -309,9 +282,9 @@ class MelCloud extends EventEmitter {
309
282
  };
310
283
 
311
284
  return [
312
- ...(building.airToAirUnits || []).map(d => createDevice(d, 0)),
313
- ...(building.airToWaterUnits || []).map(d => createDevice(d, 1)),
314
- ...(building.airToVentilationUnits || []).map(d => createDevice(d, 3))
285
+ ...(building.airToAirUnits || []).map(d => createDevice(capitalizeKeys(d), 0)),
286
+ ...(building.airToWaterUnits || []).map(d => createDevice(capitalizeKeys(d), 1)),
287
+ ...(building.airToVentilationUnits || []).map(d => createDevice(capitalizeKeys(d), 3))
315
288
  ];
316
289
  });
317
290