diff options
author | Christian Brunner <chb@muc.de> | 2016-09-13 22:02:53 +0200 |
---|---|---|
committer | Christian Brunner <chb@muc.de> | 2016-09-15 17:56:45 +0200 |
commit | 15a6d3afe17915ca077696abc58145db27d9601c (patch) | |
tree | 91685e9fdeab24a905667894eb743327cd1bffa0 | |
parent | 05933eaaf0811a2b2b7d34c814777fd66d2f7ef0 (diff) |
add GetSceneByName()
-rw-r--r-- | scene.go | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -10,6 +10,7 @@ package hue import ( "encoding/json" + "errors" "fmt" ) @@ -71,6 +72,22 @@ func (bridge *Bridge) GetScene(id string) (Scene, error) { return scene, nil } +// Bridge.GetSceneByName gets the attributes for the scene identified by a name +func (bridge *Bridge) GetSceneByName(name string) (Scene, error) { + + scenes, _ := bridge.GetAllScenes() + + // Iterate in reverse, as later entries seem to be the newest + for i := len(scenes) - 1; i >= 0; i-- { + if scenes[i].Name == name { + return scenes[i], nil + } + } + + errOut := fmt.Sprintf("Error: Scene name '%s' not found. ", name) + return Scene{}, errors.New(errOut) +} + // Bridge.CreateScene posts a new scene configuration to the bridge. func (bridge *Bridge) CreateScene(scene Scene) error { uri := fmt.Sprintf("/api/%s/scenes/", bridge.Username) |