-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.go
38 lines (30 loc) · 778 Bytes
/
state.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
package hue
import "encoding/json"
// -------------------------------------------------------------
// ~ Interfaces & Types
// -------------------------------------------------------------
// BridgeState provides all data for a bridge
type BridgeState struct {
Lights map[string]*Light `json:"lights"`
}
func (bs *BridgeState) String() string {
str := ""
for k, l := range bs.Lights {
str += k + ": " + l.String()
}
return str
}
// GetState returns the current hue state
func (b *Bridge) GetState() (state *BridgeState, err error) {
state = &BridgeState{}
res, err := b.getFromBridge("")
if err != nil {
return
}
// Unmarshal data
errDecode := json.NewDecoder(res.Body).Decode(state)
if errDecode != nil {
return nil, errDecode
}
return state, err
}