-
Notifications
You must be signed in to change notification settings - Fork 0
/
mode_white_options.go
65 lines (55 loc) · 1.29 KB
/
mode_white_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
package shelly
import (
"fmt"
)
type ModeWhiteOptions struct {
Brightness *int
Transition *int
Temp *int
Error error
}
func NewModeWhiteOptions() *ModeWhiteOptions {
return &ModeWhiteOptions{}
}
func (x *ModeWhiteOptions) SetBrightness(brightness int) *ModeWhiteOptions {
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 *ModeWhiteOptions) SetTransitionTime(milliseconds int) *ModeWhiteOptions {
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 *ModeWhiteOptions) SetTemp(kelvin int) *ModeWhiteOptions {
if kelvin < 3_000 {
x.Error = fmt.Errorf("invalid temp (kelvin) < 0: %d", kelvin)
return x
}
if kelvin > 6_500 {
x.Error = fmt.Errorf("invalid temp (kelvin) > 5000: %d", kelvin)
return x
}
x.Temp = &kelvin
return x
}
func (x *ModeWhiteOptions) MustValidate() *ModeWhiteOptions {
if x.Error == nil {
return x
}
panic(x.Error)
}