aboutsummaryrefslogtreecommitdiff
path: root/light.go
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-02-11 23:53:41 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-02-11 23:53:41 -0500
commitf407fab5c8125524103d95f8fc286338f1828688 (patch)
tree1bdf353398bb9b0531aac74e9d316cf2e81b01de /light.go
parent65f14b6bb3491e1513981082f2145ccb6fbe8369 (diff)
Finalized Light.SetName function, fixed error caused by invalid uri.
Diffstat (limited to 'light.go')
-rw-r--r--light.go50
1 files changed, 25 insertions, 25 deletions
diff --git a/light.go b/light.go
index bd471d5..ebd5a8a 100644
--- a/light.go
+++ b/light.go
@@ -18,34 +18,34 @@ import (
// Light struct defines attributes of a light.
type Light struct {
State struct {
- On bool `json:"on"` // On or Off state of the light ("true" or "false")
- Bri int `json:"bri"` // Brightness value 1-254
- Hue int `json:"hue"` // Hue value 1-65535
- Saturation int `json:"sat"` // Saturation value 0-254
- Effect string `json:"effect"` // "None" or "Colorloop"
- XY [2]float32 `json:"xy"` // Coordinates of color in CIE color space
- CT int `json:"ct"` // Mired Color Temperature (google it)
- Alert string `json:"alert"`
- ColorMode string `json:"colormode"`
- Reachable bool `json:"reachable"`
- } `json:"state"`
- Type string `json:"type"`
- Name string `json:"name"`
- ModelID string `json:"modelid"`
- ManufacturerName string `json:"manufacturername"`
- UniqueID string `json:"uniqueid"`
- SWVersion string `json:"swversion"`
- Index int // Set by index of light array response // TODO: change to smaller int
- Bridge *Bridge
+ On bool `json:"on,omitempty"` // On or Off state of the light ("true" or "false")
+ Bri int `json:"bri,omitempty"` // Brightness value 1-254
+ Hue int `json:"hue,omitempty"` // Hue value 1-65535
+ Saturation int `json:"sat,omitempty"` // Saturation value 0-254
+ Effect string `json:"effect,omitempty"` // "None" or "Colorloop"
+ XY [2]float32 `json:"xy,omitzero"` // Coordinates of color in CIE color space
+ CT int `json:"ct,omitempty"` // Mired Color Temperature (google it)
+ Alert string `json:"alert,omitempty"`
+ ColorMode string `json:"colormode,omitempty"`
+ Reachable bool `json:"reachable,omitempty"`
+ } `json:"state,omitempty"`
+ Type string `json:"type,omitempty"`
+ Name string `json:"name,omitempty"`
+ ModelID string `json:"modelid,omitempty"`
+ ManufacturerName string `json:"manufacturername,omitempty"`
+ UniqueID string `json:"uniqueid,omitempty"`
+ SWVersion string `json:"swversion,omitempty"`
+ Index int `json:"index,omitempty"` // Set by index of light array response // TODO: change to smaller int
+ Bridge *Bridge `json:"bridge,omitempty"`
}
// LightState used in SetLightState to amend light attributes.
type LightState struct {
- On bool `json:"on"`
+ 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"`
+ XY *[2]float32 `json:"xy,omitempty"`
CT uint16 `json:"ct,omitempty"`
Effect string `json:"effect,omitempty"`
Alert string `json:"alert,omitempty"`
@@ -54,13 +54,13 @@ type LightState struct {
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"`
+ Name string `json:"name,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
+ uri := fmt.Sprintf("/api/%s/lights/%d", self.Bridge.Username, self.Index)
+ body := LightState{Name: name}
_, _, err := self.Bridge.Put(uri, body)
if err != nil {
return err