homebridge-melcloud-control 4.0.0-beta.384 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.0.0-beta.384",
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
@@ -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 data = await melCloudHomeToken.buildAuthorizeUrl();
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
 
@@ -50,10 +50,13 @@ class MelCloudHomeToken extends EventEmitter {
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
  }