From 112202f1d77758cb8c3ed32c88bdfcfef4995f6c Mon Sep 17 00:00:00 2001 From: Collin Guarino Date: Wed, 10 Feb 2016 20:17:57 -0500 Subject: Simplified Light.ColorLoop to accept a boolean instead of having on/off/toggle modes. --- light.go | 25 +++++++------------------ light_test.go | 2 +- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/light.go b/light.go index 0e8312d..bd471d5 100644 --- a/light.go +++ b/light.go @@ -87,25 +87,14 @@ func (self *Light) Toggle() error { } } -// Light.ColorLoopOn will turn the light on and set the effect to "colorloop" -func (self *Light) ColorLoopOn() error { - return SetLightState(self, LightState{On: true, Effect: "colorloop"}) -} - -// Light.ColorLoopOn will turn the light on and set the effect to "none" -func (self *Light) ColorLoopOff() error { - return SetLightState(self, LightState{On: true, Effect: "none"}) -} - -// Light.ColorLoop will set the light state to a colorloop if there is no -// current effect in place or if the state is in colorloop then it will -// set it to "none". -func (self *Light) ColorLoop() error { - if self.State.Effect == "colorloop" { - return self.ColorLoopOff() - } else { - return self.ColorLoopOn() +// Light.ColorLoop will set the light state to 'colorloop' if `active` +// is true or it will set the light state to "none" if `activate` is false. +func (self *Light) ColorLoop(activate bool) error { + var state = "none" + if activate { + state = "colorloop" } + return SetLightState(self, LightState{On: true, Effect: state}) } // SetLightState will modify light attributes such as on/off, saturation, diff --git a/light_test.go b/light_test.go index f988925..98c2030 100644 --- a/light_test.go +++ b/light_test.go @@ -35,7 +35,7 @@ func TestSetLightState(t *testing.T) { time.Sleep(time.Second) selectedLight.Toggle() time.Sleep(time.Second) - selectedLight.ColorLoop() + selectedLight.ColorLoop(false) selectedLight.SetName("Ceiling Fan Outer") } -- cgit v1.2.3