From 15a6d3afe17915ca077696abc58145db27d9601c Mon Sep 17 00:00:00 2001 From: Christian Brunner Date: Tue, 13 Sep 2016 22:02:53 +0200 Subject: add GetSceneByName() --- scene.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scene.go b/scene.go index 687ca1c..3358a1b 100644 --- a/scene.go +++ b/scene.go @@ -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) -- cgit v1.2.3