-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
66 lines (59 loc) · 1.94 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
var chaconEmitter = require('./chaconEmitter');
var Service;
var Characteristic;
var noInitDone = true;
module.exports = function(homebridge) {
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
homebridge.registerAccessory("homebridge-rpi-chacon", "Chacon", ChaconAccessory);
}
function ChaconAccessory(log, config) {
this.log = log;
this.deviceId = config['deviceId'];
this.emitterId = config['emitterId'];
this.isDimmable = config['dimmable'];
if (noInitDone) {
chaconEmitter.init();
noInitDone = false;
}
}
ChaconAccessory.prototype = {
setPowerState: function(powerOn, callback) {
var that = this;
var order = chaconEmitter.buildOrder(this.emitterId, this.deviceId, powerOn);
chaconEmitter.transmit(order);
callback(null);
},
setBrightness: function(level, callback) {
var that = this;
var order = chaconEmitter.buildDimOrder(this.emitterId, this.deviceId, level);
chaconEmitter.transmit(order, true);
callback(null);
},
getServices: function() {
var switchService = new Service.Switch(this.name);
var lightBulb = new Service.Lightbulb(this.name);
//var informationService = new Service.AccessoryInformation();
/* informationService
.setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
.setCharacteristic(Characteristic.Model, this.model_name)
.setCharacteristic(Characteristic.SerialNumber, this.id);
*/
switchService
.getCharacteristic(Characteristic.On)
.on('set', this.setPowerState.bind(this));
lightBulb
.getCharacteristic(Characteristic.On)
.on('set', this.setPowerState.bind(this));
lightBulb
.getCharacteristic(Characteristic.Brightness)
.on('set', this.setBrightness.bind(this))
if (this.isDimmable === "true") {
return [lightBulb];
}
else {
return [switchService];
}
}
}
module.exports.accessory = ChaconAccessory;