forked from Bettman66/ioBroker.doorio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
56 lines (46 loc) · 1.61 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
*
* ioBroker DoorIO Adapter
*
* (c) 2020 bettman66<[email protected]>
*
* MIT License
*
*/
'use strict';
const utils = require('@iobroker/adapter-core'); // Get common adapter utils
const adapterName = require('./package.json').name.split('.').pop();
const Client = require('./lib/client');
let client = null;
let adapter;
function startAdapter(options) {
options = options || {};
Object.assign(options, { name: adapterName });
adapter = new utils.Adapter(options);
adapter.on('ready', function () {
main();
});
adapter.on('unload', function (callback) {
if (client) client.destroy();
callback();
});
adapter.on('stateChange', (id, state) => {
client.onStateChange(id, state);
});
return adapter;
}
function main() {
if ((adapter.config.ring1 != "none") && (adapter.config.ring1 != '')) { adapter.subscribeForeignStates(adapter.config.ring1) };
if ((adapter.config.ring2 != "none") && (adapter.config.ring2 != '')) { adapter.subscribeForeignStates(adapter.config.ring2) };
if ((adapter.config.ring3 != "none") && (adapter.config.ring3 != '')) { adapter.subscribeForeignStates(adapter.config.ring3) };
if ((adapter.config.ring4 != "none") && (adapter.config.ring4 != '')) { adapter.subscribeForeignStates(adapter.config.ring4) };
//adapter.subscribeStates('*');
client = new Client(adapter);
}
// 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();
}