homebridge-melcloud-control 4.0.0-beta.55 → 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.
- package/package.json +1 -1
- package/src/melcloud.js +35 -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.
|
|
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
|
|
197
|
+
const devices = buildingsList.flatMap(building => {
|
|
198
198
|
const capitalizeKeys = obj =>
|
|
199
199
|
Object.fromEntries(
|
|
200
200
|
Object.entries(obj).map(([key, value]) => [
|
|
@@ -203,60 +203,48 @@ class MelCloud extends EventEmitter {
|
|
|
203
203
|
])
|
|
204
204
|
);
|
|
205
205
|
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
232
|
-
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
DeviceID: device.Id,
|
|
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
|
|
|
246
|
+
|
|
247
|
+
|
|
260
248
|
await this.functions.saveData(this.devicesFile, devices);
|
|
261
249
|
if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
|
|
262
250
|
|