Skip to content

Commit d3e6da1

Browse files
committed
Merge branch 'http_mock'
2 parents 5723da3 + a18312f commit d3e6da1

14 files changed

+525
-310
lines changed

bridge.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ func (b *Bridge) DeleteUser(n string) error {
186186
}
187187

188188
// GetFullState returns the entire bridge configuration.
189-
func (b *Bridge) GetFullState() (*Datastore, error) {
189+
func (b *Bridge) GetFullState() (map[string]interface{}, error) {
190190

191-
var ds *Datastore
191+
var n map[string]interface{}
192192

193193
url, err := b.getAPIPath("/")
194194
if err != nil {
@@ -200,12 +200,12 @@ func (b *Bridge) GetFullState() (*Datastore, error) {
200200
return nil, err
201201
}
202202

203-
err = unmarshal(res, &ds)
203+
err = unmarshal(res, &n)
204204
if err != nil {
205205
return nil, err
206206
}
207207

208-
return ds, nil
208+
return n, nil
209209
}
210210

211211
/*
@@ -229,7 +229,6 @@ func (b *Bridge) GetGroups() ([]Group, error) {
229229
return nil, err
230230
}
231231

232-
//err = unmarshal(res, &m)
233232
err = unmarshal(res, &m)
234233
if err != nil {
235234
return nil, err
@@ -562,7 +561,7 @@ func (b *Bridge) GetNewLights() (*NewLight, error) {
562561
if k == "lastscan" {
563562
lastscan = n[k].(string)
564563
} else {
565-
lights = append(lights, n[k].(string))
564+
lights = append(lights, k)
566565
}
567566
}
568567

@@ -1486,10 +1485,7 @@ func (b *Bridge) GetNewSensors() (*NewSensor, error) {
14861485
return nil, err
14871486
}
14881487

1489-
err = unmarshal(res, &n)
1490-
if err != nil {
1491-
return nil, err
1492-
}
1488+
_ = unmarshal(res, &n)
14931489

14941490
sensors := make([]*Sensor, 0, len(n))
14951491

bridge_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@ func TestLoginUnauthorized(t *testing.T) {
2828
t.Logf("Bridge: %s, Username: %s", b.Host, b.User)
2929
t.Log("User logged in and authenticated which isn't what we want")
3030
}
31+
32+
func TestUpdateBridgeConfig(t *testing.T) {
33+
b := huego.New(hostname, username)
34+
c, err := b.GetConfig()
35+
if err != nil {
36+
t.Fatal(err)
37+
}
38+
_, err = b.UpdateConfig(c)
39+
if err != nil {
40+
t.Fatal(err)
41+
}
42+
}

capabilities.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package huego
22

33
// Capabilities holds a combined model of resource capabilities on the bridge: https://developers.meethue.com/documentation/lights-api
44
type Capabilities struct {
5-
Groups *Capability `json:"groups,omitempty"`
6-
Lights *Capability `json:"lights,omitempty"`
7-
Resourcelinks *Capability `json:"resourcelinks,omitempty"`
8-
Schedules *Capability `json:"schedules,omitempty"`
9-
Rules *Capability `json:"rules,omitempty"`
10-
Scenes *Capability `json:"scenes,omitempty"`
11-
Sensors *Capability `json:"sensors,omitempty"`
12-
Streaming *Capability `json:"streaming,omitempty"`
5+
Groups Capability `json:"groups,omitempty"`
6+
Lights Capability `json:"lights,omitempty"`
7+
Resourcelinks Capability `json:"resourcelinks,omitempty"`
8+
Schedules Capability `json:"schedules,omitempty"`
9+
Rules Capability `json:"rules,omitempty"`
10+
Scenes Capability `json:"scenes,omitempty"`
11+
Sensors Capability `json:"sensors,omitempty"`
12+
Streaming Capability `json:"streaming,omitempty"`
1313
}
1414

1515
// Capability defines the resource and subresource capabilities.

config_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,11 @@ func TestGetUsers(t *testing.T) {
9090

9191
func TestDeleteUser(t *testing.T) {
9292
b := huego.New(hostname, username)
93-
users, err := b.GetUsers()
93+
err := b.DeleteUser("ffffffffe0341b1b376a2389376a2389")
9494
if err != nil {
9595
t.Fatal(err)
9696
}
97-
for _, user := range users {
98-
if user.Name == "github.com/amimof/huego#go test" {
99-
err := b.DeleteUser(user.Username)
100-
if err != nil {
101-
t.Fatal(err)
102-
}
103-
t.Logf("Deleted user '%s' (%s)", user.Name, user.Username)
104-
}
105-
}
97+
t.Logf("Deleted user '%s'", "ffffffffe0341b1b376a2389376a2389")
10698
}
10799

108100
func TestGetFullState(t *testing.T) {

group.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package huego
22

33
// Group represents a bridge group https://developers.meethue.com/documentation/groups-api
44
type Group struct {
5-
Name string `json:"name,omitempty"`
6-
Lights []string `json:"lights,omitempty"`
7-
Type string `json:"type,omitempty"`
8-
GroupState *GroupState `json:"state,omitempty"`
9-
Recycle bool `json:"recycle,omitempty"`
10-
Class string `json:"class,omitempty"`
11-
State *State `json:"action,omitempty"`
12-
ID int `json:"-"`
5+
Name string `json:"name,omitempty"`
6+
Lights []string `json:"lights,omitempty"`
7+
Type string `json:"type,omitempty"`
8+
GroupState GroupState `json:"state,omitempty"`
9+
Recycle bool `json:"recycle,omitempty"`
10+
Class string `json:"class,omitempty"`
11+
State *State `json:"action,omitempty"`
12+
ID int `json:"-"`
1313
bridge *Bridge
1414
}
1515

group_test.go

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -45,43 +45,36 @@ func TestGetGroups(t *testing.T) {
4545

4646
func TestGetGroup(t *testing.T) {
4747
b := huego.New(hostname, username)
48-
groups, err := b.GetGroups()
49-
if err != nil {
50-
t.Fatal(err)
51-
}
52-
for _, group := range groups {
53-
g, err := b.GetGroup(group.ID)
54-
if err != nil {
55-
t.Fatal(err)
56-
}
57-
t.Logf("Name: %s", g.Name)
58-
t.Logf("Lights: %s", g.Lights)
59-
t.Logf("Type: %s", g.Type)
60-
t.Logf("GroupState:")
61-
t.Logf(" AllOn: %t", g.GroupState.AllOn)
62-
t.Logf(" AnyOn: %t", g.GroupState.AnyOn)
63-
t.Logf("Recycle: %t", g.Recycle)
64-
t.Logf("Class: %s", g.Class)
65-
t.Logf("State:")
66-
t.Logf(" On: %t", g.State.On)
67-
t.Logf(" Bri: %d", g.State.Bri)
68-
t.Logf(" Hue: %d", g.State.Hue)
69-
t.Logf(" Sat: %d", g.State.Sat)
70-
t.Logf(" Xy: %b", g.State.Xy)
71-
t.Logf(" Ct: %d", g.State.Ct)
72-
t.Logf(" Alert: %s", g.State.Alert)
73-
t.Logf(" Effect: %s", g.State.Effect)
74-
t.Logf(" TransitionTime: %d", g.State.TransitionTime)
75-
t.Logf(" BriInc: %d", g.State.BriInc)
76-
t.Logf(" SatInc: %d", g.State.SatInc)
77-
t.Logf(" HueInc: %d", g.State.HueInc)
78-
t.Logf(" CtInc: %d", g.State.CtInc)
79-
t.Logf(" XyInc: %d", g.State.XyInc)
80-
t.Logf(" ColorMode: %s", g.State.ColorMode)
81-
t.Logf(" Reachable: %t", g.State.Reachable)
82-
t.Logf("ID: %d", g.ID)
83-
break
84-
}
48+
g, err := b.GetGroup(1)
49+
if err != nil {
50+
t.Fatal(err)
51+
}
52+
t.Logf("Name: %s", g.Name)
53+
t.Logf("Lights: %s", g.Lights)
54+
t.Logf("Type: %s", g.Type)
55+
t.Logf("GroupState:")
56+
t.Logf(" AllOn: %t", g.GroupState.AllOn)
57+
t.Logf(" AnyOn: %t", g.GroupState.AnyOn)
58+
t.Logf("Recycle: %t", g.Recycle)
59+
t.Logf("Class: %s", g.Class)
60+
t.Logf("State:")
61+
t.Logf(" On: %t", g.State.On)
62+
t.Logf(" Bri: %d", g.State.Bri)
63+
t.Logf(" Hue: %d", g.State.Hue)
64+
t.Logf(" Sat: %d", g.State.Sat)
65+
t.Logf(" Xy: %b", g.State.Xy)
66+
t.Logf(" Ct: %d", g.State.Ct)
67+
t.Logf(" Alert: %s", g.State.Alert)
68+
t.Logf(" Effect: %s", g.State.Effect)
69+
t.Logf(" TransitionTime: %d", g.State.TransitionTime)
70+
t.Logf(" BriInc: %d", g.State.BriInc)
71+
t.Logf(" SatInc: %d", g.State.SatInc)
72+
t.Logf(" HueInc: %d", g.State.HueInc)
73+
t.Logf(" CtInc: %d", g.State.CtInc)
74+
t.Logf(" XyInc: %d", g.State.XyInc)
75+
t.Logf(" ColorMode: %s", g.State.ColorMode)
76+
t.Logf(" Reachable: %t", g.State.Reachable)
77+
t.Logf("ID: %d", g.ID)
8578
}
8679

8780
func TestCreateGroup(t *testing.T) {
@@ -104,7 +97,7 @@ func TestCreateGroup(t *testing.T) {
10497

10598
func TestUpdateGroup(t *testing.T) {
10699
b := huego.New(hostname, username)
107-
id := 3
100+
id := 1
108101
resp, err := b.UpdateGroup(id, huego.Group{
109102
Name: "TestGroup (Updated)",
110103
Class: "Office",
@@ -121,7 +114,7 @@ func TestUpdateGroup(t *testing.T) {
121114

122115
func TestSetGroupState(t *testing.T) {
123116
b := huego.New(hostname, username)
124-
id := 3
117+
id := 1
125118
resp, err := b.SetGroupState(id, huego.State{
126119
On: true,
127120
Bri: 150,
@@ -139,7 +132,7 @@ func TestSetGroupState(t *testing.T) {
139132

140133
func TestRenameGroup(t *testing.T) {
141134
bridge := huego.New(hostname, username)
142-
id := 3
135+
id := 1
143136
group, err := bridge.GetGroup(id)
144137
if err != nil {
145138
t.Fatal(err)
@@ -336,7 +329,7 @@ func TestSetStateGroup(t *testing.T) {
336329

337330
func TestDeleteGroup(t *testing.T) {
338331
b := huego.New(hostname, username)
339-
id := 3
332+
id := 1
340333
err := b.DeleteGroup(id)
341334
if err != nil {
342335
t.Fatal(err)

huego.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,27 @@ func delete(url string) ([]byte, error) {
189189
// DiscoverAll returns a list of Bridge objects.
190190
func DiscoverAll() ([]Bridge, error) {
191191

192-
res, err := get("https://www.meethue.com/api/nupnp")
192+
req, err := http.NewRequest("GET", "https://discovery.meethue.com", nil)
193+
if err != nil {
194+
return nil, err
195+
}
196+
197+
client := http.Client{}
198+
res, err := client.Do(req)
199+
if err != nil {
200+
return nil, err
201+
}
202+
203+
defer res.Body.Close()
204+
205+
d, err := ioutil.ReadAll(res.Body)
193206
if err != nil {
194207
return nil, err
195208
}
196209

197210
var bridges []Bridge
198211

199-
err = json.Unmarshal(res, &bridges)
212+
err = json.Unmarshal(d, &bridges)
200213
if err != nil {
201214
return nil, err
202215
}

0 commit comments

Comments
 (0)