aboutsummaryrefslogtreecommitdiff
path: root/scene.go
diff options
context:
space:
mode:
authorCollin Guarino <Collinux@users.noreply.github.com>2016-09-23 16:18:30 -0400
committerGitHub <noreply@github.com>2016-09-23 16:18:30 -0400
commite5b3cf00a075a876ce12eb8ee2816043ef8b6fac (patch)
tree0943188ca8ddc1d451a5f2dda4f25175ae5f026f /scene.go
parent05933eaaf0811a2b2b7d34c814777fd66d2f7ef0 (diff)
parent717f77eeb3be68ba8328e04f90904070df687d3d (diff)
Merge pull request #5 from chbmuc/master
Add (scene) functions
Diffstat (limited to 'scene.go')
-rw-r--r--scene.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/scene.go b/scene.go
index 687ca1c..e972de7 100644
--- a/scene.go
+++ b/scene.go
@@ -10,6 +10,7 @@ package hue
import (
"encoding/json"
+ "errors"
"fmt"
)
@@ -71,6 +72,37 @@ 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.RecallScene recalls a scene
+func (bridge *Bridge) RecallScene(id string) error {
+ action := &Action{Scene: id}
+ return bridge.SetGroupState(0, action)
+}
+
+// Bridge.RecallSceneByName recalls a scene
+func (bridge *Bridge) RecallSceneByName(name string) error {
+ scene, err := bridge.GetSceneByName(name)
+ if err != nil {
+ return err
+ }
+ return bridge.RecallScene(scene.ID)
+}
+
// 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)