aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bridge.go20
-rw-r--r--bridge_test.go10
2 files changed, 14 insertions, 16 deletions
diff --git a/bridge.go b/bridge.go
index 1d541da..a69c736 100644
--- a/bridge.go
+++ b/bridge.go
@@ -28,7 +28,7 @@ import (
// Bridge struct defines hardware that is used to communicate with the lights.
type Bridge struct {
- IPAddress string
+ IPAddress string `json:"internalipaddress"`
Username string
Info BridgeInfo
}
@@ -155,22 +155,20 @@ func HandleResponse(resp *http.Response) ([]byte, io.Reader, error) {
// FindBridge will visit www.meethue.com/api/nupnp to see if a bridge
// is available on the local network. This feature currently only supports one
// bridge on the network.
-func FindBridge() (Bridge, error) {
+func FindBridges() ([]Bridge, error) {
bridge := Bridge{IPAddress: "www.meethue.com"}
body, _, err := bridge.Get("/api/nupnp")
if err != nil {
err = errors.New("Error: Unable to locate bridge.")
log.Fatal(err)
- return Bridge{}, err
+ return []Bridge{}, err
}
- content := string(body)
- ip := content[strings.LastIndex(content, ":\"")+2 : strings.LastIndex(content, "\"}]")]
- bridge.IPAddress = ip
- err = bridge.GetInfo()
- if err != nil {
- return Bridge{}, err
- }
- return bridge, nil
+ bridges := []Bridge{}
+ err = json.Unmarshal(body, &bridges)
+ if err != nil {
+ return []Bridge{}, errors.New("Unable to parse FindBridges response. ")
+ }
+ return bridges, nil
}
// NewBridge defines hardware that is compatible with Hue.
diff --git a/bridge_test.go b/bridge_test.go
index cc312fe..04aa0d0 100644
--- a/bridge_test.go
+++ b/bridge_test.go
@@ -19,16 +19,16 @@ func TestCreateUser(t *testing.T) {
//bridge.DeleteUser(bridge.Username)
}
-func TestFindBridge(t *testing.T) {
- bridge, _ := FindBridge()
- fmt.Println(bridge.IPAddress)
+func TestFindBridges(t *testing.T) {
+ bridges, _ := FindBridges()
+ fmt.Println(bridges[0].IPAddress)
}
func TestBridgeLogin(t *testing.T) {
- bridge, err := FindBridge()
+ bridges, err := FindBridges()
if err != nil {
fmt.Println("Error on TestBridgeLogin")
}
- bridge.Login("427de8bd6d49f149c8398e4fc08f")
+ bridges[0].Login("427de8bd6d49f149c8398e4fc08f")
}