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 | |
parent | b279470a75dd6f3e59809650424a8e21d979eefc (diff) |
Split out updateLight function
-rw-r--r-- | colortemp.go | 2 | ||||
-rw-r--r-- | main.go | 26 |
2 files changed, 16 insertions, 12 deletions
diff --git a/colortemp.go b/colortemp.go index a708a0b..8cf3454 100644 --- a/colortemp.go +++ b/colortemp.go @@ -43,7 +43,7 @@ func getDesiredColorTemperature(t time.Time) ColorTemperature { // 500 <=> 2000K // ============= // 347 4500 -func translateCtForLight(ct ColorTemperature, light hue.Light) uint16 { +func (ct ColorTemperature) TranslateForLight(light hue.Light) uint16 { divisor := 12.968 scaled := float64(ct) / divisor inverted := 500 - scaled + 153 @@ -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, + }) } } |