-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
98 lines (79 loc) · 3 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
"use strict";
var LoxoneAPI = require('loxone-nodejs');
var LoxoneTemperatureSensor = require('./types/TemperatureSensor');
var LoxoneHumiditySensor = require('./types/HumiditySensor');
//var LoxoneAirQuality = require('./types/AirQualitySensor');
var LoxoneOutlet = require('./types/Outlet');
var LoxoneLightbulb = require('./types/LightBulb');
var LoxoneFan = require('./types/Fan');
var LoxoneAlarm = require('./types/Alarm');
var Service, Characteristic, HAP;
module.exports = function(homebridge) {
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
HAP = homebridge.hap;
//console.log(Service);
homebridge.registerPlatform("homebridge-loxone", "Loxone", LoxonePlatform);
};
var sensorsTypes = {
'TemperatureSensors': LoxoneTemperatureSensor,
'HumiditySensors': LoxoneHumiditySensor,
//'AirQualitySensors': LoxoneAirQuality,
'Outlets': LoxoneOutlet,
'LightBulbs': LoxoneLightbulb,
'Fans': LoxoneFan,
'Alarms': LoxoneAlarm
};
function LoxonePlatform(log, config) {
this.log = log;
this.debug = log.debug;
this.config = config;
if (!this.config['ip_address']) throw new Error("You must provide an ip address of your Loxone.");
this.loxone = new LoxoneAPI({
ip: config['ip_address'],
username: config['username'] || 'admin',
password: config['password'] || 'admin'
});
}
LoxonePlatform.prototype = {
accessories: function(callback) {
this.log("Fetching LoxonePlatform accessories.");
var platform = this;
//create array of accessories
var myAccessories = [];
for (var type in sensorsTypes) {
var AccessoryClass = sensorsTypes[type];
var accessoriesList = platform.config[type];
if (accessoriesList != undefined) {
for(var i in accessoriesList) {
var config = accessoriesList[i];
var accessory = new AccessoryClass(config, platform, HAP);
if (accessory != undefined) {
myAccessories.push(accessory);
} else {
this.log.error("Could not initialize accessory", config);
}
}
}
}
// if done, return the array to callback function
callback(myAccessories);
}
};
LoxonePlatform.prototype.getInformationService = function(accessory) {
var serial = '';
if (accessory.input != undefined) {
serial += accessory.input + "-";
}
if (accessory.output != undefined) {
serial += accessory.output + "-";
}
serial += 'loxone';
var informationService = new Service.AccessoryInformation();
informationService
.setCharacteristic(Characteristic.Name, accessory.name)
.setCharacteristic(Characteristic.Manufacturer, 'Loxone')
.setCharacteristic(Characteristic.Model, '1.0.0')
.setCharacteristic(Characteristic.SerialNumber, serial);
return informationService;
};