diff options
author | Collin Guarino <collin.guarino@gmail.com> | 2016-02-15 10:15:23 -0500 |
---|---|---|
committer | Collin Guarino <collin.guarino@gmail.com> | 2016-02-15 10:15:23 -0500 |
commit | 0653dcab284be6f05ebf8dc4b3054b49d9a5b519 (patch) | |
tree | 81da2d0154a90a2ce6359548619eb55e282f2229 | |
parent | fa89d06b0ba2a5cb8a1bc1285703a99bc8109028 (diff) |
Implementation for Bridge.CreateScene
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | scene.go | 36 | ||||
-rw-r--r-- | scene_test.go | 10 |
3 files changed, 32 insertions, 16 deletions
@@ -44,7 +44,7 @@ Pull requests happily accepted on GitHub ##### Scenes - [x] Get all scenes - [x] Get scene by ID -- [ ] Create scene +- [x] Create scene - [ ] Modify scene - [ ] Recall scene - [ ] Delete scene @@ -15,19 +15,19 @@ import ( // Scene struct defines attributes for Scene items 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 + Appdata *struct { + Data string `json:"data,omitempty"` + Version int `json:"version,omitempty"` + } `json:"appdata,omitempty"` + Lastupdated string `json:"lastupdated,omitempty"` + Lights []string `json:"lights,omitempty"` + Locked bool `json:"locked,omitempty"` + Name string `json:"name,omitempty"` + Owner string `json:"owner,omitempty"` + Picture string `json:"picture,omitempty"` + Recycle bool `json:"recycle,omitempty"` + Version int `json:"version,omitempty"` + ID string `json:",omitempty"` } // Bridge.GetScenes will get attributes for all scenes. @@ -70,3 +70,13 @@ func (bridge *Bridge) GetScene(id string) (Scene, error) { } return scene, nil } + +// Bridge.CreateScene will post a new scene configuration to the bridge. +func (bridge *Bridge) CreateScene(scene Scene) error { + uri := fmt.Sprintf("/api/%s/scenes/", bridge.Username) + body, _, err := bridge.Post(uri, scene) + if err != nil { + return err + } + return nil +} diff --git a/scene_test.go b/scene_test.go index 27998f6..07d630c 100644 --- a/scene_test.go +++ b/scene_test.go @@ -12,9 +12,9 @@ import ( "fmt" ) -func TestGetScenes(t *testing.T) { +func TestGetAllScenes(t *testing.T) { bridge, _ := NewBridge("192.168.1.128", "427de8bd6d49f149c8398e4fc08f") - scenes, _ := bridge.GetScenes() + scenes, _ := bridge.GetAllScenes() for scene := range scenes { fmt.Println("SCENE: ", scenes[scene]) } @@ -22,3 +22,9 @@ func TestGetScenes(t *testing.T) { individual, _ := bridge.GetScene(scenes[0].ID) fmt.Println("Individual scene: ", individual) } + +func TestCreateScene(t *testing.T) { + bridge, _ := NewBridge("192.168.1.128", "427de8bd6d49f149c8398e4fc08f") + scene := Scene{Lights: []string{"1", "2"}} + _ = bridge.CreateScene(scene) +} |