From a05574836d277a8ca3c75ab3a7b7b9a1e1081faa Mon Sep 17 00:00:00 2001 From: Collin Guarino Date: Sun, 7 Feb 2016 20:49:51 -0500 Subject: Simplified light.On/Off and added error returns. --- light.go | 19 +++++++++---------- light_test.go | 6 +++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/light.go b/light.go index d1908e2..8ad16f4 100644 --- a/light.go +++ b/light.go @@ -50,23 +50,22 @@ type LightState struct { XYIncrement *[2]float32 `json:"xy_inc,omitempty"` } -// light.TurnOff will change the light state to the "Off" mode. -func (self *Light) TurnOff() { - SetLightState(self, LightState{On: false}) +// light.Off will turn the light source off +func (self *Light) Off() error { + return SetLightState(self, LightState{On: false}) } -// light.TurnOn will change the light state to the "On" mode. -func (self *Light) TurnOn() { - SetLightState(self, LightState{On: true}) +// light.Off will turn the light source on +func (self *Light) On() error { + return SetLightState(self, LightState{On: true}) } -// light.Toggle will change the light state to "On" if -// the light is off or "Off" if the light is on. +// light.Toggle will toggle the light source on and off func (self *Light) Toggle() { if self.State.On { - self.TurnOff() + self.Off() } else { - self.TurnOn() + self.On() } } diff --git a/light_test.go b/light_test.go index 6c85eff..0298312 100644 --- a/light_test.go +++ b/light_test.go @@ -22,11 +22,11 @@ func TestSetLightState(t *testing.T) { lights, _ := GetAllLights(bridge) selectedLight := lights[0] - selectedLight.TurnOn() + selectedLight.On() time.Sleep(time.Second) - selectedLight.TurnOff() + selectedLight.Off() time.Sleep(time.Second) - selectedLight.TurnOn() + selectedLight.On() time.Sleep(time.Second) selectedLight.Toggle() time.Sleep(time.Second) -- cgit v1.2.3