From 666b312e0011459f471f89257c5dd8e3e495ee95 Mon Sep 17 00:00:00 2001 From: Collin Guarino Date: Thu, 4 Feb 2016 23:52:11 -0500 Subject: Added json bindings for LightState struct. --- light.go | 34 +++++++++++++++++----------------- light_test.go | 4 ++-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/light.go b/light.go index 0ec8e80..92125ea 100644 --- a/light.go +++ b/light.go @@ -28,31 +28,31 @@ type Light struct { ManufacturerName string `json:"manufacturername"` UniqueID string `json:"uniqueid"` SWVersion string `json:"swversion"` - Index int // Set by index of light array response + Index int // Set by index of light array response // TODO: change to smaller int } // LightState used in SetLightState to ammend light attributes. type LightState struct { - On bool - Bri uint8 - Hue uint16 - Sat uint8 - XY [2]float32 - CT uint16 - Alert string - Effect string - TransitionTime string - BrightnessIncrement int // TODO: -254 to 254 - SaturationIncrement int // TODO: -254 to 254 - HueIncrement int // TODO: -65534 to 65534 - CTIncrement int // TODO: -65534 to 65534 - XYIncrement [2]float32 + On bool `json:"on,omitempty"` + Bri uint8 `json:"bri,omitempty"` + Hue uint16 `json:"hue,omitempty"` + Sat uint8 `json:"sat,omitempty"` + XY [2]float32 `json:"xy,omitempty"` + CT uint16 `json:"ct,omitempty"` + Alert string `json:"alert,omitempty"` + Effect string `json:"effect,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 + CTIncrement int `json:"ct_inc,omitempty"` // TODO: -65534 to 65534 + XYIncrement [2]float32 `json:"xy_inc,omitempty"` } // 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 { - uri := fmt.Sprintf("/api/%s/lights/%s/state", bridge.Username, lightID) +func SetLightState(bridge *Bridge, index int, newState LightState) error { + uri := fmt.Sprintf("/api/%s/lights/%d/state", bridge.Username, index) _, _, err := bridge.Put(uri, newState) // TODO: change to PUT if err != nil { return err diff --git a/light_test.go b/light_test.go index 6da677d..479111b 100644 --- a/light_test.go +++ b/light_test.go @@ -19,7 +19,7 @@ func TestSetLightState(t *testing.T) { fmt.Println("\nTESTING LIGHT STATE:\n\n") bridge := NewBridge("192.168.1.128", "319b36233bd2328f3e40731b23479207") lights, _ := GetAllLights(bridge) - fmt.Println("\nUNIQUE ID: ", lights[0].UniqueID) - newState := LightState{On: false} + newState := LightState{On: true} + fmt.Println("\n\nSTATE: ", newState) SetLightState(bridge, lights[1].Index, newState) } -- cgit v1.2.3