-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
58 lines (45 loc) · 1.58 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
'use strict';
var dash = require('node-dash-button');
var Characteristic, Service;
var switchService;
module.exports = function(homebridge){
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
homebridge.registerAccessory('homebridge-dash', 'Dash', DashAccessory, false);
};
function DashAccessory(log, config, api) {
this.log = log;
this.config = config;
this.mac = config.mac;
this.name = config.name || 'Amazon Dash';
this.protocol = config.protocol || 'all';
this.isOn = false;
this.infoService = new Service.AccessoryInformation();
this.infoService
.setCharacteristic(Characteristic.Manufacturer, 'Amazon Technologies Inc.')
.setCharacteristic(Characteristic.Model, 'AmazonDash')
.setCharacteristic(Characteristic.SerialNumber, this.mac);
this.switchService = new Service.Switch();
this.switchService.setCharacteristic(Characteristic.On, this.isOn)
.on('get', this.getState.bind(this))
.on('set', this.setState.bind(this));
var dashButton = dash(this.mac, null, null, this.protocol);
dashButton.on('detected', function() {
this.on = !this.on;
this.switchService.setCharacteristic(Characteristic.On, this.on);
}.bind(this));
}
DashAccessory.prototype.identify = function(callback) {
this.log('Identify requested!');
callback();
};
DashAccessory.prototype.getServices = function() {
return [this.infoService, this.switchService];
};
DashAccessory.prototype.getState = function(callback) {
return callback(null, this.isOn);
};
DashAccessory.prototype.setState = function(value, callback) {
this.isOn = value;
callback();
};