forked from wailuen/homebridge-sensibo-sky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
96 lines (81 loc) · 2.87 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
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"] || false; //default state for ai
this.hideHumidity = config["hideHumidity"] || false;
this.hideFan = config["hideFan"] || false;
this.fixedState = config["fixedState"] || "auto";
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;
if (devices != null ) {
for (var i = 0; i < devices.length; i++) {
var device = devices[i];
var accessory = undefined;
device.AI = that.AI;
device.hideFan = that.hideFan // if AI is true, hideFan will be meaningless. If AI is false and hideFan is true, will make fan 100% all the time
device.refreshCycle = that.timeLapse + podTimeLapse;
device.hideHumidity = that.hideHumidity || false;
switch (that.fixedState.toLowerCase()) {
case "cool":
case "heat":
case "manual":
device.fixedState = that.fixedState.toLowerCase();
break;
default:
device.fixedState = "auto";
}
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);
}
}
callback(foundAccessories);
} else {
that.log("No senisbo devices return from Sensibo server ! Please check your APIkey.");
}
//refreshLoop();
});
}
};