forked from Z-Wave-Me/home-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
107 lines (75 loc) · 2.38 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*** Z-Way Home Automation Engine main executable *****************************
Version: 0.1.2
(c) ZWave.Me, 2013
-------------------------------------------------------------------------------
Author: Gregory Sitnin <sitnin@z-wave.me>
Description:
This is a main executable script which is loaded and executed solely
by the z-way-server daemon. The very magic starts here.
******************************************************************************/
//--- Define global variables and helpers
var window = global = this;
var console = {
log: debugPrint,
warn: debugPrint,
error: debugPrint,
debug: debugPrint
};
function inherits (ctor, superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
}
// Array.prototype.has = function (value) {
// return -1 != this.indexOf(value);
// };
function in_array (array, value) {
return -1 != array.indexOf(value);
}
// Object.prototype.hasKey = function (value) {
// return -1 != Object.keys(this).indexOf(value);
// };
function has_key (obj, key) {
return -1 != Object.keys(obj).indexOf(key);
}
function get_values (obj) {
var res = [];
Object.keys(obj).forEach(function (key) {
res.push(obj[key]);
});
return res;
}
//--- Load configuration
var config = loadJSON("config.json");
config.libPath = "lib";
config.classesPath = "classes";
config.resourcesPath = "res";
// console.log("CFG", JSON.stringify(config, null, " "));
//--- Load constants & 3d-party dependencies
executeFile("constants.js");
executeFile(config.libPath + "/eventemitter2.js");
//--- Load Automation subsystem classes
executeFile(config.classesPath+"/AutomationController.js");
executeFile(config.classesPath+"/AutomationModule.js");
executeFile(config.classesPath+"/VirtualDevice.js");
//--- Instantiate Automation Controller
var controller = new AutomationController(config.controller);
controller.on('init', function () {
controller.run();
});
controller.on('error', function (err) {
console.log("--- ERROR:", err.message);
});
controller.on('run', function () {
console.log('ZWay Automation Controller started');
//--- Initialize webserver
executeFile("webserver.js");
});
//--- main
controller.init();