Skip to content

Commit

Permalink
support for compact-mode added
Browse files Browse the repository at this point in the history
  • Loading branch information
unltdnetworx committed Jan 21, 2019
1 parent 2d1748c commit 205d4a2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 43 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Help or hints are welcome.

## Changelog

### 1.2.0
* support for compact-mode added

### 1.1.4
* value rounding is now optional. Wh -> kWh

Expand Down
9 changes: 7 additions & 2 deletions io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"common": {
"name": "energymanager",
"version": "1.1.4",
"version": "1.2.0",
"news": {
"1.2.0": {
"en": "support for compact-mode added",
"de": "Kompakt-Modus wird zukünftig unterstützt"
},
"1.1.4": {
"en": "value rounding is now optional. Wh -> kWh",
"de": "Rundung von Werten ist nun optional. Wh -> kWh"
Expand Down Expand Up @@ -103,7 +107,8 @@
"loglevel": "info",
"type": "energy",
"license": "MIT",
"messagebox": false
"messagebox": false,
"compact": true
},
"native": {
"managerType": "eon",
Expand Down
95 changes: 55 additions & 40 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
'use strict';

const utils = require(__dirname + '/lib/utils');
const adapter = new utils.Adapter('energymanager');
let request = require('request');
let systemLanguage;
let nameTranslation;
Expand All @@ -16,49 +15,57 @@ let valTagLang;
var url;
var c = request.jar();

adapter.on('ready', function () {
adapter.getForeignObject('system.config', function (err, obj) {
if (err) {
adapter.log.error(err);
return;
} else if (obj) {
if (!obj.common.language) {
adapter.log.info("Language not set. English set therefore.");
nameTranslation = require(__dirname + '/admin/i18n/en/translations.json')
} else {
systemLanguage = obj.common.language;
nameTranslation = require(__dirname + '/admin/i18n/' + systemLanguage + '/translations.json')
let adapter;
function startAdapter(options) {
options = options || {};
Object.assign(options, {
name: 'energymanager',
stateChange: function (id, state) {
let command = id.split('.').pop();

// you can use the ack flag to detect if it is status (true) or command (false)
if (!state || state.ack) return;

if (command == 'managerReboot') {
adapter.log.info('energymanager rebooting');
if (managerIntervall) clearInterval(managerIntervall);
rebootManager();
//wait 5 minutes for hardware-reboot
setTimeout(main, 300000);
}
},
unload: function (callback) {
try {
if (managerIntervall) clearInterval(managerIntervall);
adapter.log.info('cleaned everything up...');
callback();
} catch (e) {
callback();
}
url = "http://" + adapter.config.managerAddress + "/rest";
main();
},
ready: function () {
adapter.getForeignObject('system.config', function (err, obj) {
if (err) {
adapter.log.error(err);
return;
} else if (obj) {
if (!obj.common.language) {
adapter.log.info("Language not set. English set therefore.");
nameTranslation = require(__dirname + '/admin/i18n/en/translations.json')
} else {
systemLanguage = obj.common.language;
nameTranslation = require(__dirname + '/admin/i18n/' + systemLanguage + '/translations.json')
}
url = "http://" + adapter.config.managerAddress + "/rest";
main();
}
});
}
});
});

adapter.on('unload', function (callback) {
try {
if (managerIntervall) clearInterval(managerIntervall);
adapter.log.info('cleaned everything up...');
callback();
} catch (e) {
callback();
}
});

adapter.on('stateChange', function (id, state) {
let command = id.split('.').pop();
adapter = new utils.Adapter(options);

// you can use the ack flag to detect if it is status (true) or command (false)
if (!state || state.ack) return;

if (command == 'managerReboot') {
adapter.log.info('energymanager rebooting');
if (managerIntervall) clearInterval(managerIntervall);
rebootManager();
//wait 5 minutes for hardware-reboot
setTimeout(main, 300000);
}
});
return adapter;
};

function rebootManager(){
request({
Expand Down Expand Up @@ -273,3 +280,11 @@ function main() {
getManagerValues();
managerIntervall = setInterval(getManagerValues, (adapter.config.managerIntervall * 1000));
}

// If started as allInOne/compact mode => return function to create instance
if (module && module.parent) {
module.exports = startAdapter;
} else {
// or start the instance directly
startAdapter();
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.energymanager",
"version": "1.1.4",
"version": "1.2.0",
"description": "energymanager for kiwigrid powered devices",
"author": {
"name": "Michael Schuster",
Expand Down

0 comments on commit 205d4a2

Please sign in to comment.