-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathlight_test.go
81 lines (70 loc) · 1.77 KB
/
light_test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* light_test.go
* GoHue library for Philips Hue
* Copyright (C) 2016 Collin Guarino (Collinux) collinux[-at-]users.noreply.github.com
* License: GPL version 2 or higher http://www.gnu.org/licenses/gpl.html
*/
package hue
import (
"github.com/collinux/gohue"
"testing"
"time"
"os"
)
func TestSetLightState(t *testing.T) {
bridges, err := hue.FindBridges()
if err != nil {
t.Fatal(err)
}
bridge := bridges[0]
bridge.Login(os.Getenv("HUE_USER_TOKEN"))
//nameTest, err := bridge.GetLightByName("Desk Light") // Also tests GetAllLights
//if err != nil {
// t.Fatal(err)
//}
//_ = nameTest
selectedLight, err := bridge.GetLightByIndex(1)
if err != nil {
t.Fatal(err)
}
selectedLight.On()
selectedLight.SetBrightness(100)
time.Sleep(time.Second)
selectedLight.Off()
time.Sleep(time.Second)
selectedLight.Toggle()
time.Sleep(time.Second)
selectedLight.ColorLoop(false)
selectedLight.SetName(selectedLight.Name)
selectedLight.Blink(3)
selectedLight.Dim(20)
selectedLight.Brighten(20)
// Skip validation of colors
//selectedLight.SetColor(hue.RED)
//time.Sleep(time.Second)
//selectedLight.SetColor(hue.YELLOW)
//time.Sleep(time.Second)
//selectedLight.SetColor(hue.GREEN)
//time.Sleep(time.Second)
//selectedLight.SetColor(hue.WHITE)
//time.Sleep(time.Second)
//selectedLight.Off()
// TODO
// Skip validation of deleting and re-adding light
// _ := selectedLight.Delete()
}
func TestFindNewLights(t *testing.T) {
bridges, err := hue.FindBridges()
if err != nil {
t.Fatal(err)
}
bridge := bridges[0]
if os.Getenv("HUE_USER_TOKEN") == "" {
t.Fatal("The environment variable HUE_USER_TOKEN must be set to the value from bridge.CreateUser")
}
bridge.Login(os.Getenv("HUE_USER_TOKEN"))
err = bridge.FindNewLights()
if err != nil {
t.Fatal(err)
}
}