aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--light.go8
-rw-r--r--light_test.go10
2 files changed, 11 insertions, 7 deletions
diff --git a/light.go b/light.go
index 16fb903..2d72502 100644
--- a/light.go
+++ b/light.go
@@ -49,6 +49,14 @@ type LightState struct {
XYIncrement *[2]float32 `json:"xy_inc,omitempty"`
}
+func (self *Light) TurnOff() {
+ SetLightState(self.Index, LightState{On: false})
+}
+
+func (self *Light) TurnOn() {
+ SetLightState(self.Index, LightState{On: true})
+}
+
// SetLightState will modify light attributes such as on/off, saturation,
// brightness, and more. See `SetLightState` struct.
func SetLightState(bridge *Bridge, index int, newState LightState) error {
diff --git a/light_test.go b/light_test.go
index a1e5f61..0a63bf8 100644
--- a/light_test.go
+++ b/light_test.go
@@ -22,13 +22,9 @@ func TestSetLightState(t *testing.T) {
lights, _ := GetAllLights(bridge)
selectedLight := lights[0]
- // Turn light on, off, on again
- newState := LightState{On: true,}
- SetLightState(bridge, selectedLight.Index, newState)
+ selectedLight.TurnOn()
time.Sleep(time.Second)
- newState = LightState{On: false,}
- SetLightState(bridge, selectedLight.Index, newState)
+ selectedLight.TurnOf()
time.Sleep(time.Second)
- newState = LightState{On: true,}
- SetLightState(bridge, selectedLight.Index, newState)
+ selectedLight.TurnOn()
}