diff options
-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, + }) } } |