diff options
author | Collin Guarino <collin.guarino@gmail.com> | 2016-02-14 19:09:04 -0500 |
---|---|---|
committer | Collin Guarino <collin.guarino@gmail.com> | 2016-02-14 19:09:04 -0500 |
commit | 2026b473a63c2750cb7245f545205ff1d76f4624 (patch) | |
tree | c337a9322786dcfef6ef603af60fb584d729aeea | |
parent | f985fc200641b55526c2f094d9bf5ddafd030727 (diff) |
Added documentation and clarity to Bridge.GetAllSchedules and Bridge.GetSchedule
-rw-r--r-- | schedule.go | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/schedule.go b/schedule.go index 8c49de2..f35802d 100644 --- a/schedule.go +++ b/schedule.go @@ -31,7 +31,7 @@ type Schedule struct { ID string } -// Bridge.GetSchedules will get Alarms and Timers in a Schedule struct. +// Bridge.GetAllSchedules will get Alarms and Timers in a Schedule struct. func (bridge *Bridge) GetAllSchedules() ([]Schedule, error) { uri := fmt.Sprintf("/api/%s/schedules", bridge.Username) body, _, err := bridge.Get(uri) @@ -39,12 +39,13 @@ func (bridge *Bridge) GetAllSchedules() ([]Schedule, error) { return []Schedule{}, err } + // Each index key is the topmost element of the json array. + // Unmarshal the array, loop through each index key, and add it to the list schedules := map[string]Schedule{} err = json.Unmarshal(body, &schedules) if err != nil { return []Schedule{}, err } - scheduleList := []Schedule{} for key, value := range schedules { schedule := Schedule{} @@ -52,16 +53,12 @@ func (bridge *Bridge) GetAllSchedules() ([]Schedule, error) { schedule.ID = key scheduleList = append(scheduleList, schedule) } - - // for sched := range scheduleList { - // fmt.Println("\n\nScheduleoutput: ", scheduleList[sched]) - // } - return scheduleList, nil } // Bridge.GetSchedule will get the attributes for an individual schedule. // This is used as to optimize time when updating the state of a schedule item. +// Note: The ID is not an index, it's a unique key generated for each schedule. func (bridge *Bridge) GetSchedule(id string) (Schedule, error) { uri := fmt.Sprintf("/api/%s/schedules/%s", bridge.Username, id) body, _, err := bridge.Get(uri) |