homebridge-melcloud-control 4.1.2-beta.10 → 4.1.2-beta.12

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 +43 -26
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.10",
4
+ "version": "4.1.2-beta.12",
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,26 +235,45 @@ 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 funkcja kapitalizująca klucze w całym obiekcie
239
- const capitalizeKeysDeep = obj => {
240
- if (Array.isArray(obj)) {
241
- return obj.map(item => capitalizeKeysDeep(item));
242
- } else if (obj && typeof obj === 'object' && obj.constructor === Object) {
243
- return Object.fromEntries(
244
- Object.entries(obj).map(([key, value]) => {
245
- const safeKey =
246
- typeof key === 'string'
247
- ? key.charAt(0).toUpperCase() + key.slice(1)
248
- : key;
249
- return [safeKey, capitalizeKeysDeep(value)];
250
- })
251
- );
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
+ // Funkcja kapitalizująca tylko wybrane zagnieżdżone obiekty/tablice
248
+ const capitalizeNestedFields = device => {
249
+ const copy = { ...device };
250
+
251
+ if (copy.frostProtection && typeof copy.frostProtection === 'object') {
252
+ copy.FrostProtection = capitalizeKeys(copy.frostProtection);
253
+ delete copy.frostProtection;
252
254
  }
253
- return obj;
255
+
256
+ if (copy.overheatProtection && typeof copy.overheatProtection === 'object') {
257
+ copy.OverheatProtection = capitalizeKeys(copy.overheatProtection);
258
+ delete copy.overheatProtection;
259
+ }
260
+
261
+ if (copy.holidayMode && typeof copy.holidayMode === 'object') {
262
+ copy.HolidayMode = capitalizeKeys(copy.holidayMode);
263
+ delete copy.holidayMode;
264
+ }
265
+
266
+ if (Array.isArray(copy.schedule)) {
267
+ copy.Schedule = copy.schedule.map(item => capitalizeKeys(item));
268
+ delete copy.schedule;
269
+ }
270
+
271
+ return copy;
254
272
  };
255
273
 
256
274
  // Funkcja tworząca finalny obiekt Device
257
275
  const createDevice = (device, type) => {
276
+ // Settings już kapitalizowane w nazwach
258
277
  const settingsArray = device.Settings || [];
259
278
 
260
279
  const settingsObject = Object.fromEntries(
@@ -266,22 +285,21 @@ class MelCloud extends EventEmitter {
266
285
 
267
286
  const key = name.charAt(0).toUpperCase() + name.slice(1);
268
287
  return [key, parsedValue];
269
- }))
270
-
288
+ })
289
+ );
271
290
 
272
- // Połącz Capabilities + Settings + DeviceType
291
+ // Scal Capabilities + Settings + DeviceType w Device
273
292
  const deviceObject = {
274
- ...capitalizeKeysDeep(device.Capabilities || {}),
293
+ ...capitalizeKeys(device.Capabilities || {}),
275
294
  ...settingsObject,
276
295
  DeviceType: type
277
296
  };
278
297
 
279
- // Usuń pola, które nie mają trafić do finalnego obiektu
298
+ // Usuń stare pola Settings i Capabilities
280
299
  const { Settings, Capabilities, Id, GivenDisplayName, ...rest } = device;
281
300
 
282
- // Zwróć gotowy obiekt urządzenia
283
301
  return {
284
- ...capitalizeKeysDeep(rest),
302
+ ...capitalizeNestedFields(rest),
285
303
  Type: type,
286
304
  DeviceID: Id,
287
305
  DeviceName: GivenDisplayName,
@@ -290,11 +308,10 @@ class MelCloud extends EventEmitter {
290
308
  };
291
309
  };
292
310
 
293
- // Mapowanie urządzeń w budynku
294
311
  return [
295
- ...(building.airToAirUnits || []).map(d => createDevice(capitalizeKeysDeep(d), 0)),
296
- ...(building.airToWaterUnits || []).map(d => createDevice(capitalizeKeysDeep(d), 1)),
297
- ...(building.airToVentilationUnits || []).map(d => createDevice(capitalizeKeysDeep(d), 3))
312
+ ...(building.airToAirUnits || []).map(d => createDevice(capitalizeKeys(d), 0)),
313
+ ...(building.airToWaterUnits || []).map(d => createDevice(capitalizeKeys(d), 1)),
314
+ ...(building.airToVentilationUnits || []).map(d => createDevice(capitalizeKeys(d), 3))
298
315
  ];
299
316
  });
300
317