Skip to content

Commit

Permalink
Merge pull request #23 from iobroker-community-adapters/compactMode
Browse files Browse the repository at this point in the history
update template to compact mode
  • Loading branch information
Apollon77 authored Jan 8, 2019
2 parents 1e48d01 + 4f25759 commit 9e5a861
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 138 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ It includes both code running within iobroker and as vis widget. If you only pla

## Changelog

### 0.7.0 (2019.01.08)
* (jogibear998) compact mode and fixes

### 0.6.0 (2017.01.02)
* (bluefox) Support of admin3

Expand Down
14 changes: 13 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
{
"common": {
"name": "template",
"version": "0.6.0",
"version": "0.7.0",
"news": {
"0.7.0": {
"en": "compact mode and fixes",
"de": "Kompaktmodus und Korrekturen",
"ru": "компактный режим и исправления",
"pt": "modo compacto e correções",
"nl": "compacte modus en oplossingen",
"fr": "mode compact et correctifs",
"it": "modalità compatta e correzioni",
"es": "Modo compacto y correcciones.",
"pl": "tryb kompaktowy i poprawki"
},
"0.6.0": {
"en": "Support of admin3",
"de": "Unterstützung von admin3",
Expand Down Expand Up @@ -66,6 +77,7 @@
},
"platform": "Javascript/Node.js",
"mode": "daemon",
"compact": true,
"icon": "template.png",
"materialize": true,
"enabled": true,
Expand Down
83 changes: 0 additions & 83 deletions lib/utils.js

This file was deleted.

116 changes: 64 additions & 52 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,63 +34,69 @@
'use strict';

// you have to require the utils module and call adapter function
const utils = require(__dirname + '/lib/utils'); // Get common adapter utils
const utils = require('@iobroker/adapter-core'); // Get common adapter utils

// you have to call the adapter function and pass a options object
// name has to be set and has to be equal to adapters folder name and main file name excluding extension
// adapter will be restarted automatically every time as the configuration changed, e.g system.adapter.template.0
const adapter = new utils.Adapter('template');
// read the adapter name from package.json
const adapterName = require('./package.json').name.split('.').pop();

/*Variable declaration, since ES6 there are let to declare variables. Let has a more clearer definition where
it is available then var.The variable is available inside a block and it's childs, but not outside.
You can define the same variable name inside a child without produce a conflict with the variable of the parent block.*/
let variable = 1234;

// is called when adapter shuts down - callback has to be called under any circumstances!
adapter.on('unload', function (callback) {
try {
adapter.log.info('cleaned everything up...');
callback();
} catch (e) {
callback();
}
});

// is called if a subscribed object changes
adapter.on('objectChange', function (id, obj) {
// Warning, obj can be null if it was deleted
adapter.log.info('objectChange ' + id + ' ' + JSON.stringify(obj));
});

// is called if a subscribed state changes
adapter.on('stateChange', function (id, state) {
// Warning, state can be null if it was deleted
adapter.log.info('stateChange ' + id + ' ' + JSON.stringify(state));

// you can use the ack flag to detect if it is status (true) or command (false)
if (state && !state.ack) {
adapter.log.info('ack is not set!');
}
});

// Some message was sent to adapter instance over message box. Used by email, pushover, text2speech, ...
adapter.on('message', function (obj) {
if (typeof obj === 'object' && obj.message) {
if (obj.command === 'send') {
// e.g. send email or pushover or whatever
console.log('send command');

// Send response in callback if required
if (obj.callback) adapter.sendTo(obj.from, obj.command, 'Message received', obj.callback);
}
}
});

// is called when databases are connected and adapter received configuration.
// start here!
adapter.on('ready', function () {
main();
});
// create adapter instance wich will be used for communication with controller
let adapter;
function startAdapter(options) {
options = options || {};
Object.assign(options, {
// name has to be set and has to be equal to adapters folder name and main file name excluding extension
name: adapterName,
// is called when adapter shuts down - callback has to be called under any circumstances!
unload: function (callback) {
try {
adapter.log.info('cleaned everything up...');
callback();
} catch (e) {
callback();
}
},
// is called if a subscribed object changes
objectChange: function (id, obj) {
// Warning, obj can be null if it was deleted
adapter.log.info('objectChange ' + id + ' ' + JSON.stringify(obj));
},
// is called if a subscribed state changes
stateChange: function (id, state) {
// Warning, state can be null if it was deleted
adapter.log.info('stateChange ' + id + ' ' + JSON.stringify(state));

// you can use the ack flag to detect if it is status (true) or command (false)
if (state && !state.ack) {
adapter.log.info('ack is not set!');
}
},
// Some message was sent to adapter instance over message box. Used by email, pushover, text2speech, ...
message: function (obj) {
if (typeof obj === 'object' && obj.message) {
if (obj.command === 'send') {
// e.g. send email or pushover or whatever
console.log('send command');

// Send response in callback if required
if (obj.callback) adapter.sendTo(obj.from, obj.command, 'Message received', obj.callback);
}
}
},
// is called when databases are connected and adapter received configuration.
// start here!
ready: main()
});
// you have to call the adapter function and pass a options object
// adapter will be restarted automatically every time as the configuration changed, e.g system.adapter.template.0
adapter = new utils.Adapter(options);

return adapter;
};

function main() {

Expand Down Expand Up @@ -153,6 +159,12 @@ function main() {
console.log('check group user admin group admin: ' + res);
});



}

// 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();
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.template",
"version": "0.6.0",
"version": "0.7.0",
"description": "ioBroker template Adapter",
"author": {
"name": "@@Author@@",
Expand All @@ -24,7 +24,9 @@
"type": "git",
"url": "https://github.com/ioBroker/ioBroker.template"
},
"dependencies": {},
"dependencies": {
"@iobroker/adapter-core": "^1.0.3"
},
"devDependencies": {
"gulp": "^3.9.1",
"mocha": "^4.1.0",
Expand Down

0 comments on commit 9e5a861

Please sign in to comment.