aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-02-25 14:46:32 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-02-25 14:46:32 -0500
commit8464e1da735fb18f4d52d385d1466b1ce2044bbe (patch)
tree741795c1f26c0f3ed9d44075268e17d96d94096c
parent314ec4473e67f482e282d7cf1ebc8c392c698043 (diff)
Added clarity to Bridge.NewBridge documentation and adjusted error output line spacing.
-rw-r--r--bridge.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/bridge.go b/bridge.go
index dc2b6ff..cd0f30d 100644
--- a/bridge.go
+++ b/bridge.go
@@ -149,10 +149,14 @@ func HandleResponse(resp *http.Response) ([]byte, io.Reader, error) {
}
// NewBridge defines hardware that is compatible with Hue.
+// The function is the core of all functionality, it's necessary
+// to call `NewBridge` and `Login` or `CreateUser` to access any
+// lights, scenes, groups, etc.
func NewBridge(ip string) (*Bridge, error) {
bridge := Bridge {
IPAddress: ip,
}
+ // Test the connection by attempting to get the bridge info.
err := bridge.GetInfo()
if err != nil {
log.Fatal("Error: Unable to access bridge. ", err)
@@ -170,7 +174,7 @@ func (bridge *Bridge) GetInfo() error {
data := BridgeInfo{}
err = xml.NewDecoder(reader).Decode(&data)
if err != nil {
- err = errors.New("Error: Unable to decode XML response from bridge.")
+ err = errors.New("Error: Unable to decode XML response from bridge. ")
log.Println(err)
return err
}
@@ -229,7 +233,7 @@ func (bridge *Bridge) GetAllLights() ([]Light, error) {
lightMap := map[string]Light{}
err = json.Unmarshal(body, &lightMap)
if err != nil {
- return []Light{}, errors.New("Unable to marshal GetAllLights response.")
+ return []Light{}, errors.New("Unable to marshal GetAllLights response. ")
}
// Parse the index, add the light to the list, and return the array
@@ -256,7 +260,7 @@ func (bridge *Bridge) GetLightByIndex(index int) (Light, error) {
return Light{}, err
}
if strings.Contains(string(body), "not available") {
- return Light{}, errors.New("Error: Light selection index out of bounds")
+ return Light{}, errors.New("Error: Light selection index out of bounds. ")
}
// Parse and load the response into the light array
@@ -278,7 +282,7 @@ func (bridge *Bridge) GetLightByName(name string) (Light, error) {
return light, nil
}
}
- errOut := fmt.Sprintf("Error: Light name '%s' not found.", name)
+ errOut := fmt.Sprintf("Error: Light name '%s' not found. ", name)
return Light{}, errors.New(errOut)
}