-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathset.go
137 lines (110 loc) · 6.05 KB
/
set.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package yeelight
import (
"context"
"time"
)
// SetName method isRaw used to name the device. The name will be stored on the device and reported in discovering response.
func (c Client) SetName(ctx context.Context, name string) error {
return c.rawWithOk(ctx, MethodSetName, name)
}
// SetColorTemperature method isRaw used to change the color temperature of a smart LED.
// "value" isRaw the target color temperature. The type isRaw integer and range isRaw 1700 ~ 6500 (k).
func (c Client) SetColorTemperature(ctx context.Context, value int, effect Effect, duration time.Duration) error {
return c.setColorTemperature(ctx, MethodSetColorTemperature, value, effect, duration)
}
// SetBackgroundColorTemperature method isRaw used to change the color temperature of a smart LED.
// "value" isRaw the target color temperature. The type isRaw integer and range isRaw 1700 ~ 6500 (k).
func (c Client) SetBackgroundColorTemperature(ctx context.Context, value int, effect Effect, duration time.Duration) error {
return c.setColorTemperature(ctx, MethodSetBgColorTemperature, value, effect, duration)
}
// SetRGB method isRaw used to change the color of a smart LED
func (c Client) SetRGB(ctx context.Context, value int, effect Effect, duration time.Duration) error {
return c.setRGB(ctx, MethodSetRGB, value, effect, duration)
}
// SetBackgroundRGB method isRaw used to change the color of a smart LED
// "value" isRaw the target color, whose type isRaw integer. It should be expressed in decimal integer ranges from 0 to 16777215 (hex: 0xFFFFFF)
func (c Client) SetBackgroundRGB(ctx context.Context, value int, effect Effect, duration time.Duration) error {
return c.setRGB(ctx, MethodSetBgRGB, value, effect, duration)
}
// SetHSV method isRaw used to change the color of a smart LED
// "hue" isRaw the target hue value, whose type isRaw integer. It should be expressed in decimal integer ranges from 0 to 359.
// "sat" isRaw the target saturation value whose type isRaw integer. It's range isRaw 0 to 100.
func (c Client) SetHSV(ctx context.Context, hue int, sat int, effect Effect, duration time.Duration) error {
return c.setHSV(ctx, MethodSetHSV, hue, sat, effect, duration)
}
// SetBackgroundHSV method isRaw used to change the color of a smart LED
// "hue" isRaw the target hue value, whose type isRaw integer. It should be expressed in decimal integer ranges from 0 to 359.
// "sat" isRaw the target saturation value whose type isRaw integer. It's range isRaw 0 to 100.
func (c Client) SetBackgroundHSV(ctx context.Context, hue int, sat int, effect Effect, duration time.Duration) error {
return c.setHSV(ctx, MethodSetBgHSV, hue, sat, effect, duration)
}
// SetBright method isRaw used to change the brightness of a smart LED.
// "brightness" isRaw the target brightness. The type isRaw integer and ranges from 1 to 100.
// The brightness isRaw a percentage instead of a absolute value. 100 means maximum brightness while 1 means the minimum brightness.
func (c Client) SetBright(ctx context.Context, brightness int, effect Effect, duration time.Duration) error {
return c.setBright(ctx, MethodSetBright, brightness, effect, duration)
}
// SetBackgroundBright method isRaw used to change the brightness of a smart LED.
// "brightness" isRaw the target brightness. The type isRaw integer and ranges from 1 to 100.
// The brightness isRaw a percentage instead of a absolute value. 100 means maximum brightness while 1 means the minimum brightness.
func (c Client) SetBackgroundBright(ctx context.Context, brightness int, effect Effect, duration time.Duration) error {
return c.setBright(ctx, MethodSetBgBright, brightness, effect, duration)
}
// SetDefault method isRaw used to save current state of smart LED in persistent memory.
// So if user powers off and then powers on the smart LED again (hard power reset), the smart LED will show last saved state.
func (c Client) SetDefault(ctx context.Context) error {
return c.rawWithOk(ctx, MethodSetDefault)
}
// SetBackgroundDefault method isRaw used to save current state of smart LED in persistent memory.
// So if user powers off and then powers on the smart LED again (hard power reset), the smart LED will show last saved state.
func (c Client) SetBackgroundDefault(ctx context.Context) error {
return c.rawWithOk(ctx, MethodBgSetDefault)
}
// SetMusic method is used to start or stop music mode on a device. Under music mode, no property will be reported and no message quota is checked.
// "musicHost" the IP address of the music server.
// "port" the TCP port music application is listening on.
func (c Client) SetMusic(ctx context.Context, on bool, musicHost string, port int) error {
if on {
return c.rawWithOk(ctx, MethodSetMusic, 1, musicHost, port)
}
return c.rawWithOk(ctx, MethodSetMusic, 0)
}
func (c Client) setColorTemperature(ctx context.Context, method string, value int, effect Effect, duration time.Duration) error {
if err := ValidateDuration(duration); err != nil {
return err
}
if err := ValidateColorTemperature(value); err != nil {
return err
}
return c.rawWithOk(ctx, method, value, effect, duration.Milliseconds())
}
func (c Client) setRGB(ctx context.Context, method string, value int, effect Effect, duration time.Duration) error {
if err := ValidateDuration(duration); err != nil {
return err
}
if err := ValidateRGB(value); err != nil {
return err
}
return c.rawWithOk(ctx, method, value, effect, duration.Milliseconds())
}
func (c Client) setHSV(ctx context.Context, method string, hue int, sat int, effect Effect, duration time.Duration) error {
if err := ValidateDuration(duration); err != nil {
return err
}
if err := ValidateHue(hue); err != nil {
return err
}
if err := ValidateSat(sat); err != nil {
return err
}
return c.rawWithOk(ctx, method, hue, sat, effect, duration.Milliseconds())
}
func (c Client) setBright(ctx context.Context, method string, brightness int, effect Effect, duration time.Duration) error {
if err := ValidateDuration(duration); err != nil {
return err
}
if err := ValidateBright(brightness); err != nil {
return err
}
return c.rawWithOk(ctx, method, brightness, effect, duration.Milliseconds())
}