From 5755c3e714041281a5224d4eaa540b86ddb420af Mon Sep 17 00:00:00 2001 From: Collin Guarino Date: Sun, 14 Feb 2016 22:54:26 -0500 Subject: Added base functions and struct for groups. --- group.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ group_test.go | 21 +++++++++++++++++++++ schedule.go | 2 +- 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 group.go create mode 100644 group_test.go diff --git a/group.go b/group.go new file mode 100644 index 0000000..0ebdcb5 --- /dev/null +++ b/group.go @@ -0,0 +1,51 @@ +/* +* group.go +* 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 +*/ + +package hue + +import ( + "fmt" + "encoding/json" +) + +type Group struct { + Action struct { + Alert string `json:"alert"` + Bri int `json:"bri"` + Colormode string `json:"colormode"` + Ct int `json:"ct"` + Effect string `json:"effect"` + Hue int `json:"hue"` + On bool `json:"on"` + Sat int `json:"sat"` + Xy []float64 `json:"xy"` + } `json:"action"` + Lights []string `json:"lights"` + Name string `json:"name"` + Type string `json:"type"` +} + +// Bridge.GetGroups get the attributes for each group of lights. +// TODO: NOT TESTED, NOT FULLY IMPLEMENTED +func (bridge *Bridge) GetGroups() ([]Group, error) { + uri := fmt.Sprintf("/api/%s/groups", bridge.Username) + body, _, err := bridge.Get(uri) + if err != nil { + return []Group{}, err + } + + fmt.Println("GROUP GET: ", string(body)) + + groups := map[string]Group{} + err = json.Unmarshal(body, &groups) + if err != nil { + return []Group{}, err + } + fmt.Println("GROUPS: ", groups) + + return []Group{}, nil +} diff --git a/group_test.go b/group_test.go new file mode 100644 index 0000000..8fcbd09 --- /dev/null +++ b/group_test.go @@ -0,0 +1,21 @@ +/* +* group_test.go +* 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 +*/ + +package hue + +import ( + "testing" + "fmt" +) + +func TestGetGroups(t *testing.T) { + bridge, _ := NewBridge("192.168.1.128", "427de8bd6d49f149c8398e4fc08f") + groups, _ := bridge.GetGroups() + for group := range groups { + fmt.Println(groups[group]) + } +} diff --git a/schedule.go b/schedule.go index ce139e8..c586e1d 100644 --- a/schedule.go +++ b/schedule.go @@ -74,6 +74,7 @@ func (bridge *Bridge) GetSchedule(id string) (Schedule, error) { 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) @@ -82,7 +83,6 @@ func (bridge *Bridge) CreateSchedule(schedule Schedule) error { } fmt.Println("CREATE SCHEDULE BODY: ", string(body)) - // TODO: Not tested or fully implemented return nil } -- cgit v1.2.3