homebridge-melcloud-control 4.0.0-beta.354 → 4.0.0-beta.355
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/melcloudhometoken.js +22 -53
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.355",
|
|
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/melcloudhometoken.js
CHANGED
|
@@ -111,81 +111,50 @@ class MelCloudHomeToken extends EventEmitter {
|
|
|
111
111
|
|
|
112
112
|
async loginToMelCloudHome(url) {
|
|
113
113
|
try {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
'Accept': 'text/html',
|
|
119
|
-
},
|
|
120
|
-
withCredentials: true,
|
|
114
|
+
|
|
115
|
+
// --- Krok 1: GET strony logowania ---
|
|
116
|
+
const getResp = await this.client.get(url, {
|
|
117
|
+
headers: { 'User-Agent': MOBILE_USER_AGENT }
|
|
121
118
|
});
|
|
122
119
|
|
|
123
|
-
const cookies = getResp.headers['set-cookie'] || [];
|
|
124
120
|
const dom = new JSDOM(getResp.data);
|
|
125
|
-
const csrf = dom.window.document.querySelector('input[name="_csrf"]')?.value;
|
|
126
|
-
if (!csrf)
|
|
127
|
-
if (this.logWarn) this.emit('warn', `CSRF token not found`);
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
121
|
+
const csrf = dom.window.document.querySelector('input[name="_csrf"]')?.getAttribute('value');
|
|
122
|
+
if (!csrf) throw new Error('CSRF token not found');
|
|
130
123
|
|
|
131
|
-
//
|
|
124
|
+
// --- Krok 2: POST login ---
|
|
132
125
|
const formData = new URLSearchParams({
|
|
133
126
|
_csrf: csrf,
|
|
134
127
|
username: this.user,
|
|
135
|
-
password: this.passwd
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
if (this.logWarn) this.emit('warn', `Redirect URL: ${url}`);
|
|
128
|
+
password: this.passwd
|
|
129
|
+
}).toString();
|
|
139
130
|
|
|
140
|
-
|
|
141
|
-
const response = await axios.post(url, formData.toString(), {
|
|
131
|
+
const postResp = await this.client.post(url, formData, {
|
|
142
132
|
headers: {
|
|
143
133
|
'User-Agent': MOBILE_USER_AGENT,
|
|
144
|
-
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
|
145
|
-
'Accept-Language': 'en-US,en;q=0.9',
|
|
146
134
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
147
|
-
'Content-Length': formData.toString().length,
|
|
148
|
-
'Cookie': cookies,
|
|
149
135
|
'Origin': 'https://live-melcloudhome.auth.eu-west-1.amazoncognito.com',
|
|
150
136
|
'Referer': url,
|
|
151
137
|
},
|
|
152
138
|
maxRedirects: 0,
|
|
153
|
-
validateStatus: status => [200, 302, 400].includes(status)
|
|
139
|
+
validateStatus: status => [200, 302, 400].includes(status)
|
|
154
140
|
});
|
|
155
141
|
|
|
142
|
+
if (postResp.status === 400) throw new Error('Login failed');
|
|
156
143
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const getResp = await axios.get('https://melcloudhome.com/dashboard', {
|
|
163
|
-
headers: {
|
|
164
|
-
'User-Agent': MOBILE_USER_AGENT,
|
|
165
|
-
'Accept': 'text/html',
|
|
166
|
-
},
|
|
167
|
-
withCredentials: true,
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// --- Krok 3: GET dashboard po zalogowaniu ---
|
|
171
|
-
const dashboardResp = await axios.get('https://melcloudhome.com/dashboard', {
|
|
172
|
-
headers: { 'User-Agent': MOBILE_USER_AGENT }
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
// --- Krok 4: Pobierz cookies z dashboard ---
|
|
176
|
-
const dashboardCookies = await jar.getCookies('https://melcloudhome.com/dashboard');
|
|
177
|
-
// Możemy zwrócić jako string do użycia w nagłówku:
|
|
178
|
-
const cookieHeader = dashboardCookies.map(c => `${c.key}=${c.value}`).join('; ');
|
|
144
|
+
// --- Krok 3: GET dashboard po zalogowaniu ---
|
|
145
|
+
const dashboardResp = await this.client.get('https://melcloudhome.com/dashboard', {
|
|
146
|
+
headers: { 'User-Agent': MOBILE_USER_AGENT }
|
|
147
|
+
});
|
|
179
148
|
|
|
180
|
-
|
|
149
|
+
// --- Krok 4: Pobierz cookies z dashboard ---
|
|
150
|
+
const dashboardCookies = await jar.getCookies('https://melcloudhome.com/dashboard');
|
|
151
|
+
// Możemy zwrócić jako string do użycia w nagłówku:
|
|
152
|
+
const cookieHeader = dashboardCookies.map(c => `${c.key}=${c.value}`).join('; ');
|
|
181
153
|
|
|
182
|
-
|
|
183
|
-
return cookies
|
|
184
|
-
}
|
|
154
|
+
this.emit('debug', `Cookies ${cookieHeader}`);
|
|
185
155
|
|
|
186
|
-
|
|
156
|
+
return dashboardCookies.map(c => `${c.key}=${c.value}`);
|
|
187
157
|
|
|
188
|
-
return null;
|
|
189
158
|
} catch (error) {
|
|
190
159
|
throw new Error(`Login to MELCloud Home error: ${error}`);
|
|
191
160
|
}
|