aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-02-06 11:59:46 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-02-06 11:59:46 -0500
commit9017b157aa97e6690cf242c38112edb32568b6c8 (patch)
treeabe1a81944ccac08f4d36ba80f095c507d2e56f4
parent666b312e0011459f471f89257c5dd8e3e495ee95 (diff)
Fixed LightState struct and bridge.Put request model.
-rw-r--r--bridge.go4
-rw-r--r--light.go10
-rw-r--r--light_test.go7
3 files changed, 12 insertions, 9 deletions
diff --git a/bridge.go b/bridge.go
index 803f419..64e674f 100644
--- a/bridge.go
+++ b/bridge.go
@@ -80,6 +80,8 @@ func (self *Bridge) Put(path string, params interface{}) ([]byte, io.Reader, err
if err != nil {
return []byte{}, nil, err
}
+ //fmt.Println("\n\nPARAMS: ", params)
+ log.Println("\n\nSending HTTP PUT body: ", string(data))
request, err := http.NewRequest("PUT", uri, bytes.NewReader(data))
resp, err := client.Do(request)
@@ -99,7 +101,7 @@ func handleResponse(resp *http.Response) ([]byte, io.Reader, error) {
return []byte{}, nil, err
}
reader := bytes.NewReader(body)
- log.Println("Handled request: ", string(body))
+ log.Println("Handled response: ", string(body))
return body, reader, nil
}
diff --git a/light.go b/light.go
index 92125ea..16fb903 100644
--- a/light.go
+++ b/light.go
@@ -33,20 +33,20 @@ type Light struct {
// LightState used in SetLightState to ammend light attributes.
type LightState struct {
- On bool `json:"on,omitempty"`
+ On bool `json:"on"`
Bri uint8 `json:"bri,omitempty"`
Hue uint16 `json:"hue,omitempty"`
Sat uint8 `json:"sat,omitempty"`
- XY [2]float32 `json:"xy,omitempty"`
+ XY *[2]float32 `json:"xy,omitempty"`
CT uint16 `json:"ct,omitempty"`
- Alert string `json:"alert,omitempty"`
Effect string `json:"effect,omitempty"`
+ Alert string `json:"alert,omitempty"`
TransitionTime string `json:"transitiontime,omitempty"`
- BrightnessIncrement int `json:"bri_inc,omitempty"` // TODO: -254 to 254
SaturationIncrement int `json:"sat_inc,omitempty"` // TODO: -254 to 254
HueIncrement int `json:"hue_inc,omitempty"` // TODO: -65534 to 65534
+ BrightnessIncrement int `json:"bri_inc,omitempty"` // TODO: -254 to 254
CTIncrement int `json:"ct_inc,omitempty"` // TODO: -65534 to 65534
- XYIncrement [2]float32 `json:"xy_inc,omitempty"`
+ XYIncrement *[2]float32 `json:"xy_inc,omitempty"`
}
// SetLightState will modify light attributes such as on/off, saturation,
diff --git a/light_test.go b/light_test.go
index 479111b..cf8ce93 100644
--- a/light_test.go
+++ b/light_test.go
@@ -19,7 +19,8 @@ func TestSetLightState(t *testing.T) {
fmt.Println("\nTESTING LIGHT STATE:\n\n")
bridge := NewBridge("192.168.1.128", "319b36233bd2328f3e40731b23479207")
lights, _ := GetAllLights(bridge)
- newState := LightState{On: true}
- fmt.Println("\n\nSTATE: ", newState)
- SetLightState(bridge, lights[1].Index, newState)
+ selectedLight := lights[0]
+ newState := LightState{On: true,} //On: false, *XY: [2]float32{5.0, 5.0},
+ //fmt.Println("\n\nSTATE: ", newState)
+ SetLightState(bridge, selectedLight.Index, newState)
}