Skip to content

Commit

Permalink
API Connection handling
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed May 27, 2021
1 parent 773c4a4 commit 7af6306
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,32 @@ class OctoPrint extends utils.Adapter {
},
null
);

if (!this.apiConnected) {
this.log.debug('re-creating refresh state timeout (api not connected)');
this.refreshStateTimeout = this.refreshStateTimeout || setTimeout(() => {
this.refreshStateTimeout = null;
this.refreshState();
}, 10 * 1000);
} else if (this.printerStatus == 'Printing') {
this.log.debug('re-creating refresh state timeout (printing)');
this.refreshStateTimeout = this.refreshStateTimeout || setTimeout(() => {
this.refreshStateTimeout = null;
this.refreshState();
}, this.config.apiRefreshIntervalPrinting * 1000); // Default 10 sec
} else if (this.printerStatus == 'Operational') {
this.log.debug('re-creating refresh state timeout (operational)');
this.refreshStateTimeout = this.refreshStateTimeout || setTimeout(() => {
this.refreshStateTimeout = null;
this.refreshState();
}, this.config.apiRefreshIntervalOperational * 1000); // Default 30 sec
} else {
this.log.debug('re-creating refresh state timeout');
this.refreshStateTimeout = this.refreshStateTimeout || setTimeout(() => {
this.refreshStateTimeout = null;
this.refreshState();
}, this.config.apiRefreshInterval * 1000); // Default 60 sec
}
}

async refreshStateDetails() {
Expand Down Expand Up @@ -500,26 +526,6 @@ class OctoPrint extends utils.Adapter {
null
);
}

if (this.printerStatus == 'Printing') {
this.log.debug('re-creating refresh state timeout (printing)');
this.refreshStateTimeout = this.refreshStateTimeout || setTimeout(() => {
this.refreshStateTimeout = null;
this.refreshState();
}, this.config.apiRefreshIntervalPrinting * 1000);
} else if (this.printerStatus == 'Operational') {
this.log.debug('re-creating refresh state timeout (operational)');
this.refreshStateTimeout = this.refreshStateTimeout || setTimeout(() => {
this.refreshStateTimeout = null;
this.refreshState();
}, this.config.apiRefreshIntervalOperational * 1000);
} else {
this.log.debug('re-creating refresh state timeout');
this.refreshStateTimeout = this.refreshStateTimeout || setTimeout(() => {
this.refreshStateTimeout = null;
this.refreshState();
}, this.config.apiRefreshInterval * 1000);
}
}

flattenFiles(files) {
Expand Down

0 comments on commit 7af6306

Please sign in to comment.