-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
50 lines (40 loc) · 917 Bytes
/
main.go
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
package main
import (
"fmt"
"net"
"os"
"time"
magichome "github.com/moonliightz/magic-home/pkg"
)
func checkError(e error) {
if e != nil {
fmt.Println("Error: ", e)
os.Exit(1)
}
}
func main() {
// Create a new Magic Home LED Strip Controller
controller, err := magichome.New(net.ParseIP("192.168.1.42"), 5577)
checkError(err)
// Turn LED Strip Controller on
err = controller.SetState(magichome.On)
checkError(err)
// Sleep a few seconds to avoid spam
time.Sleep(5 * time.Second)
// Set color of LED Strip to white
err = controller.SetColor(magichome.Color{
R: 255,
G: 255,
B: 255,
W: 0,
})
checkError(err)
// Sleep again a few seconds to avoid spam
time.Sleep(5 * time.Second)
// Tun LED Strip Controller off
err = controller.SetState(magichome.Off)
checkError(err)
// And finaly close the connection to LED Strip Controller
err = controller.Close()
checkError(err)
}