diff options
author | Ben Burwell <ben@benburwell.com> | 2018-05-24 22:23:35 -0400 |
---|---|---|
committer | Ben Burwell <ben@benburwell.com> | 2018-05-24 22:23:35 -0400 |
commit | a3786c8698f8b7c85d09e241cf09dc0e8ced9da2 (patch) | |
tree | 8739737682938a3e9847a6395563ba17707c64e5 /main.go | |
parent | b279470a75dd6f3e59809650424a8e21d979eefc (diff) |
Split out updateLight function
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -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, + }) } } |