Skip to content

Commit

Permalink
Colors working with homekit
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Suderman committed Jan 20, 2020
1 parent 3db00e5 commit 3a9435f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions homekit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"github.com/brutella/hc"
"github.com/brutella/hc/accessory"
"github.com/lucasb-eyer/go-colorful"
"github.com/spf13/cobra"
"k8s.io/klog"
)
Expand Down Expand Up @@ -64,10 +65,20 @@ func startHomekit() {

ac.Lightbulb.Hue.OnValueRemoteUpdate(func(value float64) {
klog.Infof("homekit hue set to: %f", value)
led.color = modifyHue(led.color, value)
err = led.display(0)
if err != nil {
klog.Error(err)
}
})

ac.Lightbulb.Saturation.OnValueRemoteUpdate(func(value float64) {
klog.Infof("homekit saturation set to %f", value)
led.color = modifySaturation(led.color, value)
err = led.display(0)
if err != nil {
klog.Error(err)
}
})

ac.Lightbulb.Brightness.OnValueRemoteUpdate(func(value int) {
Expand Down Expand Up @@ -109,3 +120,23 @@ func scaleHomekitBrightness(value int) int {

return new
}

//modifySaturation changes the saturation and returns a new color
func modifySaturation(oldColor colorful.Color, saturation float64) colorful.Color {
h, s, v := oldColor.Hsv()
klog.V(8).Infof("old color h: %f, s: %f, v: %f", h, s, v)
s = saturation
newColor := colorful.Hsv(h, s, v)
klog.V(8).Infof("new color h: %f, s: %f, v: %f", h, s, v)
return newColor
}

//modifyHue changes the hue and returns a new color
func modifyHue(oldColor colorful.Color, hue float64) colorful.Color {
h, s, v := oldColor.Hsv()
klog.V(8).Infof("old color h: %f, s: %f, v: %f", h, s, v)
h = hue
newColor := colorful.Hsv(h, s, v)
klog.V(8).Infof("new color h: %f, s: %f, v: %f", h, s, v)
return newColor
}

0 comments on commit 3a9435f

Please sign in to comment.