From e7deedcd248dbc89623db252dcf2b0559d944abb Mon Sep 17 00:00:00 2001 From: Collin Guarino Date: Mon, 8 Feb 2016 22:24:24 -0500 Subject: Added ColorLoop on, off, toggle functions. --- light.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'light.go') diff --git a/light.go b/light.go index 8ad16f4..b62fec4 100644 --- a/light.go +++ b/light.go @@ -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 { -- cgit v1.2.3