-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
64 lines (52 loc) · 1.66 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
var rcswitch = require('rcswitch');
var Service;
var Characteristic;
module.exports = function (homebridge) {
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
homebridge.registerAccessory('homebridge-rcswitch', 'RcSwitch', RadioSwitch);
};
function RadioSwitch(log, config) {
if (config.systemcode === undefined) {
return log('Systemcode missing from configuration.');
}
if (config.unitcode === undefined) {
return log('Unitcode missing from configuration.');
}
if (config.name === undefined) {
return log('Name missing from configuration.');
}
rcswitch.enableTransmit(config.pin || 0);
var switchOn = rcswitch.switchOn.bind(rcswitch, config.systemcode, config.unitcode);
var switchOff = rcswitch.switchOff.bind(rcswitch, config.systemcode, config.unitcode);
var informationService = new Service.AccessoryInformation();
informationService
.setCharacteristic(Characteristic.Name, 'Raspberry-Projekt')
.setCharacteristic(Characteristic.Manufacturer, 'JadeHochschule')
.setCharacteristic(Characteristic.Model, 'v0.1')
.setCharacteristic(Characteristic.SerialNumber, config.systemcode + '|' + config.unitcode);
var state = false;
var switchService = new Service.Switch(config.name);
switchService
.getCharacteristic(Characteristic.On)
.on('set', function (value, callback) {
state = value;
if (state) {
switchOn();
} else {
switchOff();
}
callback();
});
switchService
.getCharacteristic(Characteristic.On)
.on('get', function (callback) {
callback(null, state);
});
this.services = [informationService, switchService];
}
RadioSwitch.prototype = {
getServices: function () {
return this.services;
}
};