aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-02-13 11:35:29 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-02-13 11:35:29 -0500
commitd676089ff95cef488963555e75929da20326f612 (patch)
treeaa2e80a4f2db3dc31a5eb56ca4fe85c61df21fb4
parent922e7290c37e46046b1a4e68818c77c44a192b2e (diff)
Cleaned up documentation and tests.
-rw-r--r--bridge.go44
-rw-r--r--light.go4
-rw-r--r--light_test.go3
3 files changed, 26 insertions, 25 deletions
diff --git a/bridge.go b/bridge.go
index 62cd252..ec2f050 100644
--- a/bridge.go
+++ b/bridge.go
@@ -60,26 +60,6 @@ func (self *Bridge) Get(path string) ([]byte, io.Reader, error) {
return handleResponse(resp)
}
-// bridge.Post will send an http POST to the bridge with
-// a body formatted with parameters (in a generic interface)
-func (self *Bridge) Post(path string, params interface{}) ([]byte, io.Reader, error) {
- // Add the params to the request
- request, err := json.Marshal(params)
- if err != nil {
- trace("", err)
- return []byte{}, nil, nil
- }
- log.Println("\nSending POST body: ", string(request))
-
- // Send the request and handle the response
- uri := fmt.Sprintf("http://" + self.IPAddress + path)
- resp, err := http.Post(uri, "text/json", bytes.NewReader(request))
- if self.Error(resp, err) {
- return []byte{}, nil, nil
- }
- return handleResponse(resp)
-}
-
// Bridge.Put will send an http PUT to the bridge with
// a body formatted with parameters (in a generic interface)
func (self *Bridge) Put(path string, params interface{}) ([]byte, io.Reader, error) {
@@ -101,6 +81,26 @@ func (self *Bridge) Put(path string, params interface{}) ([]byte, io.Reader, err
return handleResponse(resp)
}
+// bridge.Post will send an http POST to the bridge with
+// a body formatted with parameters (in a generic interface)
+func (self *Bridge) Post(path string, params interface{}) ([]byte, io.Reader, error) {
+ // Add the params to the request
+ request, err := json.Marshal(params)
+ if err != nil {
+ trace("", err)
+ return []byte{}, nil, nil
+ }
+ log.Println("\nSending POST body: ", string(request))
+
+ // Send the request and handle the response
+ uri := fmt.Sprintf("http://" + self.IPAddress + path)
+ resp, err := http.Post(uri, "text/json", bytes.NewReader(request))
+ if self.Error(resp, err) {
+ return []byte{}, nil, nil
+ }
+ return handleResponse(resp)
+}
+
// Bridge.Delete will send an http DELETE to the bridge
func (self *Bridge) Delete(path string) error {
uri := fmt.Sprintf("http://" + self.IPAddress + path)
@@ -110,7 +110,7 @@ func (self *Bridge) Delete(path string) error {
if err != nil {
return err
}
- _, _, err := handleResponse(resp)
+ _, _, err = handleResponse(resp)
if err != nil {
return err
}
@@ -132,7 +132,7 @@ func handleResponse(resp *http.Response) ([]byte, io.Reader, error) {
return body, reader, nil
}
-// bridge.Error handles all bridge response status errors
+// Bridge.Error handles all bridge response status errors
func (self *Bridge) Error(resp *http.Response, err error) (bool) {
if err != nil {
trace("", err)
diff --git a/light.go b/light.go
index aab344b..e5f7874 100644
--- a/light.go
+++ b/light.go
@@ -24,7 +24,7 @@ type Light struct {
Hue int `json:"hue"` // Hue value 1-65535
Saturation int `json:"sat"` // Saturation value 0-254
Effect string `json:"effect"` // "None" or "Colorloop"
- XY [2]float32 `json:"xy"` // Coordinates of color in CIE color space
+ XY [2]float32 `json:"xy"` // Coordinates of color in CIE color space
CT int `json:"ct"` // Mired Color Temperature (google it)
Alert string `json:"alert"`
ColorMode string `json:"colormode"`
@@ -59,6 +59,8 @@ type LightState struct {
Name string `json:"name,omitempty"`
}
+// Light.SetName will assign a new name in the light's
+// attributes as recognized by the bridge.
func (self *Light) SetName(name string) error {
uri := fmt.Sprintf("/api/%s/lights/%d", self.Bridge.Username, self.Index)
body := make(map[string]string)
diff --git a/light_test.go b/light_test.go
index 9f8f140..8961666 100644
--- a/light_test.go
+++ b/light_test.go
@@ -26,8 +26,7 @@ func TestGetLightByName(t *testing.T) {
func TestSetLightState(t *testing.T) {
fmt.Println("\nTESTING LIGHT STATE:\n\n")
bridge := NewBridge("192.168.1.128", "319b36233bd2328f3e40731b23479207")
- lights, _ := GetAllLights(bridge)
- selectedLight := lights[5]
+ selectedLight, _ := GetLightByIndex(bridge, 7)
selectedLight.On()
time.Sleep(time.Second)