diff options
author | Collin Guarino <collin.guarino@gmail.com> | 2016-02-08 22:24:24 -0500 |
---|---|---|
committer | Collin Guarino <collin.guarino@gmail.com> | 2016-02-08 22:24:24 -0500 |
commit | e7deedcd248dbc89623db252dcf2b0559d944abb (patch) | |
tree | 70338f7d49566c64847763857644ff665b377e1e | |
parent | a05574836d277a8ca3c75ab3a7b7b9a1e1081faa (diff) |
Added ColorLoop on, off, toggle functions.
-rw-r--r-- | light.go | 19 | ||||
-rw-r--r-- | light_test.go | 4 |
2 files changed, 19 insertions, 4 deletions
@@ -9,6 +9,7 @@ import ( "errors" ) +// 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") @@ -32,7 +33,7 @@ type Light struct { Bridge *Bridge } -// LightState used in SetLightState to ammend light attributes. +// LightState used in SetLightState to amend light attributes. type LightState struct { On bool `json:"on"` Bri uint8 `json:"bri,omitempty"` @@ -69,6 +70,22 @@ func (self *Light) Toggle() { } } +func (self *Light) ColorLoopOn() error { + return SetLightState(self, LightState{On: true, Effect: "colorloop"}) +} + +func (self *Light) ColorLoopOff() error { + return SetLightState(self, LightState{On: true, Effect: "none"}) +} + +func (self *Light) ColorLoop() error { + if self.State.Effect == "colorloop" { + return self.ColorLoopOff() + } else { + return self.ColorLoopOn() + } +} + // SetLightState will modify light attributes such as on/off, saturation, // brightness, and more. See `SetLightState` struct. func SetLightState(light *Light, newState LightState) error { diff --git a/light_test.go b/light_test.go index 0298312..95cab24 100644 --- a/light_test.go +++ b/light_test.go @@ -26,9 +26,7 @@ func TestSetLightState(t *testing.T) { time.Sleep(time.Second) selectedLight.Off() time.Sleep(time.Second) - selectedLight.On() - time.Sleep(time.Second) selectedLight.Toggle() time.Sleep(time.Second) - selectedLight.Toggle() + selectedLight.ColorLoop() } |