Skip to content

Commit

Permalink
Merge pull request #102 from athombv/master
Browse files Browse the repository at this point in the history
Merge Master into Production
  • Loading branch information
WeeJeWel authored Nov 6, 2024
2 parents 7d4b33d + 1cd796b commit 996b71b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
14 changes: 14 additions & 0 deletions lib/OAuth2App.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,27 @@ class OAuth2App extends Homey.App {
await this.onOAuth2Init();
}

/**
* @returns {Promise<void>}
*/
async onUninit() {
await this.onOAuth2Uninit();
}

/**
* @returns {Promise<void>}
*/
async onOAuth2Init() {
// Overload Me
}

/**
* @returns {Promise<void>}
*/
async onOAuth2Uninit() {
// Overload Me
}

/**
*/
enableOAuth2Debug() {
Expand Down
30 changes: 30 additions & 0 deletions lib/OAuth2Driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class OAuth2Driver extends Homey.Driver {
await this.onOAuth2Init();
}

/**
* @returns {Promise<void>}
*/
async onUninit() {
await this.onOAuth2Uninit();
}

/**
* @description
* > This method can be extended
Expand All @@ -33,6 +40,15 @@ class OAuth2Driver extends Homey.Driver {
// Extend me
}

/**
* @description
* > This method can be extended
* @returns {Promise<void>}
*/
async onOAuth2Uninit() {
// Extend me
}

/**
* @returns {*}
*/
Expand Down Expand Up @@ -318,6 +334,19 @@ class OAuth2Driver extends Homey.Driver {
}
};

const onLogin = async ({ username, password }) => {
await client.getTokenByCredentials({ username, password });

await device.onOAuth2Uninit();
await device.setStoreValue('OAuth2SessionId', OAuth2SessionId);
await device.setStoreValue('OAuth2ConfigId', OAuth2ConfigId);
await client.save();
device.oAuth2Client = client;
await device.onOAuth2Init();

return true;
};

const onShowView = async viewId => {
if (viewId === 'login_oauth2') {
await onShowViewLoginOAuth2();
Expand All @@ -330,6 +359,7 @@ class OAuth2Driver extends Homey.Driver {

socket
.setHandler('showView', onShowView)
.setHandler('login', onLogin)
.setHandler('disconnect', onDisconnect);
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homey-oauth2app",
"version": "3.5.7",
"version": "3.6.0",
"description": "",
"main": "index.js",
"files": [
Expand All @@ -22,6 +22,7 @@
"dependencies": {
"node-fetch": "^2.3.0"
},
"license": "MIT",
"devDependencies": {
"@athombv/jsdoc-template": "^1.6.1",
"@types/jest": "^28.1.1",
Expand Down

0 comments on commit 996b71b

Please sign in to comment.