homebridge-melcloud-control 4.0.0-beta.51 → 4.0.0-beta.53

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 -11
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.51",
4
+ "version": "4.0.0-beta.53",
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
@@ -196,10 +196,12 @@ class MelCloud extends EventEmitter {
196
196
 
197
197
  const allDevices = buildingsList.flatMap(building => {
198
198
  const capitalizeKeys = obj =>
199
- Object.fromEntries(Object.entries(obj).map(([key, value]) => [
200
- key.charAt(0).toUpperCase() + key.slice(1),
201
- value
202
- ]));
199
+ Object.fromEntries(
200
+ Object.entries(obj).map(([key, value]) => [
201
+ key.charAt(0).toUpperCase() + key.slice(1),
202
+ value
203
+ ])
204
+ );
203
205
 
204
206
  return [
205
207
  ...(building.airToAirUnits || []).map(device => ({ ...capitalizeKeys(device), Type: 0 })),
@@ -214,13 +216,46 @@ class MelCloud extends EventEmitter {
214
216
  return null;
215
217
  }
216
218
 
217
- const devices = allDevices.map(device => ({
218
- ...device, // zachowuje wszystkie pola z allDevices
219
- DeviceID: device.Id,
220
- DeviceName: device.GivenDisplayName,
221
- Settings: Object.fromEntries((device.Settings || []).map(({ Name, Value }) => [Name, Value])),
222
- Device: device.Capabilities
223
- }));
219
+ const devices = allDevices.map(device => {
220
+ const settingsArray = device.Settings || device.settings || [];
221
+
222
+ // Konwersja tablicy [{ name, value }] → { Name: Value }
223
+ const settingsObject = Object.fromEntries(
224
+ settingsArray.map(({ name, value }) => {
225
+ let parsedValue = value;
226
+
227
+ // Zamiana boolean stringów
228
+ if (value === "True") parsedValue = true;
229
+ else if (value === "False") parsedValue = false;
230
+ // Zamiana na number, jeśli da się sparsować
231
+ else if (!isNaN(value) && value !== "") parsedValue = Number(value);
232
+
233
+ // Kapitalizacja klucza
234
+ const key = name.charAt(0).toUpperCase() + name.slice(1);
235
+ return [key, parsedValue];
236
+ })
237
+ );
238
+
239
+ // Scal Capabilities i Settings w Device
240
+ const deviceObject = {
241
+ ...Object.fromEntries(
242
+ Object.entries(device.Capabilities || {}).map(([key, value]) => [
243
+ key.charAt(0).toUpperCase() + key.slice(1),
244
+ value
245
+ ])
246
+ ),
247
+ ...settingsObject
248
+ };
249
+
250
+ return {
251
+ ...device,
252
+ DeviceID: device.Id,
253
+ DeviceName: device.GivenDisplayName,
254
+ Device: deviceObject
255
+ };
256
+ });
257
+
258
+
224
259
 
225
260
  await this.functions.saveData(this.devicesFile, devices);
226
261
  if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);