-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOppleLightAccessory.js
48 lines (37 loc) · 1.82 KB
/
OppleLightAccessory.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
class OppleLightAccessory {
constructor(platform, device, config = {}) {
this.name = config.name || device.name;
this.device = device;
this.platform = platform;
}
getServices() {
const { Service, Characteristic } = this.platform;
const lightbulbService = new Service.Lightbulb(this.name);
lightbulbService
.getCharacteristic(Characteristic.On)
.on('get', callback => this.device.getPower().then(value => callback(null, value), callback))
.on('set', (value, callback) => this.device.setPower(value).then(value => callback(), callback));
lightbulbService
.getCharacteristic(Characteristic.Brightness)
.on('get', callback => this.device.getBrightness().then(value => callback(null, value), callback))
.on('set', (value, callback) => this.device.setBrightness(value).then(value => callback(), callback));
lightbulbService
.getCharacteristic(Characteristic.ColorTemperature)
.setProps({
minValue: this.device.ctMin,
maxValue: this.device.ctMax
})
.on('get', callback => this.device.getColorTemperature().then(value => callback(null, value), callback))
.on('set', (value, callback) => this.device.setColorTemperature(value).then(value => callback(), callback));
const informationService = new Service.AccessoryInformation();
informationService
.setCharacteristic(Characteristic.Manufacturer, this.device.manufacturer)
.setCharacteristic(Characteristic.Model, this.device.model)
.setCharacteristic(Characteristic.SerialNumber, this.device.localAddress);
if (this.device.isInit) {
informationService.setCharacteristic(Characteristic.FirmwareRevision, this.device.version.toString().split('').join('.'));
}
return [informationService, lightbulbService];
}
}
module.exports = OppleLightAccessory;