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
|
/*
* group.go
* GoHue library for Philips Hue
* Copyright (C) 2016 Collin Guarino (Collinux) collin.guarino@gmail.com
* License: GPL version 2 or higher http://www.gnu.org/licenses/gpl.html
*/
// http://www.developers.meethue.com/documentation/groups-api
package hue
import (
"encoding/json"
"fmt"
)
// Action struct defines the state of a group
type Action struct {
Alert string `json:"alert,omitempty"`
Bri int `json:"bri,omitempty"`
Colormode string `json:"colormode,omitempty"`
Ct int `json:"ct,omitempty"`
Effect string `json:"effect,omitempty"`
Hue int `json:"hue,omitempty"`
On bool `json:"on,omitempty"`
Sat int `json:"sat,omitempty"`
XY []float64 `json:"xy,omitempty"`
Scene string `json:"scene,omitempty"`
}
// Group struct defines the attributes for a group of lights.
type Group struct {
Action Action `json:"action"`
Lights []string `json:"lights"`
Name string `json:"name"`
Type string `json:"type"`
}
// Bridge.GetGroups gets the attributes for each group of lights.
// TODO: NOT TESTED, NOT FULLY IMPLEMENTED
func (bridge *Bridge) GetGroups() ([]Group, error) {
uri := fmt.Sprintf("/api/%s/groups", bridge.Username)
body, _, err := bridge.Get(uri)
if err != nil {
return []Group{}, err
}
//fmt.Println("GROUP GET: ", string(body))
groups := map[string]Group{}
err = json.Unmarshal(body, &groups)
if err != nil {
return []Group{}, err
}
//fmt.Println("GROUPS: ", groups)
return []Group{}, nil
}
// Bridge.SetGroupState sends an action to group
func (bridge *Bridge) SetGroupState(group int, action *Action) error {
uri := fmt.Sprintf("/api/%s/groups/%d/action", bridge.Username, group)
_, _, err := bridge.Put(uri, action)
if err != nil {
return err
}
return nil
}
|