-
Notifications
You must be signed in to change notification settings - Fork 4
/
openligadb.js
executable file
·79 lines (65 loc) · 1.99 KB
/
openligadb.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"use strict";
/*
* Created with @iobroker/create-adapter v1.12.0
*/
// The adapter-core module gives you access to the core ioBroker functions
// you need to create an adapter
const utils = require("@iobroker/adapter-core");
// Load your modules here, e.g.:
// const fs = require("fs");
const IoOlServer = require(__dirname + "/lib/openligadbserver.js");
/**
* The adapter instance
* @type {ioBroker.Adapter}
*/
let adapter;
let openligadbServer;
/**
* Starts the adapter instance
* @param {Partial<ioBroker.AdapterOptions>} [options]
*/
function startAdapter(options) {
// Create the adapter and define its methods
// @ts-ignore
return adapter = utils.adapter(Object.assign({}, options, {
name: "openligadb",
// The ready callback is called when databases are connected and adapter received configuration.
// start here!
ready: main, // Main method defined below for readability
// is called when adapter shuts down - callback has to be called under any circumstances!
unload: (callback) => {
try {
openligadbServer.closeConnections();
adapter.log.info("openligadb unloaded");
callback();
} catch {
callback();
}
},
message: (obj) => {
if (typeof obj === "object" && obj.message) {
openligadbServer.processMessages(obj);
}
},
// is called if a subscribed state changes
stateChange: (id, state) => {
if (state) {
// The state was changed
if (openligadbServer) openligadbServer.stateChange(id, state);
}
},
}));
}
function main() {
if (!openligadbServer) {
openligadbServer = new IoOlServer(adapter);
}
}
// @ts-ignore
if (module.parent) {
// Export startAdapter in compact mode
module.exports = startAdapter;
} else {
// otherwise start the instance directly
startAdapter();
}