homebridge-melcloud-control 4.0.0-beta.304 → 4.0.0-beta.305
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 +29 -24
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.305",
|
|
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
|
@@ -78,30 +78,35 @@ class MelCloudHomeToken {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
async getTokens(code) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
81
|
+
try {
|
|
82
|
+
const data = new URLSearchParams({
|
|
83
|
+
grant_type: 'authorization_code',
|
|
84
|
+
code: code,
|
|
85
|
+
redirect_uri: REDIRECT_URI,
|
|
86
|
+
client_id: CLIENT_ID,
|
|
87
|
+
code_verifier: this.verifier,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const res = await axios({
|
|
91
|
+
method: 'POST',
|
|
92
|
+
url: TOKEN_ENDPOINT,
|
|
93
|
+
headers: {
|
|
94
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
95
|
+
'Content-Length': tokenData.toString().length,
|
|
96
|
+
'Authorization': 'Basic aG9tZW1vYmlsZTo='
|
|
97
|
+
},
|
|
98
|
+
data: data
|
|
99
|
+
});
|
|
100
|
+
console.log(res);
|
|
101
|
+
if (res.status !== 200) {
|
|
102
|
+
throw new Error(`Token exchange failed: ${res.status} ${res.statusText}`);
|
|
103
|
+
}
|
|
103
104
|
|
|
104
|
-
|
|
105
|
+
return res.data;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error('Failed to obtain OAuth tokens:', error);
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
|
|
@@ -121,7 +126,7 @@ class MelCloudHomeToken {
|
|
|
121
126
|
|
|
122
127
|
return loginPage.url;
|
|
123
128
|
} catch (error) {
|
|
124
|
-
console.error('Failed to obtain OAuth
|
|
129
|
+
console.error('Failed to obtain OAuth link:', error);
|
|
125
130
|
throw error;
|
|
126
131
|
}
|
|
127
132
|
}
|