homebridge-melcloud-control 4.0.0-beta.335 → 4.0.0-beta.337

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.0.0-beta.335",
4
+ "version": "4.0.0-beta.337",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -86,44 +86,22 @@ class MelCloudHomeToken extends EventEmitter {
86
86
 
87
87
  async getTokens(code, codeVerifier) {
88
88
  try {
89
- const payload = {
90
- "client_id": CLIENT_ID,
91
- "grant_type": 'authorization_code',
92
- "code": code,
93
- "redirect_uri": REDIRECT_URI,
94
- "code_verifier": codeVerifier
95
- }
96
-
97
- const postData = QueryString.stringify(payload);
98
- const headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
99
- const response = await axios.post(TOKEN_ENDPOINT, postData, headers);
100
- const accessToken = response.data;
101
- this.emit('warn', `Token ${tokenResponse.data}`);
102
-
103
-
104
- //accessToken.issued = new Date().toISOString();
105
- //this.tokens.oauth = accessToken;
106
- //await this.functions.saveData(this.tokensFile, this.tokens);
107
- return accessToken;
108
- } catch (error) {
109
- throw new Error(`Access token error: ${error}`);
110
- }
111
- }
112
-
113
- async getTokens1(code, codeVerifier) {
114
- try {
115
- const tokenResponse = await axios.post(TOKEN_ENDPOINT, new URLSearchParams({
89
+ const tokenData = new URLSearchParams({
116
90
  grant_type: 'authorization_code',
117
- client_id: CLIENT_ID,
118
91
  code: code,
119
92
  redirect_uri: REDIRECT_URI,
93
+ client_id: CLIENT_ID,
120
94
  code_verifier: codeVerifier,
121
- }).toString(), {
95
+ });
96
+
97
+ const tokenResponse = await axios(TOKEN_ENDPOINT, {
98
+ method: 'POST',
122
99
  headers: {
123
100
  'Content-Type': 'application/x-www-form-urlencoded',
124
- 'Authorization': 'Basic aG9tZW1vYmlsZTo='
125
- }
126
- });
101
+ 'Content-Length': tokenData.toString().length,
102
+ 'Authorization': 'Basic aG9tZW1vYmlsZTo=',
103
+ },
104
+ }, tokenData.toString());
127
105
 
128
106
  this.emit('warn', `Token ${tokenResponse.data}`);
129
107
  return tokenResponse.data;