diff options
-rw-r--r-- | bridge.go | 6 | ||||
-rw-r--r-- | light.go | 10 | ||||
-rw-r--r-- | light_test.go | 15 |
3 files changed, 22 insertions, 9 deletions
@@ -62,6 +62,7 @@ func (self *Bridge) Post(path string, params interface{}) ([]byte, io.Reader, er 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) @@ -80,6 +81,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("\nSending PUT body: ", string(data)) request, err := http.NewRequest("PUT", uri, bytes.NewReader(data)) resp, err := client.Do(request) @@ -99,7 +102,8 @@ 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:\n--------------------\n", string(body) + + "\n--------------------\n") return body, reader, nil } @@ -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..a1e5f61 100644 --- a/light_test.go +++ b/light_test.go @@ -3,6 +3,7 @@ package hue import ( "testing" "fmt" + "time" ) func TestGetAllLights(t *testing.T) { @@ -19,7 +20,15 @@ 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] + + // Turn light on, off, on again + newState := LightState{On: true,} + SetLightState(bridge, selectedLight.Index, newState) + time.Sleep(time.Second) + newState = LightState{On: false,} + SetLightState(bridge, selectedLight.Index, newState) + time.Sleep(time.Second) + newState = LightState{On: true,} + SetLightState(bridge, selectedLight.Index, newState) } |