homebridge-melcloud-control 4.0.0-beta.383 → 4.0.0-beta.385
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/melcloud.js +3 -6
- package/src/melcloudhometoken.js +10 -5
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.385",
|
|
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
|
@@ -277,7 +277,7 @@ class MelCloud extends EventEmitter {
|
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
async
|
|
280
|
+
async connectToMelCloudHome() {
|
|
281
281
|
try {
|
|
282
282
|
const melCloudHomeToken = new MelCloudHomeToken({
|
|
283
283
|
user: this.user,
|
|
@@ -289,10 +289,7 @@ class MelCloud extends EventEmitter {
|
|
|
289
289
|
.on('warn', warn => this.emit('warn', warn))
|
|
290
290
|
.on('error', error => this.emit('error', error));
|
|
291
291
|
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
const url = data.url;
|
|
295
|
-
const codeVerifier = data.codeVerifier;
|
|
292
|
+
const { codeVerifier, url } = await melCloudHomeToken.buildAuthorizeUrl();
|
|
296
293
|
const code = await melCloudHomeToken.loginToMelCloudHome(url);
|
|
297
294
|
const token = await melCloudHomeToken.getTokens(code, codeVerifier);
|
|
298
295
|
|
|
@@ -305,7 +302,7 @@ class MelCloud extends EventEmitter {
|
|
|
305
302
|
}
|
|
306
303
|
}
|
|
307
304
|
|
|
308
|
-
async
|
|
305
|
+
async connectToMelCloudHome1(refresh = false) {
|
|
309
306
|
if (this.logDebug) this.emit('debug', `Connecting to MELCloud Home`);
|
|
310
307
|
|
|
311
308
|
let browser;
|
package/src/melcloudhometoken.js
CHANGED
|
@@ -7,7 +7,7 @@ import EventEmitter from 'events';
|
|
|
7
7
|
|
|
8
8
|
const MOBILE_USER_AGENT = 'MonitorAndControl.App.Mobile/35 CFNetwork/3860.100.1 Darwin/25.0.0';
|
|
9
9
|
const CLIENT_ID = 'homemobile';
|
|
10
|
-
const REDIRECT_URI = 'melcloudhome
|
|
10
|
+
const REDIRECT_URI = 'https://auth.melcloudhome.com/signin-oidc-meu';
|
|
11
11
|
const SCOPE = 'openid profile email offline_access IdentityServerApi';
|
|
12
12
|
const TOKEN_ENDPOINT = 'https://auth.melcloudhome.com/connect/token';
|
|
13
13
|
const AUTHORIZE_ENDPOINT = 'https://auth.melcloudhome.com/connect/authorize';
|
|
@@ -44,16 +44,19 @@ class MelCloudHomeToken extends EventEmitter {
|
|
|
44
44
|
try {
|
|
45
45
|
const tokenData = new URLSearchParams({
|
|
46
46
|
grant_type: 'authorization_code',
|
|
47
|
-
code:
|
|
47
|
+
code: code,
|
|
48
48
|
redirect_uri: REDIRECT_URI,
|
|
49
49
|
client_id: CLIENT_ID,
|
|
50
50
|
code_verifier: codeVerifier,
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
+
this.emit('warn', `Code used: ${code}`);
|
|
54
|
+
this.emit('warn', `Verifier: ${codeVerifier}`);
|
|
55
|
+
this.emit('warn', `Redirect URI: ${REDIRECT_URI}`);
|
|
56
|
+
|
|
53
57
|
const tokenResponse = await this.client.post(TOKEN_ENDPOINT, tokenData.toString(), {
|
|
54
58
|
headers: {
|
|
55
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
56
|
-
'Authorization': 'Basic aG9tZW1vYmlsZTo=',
|
|
59
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
57
60
|
},
|
|
58
61
|
});
|
|
59
62
|
|
|
@@ -61,6 +64,9 @@ class MelCloudHomeToken extends EventEmitter {
|
|
|
61
64
|
this.emit('warn', `Token ${JSON.stringify(tokens)}`);
|
|
62
65
|
return tokens;
|
|
63
66
|
} catch (error) {
|
|
67
|
+
if (error.response) {
|
|
68
|
+
this.emit('warn', `Token error response: ${JSON.stringify(error.response.data)}`);
|
|
69
|
+
}
|
|
64
70
|
throw new Error(`Failed to obtain OAuth token: ${error}`);
|
|
65
71
|
}
|
|
66
72
|
}
|
|
@@ -115,7 +121,6 @@ class MelCloudHomeToken extends EventEmitter {
|
|
|
115
121
|
if (match) {
|
|
116
122
|
const code = match[1];
|
|
117
123
|
if (this.logWarn) this.emit('warn', `Redirect URL found code: ${code}`);
|
|
118
|
-
this.code = code
|
|
119
124
|
return code;
|
|
120
125
|
} else {
|
|
121
126
|
if (this.logWarn) this.emit('warn', `Redirect URL found, but no "code=" param: ${redirectUrl}`);
|