Skip to content

Commit

Permalink
Timeout of 5 seconds for sending commands to gather multiple commands…
Browse files Browse the repository at this point in the history
… to reduce the load of the ISG
  • Loading branch information
unltdnetworx committed Apr 22, 2019
1 parent 8a53f67 commit 45c607b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 39 deletions.
23 changes: 4 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Help or hints are welcome.
* stiebel-eltron/tecalor internet service gateway (ISG)

## Changelog
### 1.4.3
* Timeout of 5 seconds for sending commands to gather multiple commands to reduce the load of the ISG
* Timeout for pulling deleted

### 1.4.2
* Timeout of 10 seconds for pulling settings after multiple commands to reduce the load of the ISG

Expand Down Expand Up @@ -64,25 +68,6 @@ Help or hints are welcome.
### 1.1.0
* Energymanagment added (ISG plus required)

### 1.0.3
* bugfix in version number

### 1.0.2
* code cleanup

### 1.0.1
* added two new groups for controls, roomtemp 1 and 2

### 1.0.0
* confirmed stable release

### 0.1.0
* release candidate for stable
* additional controles added

### 0.0.1
* initial release

## License
The MIT License (MIT)

Expand Down
6 changes: 5 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"common": {
"name": "stiebel-isg",
"version": "1.4.2",
"version": "1.4.3",
"news": {
"1.4.3": {
"en": "Timeout of 5 seconds for sending commands to gather multiple commands to reduce the load of the ISG",
"de": "5 Sekunden Wartezeit für das Senden von Einstellungen eingefügt um Befehle zu gesammelt zu senden, zur Reduzierung der Auslastung des ISG"
},
"1.4.2": {
"en": "Timeout of 10 seconds for pulling settings after multiple commands",
"de": "10 Sekunden Wartezeit für das Neuladen von Einstellungen eingefügt, zur Reduzierung der Auslastung des ISG bei vielen gleichzeitigen Befehlen"
Expand Down
49 changes: 31 additions & 18 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
'use strict';

/**
*
* stiebel-eltron/tecalor isg adapter
*
*/

'use strict';

const utils = require('@iobroker/adapter-core');
const querystring = require("querystring");
let systemLanguage;
let nameTranslation;
let isgIntervall;
let isgCommandIntervall;
let commands = [];
let CommandTimeout
var jar;
let host;
let commandPaths = ["/?s=0","/?s=4,0,0","/?s=4,0,1","/?s=4,0,2","/?s=4,0,3","/?s=4,0,4","/?s=4,0,5","/?s=4,1,0","/?s=4,1,1","/?s=4,2,0","/?s=4,2,1","/?s=4,2,2","/?s=4,2,4","/?s=4,2,6","/?s=4,2,3","/?s=4,2,5","/?s=4,2,7","/?s=4,3","/?s=4,3,0","/?s=4,3,1","/?s=4,3,2","/?s=4,3,3","/?s=4,3,4"];
Expand Down Expand Up @@ -45,6 +47,8 @@ function startAdapter(options) {
adapter.getForeignObject('system.config', function (err, obj) {
if (err) {
adapter.log.error(err);
adapter.log.error("statusCode: " + response.statusCode);
adapter.log.error("statusText: " + response.statusText);
return;
} else if (obj) {
if (!obj.common.language) {
Expand Down Expand Up @@ -235,6 +239,8 @@ function getIsgStatus(sidePath) {
})
} else {
adapter.log.error(error);
adapter.log.error("statusCode: " + response.statusCode);
adapter.log.error("statusText: " + response.statusText);
}
});
}
Expand Down Expand Up @@ -326,6 +332,8 @@ function getIsgValues(sidePath) {
})
} else {
adapter.log.error(error);
adapter.log.error("statusCode: " + response.statusCode);
adapter.log.error("statusText: " + response.statusText);
}
});
}
Expand Down Expand Up @@ -534,20 +542,23 @@ function getIsgCommands(sidePath) {
})
} else {
adapter.log.error(error);
adapter.log.error("statusCode: " + response.statusCode);
adapter.log.error("statusText: " + response.statusText);
}
});
}

function setIsgCommands(strKey, strValue) {
const commands = JSON.stringify(
[{'name': strKey,
'value': strValue}]
)
let newCommand =
{'name': strKey,
'value': strValue}

commands.push(newCommand);

const payload = querystring.stringify({
user: adapter.config.isgUser,
pass: adapter.config.isgPassword,
data: commands
data: JSON.stringify(commands)
});

const postOptions = {
Expand All @@ -562,20 +573,22 @@ function setIsgCommands(strKey, strValue) {
}
};

//renew all settings after waitingtime of 10 Seconds. If more commands are sent.
var timeoutHandle;
request(postOptions, function (error, response, content) {
if (!error && response.statusCode == 200) {
clearTimeout(timeoutHandle);
timeoutHandle = setTimeout(function(){
//send all settings to device after waitingtime of 5 Seconds. If more commands are sent.
clearTimeout(CommandTimeout);
CommandTimeout = setTimeout(function(){
request(postOptions, function (error, response, content) {
if (!error && response.statusCode == 200) {
commandPaths.forEach(function(item){
getIsgCommands(item);
})
},10000);
} else {
adapter.log.error(error);
}
});
} else {
adapter.log.error(error);
adapter.log.error("statusCode: " + response.statusCode);
adapter.log.error("statusText: " + response.statusText);
}
});
commands = [];
},5000);
}

function main() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.stiebel-isg",
"version": "1.4.2",
"version": "1.4.3",
"description": "stiebel/tecalor internet service gateway",
"author": {
"name": "Michael Schuster",
Expand Down

0 comments on commit 45c607b

Please sign in to comment.