homebridge-melcloud-control 4.0.0-beta.333 → 4.0.0-beta.334

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.333",
4
+ "version": "4.0.0-beta.334",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -3,6 +3,7 @@ import crypto from 'crypto';
3
3
  import { wrapper } from 'axios-cookiejar-support';
4
4
  import { CookieJar } from 'tough-cookie';
5
5
  import { JSDOM } from 'jsdom';
6
+ import QueryString from 'querystring';
6
7
  import EventEmitter from 'events';
7
8
 
8
9
  const MOBILE_USER_AGENT = 'MonitorAndControl.App.Mobile/35 CFNetwork/3860.100.1 Darwin/25.0.0';
@@ -84,6 +85,33 @@ class MelCloudHomeToken extends EventEmitter {
84
85
  }
85
86
 
86
87
  async getTokens(code, codeVerifier) {
88
+ try {
89
+ const payload = {
90
+ "client_id": CLIENT_ID,
91
+ "grant_type": 'authorization_code',
92
+ "scope": SCOPE,
93
+ "code": code,
94
+ "redirect_uri": REDIRECT_URI,
95
+ "code_verifier": codeVerifier
96
+ }
97
+
98
+ const postData = QueryString.stringify(payload);
99
+ const headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
100
+ const response = await axios.post(TOKEN_ENDPOINT, postData, headers);
101
+ const accessToken = response.data;
102
+ this.emit('warn', `Token ${tokenResponse.data}`);
103
+
104
+
105
+ //accessToken.issued = new Date().toISOString();
106
+ //this.tokens.oauth = accessToken;
107
+ //await this.functions.saveData(this.tokensFile, this.tokens);
108
+ return accessToken;
109
+ } catch (error) {
110
+ throw new Error(`Access token error: ${error}`);
111
+ }
112
+ }
113
+
114
+ async getTokens1(code, codeVerifier) {
87
115
  try {
88
116
  const tokenResponse = await axios.post(TOKEN_ENDPOINT, new URLSearchParams({
89
117
  grant_type: 'authorization_code',