-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
587 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const { DEVICE_PARAMS } = require('../utils/constants'); | ||
|
||
module.exports = { | ||
EWELINK_KEY_PATH: 'apikey', | ||
GLADYS_PARAM_KEY: DEVICE_PARAMS.API_KEY, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
const { DEVICE_PARAMS } = require('../utils/constants'); | ||
|
||
module.exports = { | ||
EWELINK_KEY_PATH: 'params.fwVersion', | ||
GLADYS_PARAM_KEY: 'FIRMWARE', | ||
GLADYS_PARAM_KEY: DEVICE_PARAMS.FIRMWARE, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
server/services/ewelink/lib/user/ewelink.retrieveUserApiKey.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { ServiceNotConfiguredError } = require('../../../../utils/coreErrors'); | ||
const logger = require('../../../../utils/logger'); | ||
const { CONFIGURATION_KEYS } = require('../utils/constants'); | ||
|
||
/** | ||
* @description Retrieve the user API key from eWeLink user family. It also store in database. | ||
* @example | ||
* await this.retrieveUserApiKey(); | ||
*/ | ||
async function retrieveUserApiKey() { | ||
logger.info('eWeLink: loading user API key...'); | ||
|
||
// Load API key | ||
const { currentFamilyId, familyList } = await this.handleRequest( | ||
() => this.ewelinkWebAPIClient.home.getFamily(), | ||
true, | ||
); | ||
const { apikey: apiKey } = familyList.find((family) => family.id === currentFamilyId) || {}; | ||
|
||
// Store API key | ||
if (apiKey) { | ||
logger.info('eWeLink: saving user API key...'); | ||
this.userApiKey = apiKey; | ||
await this.gladys.variable.setValue(CONFIGURATION_KEYS.USER_API_KEY, apiKey, this.serviceId); | ||
} else { | ||
throw new ServiceNotConfiguredError('eWeLink: no user API key retrieved'); | ||
} | ||
} | ||
|
||
module.exports = { | ||
retrieveUserApiKey, | ||
}; |
Oops, something went wrong.