homebridge-melcloud-control 4.2.3-beta.35 → 4.2.3-beta.36
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/constants.js +1 -1
- package/src/melcloudata.js +4 -12
- package/src/melcloudatw.js +2 -4
- package/src/melclouderv.js +3 -5
- package/src/melcloudhome.js +40 -4
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.36",
|
|
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/constants.js
CHANGED
|
@@ -36,7 +36,7 @@ export const ApiUrlsHome = {
|
|
|
36
36
|
PostHolidayMode: "https://melcloudhome.com/ata/deviceid/holidaymode",
|
|
37
37
|
PostProtectionFrost: "https://melcloudhome.com/ata/deviceid/frostprotection",
|
|
38
38
|
PostProtectionOverheat: "https://melcloudhome.com/ata/deviceid/overheatprotection",
|
|
39
|
-
|
|
39
|
+
PutDeviceSettings: "https://melcloudhome.com/dashboard",
|
|
40
40
|
PutScheduleEnabled: "https://melcloudhome.com/ata/deviceid/schedule",
|
|
41
41
|
},
|
|
42
42
|
Origin: "https://melcloudhome.com"
|
package/src/melcloudata.js
CHANGED
|
@@ -205,17 +205,10 @@ class MelCloudAta extends EventEmitter {
|
|
|
205
205
|
deviceData.Headers.Referer = ApiUrlsHome.Referers.PostProtectionOverheat.replace('deviceid', deviceData.DeviceID);
|
|
206
206
|
break;
|
|
207
207
|
case 'holidaymode':
|
|
208
|
-
const formatDateNoSeconds = (date) => {
|
|
209
|
-
const d = new Date(date);
|
|
210
|
-
const pad = (n) => n.toString().padStart(2, '0');
|
|
211
|
-
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
// przykład użycia
|
|
215
208
|
payload = {
|
|
216
209
|
enabled: deviceData.HolidayMode.Enabled,
|
|
217
|
-
startDate:
|
|
218
|
-
endDate:
|
|
210
|
+
startDate: deviceData.HolidayMode.StartDate,
|
|
211
|
+
endDate: deviceData.HolidayMode.EndDate,
|
|
219
212
|
units: { "ATA": [deviceData.DeviceID] }
|
|
220
213
|
};
|
|
221
214
|
method = 'POST';
|
|
@@ -226,7 +219,6 @@ class MelCloudAta extends EventEmitter {
|
|
|
226
219
|
payload = { enabled: deviceData.ScheduleEnabled };
|
|
227
220
|
method = 'PUT';
|
|
228
221
|
path = ApiUrlsHome.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
229
|
-
deviceData.Headers.Origin = ApiUrlsHome.Origin;
|
|
230
222
|
deviceData.Headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
231
223
|
break;
|
|
232
224
|
default:
|
|
@@ -240,7 +232,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
240
232
|
};
|
|
241
233
|
method = 'PUT';
|
|
242
234
|
path = ApiUrlsHome.PutAta.replace('deviceid', deviceData.DeviceID);
|
|
243
|
-
deviceData.Headers.Referer = ApiUrlsHome.Referers.
|
|
235
|
+
deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
|
|
244
236
|
break
|
|
245
237
|
}
|
|
246
238
|
|
|
@@ -271,7 +263,7 @@ class MelCloudAta extends EventEmitter {
|
|
|
271
263
|
|
|
272
264
|
setTimeout(() => {
|
|
273
265
|
this.lock = false
|
|
274
|
-
},
|
|
266
|
+
}, 2500);
|
|
275
267
|
}
|
|
276
268
|
};
|
|
277
269
|
export default MelCloudAta;
|
package/src/melcloudatw.js
CHANGED
|
@@ -185,14 +185,12 @@ class MelCloudAtw extends EventEmitter {
|
|
|
185
185
|
};
|
|
186
186
|
method = 'POST';
|
|
187
187
|
path = ApiUrlsHome.PostHolidayMode;
|
|
188
|
-
deviceData.Headers.Origin = ApiUrlsHome.Origin;
|
|
189
188
|
deviceData.Headers.Referer = ApiUrlsHome.Referers.PostHolidayMode.replace('deviceid', deviceData.DeviceID);
|
|
190
189
|
break;
|
|
191
190
|
case 'schedule':
|
|
192
191
|
payload = { enabled: deviceData.ScheduleEnabled };
|
|
193
192
|
method = 'PUT';
|
|
194
193
|
path = ApiUrlsHome.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
195
|
-
deviceData.Headers.Origin = ApiUrlsHome.Origin;
|
|
196
194
|
deviceData.Headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
197
195
|
break;
|
|
198
196
|
default:
|
|
@@ -213,7 +211,7 @@ class MelCloudAtw extends EventEmitter {
|
|
|
213
211
|
};
|
|
214
212
|
method = 'PUT';
|
|
215
213
|
path = ApiUrlsHome.PutAtw.replace('deviceid', deviceData.DeviceID);
|
|
216
|
-
deviceData.Headers.Referer = ApiUrlsHome.Referers.
|
|
214
|
+
deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
|
|
217
215
|
break
|
|
218
216
|
}
|
|
219
217
|
|
|
@@ -244,7 +242,7 @@ class MelCloudAtw extends EventEmitter {
|
|
|
244
242
|
|
|
245
243
|
setTimeout(() => {
|
|
246
244
|
this.lock = false
|
|
247
|
-
},
|
|
245
|
+
}, 2500);
|
|
248
246
|
}
|
|
249
247
|
};
|
|
250
248
|
export default MelCloudAtw;
|
package/src/melclouderv.js
CHANGED
|
@@ -195,18 +195,16 @@ class MelCloudErv extends EventEmitter {
|
|
|
195
195
|
enabled: deviceData.HolidayMode.Enabled,
|
|
196
196
|
startDate: deviceData.HolidayMode.StartDate,
|
|
197
197
|
endDate: deviceData.HolidayMode.EndDate,
|
|
198
|
-
units: { "
|
|
198
|
+
units: { "ERV": [deviceData.DeviceID] }
|
|
199
199
|
};
|
|
200
200
|
method = 'POST';
|
|
201
201
|
path = ApiUrlsHome.PostHolidayMode;
|
|
202
|
-
deviceData.Headers.Origin = ApiUrlsHome.Origin;
|
|
203
202
|
deviceData.Headers.Referer = ApiUrlsHome.Referers.PostHolidayMode.replace('deviceid', deviceData.DeviceID);
|
|
204
203
|
break;
|
|
205
204
|
case 'schedule':
|
|
206
205
|
payload = { enabled: deviceData.ScheduleEnabled };
|
|
207
206
|
method = 'PUT';
|
|
208
207
|
path = ApiUrlsHome.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
209
|
-
deviceData.Headers.Origin = ApiUrlsHome.Origin;
|
|
210
208
|
deviceData.Headers.Referer = ApiUrlsHome.Referers.PutScheduleEnabled.replace('deviceid', deviceData.DeviceID);
|
|
211
209
|
break;
|
|
212
210
|
default:
|
|
@@ -219,7 +217,7 @@ class MelCloudErv extends EventEmitter {
|
|
|
219
217
|
};
|
|
220
218
|
method = 'PUT';
|
|
221
219
|
path = ApiUrlsHome.PutErv.replace('deviceid', deviceData.DeviceID);
|
|
222
|
-
deviceData.Headers.Referer = ApiUrlsHome.Referers.
|
|
220
|
+
deviceData.Headers.Referer = ApiUrlsHome.Referers.PutDeviceSettings
|
|
223
221
|
break
|
|
224
222
|
}
|
|
225
223
|
|
|
@@ -250,7 +248,7 @@ class MelCloudErv extends EventEmitter {
|
|
|
250
248
|
|
|
251
249
|
setTimeout(() => {
|
|
252
250
|
this.lock = false
|
|
253
|
-
},
|
|
251
|
+
}, 2500);
|
|
254
252
|
}
|
|
255
253
|
};
|
|
256
254
|
export default MelCloudErv;
|
package/src/melcloudhome.js
CHANGED
|
@@ -64,7 +64,7 @@ class MelCloud extends EventEmitter {
|
|
|
64
64
|
// MELCloud Home
|
|
65
65
|
async checkDevicesList() {
|
|
66
66
|
try {
|
|
67
|
-
const devicesList = { State: false, Info: null, Devices: [] }
|
|
67
|
+
const devicesList = { State: false, Info: null, Devices: [], Scenes: [] }
|
|
68
68
|
if (this.logDebug) this.emit('debug', `Scanning for devices`);
|
|
69
69
|
const listDevicesData = await axios(ApiUrlsHome.GetUserContext, {
|
|
70
70
|
method: 'GET',
|
|
@@ -72,15 +72,21 @@ class MelCloud extends EventEmitter {
|
|
|
72
72
|
timeout: 25000,
|
|
73
73
|
headers: this.headers
|
|
74
74
|
});
|
|
75
|
-
|
|
75
|
+
|
|
76
|
+
const userContext = listDevicesData.data;
|
|
77
|
+
const buildings = userContext.buildings ?? [];
|
|
78
|
+
const guestBuildings = userContext.guestBuildings ?? [];
|
|
79
|
+
const buildingsList = [...buildings, ...guestBuildings];
|
|
80
|
+
const scenesList = userContext.scenes;
|
|
76
81
|
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)}`);
|
|
77
83
|
|
|
78
84
|
if (!buildingsList) {
|
|
79
85
|
devicesList.Info = 'No building found'
|
|
80
86
|
return devicesList;
|
|
81
87
|
}
|
|
82
88
|
|
|
83
|
-
await this.functions.saveData(this.buildingsFile,
|
|
89
|
+
await this.functions.saveData(this.buildingsFile, userContext);
|
|
84
90
|
if (this.logDebug) this.emit('debug', `Buildings list saved`);
|
|
85
91
|
|
|
86
92
|
const devices = buildingsList.flatMap(building => {
|
|
@@ -137,7 +143,7 @@ class MelCloud extends EventEmitter {
|
|
|
137
143
|
if (device.FrostProtection) device.FrostProtection = { ...capitalizeKeys(device.FrostProtection || {}) };
|
|
138
144
|
if (device.OverheatProtection) device.OverheatProtection = { ...capitalizeKeys(device.OverheatProtection || {}) };
|
|
139
145
|
if (device.HolidayMode) device.HolidayMode = { ...capitalizeKeys(device.HolidayMode || {}) };
|
|
140
|
-
if (Array.isArray(device.Schedule)) device.Schedule = device.Schedule.map(capitalizeKeysDeep);
|
|
146
|
+
if (Array.isArray(device.Schedule)) device.Schedule = device.Schedule.map(capitalizeKeysDeep || []);
|
|
141
147
|
|
|
142
148
|
// Usuń stare pola Settings i Capabilities
|
|
143
149
|
const { Settings, Capabilities, Id, GivenDisplayName, ...rest } = device;
|
|
@@ -160,6 +166,35 @@ class MelCloud extends EventEmitter {
|
|
|
160
166
|
];
|
|
161
167
|
});
|
|
162
168
|
|
|
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
|
+
|
|
163
198
|
const devicesCount = devices.length;
|
|
164
199
|
if (devicesCount === 0) {
|
|
165
200
|
devicesList.Info = 'No devices found'
|
|
@@ -169,6 +204,7 @@ class MelCloud extends EventEmitter {
|
|
|
169
204
|
devicesList.State = true;
|
|
170
205
|
devicesList.Info = `Found ${devicesCount} devices`;
|
|
171
206
|
devicesList.Devices = devices;
|
|
207
|
+
devicesList.Scenes = scenes;
|
|
172
208
|
|
|
173
209
|
await this.functions.saveData(this.devicesFile, devicesList);
|
|
174
210
|
if (this.logDebug) this.emit('debug', `${devicesCount} devices saved`);
|