aboutsummaryrefslogtreecommitdiff
path: root/bridge.go
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-02-29 19:32:17 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-02-29 19:32:17 -0500
commitd115895133ffd0f287eb0de096a897faaa7756e2 (patch)
tree4353df14299e8d57901ec0b2a7b44fef1b4717c6 /bridge.go
parent7367e699d3c4c9a3c728c95e42b8ffcb7163f1ec (diff)
Changed FindBridge to FindBridges (plural) and refactored the function to return []Bridge instead of just the first one.
Diffstat (limited to 'bridge.go')
-rw-r--r--bridge.go20
1 files changed, 9 insertions, 11 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.