-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
55 lines (45 loc) · 1.13 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
/*
*
* ioBroker wioBrowser Adapter
*
* (c) 2023 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) => {
if (state && !state.ack) {
client.onStateChange(id, state);
}
});
return adapter;
}
function main() {
adapter.subscribeStates('*');
client = new Client(adapter);
}
// If started as allInOne/compact mode => return function to create instance
// @ts-ignore
if (module.parent) {
module.exports = startAdapter;
} else {
// or start the instance directly
startAdapter();
}