Skip to content

Commit

Permalink
New AuthCode needed #6
Browse files Browse the repository at this point in the history
  • Loading branch information
sebilm committed Dec 30, 2021
1 parent 5343bc7 commit ee37a71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ If you (later) get a "400 bad request" error in the log, you must get a new Auth

### 1.0.0 - 2021-12-30
* Support to manage Nibe heat pump (write support #6)
- You need to run the new version 30 minutes and then get a new AuthCode in the settings to use it!

### 0.5.3 - 2021-11-21
* Bump dependencies
Expand Down
16 changes: 14 additions & 2 deletions nibe-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -17237,6 +17237,9 @@ class Fetcher extends EventEmitter {
{
this.adapter.log.debug("Fetch data.");
try {
if (this._hasNewAuthCode()) {
this.clearSesssion();
}
if (!this._hasRefreshToken()) {
if (this.options.authCode) {
let token = await this.getToken(this.options.authCode);
Expand Down Expand Up @@ -17494,6 +17497,9 @@ class Fetcher extends EventEmitter {

setSesssion (auth) {
this.adapter.log.debug("Set session.");
if (auth.authCode == null) {
auth.authCode = this.options.authCode;
}
this._auth = auth;
if (!this.options.sessionStore)
return;
Expand All @@ -17505,14 +17511,20 @@ class Fetcher extends EventEmitter {
this.setSesssion({});
}

_hasNewAuthCode() {
let hasNewAuthCode = (this.getSession('authCode') != null) && (this.getSession('authCode') != this.options.authCode);
this.adapter.log.debug("Has new auth code: " + hasNewAuthCode);
return hasNewAuthCode;
}

_isTokenExpired () {
var expired = (this.getSession('expires_at') || 0) < (Date.now() + this.options.renewBeforeExpiry);
let expired = (this.getSession('expires_at') || 0) < (Date.now() + this.options.renewBeforeExpiry);
this.adapter.log.debug("Is token expired: " + expired);
return expired;
}

_hasRefreshToken () {
var hasToken = !!this.getSession('refresh_token');
let hasToken = !!this.getSession('refresh_token');
this.adapter.log.debug("Has refresh token: " + hasToken);
return hasToken;
}
Expand Down

0 comments on commit ee37a71

Please sign in to comment.