Skip to content

Commit

Permalink
optimize axios promise
Browse files Browse the repository at this point in the history
  • Loading branch information
HGlab01 authored Oct 6, 2024
1 parent 56bf042 commit 9987680
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ If someone is supporting to add Tado X functionality, raise a ticket or send an
Placeholder for the next version (at the beginning of the line):
### __WORK IN PROGRESS__
-->
### __WORK IN PROGRESS__
* (HGlab01) Improve axios promise handling

### 0.5.7 (2024-09-30)
* (HGlab01) Change of attribute "light" supported
* (HGlab01) Add attribute 'connection'
Expand Down
4 changes: 3 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@ class Tado extends utils.Adapter {
* @param {any} data
*/
async apiCall(url, method = 'get', data = null) {
let promise;
try {
const waitingTime = 300; //time in ms to wait between calls
// check if other call is in progress and if yes loop and wait
Expand All @@ -1222,7 +1223,7 @@ class Tado extends utils.Adapter {
console.log(`Body "${JSON.stringify(data)}" for API call "${url}"`);
this.log.debug(`Body "${JSON.stringify(data)}" for API call "${url}"`);
}
return new Promise((resolve, reject) => {
promise = await new Promise((resolve, reject) => {
if (this.accessToken) {
this.refreshToken().then(() => {

Expand Down Expand Up @@ -1264,6 +1265,7 @@ class Tado extends utils.Adapter {
console.error(`Issue at apiCall: ${error}`);
this.errorHandling(error);
}
return promise;
}

/**
Expand Down

0 comments on commit 9987680

Please sign in to comment.