homebridge-melcloud-control 4.0.0-beta.56 → 4.0.0-beta.57

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 +34 -47
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.56",
4
+ "version": "4.0.0-beta.57",
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
@@ -194,7 +194,7 @@ class MelCloud extends EventEmitter {
194
194
  await this.functions.saveData(this.buildingsFile, buildingsList);
195
195
  if (this.logDebug) this.emit('debug', `Buildings list saved`);
196
196
 
197
- const allDevices = buildingsList.flatMap(building => {
197
+ const devices = buildingsList.flatMap(building => {
198
198
  const capitalizeKeys = obj =>
199
199
  Object.fromEntries(
200
200
  Object.entries(obj).map(([key, value]) => [
@@ -203,61 +203,48 @@ class MelCloud extends EventEmitter {
203
203
  ])
204
204
  );
205
205
 
206
- return [
207
- ...(building.airToAirUnits || []).map(device => ({ ...capitalizeKeys(device), Type: 0 })),
208
- ...(building.airToWaterUnits || []).map(device => ({ ...capitalizeKeys(device), Type: 1 })),
209
- ...(building.airToVentilationUnits || []).map(device => ({ ...capitalizeKeys(device), Type: 3 }))
210
- ];
211
- });
212
-
213
- const devicesCount = allDevices.length;
214
- if (devicesCount === 0) {
215
- if (this.logWarn) this.emit('warn', `No devices found`);
216
- return null;
217
- }
218
-
219
- const devices = allDevices.map(device => {
220
- const settingsArray = device.Settings || device.settings || [];
221
-
222
- // Konwersja tablicy [{ name, value }] → { Name: Value } z poprawnym typem
223
- const settingsObject = Object.fromEntries(
224
- settingsArray.map(({ name, value }) => {
225
- let parsedValue = value;
206
+ const createDevice = (device, type) => {
207
+ const settingsArray = device.Settings || device.settings || [];
226
208
 
227
- if (value === "True") parsedValue = true;
228
- else if (value === "False") parsedValue = false;
229
- else if (!isNaN(value) && value !== "") parsedValue = Number(value);
209
+ const settingsObject = Object.fromEntries(
210
+ settingsArray.map(({ name, value }) => {
211
+ let parsedValue = value;
212
+ if (value === "True") parsedValue = true;
213
+ else if (value === "False") parsedValue = false;
214
+ else if (!isNaN(value) && value !== "") parsedValue = Number(value);
230
215
 
231
- const key = name.charAt(0).toUpperCase() + name.slice(1);
232
- return [key, parsedValue];
233
- })
234
- );
216
+ // W tym miejscu nie musimy już kapitalizować, bo w allDevices klucze są z dużej litery
217
+ return [name, parsedValue];
218
+ })
219
+ );
235
220
 
236
- // Scal Capabilities + Settings w Device + dodaj DeviceType
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
- DeviceType: device.Type
221
+ // Device = Capabilities + Settings + DeviceType
222
+ const deviceObject = {
223
+ ...device.Capabilities, // już kapitalizowane w allDevices
224
+ ...settingsObject,
225
+ DeviceType: type
226
+ };
227
+
228
+ const { Settings, settings, Capabilities, Id, GivenDisplayName, ...rest } = device;
229
+
230
+ return {
231
+ ...rest,
232
+ DeviceID: Id,
233
+ DeviceName: GivenDisplayName,
234
+ Device: deviceObject
235
+ };
246
236
  };
247
237
 
248
- // Usuń stare pola Settings i Capabilities
249
- const { Settings, settings, Capabilities, Id, ...rest } = device;
250
-
251
- return {
252
- ...rest,
253
- DeviceID: Id, // <-- zmiana na DeviceID
254
- DeviceName: device.GivenDisplayName,
255
- Device: deviceObject
256
- };
238
+ return [
239
+ ...(building.airToAirUnits || []).map(d => createDevice(capitalizeKeys(d), 0)),
240
+ ...(building.airToWaterUnits || []).map(d => createDevice(capitalizeKeys(d), 1)),
241
+ ...(building.airToVentilationUnits || []).map(d => createDevice(capitalizeKeys(d), 3))
242
+ ];
257
243
  });
258
244
 
259
245
 
260
246
 
247
+
261
248
  await this.functions.saveData(this.devicesFile, devices);
262
249
  if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
263
250