diff options
author | Collin Guarino <collin.guarino@gmail.com> | 2016-02-14 23:07:38 -0500 |
---|---|---|
committer | Collin Guarino <collin.guarino@gmail.com> | 2016-02-14 23:07:38 -0500 |
commit | b0913d3b9b7fb9166f24d9e1c7f2212dc7116ce5 (patch) | |
tree | 7ec2b8e073b927b2d02f3fc3768eab88f785f1b9 /scene.go | |
parent | 1a8b98f271396f412c0ee1b4ca2bf221a3c6a5cc (diff) |
Scene struct and Bridge.GetScenes func implementation.
Diffstat (limited to 'scene.go')
-rw-r--r-- | scene.go | 44 |
1 files changed, 43 insertions, 1 deletions
@@ -8,5 +8,47 @@ package hue import ( - + "fmt" + "encoding/json" ) + +type Scene struct { + Appdata struct { + Data string `json:"data"` + Version int `json:"version"` + } `json:"appdata"` + Lastupdated string `json:"lastupdated"` + Lights []string `json:"lights"` + Locked bool `json:"locked"` + Name string `json:"name"` + Owner string `json:"owner"` + Picture string `json:"picture"` + Recycle bool `json:"recycle"` + Version int `json:"version"` + ID string +} + +// Bridge.GetScenes will get attributes for all scenes. +func (bridge *Bridge) GetScenes() ([]Scene, error) { + uri := fmt.Sprintf("/api/%s/scenes", bridge.Username) + body, _, err := bridge.Get(uri) + if err != nil { + return []Scene{}, err + } + + fmt.Sprintf("GET SCENES BODY: ", string(body)) + + scenes := map[string]Scene{} + err = json.Unmarshal(body, &scenes) + if err != nil { + return []Scene{}, err + } + scenesList := []Scene{} + for key, value := range scenes { + scene := Scene{} + scene = value + scene.ID = key + scenesList = append(scenesList, scene) + } + return scenesList, nil +} |