forked from amimof/huego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene_test.go
173 lines (163 loc) · 4.15 KB
/
scene_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package huego_test
import (
"os"
"testing"
"github.com/Felixls/huego"
)
func TestGetScenes(t *testing.T) {
b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME"))
scenes, err := b.GetScenes()
if err != nil {
t.Fatal(err)
}
t.Logf("Found %d scenes", len(scenes))
for i, scene := range scenes {
t.Logf("%d", i)
t.Logf(" Name: %s", scene.Name)
t.Logf(" Lights: %s", scene.Lights)
t.Logf(" Owner: %s", scene.Owner)
t.Logf(" Recycle: %t", scene.Recycle)
t.Logf(" Locked: %t", scene.Locked)
t.Logf(" AppData: %s", scene.AppData)
t.Logf(" Picture: %s", scene.Picture)
t.Logf(" LastUpdated: %s", scene.LastUpdated)
t.Logf(" Version: %d", scene.Version)
t.Logf(" StoreSceneState: %t", scene.StoreSceneState)
t.Logf(" ID: %s", scene.ID)
}
}
func TestGetScene(t *testing.T) {
b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME"))
scenes, err := b.GetScenes()
if err != nil {
t.Fatal(err)
}
for _, scene := range scenes {
t.Logf("Getting scene %s", scene.ID)
s, err := b.GetScene(scene.ID)
if err != nil {
t.Fatal(err)
}
t.Logf(" Name: %s", s.Name)
t.Logf(" Lights: %s", s.Lights)
t.Logf(" Owner: %s", s.Owner)
t.Logf(" Recycle: %t", s.Recycle)
t.Logf(" Locked: %t", s.Locked)
t.Logf(" AppData: %s", s.AppData)
t.Logf(" Picture: %s", s.Picture)
t.Logf(" LastUpdated: %s", s.LastUpdated)
t.Logf(" Version: %d", s.Version)
t.Logf(" StoreSceneState: %t", s.StoreSceneState)
t.Logf(" ID: %s", s.ID)
t.Logf(" LightStates: %d", len(s.LightStates))
for k := range s.LightStates {
t.Logf(" Light %d: %+v", k, s.LightStates[k])
}
break
}
}
func TestCreateScene(t *testing.T) {
b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME"))
resp, err := b.CreateScene(&huego.Scene{
Name: "New Scene",
Lights: []string{"4", "5"},
Recycle: true,
})
if err != nil {
t.Fatal(err)
}
t.Logf("Scene created")
for k, v := range resp.Success {
t.Logf("%v: %s", k, v)
}
}
func TestUpdateScene(t *testing.T) {
b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME"))
scenes, err := b.GetScenes()
if err != nil {
t.Fatal(err)
}
for _, scene := range scenes {
if scene.Name == "New Scene" {
resp, err := b.UpdateScene(scene.ID, &huego.Scene{
Name: "New Scene",
Lights: []string{},
})
if err != nil {
t.Fatal(err)
}
t.Logf("Scene '%s' (%s) updated", scene.Name, scene.ID)
for k, v := range resp.Success {
t.Logf("%v: %s", k, v)
}
}
}
}
func TestSetSceneLightState(t *testing.T) {
b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME"))
scenes, err := b.GetScenes()
if err != nil {
t.Fatal(err)
}
for _, scene := range scenes {
if scene.Name == "New Scene" {
light := 4
t.Logf("Name: %s", scene.Name)
t.Logf("ID: %s", scene.ID)
t.Logf("LightStates: %+v", scene.LightStates)
_, err := b.SetSceneLightState(scene.ID, light, &huego.State{
On: true,
Bri: 255,
})
if err != nil {
t.Fatal(err)
}
t.Logf("Successfully set the state of light %d of scene '%s'", light, scene.Name)
}
}
}
func TestDeleteScene(t *testing.T) {
b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME"))
scenes, err := b.GetScenes()
if err != nil {
t.Fatal(err)
}
for _, scene := range scenes {
if scene.Name == "New Scene" {
err := b.DeleteScene(scene.ID)
if err != nil {
t.Fatal(err)
}
t.Logf("Scene %s (%s) deleted", scene.Name, scene.ID)
}
}
}
func TestRecallScene(t *testing.T) {
b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME"))
scene := "HcK1mEcgS7gcVcT"
group := 1
resp, err := b.RecallScene("HcK1mEcgS7gcVcT", group)
if err != nil {
t.Fatal(err)
}
t.Logf("Scene %s recalled in group %d", scene, group)
for k, v := range resp.Success {
t.Logf("%v: %s", k, v)
}
}
func TestRecallScene2(t *testing.T) {
b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME"))
group := 1
scenes, err := b.GetScenes()
if err != nil {
t.Fatal(err)
}
for _, scene := range scenes {
err = scene.Recall(group)
if err != nil {
t.Fatal(err)
}
t.Logf("Scene %s (%s) recalled in group %d", scene.Name, scene.ID, group)
break
}
}