Skip to content

Commit

Permalink
Stability improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ricott committed Apr 23, 2022
1 parent 969cd37 commit d2e9fe8
Show file tree
Hide file tree
Showing 19 changed files with 6,322 additions and 49 deletions.
4 changes: 4 additions & 0 deletions .homeychangelog.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"1.3.1": {
"en": "Stability improvements",
"sv": "Stabilitetsförbättringar"
},
"1.3.0": {
"en": "Further improvements for IT grids",
"sv": "Ytterligare förbättring för IT nät"
Expand Down
2 changes: 1 addition & 1 deletion .homeycompose/app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "no.easee",
"version": "1.3.0",
"version": "1.3.1",
"brandColor": "#323232",
"compatibility": ">=5.0.0",
"sdk": 3,
Expand Down
42 changes: 42 additions & 0 deletions Debug_app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Debug the Easee app
To access the logs from an Homey Pro app you need to install the app via the Homey Command Line Interface (CLI) from a laptop. This guide intends to explain how this is done.

## Install Node
Install Node from https://nodejs.org/.

Depending on your OS there are other options, like on a Mac using brew `brew install node`

## Install Homey CLI
Using the `-g` flag will install the Homey CLI globally
```
npm install -g homey
```

## Login to Homey via CLI
```
homey login
```

## Uninstall the Easee app
If you are here you have most likely installed the Easee app previously from the Homey app store. Due to the use of an encryption key for the Easee account details you need to uninstall the Easee app before installing it via CLI.

## Download and configure the Easee app
Download the source code to the Easee app from here, https://github.com/ricott/homey-no.easee/archive/refs/heads/master.zip.

1. Unzipp all files
2. In the root folder create a file called `env.json`
3. Place the following content in the file
```
{
"ENCRYPTION_KEY": "key"
}
```
4. Type a string that is exactly 32 characters long, and place within the double quotes instead of the value `key`. For instance if the key would be `IHaveToUse32CharactersForThisKey` then the file should look like this.
```
{
"ENCRYPTION_KEY": "IHaveToUse32CharactersForThisKey"
}
```

## Run the Easee app
To run the app and see logs from the app in your computers terminal window, use `homey app run`. To install the app permanently via CLI then use `homey app install`. All commands are executed from the root folder of the app's file structure.
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"_comment": "This file is generated. Please edit .homeycompose/app.json instead.",
"id": "no.easee",
"version": "1.3.0",
"version": "1.3.1",
"brandColor": "#323232",
"compatibility": ">=5.0.0",
"sdk": 3,
Expand Down
2 changes: 1 addition & 1 deletion drivers/charger/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ class ChargerDevice extends Homey.Device {
return self.tokenManager.getTokens(self.getUsername(), self.getPassword(), force)
.then(function (tokens) {
if (self.getToken().accessToken != tokens.accessToken) {
self.logMessage('Renewed access token');
self.logMessage('We have a new access token from TokenManager');
}
self.setToken(tokens);
return Promise.resolve(true);
Expand Down
39 changes: 21 additions & 18 deletions lib/tokenManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,32 @@ class TokenManager {
return createConn(username, password)
.then(function (tokens) {
self.connections[username] = new EaseeToken(username, password, tokens);
return self.connections[username].tokens;
}).catch(reason => {
return Promise.resolve(self.connections[username].tokens);
}).catch(function (reason) {
return Promise.reject(reason);
});
} else if (force) {
let tokenAge = new Date().getTime() - self.connections[username].timestamp;
const now = new Date().getTime();
let tokenAge = now - self.connections[username].timestamp;
//console.log(`[${username}] Token is from '${self.connections[username].timestamp}', time now '${now}'`);
//Even with force, if token is less than 5 mins old then ignore that request
if (tokenAge < (5 * 60 * 1000)) {
if (tokenAge > (5 * 60 * 1000)) {
return createConn(username, password)
.then(function (tokens) {
self.connections[username] = new EaseeToken(username, password, tokens);
return self.connections[username].tokens;
}).catch(reason => {
return Promise.resolve(self.connections[username].tokens);
}).catch(function (reason) {
return Promise.reject(reason);
});
} else {
return Promise.resolve(Object.freeze(self.connections[username].tokens));
console.log(`[${username}] Create new token using force ignored, less than 5 mins old token`);
return Promise.resolve(self.connections[username].tokens);
}
} else {
return Promise.resolve(Object.freeze(self.connections[username].tokens));
return Promise.resolve(self.connections[username].tokens);
}
})
.catch(reason => {
.catch(function (reason) {
//console.log('Error getting token', reason);
return Promise.reject(reason);
})
Expand All @@ -64,20 +67,20 @@ class EaseeToken {
//If refresh fails, then login from start
this._timer = setInterval(() => {
let self = this;
console.log(`Refreshing access tokens for username '${self.username}'`);
console.log(`[${self.username}] Refreshing access tokens for username`);
refreshToken(self.tokens)
.then(function (tokens) {
self._tokens = tokens;
self._timestamp = new Date().getTime();
}).catch(reason => {
console.log('Failed to refresh tokens, generating new using user/password');
}).catch(function (reason) {
console.log(`[${self.username}] Failed to refresh tokens, generating new using user/password`);
console.error(reason);
createConn(self.username, self.password)
.then(function (tokens) {
self._tokens = tokens;
self._timestamp = new Date().getTime();
}).catch(reason => {
console.log('Failed to generate new tokens, out of luck :(');
}).catch(function (reason) {
console.log(`[${self.username}] Failed to generate new tokens, out of luck :(`);
console.error(reason);
});
});
Expand All @@ -93,7 +96,7 @@ class EaseeToken {
}

get tokens() {
return this._tokens;
return Object.freeze(this._tokens);
}

get timestamp() {
Expand All @@ -105,20 +108,20 @@ function refreshToken(tokens) {
return LoginHelper.refreshToken(tokens)
.then(function (tokens) {
return tokens;
}).catch(reason => {
}).catch(function (reason) {
console.log(reason);
return Promise.reject(reason);
});
}

function createConn(username, password) {
console.log(`Generating new access tokens for username '${username}'`);
console.log(`[${username}] Generating new access token`);
return LoginHelper.login({
userName: username,
password: password
}).then(function (tokens) {
return tokens;
}).catch(reason => {
}).catch(function (reason) {
console.log(reason);
return Promise.reject(reason);
});
Expand Down
6 changes: 3 additions & 3 deletions node_modules/.package-lock.json

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

3,115 changes: 3,114 additions & 1 deletion node_modules/@microsoft/signalr/dist/browser/signalr.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node_modules/@microsoft/signalr/dist/cjs/Utils.js

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

2 changes: 1 addition & 1 deletion node_modules/@microsoft/signalr/dist/esm/Utils.d.ts

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

2 changes: 1 addition & 1 deletion node_modules/@microsoft/signalr/dist/esm/Utils.js

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

3,115 changes: 3,114 additions & 1 deletion node_modules/@microsoft/signalr/dist/webworker/signalr.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions node_modules/@microsoft/signalr/package.json

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

2 changes: 1 addition & 1 deletion node_modules/@microsoft/signalr/src/Utils.ts

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

14 changes: 7 additions & 7 deletions 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
Expand Up @@ -7,7 +7,7 @@
"lib": "lib"
},
"dependencies": {
"@microsoft/signalr": "^6.0.2",
"@microsoft/signalr": "^6.0.3",
"async-mutex": "^0.3.2",
"enum": "^3.0.4",
"events": "^3.3.0",
Expand Down
8 changes: 4 additions & 4 deletions test/schedule/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ describe('#Basic Charge Plan', function () {
let tokens = await tokenManager.getTokens(config.credentials.userName, config.credentials.password);
let easee = new Easee(tokens);
let result = await easee.setBasicChargePlan(config.charger, '01:00', '04:00', true);
//console.log(util.inspect(result, {showHidden: false, depth: null}));
console.log(util.inspect(result, {showHidden: false, depth: null}));
assert.strictEqual(result.device, config.charger);
});

/*
it('Get charge plan', async () => {
let tokens = await tokenManager.getTokens(config.credentials.userName, config.credentials.password);
let easee = new Easee(tokens);
let chargePlan = await easee.getBasicChargePlan(config.charger);
//console.log(util.inspect(chargePlan, { showHidden: false, depth: null }));
console.log(util.inspect(chargePlan, { showHidden: false, depth: null }));
assert.strictEqual(chargePlan.id, config.charger);
});
Expand All @@ -31,6 +31,6 @@ describe('#Basic Charge Plan', function () {
let chargePlan = await easee.deleteBasicChargePlan(config.charger);
//console.log(util.inspect(chargePlan, {showHidden: false, depth: null}));
assert.strictEqual(chargePlan.device, config.charger);
});
});*/
});

0 comments on commit d2e9fe8

Please sign in to comment.