aboutsummaryrefslogtreecommitdiff
path: root/schedule.go
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-02-28 11:06:00 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-02-28 11:06:00 -0500
commitd32ef65eeedf6236bc007cbd1e8c874087167eaa (patch)
treed7798fa306b5343688a499c2c374e8c829355b1b /schedule.go
parent76d36f528ea622a66b3e65991082fd53120737ee (diff)
Ran go fmt on all files.
Diffstat (limited to 'schedule.go')
-rw-r--r--schedule.go94
1 files changed, 47 insertions, 47 deletions
diff --git a/schedule.go b/schedule.go
index a251d3c..50755ef 100644
--- a/schedule.go
+++ b/schedule.go
@@ -3,88 +3,88 @@
* GoHue library for Philips Hue
* Copyright (C) 2016 Collin Guarino (Collinux) collin.guarino@gmail.com
* License: GPL version 2 or higher http://www.gnu.org/licenses/gpl.html
-*/
+ */
// http://www.developers.meethue.com/documentation/schedules-api-0
package hue
import (
- "fmt"
- "encoding/json"
+ "encoding/json"
+ "fmt"
)
// Schedule struct defines attributes of Alarms and Timers
type Schedule struct {
- Name string `json:"name"`
- Description string `json:"description"`
- Command struct {
- Address string `json:"address"`
+ Name string `json:"name"`
+ Description string `json:"description"`
+ Command struct {
+ Address string `json:"address"`
Body struct {
- Scene string `json:"scene"`
+ Scene string `json:"scene"`
} `json:"body"`
- Method string `json:"method"`
+ 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
+ Localtime string `json:"localtime"`
+ Time string `json:"time"`
+ Created string `json:"created"`
+ Status string `json:"status"`
+ Autodelete bool `json:"autodelete"`
+ ID string
}
// Bridge.GetAllSchedules gets 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)
- if err != nil {
- return []Schedule{}, err
- }
+ uri := fmt.Sprintf("/api/%s/schedules", bridge.Username)
+ body, _, err := bridge.Get(uri)
+ if err != nil {
+ 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)
+ // 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{}
- schedule = value
- schedule.ID = key
- scheduleList = append(scheduleList, schedule)
- }
- return scheduleList, nil
+ scheduleList := []Schedule{}
+ for key, value := range schedules {
+ schedule := Schedule{}
+ schedule = value
+ schedule.ID = key
+ scheduleList = append(scheduleList, schedule)
+ }
+ return scheduleList, nil
}
// Bridge.GetSchedule gets the attributes for an individual schedule.
// This is used 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)
- if err != nil {
- return Schedule{}, err
- }
+ uri := fmt.Sprintf("/api/%s/schedules/%s", bridge.Username, id)
+ body, _, err := bridge.Get(uri)
+ if err != nil {
+ return Schedule{}, err
+ }
- schedule := Schedule{}
- err = json.Unmarshal(body, &schedule)
+ schedule := Schedule{}
+ err = json.Unmarshal(body, &schedule)
if err != nil {
return Schedule{}, err
}
- return schedule, nil
+ return schedule, nil
}
// TODO: NOT TESTED, NOT FULLY IMPLEMENTED
func (bridge *Bridge) CreateSchedule(schedule Schedule) error {
- uri := fmt.Sprintf("/api/%s/schedules", bridge.Username)
- body, _, err := bridge.Post(uri, schedule)
- if err != nil {
- return err
- }
+ uri := fmt.Sprintf("/api/%s/schedules", bridge.Username)
+ body, _, err := bridge.Post(uri, schedule)
+ if err != nil {
+ return err
+ }
- fmt.Println("CREATE SCHEDULE BODY: ", string(body))
- return nil
+ fmt.Println("CREATE SCHEDULE BODY: ", string(body))
+ return nil
}
// func (schedule *Schedule) Disable() {