Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
- fixed sentry
- better error messages
- improved reconnect
  • Loading branch information
stephan1827 committed Dec 4, 2023
1 parent 33006f2 commit 64250a8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions admin/jsonConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"items": {
"label": "Synology Router",
"IP": {
"newLine": true,
"type": "text",
"sm": 12,
"md": 6,
Expand Down
26 changes: 13 additions & 13 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ class Srm extends utils.Adapter {
// Force polling minimum to 60 seconds
if (this.config.interval < 60) { this.config.interval = 60; }

setTimeout(async () => {
this.srmConnect();
}, 5000);
this.srmConnect();
}

/**
Expand Down Expand Up @@ -110,7 +108,7 @@ class Srm extends utils.Adapter {
async setSentryLogging(value) {
try {
value = value === true;
const idSentry = `system.this.${this.namespace}.plugins.sentry.enabled`;
const idSentry = `system.adapter.${this.namespace}.plugins.sentry.enabled`;
const stateSentry = await this.getForeignStateAsync(idSentry);
if (stateSentry && stateSentry.val !== value) {
await this.setForeignStateAsync(idSentry, value);
Expand Down Expand Up @@ -139,8 +137,12 @@ class Srm extends utils.Adapter {
this.srmCyclicCall();

} catch (error) {
this.log.error(error);
this.srmStop();
this.log.error(error.message + " for " + this.config.IP);

Check failure on line 140 in main.js

View workflow job for this annotation

GitHub Actions / check-and-lint

Strings must use singlequote
if (error.message === 'Request timeout') {
this.srmReconnect();
} else {
this.srmStop();
}
return;
}
}
Expand All @@ -150,13 +152,14 @@ class Srm extends utils.Adapter {
async srmReconnect() {
this.client = null;
this.client = new this.SrmClient();
this.log.info('Try to reconnect in 60s ...');
setTimeout(async () => {
this.srmConnect();
}, 5000);
}, 60000);
}

// ---------------------------------------------------------------------------------------------
// Is called when adapter shuts down - callback has to be called under any circumstances!
// Stop communication with Synology router
async srmStop() {
if (this.stopTimer) clearTimeout(this.stopTimer);

Expand Down Expand Up @@ -254,9 +257,7 @@ class Srm extends utils.Adapter {
if (String(error) === 'Error: Not connected') {
this.log.error('Router is not connected, try new reconnect in 90s');
this.stopExecute = true;
setTimeout(async () => {
this.srmReconnect();
}, 90000);
this.srmReconnect();
} else {
this.log.error(error);
this.stopExecute = true;
Expand All @@ -282,5 +283,4 @@ if (require.main !== module) {
} else {
// otherwise start the instance directly
new Srm();
}

}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "iobroker.srm",
"version": "0.0.1",
"description": "This adapater allows you to connect to a Synology router",
"description": "This adapter allows you to connect to a Synology router",
"author": {
"name": "stephan stricker",
"email": "[email protected]"
Expand Down

0 comments on commit 64250a8

Please sign in to comment.