homebridge-melcloud-control 4.0.0-beta.29 → 4.0.0-beta.30
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/index.js +1 -5
- package/package.json +1 -1
- package/src/melcloud.js +19 -47
package/index.js
CHANGED
|
@@ -95,14 +95,10 @@ class MelCloudPlatform {
|
|
|
95
95
|
.on('warn', (msg) => logLevel.warn && log.warn(`${accountName}, ${msg}`))
|
|
96
96
|
.on('error', (msg) => logLevel.error && log.error(`${accountName}, ${msg}`));
|
|
97
97
|
|
|
98
|
-
await melCloud.connectHomeCookies();
|
|
99
|
-
return;
|
|
100
|
-
|
|
101
|
-
|
|
102
98
|
//connect
|
|
103
99
|
let response;
|
|
104
100
|
try {
|
|
105
|
-
response = await melCloud.connect();
|
|
101
|
+
response = await melCloud.connect('home');
|
|
106
102
|
} catch (error) {
|
|
107
103
|
if (logLevel.error) log.error(`${accountName}, Connect error: ${error.message ?? error}`);
|
|
108
104
|
return;
|
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.30",
|
|
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
|
@@ -109,7 +109,7 @@ class MelCloud extends EventEmitter {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
async
|
|
112
|
+
async connectMelCloud() {
|
|
113
113
|
if (this.logDebug) this.emit('debug', `Connecting to MELCloud`);
|
|
114
114
|
|
|
115
115
|
try {
|
|
@@ -166,14 +166,15 @@ class MelCloud extends EventEmitter {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
async
|
|
169
|
+
async connectMelCloudHome() {
|
|
170
170
|
if (this.logDebug) this.emit('debug', `Connecting to MELCloud Home`);
|
|
171
171
|
|
|
172
172
|
try {
|
|
173
|
-
const
|
|
174
|
-
const
|
|
173
|
+
const coocies = await this.getCookies();
|
|
174
|
+
const c1 = coocies.C1.trim();
|
|
175
|
+
const c2 = coocies.C2.trim();
|
|
175
176
|
|
|
176
|
-
const
|
|
177
|
+
const cookies = [
|
|
177
178
|
'__Secure-monitorandcontrol=chunks-2',
|
|
178
179
|
`__Secure-monitorandcontrolC1=${c1}`,
|
|
179
180
|
`__Secure-monitorandcontrolC2=${c2}`,
|
|
@@ -189,7 +190,7 @@ class MelCloud extends EventEmitter {
|
|
|
189
190
|
headers: {
|
|
190
191
|
'Accept': '*/*',
|
|
191
192
|
'Accept-Language': 'en-US,en;q=0.9',
|
|
192
|
-
'Cookie':
|
|
193
|
+
'Cookie': cookies,
|
|
193
194
|
'User-Agent': 'homebridge-melcloud-home/0.2.0',
|
|
194
195
|
'DNT': '1',
|
|
195
196
|
'Origin': 'https://melcloudhome.com',
|
|
@@ -203,7 +204,7 @@ class MelCloud extends EventEmitter {
|
|
|
203
204
|
|
|
204
205
|
const response = await axiosInstance.get(ApiUrlsHome.GetUserContext);
|
|
205
206
|
const homeData = response.data;
|
|
206
|
-
if (this.logDebug) this.emit('debug', `
|
|
207
|
+
if (this.logDebug) this.emit('debug', `MELCloud Home data: ${JSON.stringify(homeData, null, 2)}`);
|
|
207
208
|
|
|
208
209
|
this.emit('success', `Connect to MELCloud Home Success`);
|
|
209
210
|
|
|
@@ -213,48 +214,13 @@ class MelCloud extends EventEmitter {
|
|
|
213
214
|
}
|
|
214
215
|
}
|
|
215
216
|
|
|
216
|
-
async
|
|
217
|
-
try {
|
|
218
|
-
const form = new URLSearchParams();
|
|
219
|
-
form.append('user[email]', this.user);
|
|
220
|
-
form.append('user[password]', this.passwd);
|
|
221
|
-
|
|
222
|
-
const response = await axios({
|
|
223
|
-
method: 'POST',
|
|
224
|
-
baseURL: EnphaseUrls.BaseUrl,
|
|
225
|
-
url: EnphaseUrls.Login,
|
|
226
|
-
headers: {
|
|
227
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
228
|
-
},
|
|
229
|
-
data: form,
|
|
230
|
-
timeout: 10000
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
if (response.status !== 200) {
|
|
234
|
-
if (this.logError) this.emit('error', `Login failed with status code: ${response.status}`);
|
|
235
|
-
return null;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const cookie = response.headers['set-cookie'];
|
|
239
|
-
if (!cookie) {
|
|
240
|
-
if (this.logWarn) this.emit('warn', `No cookie returned from login. Response headers: ${JSON.stringify(response.headers)}`);
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return cookie;
|
|
245
|
-
} catch (error) {
|
|
246
|
-
throw new Error(`Login to Enlighten error: ${error}`);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
async connectHomeCookies() {
|
|
251
|
-
const loginUrl = 'https://melcloudhome.com';
|
|
217
|
+
async getCookies() {
|
|
252
218
|
const browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] });
|
|
253
219
|
const page = await browser.newPage();
|
|
254
220
|
|
|
255
221
|
try {
|
|
256
222
|
this.emit('warn', 'Opening login page...');
|
|
257
|
-
await page.goto(
|
|
223
|
+
await page.goto(ApiUrlsHome.BaseURL, { waitUntil: 'networkidle2' });
|
|
258
224
|
|
|
259
225
|
// Kliknij przycisk logowania
|
|
260
226
|
const buttons = await page.$$('button.btn--blue');
|
|
@@ -301,7 +267,7 @@ class MelCloud extends EventEmitter {
|
|
|
301
267
|
|
|
302
268
|
if (!c1 || !c2) {
|
|
303
269
|
await browser.close();
|
|
304
|
-
throw new Error('
|
|
270
|
+
throw new Error('Cookies C1/C2 not found after login');
|
|
305
271
|
}
|
|
306
272
|
|
|
307
273
|
// Zapis do pliku
|
|
@@ -310,7 +276,6 @@ class MelCloud extends EventEmitter {
|
|
|
310
276
|
|
|
311
277
|
this.emit('warn', 'Login successful.');
|
|
312
278
|
return data;
|
|
313
|
-
|
|
314
279
|
} catch (err) {
|
|
315
280
|
this.emit('error', `Login failed: ${err.message}`);
|
|
316
281
|
return null;
|
|
@@ -319,7 +284,14 @@ class MelCloud extends EventEmitter {
|
|
|
319
284
|
}
|
|
320
285
|
}
|
|
321
286
|
|
|
322
|
-
|
|
287
|
+
async connect(mode) {
|
|
288
|
+
switch (mode) {
|
|
289
|
+
case 'home':
|
|
290
|
+
return await this.connectMelCloudHome();
|
|
291
|
+
default:
|
|
292
|
+
return await this.connectMelCloud();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
323
295
|
|
|
324
296
|
async send(accountInfo) {
|
|
325
297
|
try {
|