-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.js
55 lines (49 loc) · 1.21 KB
/
Client.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
import Govee from "node-govee-led";
class Client {
govee = new Govee({
apiKey: process.env.API,
mac: process.env.MAC,
model: process.env.MODEL
})
init() {
this.govee = new Govee({
apiKey: process.env.API,
mac: process.env.MAC,
model: process.env.MODEL
});
this.turnOn();
}
on = false;
toHex(n) {
const h = n.toString(16);
if(h.length == 1) return "0" + h;
return h;
}
setColor(r, g, b) {
if(!this.on) this.turnOn();
const hexCode = "#" + this.toHex(r) + this.toHex(g) + this.toHex(b);
console.log("Setting color to: " + hexCode);
this.govee.setColor(hexCode);
}
setBrightness(b) {
if(!this.on) this.turnOn();
this.govee.setBrightness(b);
}
setTemperature(t) {
if(!this.on) this.turnOn();
this.govee.setColorTemperature(t);
}
turnOn() {
this.govee.turnOn();
this.on = true;
setTimeout(() => {
this.on = false;
}, 30 * 1000);
}
turnOff() {
this.govee.turnOff();
this.on = false;
}
}
const client = new Client({});
export default client;