aboutsummaryrefslogtreecommitdiff
path: root/lights.go
diff options
context:
space:
mode:
authorCollin Guarino <collin.guarino@gmail.com>2016-01-24 13:23:07 -0500
committerCollin Guarino <collin.guarino@gmail.com>2016-01-24 13:23:07 -0500
commitc05519e646091a1791aa278f468962407e691bc3 (patch)
tree0da788816c8bfe3a4dbae2a092f523bed5b08f7d /lights.go
parent5c2673de469cd9b812431ee4dc7093f141ab202d (diff)
Rough implementation for GetAllLights.
Diffstat (limited to 'lights.go')
-rw-r--r--lights.go66
1 files changed, 49 insertions, 17 deletions
diff --git a/lights.go b/lights.go
index b64eaed..eea2daf 100644
--- a/lights.go
+++ b/lights.go
@@ -2,29 +2,61 @@ package main
import (
"log"
+ "fmt"
+ "os"
+ "net/http"
+ "io/ioutil"
+ "encoding/json"
)
type Light struct {
State struct {
- On bool
- Bri int
- hue int
- sat int
- effect string // TODO: what is this?
- xy []string // TODO: what is this?
- ct int // TODO: what is this?
- alert string
- colormode string
- reachable bool
+ On bool `json:"on"`
+ Bri int `json:"bri"`
+ hue int `json:"hue"`
+ sat int `json:"sat"`
+ effect string `json:"effect"`
+ xy []string `json:"xy"` // TODO: what is this?
+ ct int `json:"ct"` // TODO: what is this?
+ alert string `json:"alert"`
+ colormode string `json:"colormode"`
+ reachable bool `json:"reachable"`
}
- Type string
- Name string
- ModelID string
- ManufacturerName string
- UniqueID string
- SWVersion string // TODO: what is this?
+ Type string `json:"type"`
+ Name string `json:"name"`
+ ModelID string `json:"modelid"`
+ ManufacturerName string `json:"manufacturername"`
+ UniqueID string `json:"uniqueid"`
+ SWVersion string `json:"swversion"`
}
-func GetAllLights() {
+//http://192.168.1.128/api/319b36233bd2328f3e40731b23479207/lights/
+// http://<bridge_ip>/api/<username>/lights/
+func GetAllLights(bridge *Bridge) {
+ response, error := http.Get(
+ fmt.Sprintf("http://%s/api/%s/lights/", bridge.IPAddress, bridge.Username))
+ if error != nil {
+ trace("", error)
+ os.Exit(1)
+ } else if response.StatusCode != 200 {
+ trace(fmt.Sprintf("Bridge status error %d", response.StatusCode), nil)
+ os.Exit(1)
+ }
+
+ body, error := ioutil.ReadAll(response.Body)
+ defer response.Body.Close()
+ if error != nil {
+ trace("", error)
+ os.Exit(1)
+ }
+
+ data := []Light{}
+ error = json.Unmarshal(body, &data)
+ if error != nil {
+ trace("", error)
+ os.Exit(1)
+ }
+
+ log.Println(data)
} \ No newline at end of file