-
Notifications
You must be signed in to change notification settings - Fork 23
/
discover_test.go
73 lines (58 loc) · 1.4 KB
/
discover_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
package hue
import (
"bytes"
"encoding/json"
"fmt"
"log"
"os"
"testing"
)
var host = os.Getenv("HUE_HOST")
var username = os.Getenv("HUE_USERNAME")
func ExampleDiscoverBridges() {
locators, _ := DiscoverBridges(false)
locator := locators[0] // find the first locator
deviceType := "my nifty app"
// remember to push the button on your hue first
bridge, _ := locator.CreateUser(deviceType)
fmt.Printf("registered new device => %+v\n", bridge)
}
func ExampleNewBridge() {
bridge := NewBridge("your-ip-address", "your-username")
lights, _ := bridge.GetAllLights()
for _, light := range lights {
light.On()
}
}
func TestDiscoverBridges(t *testing.T) {
locators, err := DiscoverBridges(false)
if err != nil {
log.Printf("%+v\n", err)
t.Fail()
}
if locators == nil {
t.Error("locators was null! this should never happen")
}
log.Printf("%+v\n", locators)
}
func TestDeserializeComplexMap(t *testing.T) {
data := []byte(`[{"success":{"username": "1234567890"}}]`)
var results []map[string]map[string]string
json.NewDecoder(bytes.NewReader(data)).Decode(&results)
if results == nil {
t.Fail()
}
fmt.Printf("%+v\n", results)
}
func TestGetAllLights(t *testing.T) {
bridge := NewBridge(host, username)
lights, err := bridge.GetAllLights()
if err != nil {
log.Printf("%+v\n", err)
t.Fail()
}
if len(lights) != 8 {
t.Error("expected 8 lights")
}
fmt.Printf("%+v\n", lights)
}