aboutsummaryrefslogtreecommitdiff
path: root/light.go
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-02-08 23:04:28 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-02-08 23:04:28 -0500
commit1eaa5a1a8c28965ff59ef2d8c3f827e53ba54747 (patch)
tree838d8f25285342400adfb2771945f152c7599544 /light.go
parentca632c436ca03c97e30e9969fecd12000a6911f8 (diff)
Rough implementation for Light.SetName and simplified Bridge.Put returns.
Diffstat (limited to 'light.go')
-rw-r--r--light.go15
1 files changed, 10 insertions, 5 deletions
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.