homebridge-melcloud-control 4.0.0-beta.58 → 4.0.0-beta.59
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 +17 -5
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.59",
|
|
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
|
@@ -195,6 +195,7 @@ class MelCloud extends EventEmitter {
|
|
|
195
195
|
if (this.logDebug) this.emit('debug', `Buildings list saved`);
|
|
196
196
|
|
|
197
197
|
const devices = buildingsList.flatMap(building => {
|
|
198
|
+
// Funkcja kapitalizująca klucze obiektu
|
|
198
199
|
const capitalizeKeys = obj =>
|
|
199
200
|
Object.fromEntries(
|
|
200
201
|
Object.entries(obj).map(([key, value]) => [
|
|
@@ -203,9 +204,12 @@ class MelCloud extends EventEmitter {
|
|
|
203
204
|
])
|
|
204
205
|
);
|
|
205
206
|
|
|
207
|
+
// Funkcja tworząca finalny obiekt Device
|
|
206
208
|
const createDevice = (device, type) => {
|
|
209
|
+
// Upewniamy się, że Settings jest tablicą
|
|
207
210
|
const settingsArray = device.Settings || [];
|
|
208
211
|
|
|
212
|
+
// Zamiana settings na obiekt z poprawnymi typami
|
|
209
213
|
const settingsObject = Object.fromEntries(
|
|
210
214
|
settingsArray.map(({ name, value }) => {
|
|
211
215
|
let parsedValue = value;
|
|
@@ -213,19 +217,20 @@ class MelCloud extends EventEmitter {
|
|
|
213
217
|
else if (value === "False") parsedValue = false;
|
|
214
218
|
else if (!isNaN(value) && value !== "") parsedValue = Number(value);
|
|
215
219
|
|
|
216
|
-
|
|
217
|
-
return [
|
|
220
|
+
const key = name.charAt(0).toUpperCase() + name.slice(1);
|
|
221
|
+
return [key, parsedValue];
|
|
218
222
|
})
|
|
219
223
|
);
|
|
220
224
|
|
|
221
|
-
//
|
|
225
|
+
// Scal Capabilities + Settings + DeviceType w Device, kapitalizując Capabilities
|
|
222
226
|
const deviceObject = {
|
|
223
|
-
...device.Capabilities
|
|
227
|
+
...capitalizeKeys(device.Capabilities || {}),
|
|
224
228
|
...settingsObject,
|
|
225
229
|
DeviceType: type
|
|
226
230
|
};
|
|
227
231
|
|
|
228
|
-
|
|
232
|
+
// Usuń stare pola Settings i Capabilities
|
|
233
|
+
const { Settings, Capabilities, Id, GivenDisplayName, ...rest } = device;
|
|
229
234
|
|
|
230
235
|
return {
|
|
231
236
|
...rest,
|
|
@@ -242,6 +247,13 @@ class MelCloud extends EventEmitter {
|
|
|
242
247
|
];
|
|
243
248
|
});
|
|
244
249
|
|
|
250
|
+
// Jeśli nie ma urządzeń
|
|
251
|
+
if (devices.length === 0) {
|
|
252
|
+
if (this.logWarn) this.emit('warn', `No devices found`);
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
|
|
245
257
|
await this.functions.saveData(this.devicesFile, devices);
|
|
246
258
|
if (this.logDebug) this.emit('debug', `${devices.length} devices saved`);
|
|
247
259
|
|