aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Brunner <chb@muc.de>2016-09-13 22:02:53 +0200
committerChristian Brunner <chb@muc.de>2016-09-15 17:56:45 +0200
commit15a6d3afe17915ca077696abc58145db27d9601c (patch)
tree91685e9fdeab24a905667894eb743327cd1bffa0
parent05933eaaf0811a2b2b7d34c814777fd66d2f7ef0 (diff)
add GetSceneByName()
-rw-r--r--scene.go17
1 files changed, 17 insertions, 0 deletions
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)