forked from amimof/huego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedule_test.go
109 lines (102 loc) · 2.58 KB
/
schedule_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
package huego_test
import (
"os"
"testing"
"github.com/Felixls/huego"
)
func TestGetSchedules(t *testing.T) {
b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME"))
schedules, err := b.GetSchedules()
if err != nil {
t.Fatal(err)
}
t.Logf("Found %d schedules", len(schedules))
for i, schedule := range schedules {
t.Logf("%d:", i)
t.Logf(" Name: %s", schedule.Name)
t.Logf(" Description: %s", schedule.Description)
t.Logf(" Command:")
t.Logf(" Address: %s", schedule.Command.Address)
t.Logf(" Method: %s", schedule.Command.Method)
t.Logf(" Body: %s", schedule.Command.Body)
t.Logf(" Time: %s", schedule.Time)
t.Logf(" LocalTime: %s", schedule.LocalTime)
t.Logf(" StartTime: %s", schedule.StartTime)
t.Logf(" Status: %s", schedule.Status)
t.Logf(" AutoDelete: %t", schedule.AutoDelete)
t.Logf(" ID: %d", schedule.ID)
}
}
func TestGetSchedule(t *testing.T) {
b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME"))
schedules, err := b.GetSchedules()
if err != nil {
t.Fatal(err)
}
for _, schedule := range schedules {
s, err := b.GetSchedule(schedule.ID)
if err != nil {
t.Fatal(err)
}
t.Logf("Time: %s", s.Time)
t.Logf("LocalTime: %s", s.LocalTime)
t.Logf("StartTime: %s", s.StartTime)
t.Logf("Status: %s", s.Status)
t.Logf("AutoDelete: %t", s.AutoDelete)
t.Logf("ID: %d", s.ID)
break
}
}
func TestCreateSchedule(t *testing.T) {
b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME"))
command := &huego.Command{
Address: "/api/" + os.Getenv("HUE_USERNAME") + "/lights/0",
Body: &struct {
on bool
}{
false,
},
Method: "PUT",
}
schedule := &huego.Schedule{
Name: "TestSchedule",
Description: "Huego test schedule",
Command: command,
LocalTime: "2019-09-22T13:37:00",
}
resp, err := b.CreateSchedule(schedule)
if err != nil {
t.Fatal(err)
} else {
t.Logf("Schedule created")
for k, v := range resp.Success {
t.Logf("%v: %s", k, v)
}
}
}
func TestUpdateSchedule(t *testing.T) {
b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME"))
id := 3
resp, err := b.UpdateSchedule(id, &huego.Schedule{
Name: "New Scehdule",
Description: "Updated parameter",
})
if err != nil {
t.Fatal(err)
} else {
t.Logf("Schedule %d updated", id)
for k, v := range resp.Success {
t.Logf("%v: %s", k, v)
}
}
}
func TestDeleteSchedule(t *testing.T) {
b := huego.New(os.Getenv("HUE_HOSTNAME"), os.Getenv("HUE_USERNAME"))
id := 3
err := b.DeleteSchedule(id)
if err != nil {
t.Fatal(err)
} else {
t.Logf("Schedule %d deleted", id)
}
}