-
Notifications
You must be signed in to change notification settings - Fork 0
/
mode_color_options.go
72 lines (61 loc) · 1.43 KB
/
mode_color_options.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package shelly
import (
"fmt"
"github.com/lucasb-eyer/go-colorful"
)
type ModeColorOptions struct {
Brightness *int
Transition *int
Gain *int
Color *colorful.Color
Error error
}
func NewModeColorOptions() *ModeColorOptions {
return &ModeColorOptions{}
}
func (x *ModeColorOptions) SetBrightness(brightness int) *ModeColorOptions {
if brightness < 0 {
x.Error = fmt.Errorf("invalid brightness < 0: %d", brightness)
return x
}
if brightness > 100 {
x.Error = fmt.Errorf("invalid brightness > 100: %d", brightness)
return x
}
x.Brightness = &brightness
return x
}
func (x *ModeColorOptions) SetGain(gain int) *ModeColorOptions {
if gain < 0 {
x.Error = fmt.Errorf("invalid brightness < 0: %d", gain)
return x
}
if gain > 100 {
x.Error = fmt.Errorf("invalid brightness > 100: %d", gain)
return x
}
x.Gain = &gain
return x
}
func (x *ModeColorOptions) SetTransitionTime(milliseconds int) *ModeColorOptions {
if milliseconds < 0 {
x.Error = fmt.Errorf("invalid transition time (ms) < 0: %d", milliseconds)
return x
}
if milliseconds > 5_000 {
x.Error = fmt.Errorf("invalid transition time (ms) > 5000: %d", milliseconds)
return x
}
x.Transition = &milliseconds
return x
}
func (x *ModeColorOptions) SetColor(color colorful.Color) *ModeColorOptions {
x.Color = &color
return x
}
func (x *ModeColorOptions) MustValidate() *ModeColorOptions {
if x.Error == nil {
return x
}
panic(x.Error)
}