diff options
-rw-r--r-- | group.go | 2 | ||||
-rw-r--r-- | scene.go | 44 | ||||
-rw-r--r-- | scene_test.go | 11 |
3 files changed, 54 insertions, 3 deletions
@@ -23,7 +23,7 @@ type Group struct { Hue int `json:"hue"` On bool `json:"on"` Sat int `json:"sat"` - Xy []float64 `json:"xy"` + XY []float64 `json:"xy"` } `json:"action"` Lights []string `json:"lights"` Name string `json:"name"` @@ -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 +} diff --git a/scene_test.go b/scene_test.go index 4b9564b..82646d6 100644 --- a/scene_test.go +++ b/scene_test.go @@ -8,5 +8,14 @@ package hue import ( - + "testing" + "fmt" ) + +func TestGetScenes(t *testing.T) { + bridge, _ := NewBridge("192.168.1.128", "427de8bd6d49f149c8398e4fc08f") + scenes, _ := bridge.GetScenes() + for scene := range scenes { + fmt.Println("SCENE: ", scenes[scene]) + } +} |