From b0913d3b9b7fb9166f24d9e1c7f2212dc7116ce5 Mon Sep 17 00:00:00 2001 From: Collin Guarino Date: Sun, 14 Feb 2016 23:07:38 -0500 Subject: Scene struct and Bridge.GetScenes func implementation. --- scene.go | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'scene.go') diff --git a/scene.go b/scene.go index 0db1e1c..fdc4fcd 100644 --- a/scene.go +++ b/scene.go @@ -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 +} -- cgit v1.2.3