diff --git a/lib/OAuth2App.js b/lib/OAuth2App.js index 7693c29..3a3c7f7 100644 --- a/lib/OAuth2App.js +++ b/lib/OAuth2App.js @@ -54,6 +54,13 @@ class OAuth2App extends Homey.App { await this.onOAuth2Init(); } + /** + * @returns {Promise} + */ + async onUninit() { + await this.onOAuth2Uninit(); + } + /** * @returns {Promise} */ @@ -61,6 +68,13 @@ class OAuth2App extends Homey.App { // Overload Me } + /** + * @returns {Promise} + */ + async onOAuth2Uninit() { + // Overload Me + } + /** */ enableOAuth2Debug() { diff --git a/lib/OAuth2Driver.js b/lib/OAuth2Driver.js index 060e606..78ef1dd 100644 --- a/lib/OAuth2Driver.js +++ b/lib/OAuth2Driver.js @@ -24,6 +24,13 @@ class OAuth2Driver extends Homey.Driver { await this.onOAuth2Init(); } + /** + * @returns {Promise} + */ + async onUninit() { + await this.onOAuth2Uninit(); + } + /** * @description * > This method can be extended @@ -33,6 +40,15 @@ class OAuth2Driver extends Homey.Driver { // Extend me } + /** + * @description + * > This method can be extended + * @returns {Promise} + */ + async onOAuth2Uninit() { + // Extend me + } + /** * @returns {*} */ @@ -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(); @@ -330,6 +359,7 @@ class OAuth2Driver extends Homey.Driver { socket .setHandler('showView', onShowView) + .setHandler('login', onLogin) .setHandler('disconnect', onDisconnect); } diff --git a/package-lock.json b/package-lock.json index ad01a9a..1198866 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "homey-oauth2app", - "version": "3.5.7", + "version": "3.6.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "homey-oauth2app", - "version": "3.5.7", + "version": "3.6.0", "dependencies": { "node-fetch": "^2.3.0" }, diff --git a/package.json b/package.json index 6723749..30719d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homey-oauth2app", - "version": "3.5.7", + "version": "3.6.0", "description": "", "main": "index.js", "files": [ @@ -22,6 +22,7 @@ "dependencies": { "node-fetch": "^2.3.0" }, + "license": "MIT", "devDependencies": { "@athombv/jsdoc-template": "^1.6.1", "@types/jest": "^28.1.1",