-
Notifications
You must be signed in to change notification settings - Fork 0
/
light.go
324 lines (258 loc) · 9.84 KB
/
light.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
package shelly
import (
"context"
"github.com/mongoose-os/mos/common/mgrpc"
"github.com/mongoose-os/mos/common/mgrpc/frame"
)
// LightGetConfigRequest contains parameters for the Light.GetConfig RPC request.
type LightGetConfigRequest struct {
// ID of the light component instance.
ID int `json:"id"`
}
func (r *LightGetConfigRequest) Method() string {
return "Light.GetConfig"
}
func (r *LightGetConfigRequest) NewTypedResponse() *LightConfig {
return &LightConfig{}
}
func (r *LightGetConfigRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *LightGetConfigRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*LightConfig,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
// LightSetConfigRequest contains parameters for the Light.SetConfig RPC request.
type LightSetConfigRequest struct {
// ID of the light component instance.
ID int `json:"id"`
// Config that the method takes.
Config LightConfig `json:"config"`
}
func (r *LightSetConfigRequest) Method() string {
return "Light.SetConfig"
}
func (r *LightSetConfigRequest) NewTypedResponse() *SetConfigResponse {
return &SetConfigResponse{}
}
func (r *LightSetConfigRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *LightSetConfigRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*SetConfigResponse,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
// LightGetStatusRequst contains parameters for the Light.GetStatus RPC request.
type LightGetStatusRequest struct {
// ID of the light component instance.
ID int `json:"id"`
}
func (r *LightGetStatusRequest) Method() string {
return "Light.GetStatus"
}
func (r *LightGetStatusRequest) NewTypedResponse() *LightStatus {
return &LightStatus{}
}
func (r *LightGetStatusRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *LightGetStatusRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*LightStatus,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
// LightSetRequest is the parameters for the Light.Set RPC, which enables or disables a light.
type LightSetRequest struct {
// ID of the light component instance.
ID int `json:"id"`
// On is true for light on, false otherwise. (optional). On or Brightness must be provided.
On *bool `json:"on,omitempty"`
// Brightness level (optional). On or Brightness must be provided.
Brightness *float64 `json:"brightness,omitempty"`
// TransitionDuration in seconds - time between change from current brightness level
// to desired brightness level in request. (optional)
TransitionDuration *float64 `json:"transition_duration,omitempty"`
// ToggleAfter is the number of seconds afterwhich the light will flip-back. (optional)
ToggleAfter *float64 `json:"toggle_after,omitempty"`
}
func (r *LightSetRequest) Method() string {
return "Light.Set"
}
func (r *LightSetRequest) NewTypedResponse() *LightSetResponse {
return &LightSetResponse{}
}
func (r *LightSetRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *LightSetRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*LightSetResponse,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
// LightSetResponse is the response body for the Light.Set RPC.
type LightSetResponse struct{}
// LightToggleRequest contains parameters for the Light.Toggle RPC request.
type LightToggleRequest struct {
// ID of the light component instance.
ID int `json:"id"`
}
func (r *LightToggleRequest) Method() string {
return "Light.Toggle"
}
func (r *LightToggleRequest) NewTypedResponse() *LightToggleResponse {
return &LightToggleResponse{}
}
func (r *LightToggleRequest) NewResponse() any {
return r.NewTypedResponse()
}
func (r *LightToggleRequest) Do(
ctx context.Context,
c mgrpc.MgRPC,
credsCallback mgrpc.GetCredsCallback,
) (
*LightToggleResponse,
*frame.Response,
error,
) {
resp := r.NewTypedResponse()
raw, err := Do(ctx, c, credsCallback, r, resp)
return resp, raw, err
}
// LightToggleResponse is the body for the Light.Toggle RPC response.
type LightToggleResponse struct{}
// LightConfig provides configuration for light component instances.
type LightConfig struct {
// ID of the light component instance.
ID int `json:"id"`
// Name of the light instance.
Name *string `json:"name"`
// InMode is the mode of the associated input. Range of values: follow, flip,
// activate, detached, dim (if applicable), dual_dim (if applicable).
InMode *string `json:"in_mode,omitempty"`
// InitialState is the output state to set on power_on. Range of values: off,
// on, restore_last, match_input
InitialState *string `json:"initial_state,omitempty"`
// AutoOn is true if the "Automatic ON" function is enabled, false otherwise.
AutoOn *bool `json:"auto_on,omitempty"`
// AutoOnDelay is the number of seconds to pass until the component is
// lighted back.
AutoOnDelay *float64 `json:"auto_on_delay,omitempty"`
// AutoOff is true if the "Automatic OFF" function is enabled, false otherwise.
AutoOff *bool `json:"auto_off,omitempty"`
// AutoOffDelay is the number of seconds to pass until the component is lighted back off.
AutoOffDelay *float64 `json:"auto_off_delay,omitempty"`
// TransitionDuration (in seconds) - time to change from 0% to 100% of brightness (if
// applicable).
TransitionDuration *float64 `json:"transition_duration,omitempty"`
// MinBrightnessOnToggle is the brightness level (in percent) applied when there is
// a toggle and current brightness is lower than min_brightness_on_toggle.
MinBrightnessOnToggle *float64 `json:"min_brightness_on_toggle,omitempty"`
// NightMode configures the night mode feature.
NightMode *LightNightModeConfig `json:"night_mode,omitempty"`
// ButtonFadeRate controls how quickly the output level changes while a button is
// held down for dimming (if applicable). Default value 3. Range [1,5] where 5 is
// fastest, 1 is slowest.
ButtonFadeRate *float64 `json:"button_fade_rate,omitempty"`
// ButtonPresets provides configuration for button presets.
ButtonPresets *LightButtonPresetsConfig `json:"button_presets,omitempty"`
// RangeMap remaps output 0%-100% range to values in array (if applicable). First
// value in array is min setting, second value is max setting. Array elements are
// of type number. Float values are supported. Accepted range for values is from
// 0% to 100%. Default values are [0, 100]. max must be greater than min.
// nil may be specified to reset.
RangeMap *[]float64 `json:"range_map,omitempty"`
}
// LightNightModeConfig configures the night mode feature.
type LightNightModeConfig struct {
// Enable or disable night mode.
Enable *bool `json:"enable,omitempty"`
// Brightness level limit when night mode is active.
Brightness *float64 `json:"brightness,omitempty"`
// ActiveBetween is a slice containing 2 elements of type string, the first element
// indicates the start of the period during which the night mode will be active,
// the second indicates the end of that period. Both start and end are strings in
// the format HH:MM, where HH and MM are hours and minutes with optinal leading zeros.
ActiveBetween []string `json:"active_between,omitempty"`
}
// LightButtonPresetsConfig provides configuration for button presets.
type LightButtonPresetsConfig struct {
// ButtonDoublePush configures button double push behavior. nil disables button_doublepush.
ButtonDoublePush *LightButtonPresetsDoublePushConfig `json:"button_doublepush,omitempty"`
}
// LightButtonPresetsDoublePushConfig configures button double push behavior.
type LightButtonPresetsDoublePushConfig struct {
// Brightness level (in percent) set on double click (if applicable), default: 100
Brightness *float64 `json:"brightness,omitempty"`
}
// LightStatus describes the status of light component instances.
type LightStatus struct {
// ID of the light component instance.
ID int `json:"id"`
// Source of the last command, for example: init, WS_in, http, ...
Source *string `json:"source,omitempty"`
// Output is true if the output channel is currently on, false otherwise.
Output *bool `json:"output,omitempty"`
// Brightness level (in percent)
Brightness *float64 `json:"brightness,omitempty"`
// TimerStartedAt is the unix timestamp, start time of the timer (in UTC)
// (shown if the timer is triggered)
TimerStartedAt *float64 `json:"timer_started_at,omitempty"`
// TimerDuration is the number of seconds for the timer (shown if the timer
// is triggered).
TimerDuration *float64 `json:"timer_duration,omitempty"`
// Transition provides information about the transition (shown if transition is triggered).
Transition *LightTransitionStatus `json:"transition,omitempty"`
// Temperature describes the internal temperature of the relay.
Temperature *Temperature `json:"temperature,omitempty"`
}
// LightTransitionStatus provides information about the transition (shown if transition
// is triggered).
type LightTransitionStatus struct {
// Target describes the desired result of the transition.
Target LightTransitionTargetStatus `json:"target,omitempty"`
// StartedAt is the unix timestamp start time of the transition (in UTC).
StartedAt *float64 `json:"started_at,omitempty"`
// Duration of the transition in seconds.
Duration *float64 `json:"duration,omitempty"`
}
// LightTransitionTargetStatus describes the desired result of the transition.
type LightTransitionTargetStatus struct {
// Output is true if the output channel becomes on, false otherwise
Output bool `json:"output"`
// Brightness level (in percent).
Brightness *float64 `json:"brightness,omitempty"`
}