diff --git a/HISTORY.md b/HISTORY.md index 4a69b2c..8f19ef5 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,8 @@ ## version history +### 1.1.2 +- Fixing "Invalid access token"-issue on restart (https://github.com/skrollme/homebridge-eveatmo/issues/81) + ### 1.1.1 - Thanks to a PR (https://github.com/skrollme/homebridge-eveatmo/pull/76) from @Tellicious: - Add new flag to enable/disable AirQuality sensor for indoor modules diff --git a/lib/netatmo-api.js b/lib/netatmo-api.js index 6679a38..4a913e3 100644 --- a/lib/netatmo-api.js +++ b/lib/netatmo-api.js @@ -29,7 +29,7 @@ var netatmo = function (args, homebridge) { if (fs.existsSync(filename)) { let rawData = fs.readFileSync(filename); let tokenData = JSON.parse(rawData); - access_token = tokenData.access_token; + // access_token = tokenData.access_token; // dont read access_token because it may be already invalid on first use after restart refresh_token = tokenData.refresh_token; } else { refresh_token = args.refresh_token; @@ -182,8 +182,13 @@ netatmo.prototype.authenticate_refresh = function () { } body = JSON.parse(body); - refresh_token = body.refresh_token; + fs.writeFileSync(filename, JSON.stringify({ + //'access_token': body.access_token, // dont store access_token because it may be already invalid on first use after restart + 'refresh_token': body.refresh_token + })); + + refresh_token = body.refresh_token; if(access_token == null) { access_token = body.access_token; this.emit('authenticated'); @@ -191,11 +196,6 @@ netatmo.prototype.authenticate_refresh = function () { access_token = body.access_token; } - fs.writeFileSync(filename, JSON.stringify({ - 'access_token': body.access_token, - 'refresh_token': body.refresh_token - })); - if (body.expires_in) { setTimeout(this.authenticate_refresh.bind(this), (body.expires_in - 300) * 1000); // try refreshing the tokens 5min early }