diff options
author | Collin Guarino <collin.guarino@gmail.com> | 2016-02-04 13:50:28 -0500 |
---|---|---|
committer | Collin Guarino <collin.guarino@gmail.com> | 2016-02-04 13:50:28 -0500 |
commit | 89217de4c5384feec23342fdec4fe2b896cf559a (patch) | |
tree | 3bbf15e39e8afd2ac6c15db26cb0fb85b317816b /light.go | |
parent | 4a6869ee9c78f6c1496fefa35cd5b71afd1bd44d (diff) |
Prepared SetLightState for bridge.Put
Diffstat (limited to 'light.go')
-rw-r--r-- | light.go | 28 |
1 files changed, 2 insertions, 26 deletions
@@ -4,12 +4,9 @@ package hue import ( "fmt" - "net/http" - "io/ioutil" "encoding/json" "strings" "errors" - "bytes" ) type Light struct { @@ -54,32 +51,11 @@ type LightState struct { // SetLightState will modify light attributes such as on/off, saturation, // brightness, and more. See `SetLightState` struct. func SetLightState(bridge *Bridge, lightID string, newState LightState) error { - // Construct the http POST - req, err := json.Marshal(newState) + uri := fmt.Sprintf("/api/%s/lights/%s/state", bridge.Username, lightID) + _, _, err := bridge.Post(uri, newState) // TODO: change to PUT if err != nil { - trace("", err) return err } - - // Send the request and read the response - uri := fmt.Sprintf("http://%s/api/%s/lights/%s/state", - bridge.IPAddress, bridge.Username, lightID) - resp, err := http.Post(uri, "text/json", bytes.NewReader(req)) - if err != nil { - trace("", err) - return err - } - defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - trace("", err) - return err - } - - _ = body - - // TODO: Parse the response and return any error - //fmt.Println("LightState: ", string(body)) return nil } |