homebridge-melcloud-control 4.2.3-beta.36 → 4.2.3-beta.37
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/melcloudhome.js +47 -31
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "4.2.3-beta.
|
|
4
|
+
"version": "4.2.3-beta.37",
|
|
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/melcloudhome.js
CHANGED
|
@@ -62,6 +62,51 @@ class MelCloud extends EventEmitter {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
// MELCloud Home
|
|
65
|
+
async checkScenesList() {
|
|
66
|
+
try {
|
|
67
|
+
if (this.logDebug) this.emit('debug', `Scanning for scenes`);
|
|
68
|
+
const listScenesData = await axios(ApiUrlsHome.GetUserScenes, {
|
|
69
|
+
method: 'GET',
|
|
70
|
+
baseURL: ApiUrlsHome.BaseURL,
|
|
71
|
+
timeout: 25000,
|
|
72
|
+
headers: this.headers
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const scenesList = listScenesData.data;
|
|
76
|
+
if (this.logDebug) this.emit('debug', `Scenes: ${JSON.stringify(scenesList, null, 2)}`);
|
|
77
|
+
|
|
78
|
+
const scenes = scenesList.flatMap(scene => {
|
|
79
|
+
const capitalizeKeysDeep = obj => {
|
|
80
|
+
if (Array.isArray(obj)) {
|
|
81
|
+
return obj.map(item => capitalizeKeysDeep(item));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (obj && typeof obj === 'object') {
|
|
85
|
+
return Object.fromEntries(
|
|
86
|
+
Object.entries(obj).map(([key, value]) => [
|
|
87
|
+
key.charAt(0).toUpperCase() + key.slice(1),
|
|
88
|
+
capitalizeKeysDeep(value)
|
|
89
|
+
])
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return obj;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const allSettings = [
|
|
97
|
+
...(scene.ataSceneSettings || []),
|
|
98
|
+
...(scene.ervSceneSettings || []),
|
|
99
|
+
...(scene.atwSceneSettings || [])
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
return allSettings.map(setting => capitalizeKeysDeep(setting));
|
|
103
|
+
});
|
|
104
|
+
return scenes;
|
|
105
|
+
} catch (error) {
|
|
106
|
+
throw new Error(`Check scenes list error: ${error.message}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
65
110
|
async checkDevicesList() {
|
|
66
111
|
try {
|
|
67
112
|
const devicesList = { State: false, Info: null, Devices: [], Scenes: [] }
|
|
@@ -77,9 +122,7 @@ class MelCloud extends EventEmitter {
|
|
|
77
122
|
const buildings = userContext.buildings ?? [];
|
|
78
123
|
const guestBuildings = userContext.guestBuildings ?? [];
|
|
79
124
|
const buildingsList = [...buildings, ...guestBuildings];
|
|
80
|
-
const scenesList = userContext.scenes;
|
|
81
125
|
if (this.logDebug) this.emit('debug', `Buildings: ${JSON.stringify(buildingsList, null, 2)}`);
|
|
82
|
-
if (this.logDebug) this.emit('debug', `Scenes: ${JSON.stringify(scenesList, null, 2)}`);
|
|
83
126
|
|
|
84
127
|
if (!buildingsList) {
|
|
85
128
|
devicesList.Info = 'No building found'
|
|
@@ -166,41 +209,14 @@ class MelCloud extends EventEmitter {
|
|
|
166
209
|
];
|
|
167
210
|
});
|
|
168
211
|
|
|
169
|
-
const scenes = scenesList.flatMap(scene => {
|
|
170
|
-
const capitalizeKeysDeep = obj => {
|
|
171
|
-
if (Array.isArray(obj)) {
|
|
172
|
-
return obj.map(item => capitalizeKeysDeep(item));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (obj && typeof obj === 'object') {
|
|
176
|
-
return Object.fromEntries(
|
|
177
|
-
Object.entries(obj).map(([key, value]) => [
|
|
178
|
-
key.charAt(0).toUpperCase() + key.slice(1),
|
|
179
|
-
capitalizeKeysDeep(value)
|
|
180
|
-
])
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return obj;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
// merge ATA + ATW arrays
|
|
188
|
-
const allSettings = [
|
|
189
|
-
...(scene.ataSceneSettings || []),
|
|
190
|
-
...(scene.ervSceneSettings || []),
|
|
191
|
-
...(scene.atwSceneSettings || [])
|
|
192
|
-
];
|
|
193
|
-
|
|
194
|
-
return allSettings.map(setting => capitalizeKeysDeep(setting));
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
|
|
198
212
|
const devicesCount = devices.length;
|
|
199
213
|
if (devicesCount === 0) {
|
|
200
214
|
devicesList.Info = 'No devices found'
|
|
201
215
|
return devicesList;
|
|
202
216
|
}
|
|
203
217
|
|
|
218
|
+
const scenes = this.checkScenesList();
|
|
219
|
+
|
|
204
220
|
devicesList.State = true;
|
|
205
221
|
devicesList.Info = `Found ${devicesCount} devices`;
|
|
206
222
|
devicesList.Devices = devices;
|