forked from leoneleone/homebridge-sensibo-sky-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (65 loc) · 2.23 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
var sensibo = require('./lib/sensiboapi');
var Service, Characteristic, Accessory, uuid;
var SensiboPodAccessory;
const timeRefresh = 30000; // refresh state cycle time in ms
module.exports = function (homebridge) {
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
Accessory = homebridge.hap.Accessory;
uuid = homebridge.hap.uuid;
SensiboPodAccessory = require('./accessories/pods')(Accessory, Service, Characteristic, uuid);
homebridge.registerPlatform("homebridge-sensibo-sky", "SensiboSky", SensiboPlatform);
};
function SensiboPlatform(log, config) {
// Load Wink Authentication From Config File
this.apiKey = config["apiKey"];
this.apiDebug = config["apiDebug"];
this.timeLapse = config["timeLapse"];
this.AI = config["ai"]; //default state for ai
this.hideHumidity = config["hideHumidity"];
this.api=sensibo;
this.log = log;
this.debug = log.debug;
this.deviceLookup = {};
}
SensiboPlatform.prototype = {
reloadData: function (callback) {
//This is called when we need to refresh all Wink device information.
this.debug("Refreshing Sensibo Data");
for (var i = 0; i < this.deviceLookup.length; i++) {
this.deviceLookup[i].loadData();
}
},
accessories: function (callback) {
this.log("Fetching Sensibo devices...");
var that = this;
var foundAccessories = [];
this.deviceLookup = [];
/*
var refreshLoop = function () {
setInterval(that.reloadData.bind(that), timeRefresh);
};
*/
sensibo.init(this.apiKey, this.debug);
sensibo.getPods(that.log, function (devices) {
// success
var podTimeLapse = 0;
for (var i = 0; i < devices.length; i++) {
var device = devices[i];
var accessory = undefined;
device.AI = that.AI;
device.refreshCycle = that.timeLapse + podTimeLapse;
device.hideHumidity = that.hideHumidity || false;
podTimeLapse += 0.5;
accessory = new SensiboPodAccessory(that, device);
if (accessory != undefined) {
that.log("Device Added (Name: %s, ID: %s, Group: %s)", accessory.name, accessory.deviceid, accessory.deviceGroup);
that.deviceLookup.push(accessory);
foundAccessories.push(accessory);
}
}
//refreshLoop();
callback(foundAccessories);
});
}
};