aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-02-14 18:56:39 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-02-14 18:56:39 -0500
commit476acf944f7f859a5ad2e7003f82d3f96fbff1a5 (patch)
treedeb9943ea5846202634c3bf72958b60f407940d4
parent1f936737809a85281091496e8668bda56214d255 (diff)
Implemented GetSchedules func with new Schedule struct.
-rw-r--r--bridge_test.go2
-rw-r--r--schedule.go73
-rw-r--r--schedule_test.go7
3 files changed, 50 insertions, 32 deletions
diff --git a/bridge_test.go b/bridge_test.go
index d750f58..02f44bc 100644
--- a/bridge_test.go
+++ b/bridge_test.go
@@ -12,7 +12,7 @@ import (
)
func TestCreateUser(t *testing.T) {
- bridge, _ := NewBridge("192.168.1.128", "319b36233bd2328f3e40731b23479207")
+ bridge, _ := NewBridge("192.168.1.128", "427de8bd6d49f149c8398e4fc08f")
bridge.CreateUser("test")
//bridge.DeleteUser(bridge.Username)
}
diff --git a/schedule.go b/schedule.go
index 0d1faab..43c7056 100644
--- a/schedule.go
+++ b/schedule.go
@@ -8,43 +8,56 @@
package hue
import (
- //"fmt"
+ "fmt"
+ "encoding/json"
)
-type Timer struct {
- Index int
- Name string `json:"name,omitempty"`
- Description string `json:"description,omitempty"`
- Command CommandInfo `json:"command,omitempty"`
- Time string `json:"time,omitempty"`
- Created string `json:"created,omitempty"`
- Status string `json:"status,omitempty"`
- AutoDelete bool `json:"autodelete,omitempty"`
- StartTime string `json:"starttime,omitempty"`
+type Schedule struct {
+ Name string `json:"name"`
+ Description string `json:"description"`
+ Command struct {
+ Address string `json:"address"`
+ Body struct {
+ Scene string `json:"scene"`
+ } `json:"body"`
+ Method string `json:"method"`
+ } `json:"command"`
+ Localtime string `json:"localtime"`
+ Time string `json:"time"`
+ Created string `json:"created"`
+ Status string `json:"status"`
+ Autodelete bool `json:"autodelete"`
+ ID string
}
-type Alarm struct {
- Index string
- Name string `json:"name,omitempty"`
- Description string `json:"description,omitempty"`
- Command CommandInfo `json:"command,omitempty"`
- LocalTime string `json:"localtime,omitempty"`
- Time string `json:"time,omitempty"`
- Created string `json:"created,omitempty"`
- Status string `json:"status,omitempty"`
- AutoDelete bool `json:"autodelete,omitempty"`
-}
+func (bridge *Bridge) GetSchedules() ([]Schedule, error) {
+ uri := fmt.Sprintf("/api/%s/schedules", bridge.Username)
+ body, _, err := bridge.Get(uri)
+ if err != nil {
+ return []Schedule{}, err
+ }
+
+ schedules := map[string]Schedule{}
+ err = json.Unmarshal(body, &schedules)
+ if err != nil {
+ return []Schedule{}, err
+ }
+
+ scheduleList := []Schedule{}
+ for key, value := range schedules {
+ schedule := Schedule{}
+ schedule = value
+ schedule.ID = key
+ scheduleList = append(scheduleList, schedule)
+ }
+
+ // for sched := range scheduleList {
+ // fmt.Println("\n\nScheduleoutput: ", scheduleList[sched])
+ // }
-type CommandInfo struct {
- Address string `json:"address,omitempty"`
- Body string `json:"body,omitempty"` // TODO: may be diff type
- Method string `json:"method,omitempty"`
+ return scheduleList, nil
}
-// func (bridge *Bridge) GetSchedules() ([]interface{}, error) {
-// return []interface{}, nil
-// }
-//
// func (bridge *Bridge) CreateSchedule(schedule interface{}) error {
// return nil
// }
diff --git a/schedule_test.go b/schedule_test.go
index 438d3fd..43d6e70 100644
--- a/schedule_test.go
+++ b/schedule_test.go
@@ -8,5 +8,10 @@
package hue
import (
- //"testing"
+ "testing"
)
+
+func TestGetSchedules(t *testing.T) {
+ bridge, _ := NewBridge("192.168.1.128", "427de8bd6d49f149c8398e4fc08f")
+ _, _ = bridge.GetSchedules()
+}