homebridge-melcloud-control 4.0.0-beta.52 → 4.0.0-beta.54

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 +28 -10
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.0.0-beta.52",
4
+ "version": "4.0.0-beta.54",
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
@@ -217,26 +217,44 @@ class MelCloud extends EventEmitter {
217
217
  }
218
218
 
219
219
  const devices = allDevices.map(device => {
220
- const settingsArray = device.Settings || device.settings || []; // obsługa różnych nazw
220
+ const settingsArray = device.Settings || device.settings || [];
221
221
 
222
- // Konwersja tablicy [{ name, value }] → { Name: Value }
222
+ // Konwersja tablicy [{ name, value }] → { Name: Value } z typami
223
223
  const settingsObject = Object.fromEntries(
224
- settingsArray.map(({ name, value }) => [
225
- name.charAt(0).toUpperCase() + name.slice(1),
226
- value
227
- ])
224
+ settingsArray.map(({ name, value }) => {
225
+ let parsedValue = value;
226
+
227
+ if (value === "True") parsedValue = true;
228
+ else if (value === "False") parsedValue = false;
229
+ else if (!isNaN(value) && value !== "") parsedValue = Number(value);
230
+
231
+ const key = name.charAt(0).toUpperCase() + name.slice(1);
232
+ return [key, parsedValue];
233
+ })
228
234
  );
229
235
 
236
+ // Scal Capabilities + Settings w Device
237
+ const deviceObject = {
238
+ ...Object.fromEntries(
239
+ Object.entries(device.Capabilities || {}).map(([key, value]) => [
240
+ key.charAt(0).toUpperCase() + key.slice(1),
241
+ value
242
+ ])
243
+ ),
244
+ ...settingsObject
245
+ };
246
+
247
+ // Usuń stare pola Settings i Capabilities
248
+ const { Settings, settings, Capabilities, ...rest } = device;
249
+
230
250
  return {
231
- ...device, // zachowuje wszystko z allDevices
251
+ ...rest,
232
252
  DeviceID: device.Id,
233
253
  DeviceName: device.GivenDisplayName,
234
- Settings: settingsObject,
235
- Device: device.Capabilities
254
+ Device: deviceObject
236
255
  };
237
256
  });
238
257
 
239
-
240
258
  await this.functions.saveData(this.devicesFile, devices);
241
259
  if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
242
260