homebridge-melcloud-control 4.0.0-beta.304 → 4.0.0-beta.306

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.304",
4
+ "version": "4.0.0-beta.306",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -78,30 +78,35 @@ class MelCloudHomeToken {
78
78
  }
79
79
 
80
80
  async getTokens(code) {
81
- const data = new URLSearchParams({
82
- grant_type: 'authorization_code',
83
- code: code,
84
- redirect_uri: REDIRECT_URI,
85
- client_id: CLIENT_ID,
86
- code_verifier: this.verifier,
87
- });
88
-
89
- const res = await axios({
90
- method: 'POST',
91
- url: TOKEN_ENDPOINT,
92
- headers: {
93
- 'Content-Type': 'application/x-www-form-urlencoded',
94
- 'Content-Length': tokenData.toString().length,
95
- 'Authorization': 'Basic aG9tZW1vYmlsZTo='
96
- },
97
- data: data
98
- });
99
- console.log(res);
100
- if (res.status !== 200) {
101
- throw new Error(`Token exchange failed: ${res.status} ${res.statusText}`);
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': data.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
- return res.data;
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 tokens:', error);
129
+ console.error('Failed to obtain OAuth link:', error);
125
130
  throw error;
126
131
  }
127
132
  }