From a3786c8698f8b7c85d09e241cf09dc0e8ced9da2 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Thu, 24 May 2018 22:23:35 -0400 Subject: Split out updateLight function --- main.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 481f712..76f5838 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,7 @@ func main() { } } -func updateBridge(bridge hue.Bridge, desiredColorTemp ColorTemperature) { +func updateBridge(bridge hue.Bridge, ct ColorTemperature) { //username, err := bridge.CreateUser(username) //if err != nil { // panic("Could not create user on bridge") @@ -40,15 +40,19 @@ func updateBridge(bridge hue.Bridge, desiredColorTemp ColorTemperature) { } log.Printf("Found %d lights\n", len(lights)) for _, light := range lights { - log.Printf("Light %d: %s (%s)\n", light.Index, light.Name, light.Type) - if supportsColorTemp(light) { - log.Printf(" CT range: %d-%d\n", light.Capabilities.Control.CT.Min, light.Capabilities.Control.CT.Max) - newCt := translateCtForLight(desiredColorTemp, light) - log.Printf(" Setting CT to %d\n", newCt) - light.SetState(hue.LightState{ - On: light.State.On, - CT: newCt, - }) - } + updateLight(light, ct) + } +} + +func updateLight(light hue.Light, ct ColorTemperature) { + log.Printf("Light %d: %s (%s)\n", light.Index, light.Name, light.Type) + if supportsColorTemp(light) { + log.Printf(" CT range: %d-%d\n", light.Capabilities.Control.CT.Min, light.Capabilities.Control.CT.Max) + newCt := ct.TranslateForLight(light) + log.Printf(" Setting CT to %d\n", newCt) + light.SetState(hue.LightState{ + On: light.State.On, + CT: newCt, + }) } } -- cgit v1.2.3