homebridge-melcloud-control 4.1.2-beta.8 → 4.1.2-beta.9
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.
- package/package.json +1 -1
- package/src/melcloud.js +23 -18
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.
|
|
4
|
+
"version": "4.1.2-beta.9",
|
|
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,16 +235,17 @@ 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
|
|
238
|
+
// Rekurencyjna funkcja kapitalizująca klucze w całym obiekcie
|
|
239
239
|
const capitalizeKeysDeep = obj => {
|
|
240
240
|
if (Array.isArray(obj)) {
|
|
241
241
|
return obj.map(item => capitalizeKeysDeep(item));
|
|
242
242
|
} else if (obj && typeof obj === 'object' && obj.constructor === Object) {
|
|
243
243
|
return Object.fromEntries(
|
|
244
244
|
Object.entries(obj).map(([key, value]) => {
|
|
245
|
-
const safeKey =
|
|
246
|
-
|
|
247
|
-
|
|
245
|
+
const safeKey =
|
|
246
|
+
typeof key === 'string'
|
|
247
|
+
? key.charAt(0).toUpperCase() + key.slice(1)
|
|
248
|
+
: key;
|
|
248
249
|
return [safeKey, capitalizeKeysDeep(value)];
|
|
249
250
|
})
|
|
250
251
|
);
|
|
@@ -254,21 +255,24 @@ class MelCloud extends EventEmitter {
|
|
|
254
255
|
|
|
255
256
|
// Funkcja tworząca finalny obiekt Device
|
|
256
257
|
const createDevice = (device, type, headers = {}) => {
|
|
257
|
-
// Zabezpieczenie – jeśli Settings to nie tablica, użyj pustej
|
|
258
258
|
const settingsArray = Array.isArray(device.Settings) ? device.Settings : [];
|
|
259
259
|
|
|
260
|
-
//
|
|
261
|
-
const
|
|
260
|
+
// Parsowanie Settings → obiekt z poprawnymi typami i kapitalizacją
|
|
261
|
+
const parsedSettings = Object.fromEntries(
|
|
262
262
|
settingsArray
|
|
263
|
-
.filter(
|
|
263
|
+
.filter(s => s && typeof s.name === 'string')
|
|
264
264
|
.map(({ name, value }) => {
|
|
265
265
|
let parsedValue = value;
|
|
266
|
-
if (value ===
|
|
267
|
-
else if (value ===
|
|
268
|
-
else if (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
266
|
+
if (value === 'True') parsedValue = true;
|
|
267
|
+
else if (value === 'False') parsedValue = false;
|
|
268
|
+
else if (
|
|
269
|
+
typeof value === 'string' &&
|
|
270
|
+
!isNaN(Number(value)) &&
|
|
271
|
+
value.trim() !== ''
|
|
272
|
+
) parsedValue = Number(value);
|
|
273
|
+
|
|
274
|
+
const key =
|
|
275
|
+
name.charAt(0).toUpperCase() + name.slice(1);
|
|
272
276
|
return [key, parsedValue];
|
|
273
277
|
})
|
|
274
278
|
);
|
|
@@ -276,14 +280,14 @@ class MelCloud extends EventEmitter {
|
|
|
276
280
|
// Połącz Capabilities + Settings + DeviceType
|
|
277
281
|
const deviceObject = {
|
|
278
282
|
...capitalizeKeysDeep(device.Capabilities || {}),
|
|
279
|
-
...
|
|
283
|
+
...parsedSettings,
|
|
280
284
|
DeviceType: type
|
|
281
285
|
};
|
|
282
286
|
|
|
283
|
-
// Usuń
|
|
287
|
+
// Usuń pola, które nie mają trafić do finalnego obiektu
|
|
284
288
|
const { Settings, Capabilities, Id, GivenDisplayName, ...rest } = device;
|
|
285
289
|
|
|
286
|
-
//
|
|
290
|
+
// Zwróć gotowy obiekt urządzenia
|
|
287
291
|
return {
|
|
288
292
|
...capitalizeKeysDeep(rest),
|
|
289
293
|
Type: type,
|
|
@@ -294,13 +298,14 @@ class MelCloud extends EventEmitter {
|
|
|
294
298
|
};
|
|
295
299
|
};
|
|
296
300
|
|
|
297
|
-
// Mapowanie urządzeń
|
|
301
|
+
// Mapowanie urządzeń w budynku
|
|
298
302
|
return [
|
|
299
303
|
...(building.airToAirUnits || []).map(d => createDevice(capitalizeKeysDeep(d), 0)),
|
|
300
304
|
...(building.airToWaterUnits || []).map(d => createDevice(capitalizeKeysDeep(d), 1)),
|
|
301
305
|
...(building.airToVentilationUnits || []).map(d => createDevice(capitalizeKeysDeep(d), 3))
|
|
302
306
|
];
|
|
303
307
|
|
|
308
|
+
|
|
304
309
|
});
|
|
305
310
|
|
|
306
311
|
const devicesCount = devices.length;
|