homebridge-melcloud-control 4.0.0-beta.401 → 4.0.0-beta.403
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 +10 -0
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.403",
|
|
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
|
@@ -4,6 +4,11 @@ import { CookieJar } from 'tough-cookie';
|
|
|
4
4
|
import { wrapper } from 'axios-cookiejar-support';
|
|
5
5
|
import EventEmitter from 'events';
|
|
6
6
|
|
|
7
|
+
const MOBILE_USER_AGENT = 'MonitorAndControl.App.Mobile/35 CFNetwork/3860.100.1 Darwin/25.0.0';
|
|
8
|
+
const CLIENT_ID = 'homemobile';
|
|
9
|
+
const REDIRECT_URI = 'melcloudhome://';
|
|
10
|
+
const SCOPE = 'openid profile';
|
|
11
|
+
|
|
7
12
|
class MelCloudHomeToken extends EventEmitter {
|
|
8
13
|
constructor() {
|
|
9
14
|
super();
|
|
@@ -111,6 +116,7 @@ class MelCloudHomeToken extends EventEmitter {
|
|
|
111
116
|
validateStatus: () => true,
|
|
112
117
|
maxRedirects: 0,
|
|
113
118
|
responseType: 'text',
|
|
119
|
+
transformResponse: [(data) => data], // <— force raw string
|
|
114
120
|
});
|
|
115
121
|
if (resp.headers['set-cookie']) {
|
|
116
122
|
await this.cookieJar.setCookie(resp.headers['set-cookie'].join('; '), url);
|
|
@@ -131,6 +137,7 @@ class MelCloudHomeToken extends EventEmitter {
|
|
|
131
137
|
validateStatus: () => true,
|
|
132
138
|
maxRedirects: 0,
|
|
133
139
|
responseType: 'text',
|
|
140
|
+
transformResponse: [(data) => data], // <— force raw string
|
|
134
141
|
});
|
|
135
142
|
if (resp.headers['set-cookie']) {
|
|
136
143
|
await this.cookieJar.setCookie(resp.headers['set-cookie'].join('; '), url);
|
|
@@ -138,12 +145,15 @@ class MelCloudHomeToken extends EventEmitter {
|
|
|
138
145
|
return resp;
|
|
139
146
|
}
|
|
140
147
|
|
|
148
|
+
|
|
141
149
|
_extractCsrf(html) {
|
|
150
|
+
if (typeof html !== 'string') return null;
|
|
142
151
|
const match = html.match(/name="_csrf" value="([^"]+)"/);
|
|
143
152
|
return match ? match[1] : null;
|
|
144
153
|
}
|
|
145
154
|
|
|
146
155
|
_extractAuthCode(html) {
|
|
156
|
+
if (typeof html !== 'string') return null;
|
|
147
157
|
const urlMatch = html.match(/[?&]code=([^&]+)/);
|
|
148
158
|
if (urlMatch) return urlMatch[1];
|
|
149
159
|
const formMatch = html.match(/name="code"\s+value="([^"]+)"/);
|