/
Structs.go
68 lines (54 loc) · 1.7 KB
/
Structs.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
/**
Lux
Copyright (C) 2021 BanDev
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package brightness
import (
"encoding/json"
"github.com/bandev/lux/api/general"
"github.com/bandev/lux/commands/devices"
)
// Control struct manages the control
// json data that will be send to govee.
type Control struct {
Device string `json:"device"`
Model string `json:"model"`
Cmd ControlCmd `json:"cmd"`
}
// ControlCmd is the control command
// json that will be sent to govee.
type ControlCmd struct {
Name string `json:"name"`
Value int `json:"value"`
}
// Send sends all the data to govee to set
// the value of the brightness
func (c *Control) Send (d devices.Device, conn general.Connection, power int) []byte {
c.Device = d.MAC
c.Model = d.Model
c.Cmd.Name = "brightness"
c.Cmd.Value = power
var data, _ = json.Marshal(&c)
return conn.Put("v1/devices/control", data)
}
// Response struct is for parsing the json
// returned by govee.
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
}
// Fill fills the response struct with the
// data provided by govee.
func (r *Response) Fill (c []byte) {
_ = json.Unmarshal(c, &r)
}