Skip to content

Commit

Permalink
Refresh token more often to hopefully get less undefined errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rgallo committed Feb 24, 2021
1 parent 52af103 commit 7b39c82
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Homebridge Sunpower",
"name": "homebridge-sunpower",
"version": "0.1.1",
"version": "0.1.2",
"description": "Adds monitoring of Sunpower solar panels to Homebridge",
"license": "Apache-2.0",
"repository": {
Expand Down
8 changes: 4 additions & 4 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ export class SunpowerPlatform implements DynamicPlatformPlugin {

let token = '';
let address = '';
let lastTokenDate = -1;
let lastTokenHour = -1;
setInterval(async () => {
const today = new Date().getDate();
if (!token || lastTokenDate !== today) { // Refresh token daily
const today = new Date().getHours();
if (!token || lastTokenHour !== today) { // Refresh token hourly
const loginData = { 'password': this.config.password, 'username': this.config.username, 'isPersistent': false };
const authResponse = await fetch('https://elhapi.edp.sunpower.com/v1/elh/authenticate', {
method: 'POST',
Expand All @@ -98,7 +98,7 @@ export class SunpowerPlatform implements DynamicPlatformPlugin {
const authJson = await authResponse.json();
token = authJson.tokenID;
address = authJson.addresses[0]; // TODO multiple addresses?
lastTokenDate = today;
lastTokenHour = today;
}

const headers = {
Expand Down

0 comments on commit 7b39c82

Please sign in to comment.