-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlights_test.go
144 lines (133 loc) · 2.66 KB
/
lights_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
package hue
import (
"fmt"
"os"
"testing"
"time"
"github.com/gosticks/go-hue-interface/utils"
)
func TestParseLights(t *testing.T) {
v := make(map[string]*Light)
err := utils.CompareJSONDecode(LightsTestData, &v)
if err != nil {
t.Fail()
}
}
func TestLightToggle(t *testing.T) {
userID, okUser := os.LookupEnv("HUE_BRIDGE_USER")
addr, okAddr := os.LookupEnv("HUE_BRIDGE_ADDR")
if !okAddr || !okUser {
fmt.Println("HUE_BRIDGE_USER and HUE_BRIDGE_ADDR must be set in env for this test to work")
t.Fail()
}
conf := &Config{
Username: userID,
BridgeAddr: addr,
BridgeAddrScheme: "http",
}
b := NewBridge(conf)
ticker := time.NewTicker(200 * time.Millisecond)
defer ticker.Stop()
go func() {
var state = true
for range ticker.C {
b.ToggleLight("2", state)
state = !state
}
}()
select {}
}
func TestBridgeLightsParse(t *testing.T) {
userID, okUser := os.LookupEnv("HUE_BRIDGE_USER")
addr, okAddr := os.LookupEnv("HUE_BRIDGE_ADDR")
if !okAddr || !okUser {
fmt.Println("HUE_BRIDGE_USER and HUE_BRIDGE_ADDR must be set in env for this test to work")
t.Fail()
}
conf := &Config{
Username: userID,
BridgeAddr: addr,
BridgeAddrScheme: "http",
}
b := NewBridge(conf)
resp, respErr := b.getRawResponse(LightsEndpoint)
if respErr != nil {
t.Log(respErr)
t.Error()
}
lights, errLights := b.GetLights()
if errLights != nil {
t.Log(errLights)
t.Error()
}
errComp := utils.CompareStructToJSON(lights, string(resp))
if errComp != nil {
t.Fail()
}
}
const LightsTestData = `{
"1": {
"state": {
"on": false,
"bri": 1,
"hue": 33761,
"sat": 254,
"effect": "none",
"xy": [
0.3171,
0.3366
],
"ct": 159,
"alert": "none",
"colormode": "xy",
"mode": "homeautomation",
"reachable": true
},
"swupdate": {
"state": "noupdates",
"lastinstall": "2018-01-02T19:24:20"
},
"type": "Extended color light",
"name": "Hue color lamp 7",
"modelid": "LCT007",
"manufacturername": "Philips",
"productname": "Hue color lamp",
"capabilities": {
"certified": true,
"control": {
"mindimlevel": 5000,
"maxlumen": 600,
"colorgamuttype": "B",
"colorgamut": [
[
0.675,
0.322
],
[
0.409,
0.518
],
[
0.167,
0.04
]
],
"ct": {
"min": 153,
"max": 500
}
},
"streaming": {
"renderer": true,
"proxy": false
}
},
"config": {
"archetype": "sultanbulb",
"function": "mixed",
"direction": "omnidirectional"
},
"uniqueid": "00:17:88:01:00:bd:c7:b9-0b",
"swversion": "5.105.0.21169"
}
}`