-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlight.class.js
63 lines (48 loc) · 1.41 KB
/
light.class.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
const HomeKit = require('./HomeKit.class');
module.exports = class rgbwLight extends HomeKit {
constructor(device, { startChannel, channels, switchType = 'render' } = {}) {
super(device);
this.startChannel = startChannel;
this.channels = {
brightness: startChannel + channels.brightness,
};
this.values = {
brightness: 0,
on: 0
};
this.switchType = switchType;
this.init();
}
init() {
// getter
//
super.on('get', 'On', (callback) => {
callback(null, this.values.on);
});
super.on('get', 'Brightness', (callback) => {
callback(null, this.values.brightness * 100);
});
// setter
//
super.on('set', 'On', (value, callback) => {
this.values.on = !!value;
if (!this.values.on) {
this.updateDMX(true);
} else {
this.updateDMX();
}
callback();
});
super.on('set', 'Brightness', (value, callback) => {
this.values.brightness = +value / 100;
this.updateDMX();
callback();
});
super.publish();
}
updateDMX(zero) {
global.d2HK.DMX
.set(this.channels.brightness, zero ? 0 : this.values.brightness * 255)
[this.switchType]();
}
}