-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
134 lines (108 loc) · 5.05 KB
/
index.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
let Accessory, Service, Characteristic, UUIDGen;
const ItemFactory = require('./libs/ItemFactory.js');
const Utility = require('./libs/Utility.js');
const WSListener = require('./libs/WSListener.js');
module.exports = homebridge => {
console.log(`homebridge API version: ${homebridge.version}`);
// Accessory must be created from PlatformAccessory Constructor
Accessory = homebridge.platformAccessory;
// Keep refference to the passes API object
Homebridge = homebridge;
//Add inheritance of the AbstractItem to the Accessory object
Utility.addSupportTo(ItemFactory.AbstractItem, Accessory);
//All other items are child of the abstractItem
Utility.addSupportTo(ItemFactory.LightControllerV2MoodSwitch, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.Trigger, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.TemperatureSensor, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.HumiditySensor, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.MotionSensor, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.ContactSensor, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.LightSensor, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.LeakSensor, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.Dimmer, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.Colorpicker, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.Gate, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.Doorbell, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.Blinds, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.Shutters, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.TimedSwitch, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.Switch, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.SmokeSensor, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.Alarm, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.RadioSwitchItem, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.Lock, ItemFactory.AbstractItem);
Utility.addSupportTo(ItemFactory.Valve, ItemFactory.AbstractItem);
//Add childs of switch
Utility.addSupportTo(ItemFactory.Lightbulb, ItemFactory.Switch);
Utility.addSupportTo(ItemFactory.Outlet, ItemFactory.Switch);
Utility.addSupportTo(ItemFactory.Pushbutton, ItemFactory.Switch);
Utility.addSupportTo(ItemFactory.Fan, ItemFactory.Switch);
//Add childs of shower
Utility.addSupportTo(ItemFactory.Sprinkler, ItemFactory.Valve);
homebridge.registerPlatform("homebridge-loxone-connect", "LoxoneWs", LoxPlatform);
};
// Platform constructor
function LoxPlatform(log, config) {
this.log = log;
this.config = config;
this.protocol = "http";
if (!this.config['host']) throw new Error("Configuration missing: loxone host (please provide the IP address here)");
if (!this.config['username']) throw new Error("Configuration missing: loxone username");
if (!this.config['password']) throw new Error("Configuration missing: loxone password");
if (!this.config['port']) this.config['port'] = 80;
this.host = config["host"];
this.port = config["port"];
this.username = config["username"];
this.password = config["password"];
//* Options *//
if (!config['options']) {
config['options'] = "";
}
const options = config['options'];
this.rooms = [];
if (options['rooms']) {
this.rooms = options["rooms"];
}
this.moodSwitches = 'none';
if (options['moodSwitches']) {
this.moodSwitches = options["moodSwitches"];
}
this.radioSwitches = 1;
if (options['radioSwitches'] !== undefined) {
this.radioSwitches = options["radioSwitches"];
}
this.timedswitch_method = "pulse";
if (options['stairwellSwitch'] == "on") {
this.timedswitch_method = "on";
}
this.alarmsystem_method = "delayedon";
if (options['alarmSystem'] == "on") {
this.alarmsystem_method = "on";
}
this.alarmsystem_trigger = 5;
if (options['alarmTrigerLevel']) {
if (options['alarmTrigerLevel'] > 0 && options['alarmTrigerLevel'] < 7) {
this.alarmsystem_trigger = options['alarmTrigerLevel'];
} else {
this.log("Info: alarmTrigerLevel must be an integer between 1 and 6");
}
}
this.autoLock = 1;
if (options['autoLock']) {
this.autoLock = options['autoLock'];
}
this.autoLockDelay = 5;
if (options['autoLockDelay']) {
this.autoLockDelay = options['autoLockDelay'];
}
//* Alias *//
this.alias = config['alias'];
}
LoxPlatform.prototype.accessories = async function (callback) {
const platform = this;
this.ws = new WSListener(platform);
while (!this.ws.loxdata) // Wait for json data
await new Promise(resolve => setTimeout(resolve, 1000));
const itemFactory = new ItemFactory.Factory(this, Homebridge);
callback(itemFactory.parseSitemap(this.ws.loxdata));
};