homebridge-melcloud-control 4.0.0-beta.49 → 4.0.0-beta.50

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 +20 -29
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.49",
4
+ "version": "4.0.0-beta.50",
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,26 +194,19 @@ 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 => [
198
- ...(building.airToAirUnits || []).map(device => ({
199
- ...Object.fromEntries(
200
- Object.entries(device).map(([key, value]) => [key.charAt(0).toUpperCase() + key.slice(1), value])
201
- ),
202
- Type: 0
203
- })),
204
- ...(building.airToWaterUnits || []).map(device => ({
205
- ...Object.fromEntries(
206
- Object.entries(device).map(([key, value]) => [key.charAt(0).toUpperCase() + key.slice(1), value])
207
- ),
208
- Type: 1
209
- })),
210
- ...(building.airToVentilationUnits || []).map(device => ({
211
- ...Object.fromEntries(
212
- Object.entries(device).map(([key, value]) => [key.charAt(0).toUpperCase() + key.slice(1), value])
213
- ),
214
- Type: 3
215
- }))
216
- ]);
197
+ const allDevices = buildingsList.flatMap(building => {
198
+ const capitalizeKeys = obj =>
199
+ Object.fromEntries(Object.entries(obj).map(([key, value]) => [
200
+ key.charAt(0).toUpperCase() + key.slice(1),
201
+ value
202
+ ]));
203
+
204
+ return [
205
+ ...(building.airToAirUnits || []).map(device => ({ ...capitalizeKeys(device), Type: 0 })),
206
+ ...(building.airToWaterUnits || []).map(device => ({ ...capitalizeKeys(device), Type: 1 })),
207
+ ...(building.airToVentilationUnits || []).map(device => ({ ...capitalizeKeys(device), Type: 3 }))
208
+ ];
209
+ });
217
210
 
218
211
  const devicesCount = allDevices.length;
219
212
  if (devicesCount === 0) {
@@ -221,15 +214,13 @@ class MelCloud extends EventEmitter {
221
214
  return null;
222
215
  }
223
216
 
224
- const devices = [];
225
- for (const device of allDevices) {
226
- devices.push({
227
- DeviceID: device.Id,
228
- DeviceName: device.GivenDisplayName,
229
- Settings: Object.fromEntries(device.Settings.map(({ Name, Value }) => [Name, Value])),
230
- Device: device.Capabilities
231
- });
232
- }
217
+ const devices = allDevices.map(device => ({
218
+ DeviceID: device.Id,
219
+ DeviceName: device.GivenDisplayName,
220
+ Settings: Object.fromEntries((device.Settings || []).map(({ Name, Value }) => [Name, Value])),
221
+ Device: device.Capabilities,
222
+ Type: device.Type
223
+ }));
233
224
 
234
225
  await this.functions.saveData(this.devicesFile, devices);
235
226
  if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);