-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequestcreator.go
54 lines (42 loc) · 939 Bytes
/
requestcreator.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
package huecontroller
import (
"encoding/json"
"log"
)
func CreateLightPropertiesRequest(lp LightProps) []byte {
type On struct {
On bool `json:"on"`
}
type Dimming struct {
Brightness float64 `json:"brightness"`
}
type Xy struct {
X float64 `json:"x"`
Y float64 `json:"y"`
}
type Color struct {
Xy Xy `json:"xy"`
}
type Option struct {
On On `json:"on"`
Dimming Dimming `json:"dimming"`
Color Color `json:"color"`
}
opt := Option{On{lp.On}, Dimming{lp.Brightness}, Color{Xy{lp.ColorX, lp.ColorY}}}
requestBody, err := json.Marshal(opt)
if err != nil {
log.Println(err)
}
return requestBody
}
func CreateNewClientRequest() []byte {
type Client struct {
DeviceType string `json:"devicetype"`
GenerateClientKey bool `json:"generateclientkey"`
}
requestBody, err := json.Marshal(Client{"go-hue-lights", true})
if err != nil {
return nil
}
return requestBody
}