From 1eaa5a1a8c28965ff59ef2d8c3f827e53ba54747 Mon Sep 17 00:00:00 2001 From: Collin Guarino Date: Mon, 8 Feb 2016 23:04:28 -0500 Subject: Rough implementation for Light.SetName and simplified Bridge.Put returns. --- light.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'light.go') diff --git a/light.go b/light.go index ab0afe8..cc8a112 100644 --- a/light.go +++ b/light.go @@ -51,6 +51,14 @@ type LightState struct { XYIncrement *[2]float32 `json:"xy_inc,omitempty"` } +func (self *Light) SetName(name string) error { + uri := fmt.Sprintf("/api/%s/lights/%s", self.Bridge.Username, self.Index) + body := make(map[string]string) + body["name"] = name + _, _, err := self.Bridge.Put(uri, body) + return err +} + // Light.Off will turn the light source off func (self *Light) Off() error { return SetLightState(self, LightState{On: false}) @@ -95,11 +103,8 @@ func (self *Light) ColorLoop() error { // brightness, and more. See `SetLightState` struct. func SetLightState(light *Light, newState LightState) error { uri := fmt.Sprintf("/api/%s/lights/%d/state", light.Bridge.Username, light.Index) - _, _, err := light.Bridge.Put(uri, newState) // TODO: change to PUT - if err != nil { - return err - } - return nil + _, _, err := light.Bridge.Put(uri, newState) + return err } // GetAllLights retreives the state of all lights that the bridge is aware of. -- cgit v1.2.3