aboutsummaryrefslogtreecommitdiff
path: root/light.go
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-02-13 11:54:05 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-02-13 11:54:05 -0500
commitb2ae1e0fc5c8e93fef1a9ae81d097f90435cb435 (patch)
tree323eda62a3a974626058e6403d2757a0897a6c8f /light.go
parent32df96e1dc02531c42435dd6a12a0ac6f8725ff0 (diff)
Converted SetLightState to Light.SetState
Diffstat (limited to 'light.go')
-rw-r--r--light.go21
1 files changed, 10 insertions, 11 deletions
diff --git a/light.go b/light.go
index e5f7874..efdf188 100644
--- a/light.go
+++ b/light.go
@@ -40,7 +40,7 @@ type Light struct {
Bridge *Bridge
}
-// LightState used in SetLightState to amend light attributes.
+// LightState used in Light.SetState to amend light attributes.
type LightState struct {
On bool `json:"on"`
Bri uint8 `json:"bri,omitempty"`
@@ -74,12 +74,12 @@ func (self *Light) SetName(name string) error {
// Light.Off will turn the light source off
func (self *Light) Off() error {
- return SetLightState(self, LightState{On: false})
+ return self.SetState(LightState{On: false})
}
// Light.Off will turn the light source on
func (self *Light) On() error {
- return SetLightState(self, LightState{On: true})
+ return self.SetState(LightState{On: true})
}
// Light.Toggle will toggle the light source on and off
@@ -103,7 +103,6 @@ func (self *Light) Delete() error {
return nil
}
-
// Light.Blink will turn the light off and on repeatedly for a given seconds
// interval and return the light back to its off or on state afterwards.
// Note: time will vary based on connection speed and algorithm speed.
@@ -136,20 +135,20 @@ func (self *Light) ColorLoop(activate bool) error {
if activate {
state = "colorloop"
}
- return SetLightState(self, LightState{On: true, Effect: state})
+ return self.SetState(LightState{On: true, Effect: state})
}
-// SetLightState will modify light attributes such as on/off, saturation,
-// 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)
+// Light.SetState will modify light attributes such as on/off, saturation,
+// brightness, and more. See `LightState` struct.
+func (self *Light) SetState(newState LightState) error {
+ uri := fmt.Sprintf("/api/%s/lights/%d/state", self.Bridge.Username, self.Index)
+ _, _, err := self.Bridge.Put(uri, newState)
if err != nil {
return err
}
// Get the new light state and update the current Light struct
- *light, err = GetLightByIndex(light.Bridge, light.Index)
+ *self, err = GetLightByIndex(self.Bridge, self.Index)
if err != nil {
return err
}