-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.go
35 lines (31 loc) · 892 Bytes
/
color.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package color
import (
"errors"
"github.com/niklas88/feel-at-home-server/devices"
"github.com/niklas88/feel-at-home-server/server/deviceapi"
"github.com/pwaller/go-hexcolor"
"image/color"
)
type ColorConfig struct {
Color hexcolor.Hex
}
func init() {
deviceapi.DefaultRegistry.Register(&deviceapi.Registration{
Info: deviceapi.Info{
Name: "Color",
Description: "Set a static color for your color lamp"},
ConfigFactory: func() deviceapi.Config {
return &ColorConfig{"#ffffff"}
},
EffectFactory: deviceapi.ColorLampEffectFactory(ColorEffectFactory)})
}
func ColorEffectFactory(l devices.ColorLamp) deviceapi.Effect {
return deviceapi.EffectFunc(func(config deviceapi.Config) error {
conf, ok := config.(*ColorConfig)
if !ok {
return errors.New("Not a ColorConfig")
}
m := color.RGBAModel
return l.Color(m.Convert(conf.Color).(color.RGBA))
})
}