aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCollin Guarino <Collinux@users.noreply.github.com>2016-11-09 14:38:51 -0500
committerGitHub <noreply@github.com>2016-11-09 14:38:51 -0500
commit23e6757464bf225f806b2ba586597af6d83c9609 (patch)
tree83b0441a0b0a0c9f02f0ddd2d7ef96afa55323f3
parent541bfc66cb1dd94c9ab4d7089adc0f31a77799d4 (diff)
parenta712f307fe27070aa449452091553acf85e3d8f8 (diff)
Merge pull request #6 from inhies/master
Added Go Report Card score to README and fixed issues lowering score related to formatting
-rw-r--r--README.md2
-rw-r--r--bridge.go36
-rw-r--r--light.go5
3 files changed, 21 insertions, 22 deletions
diff --git a/README.md b/README.md
index 9096f8b..078474d 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
Package hue interfaces Philips Hue devices to control lights, scenes, schedules, and groups.
[![GoDoc](https://camo.githubusercontent.com/b3b2a2b7fad4e76052830945cd839a3bba5be723/687474703a2f2f696d672e736869656c64732e696f2f62616467652f676f646f632d7265666572656e63652d3532373242342e706e67)](https://godoc.org/github.com/Collinux/GoHue)
-
+[![Go Report Card](https://goreportcard.com/badge/github.com/Collinux/GoHue)](https://goreportcard.com/report/github.com/Collinux/GoHue)
## Installation
```
go get github.com/collinux/gohue
diff --git a/bridge.go b/bridge.go
index 2a6fb26..9502af7 100644
--- a/bridge.go
+++ b/bridge.go
@@ -92,17 +92,17 @@ func (bridge *Bridge) Put(path string, params interface{}) ([]byte, io.Reader, e
// a body formatted with parameters (in a generic interface).
// If `params` is nil then it will send an empty body with the post request.
func (bridge *Bridge) Post(path string, params interface{}) ([]byte, io.Reader, error) {
- // Add the params to the request or allow an empty body
- request := []byte{}
- if params != nil {
- reqBody, err := json.Marshal(params)
- if err != nil {
- err = errors.New("Error: Unable to add POST body parameters due to json marshal error.")
- log.Println(err)
- return []byte{}, nil, err
- }
- request = reqBody
- }
+ // Add the params to the request or allow an empty body
+ request := []byte{}
+ if params != nil {
+ reqBody, err := json.Marshal(params)
+ if err != nil {
+ err = errors.New("Error: Unable to add POST body parameters due to json marshal error.")
+ log.Println(err)
+ return []byte{}, nil, err
+ }
+ request = reqBody
+ }
// Send the request and handle the response
uri := fmt.Sprintf("http://" + bridge.IPAddress + path)
resp, err := http.Post(uri, "text/json", bytes.NewReader(request))
@@ -111,7 +111,7 @@ func (bridge *Bridge) Post(path string, params interface{}) ([]byte, io.Reader,
log.Println(err)
return []byte{}, nil, err
}
- return HandleResponse(resp)
+ return HandleResponse(resp)
}
// Bridge.Delete sends an http DELETE to the bridge
@@ -134,7 +134,7 @@ func (bridge *Bridge) Delete(path string) error {
// and invalid return types.
func HandleResponse(resp *http.Response) ([]byte, io.Reader, error) {
body, err := ioutil.ReadAll(resp.Body)
- defer resp.Body.Close()
+ defer resp.Body.Close()
if err != nil {
trace("Error parsing bridge description xml.", nil)
return []byte{}, nil, err
@@ -162,11 +162,11 @@ func FindBridges() ([]Bridge, error) {
log.Fatal(err)
return []Bridge{}, err
}
- bridges := []Bridge{}
- err = json.Unmarshal(body, &bridges)
- if err != nil {
- return []Bridge{}, errors.New("Unable to parse FindBridges response. ")
- }
+ bridges := []Bridge{}
+ err = json.Unmarshal(body, &bridges)
+ if err != nil {
+ return []Bridge{}, errors.New("Unable to parse FindBridges response. ")
+ }
return bridges, nil
}
diff --git a/light.go b/light.go
index fc1229e..fcf54fe 100644
--- a/light.go
+++ b/light.go
@@ -88,7 +88,6 @@ func (light *Light) Toggle() error {
} else {
return light.On()
}
- return nil
}
// Light.Delete removes the light from the
@@ -185,7 +184,7 @@ func (light *Light) Dim(percent int) error {
newBri := uint8(originalBri - uint8(decreaseBri))
if newBri < 0 {
newBri = 0
- log.Println("Light.Dim state set under 0%, setting brightness to 0. ")
+ log.Printf("Light.Dim state set under 0%%, setting brightness to 0. ")
}
lightState := LightState{On: true, Bri: newBri}
err := light.SetState(lightState)
@@ -222,7 +221,7 @@ func (light *Light) Brighten(percent int) error {
newBri := uint8(originalBri + uint8(increaseBri))
if newBri > 254 { // LightState.Bri must be between 1 and 254 inclusive
newBri = 254
- log.Println("Light.Brighten state set over 100%, setting brightness to 100%. ")
+ log.Printf("Light.Brighten state set over 100%%, setting brightness to 100%%. ")
}
lightState := LightState{On: true, Bri: newBri}
err := light.SetState(lightState)