aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bridge.go20
-rw-r--r--bridge_test.go3
-rw-r--r--light_test.go2
3 files changed, 21 insertions, 4 deletions
diff --git a/bridge.go b/bridge.go
index 878494f..5d1ea35 100644
--- a/bridge.go
+++ b/bridge.go
@@ -177,10 +177,26 @@ func (self *Bridge) GetInfo() (BridgeInfo, error) {
return data, nil
}
-// CreateUser posts to ./api on the bridge to create a new whitelisted user.
+// Bridge.CreateUser posts to ./api on the bridge to create a new whitelisted user.
func (bridge *Bridge) CreateUser(deviceType string) error {
params := map[string]string{"devicetype": deviceType}
- _, _, err := bridge.Post("/api", params)
+ body, _, err := bridge.Post("/api", params)
+ if err != nil {
+ return err
+ }
+ content := string(body)
+ username := content[strings.LastIndex(content, ":\"")+2 :
+ strings.LastIndex(content, "\"")]
+ bridge.Username = username
+ return nil
+}
+
+// Bridge.DeleteUser will delete a user given its USER KEY, not the string name.
+// See http://www.developers.meethue.com/documentation/configuration-api
+// for description on `username` deprecation in place of the devicetype key.
+func (bridge *Bridge) DeleteUser(username string) error {
+ uri := fmt.Sprintf("/api/%s/config/whitelist/%s", bridge.Username, username)
+ err := bridge.Delete(uri)
if err != nil {
return err
}
diff --git a/bridge_test.go b/bridge_test.go
index 2100089..d750f58 100644
--- a/bridge_test.go
+++ b/bridge_test.go
@@ -13,5 +13,6 @@ import (
func TestCreateUser(t *testing.T) {
bridge, _ := NewBridge("192.168.1.128", "319b36233bd2328f3e40731b23479207")
- bridge.CreateUser("linux")
+ bridge.CreateUser("test")
+ //bridge.DeleteUser(bridge.Username)
}
diff --git a/light_test.go b/light_test.go
index 7a46889..c03b412 100644
--- a/light_test.go
+++ b/light_test.go
@@ -15,7 +15,7 @@ import (
func TestSetLightState(t *testing.T) {
fmt.Println("\nTESTING LIGHT STATE:\n\n")
- bridge, _ := NewBridge("192.168.1.128", "319b36233bd2328f3e40731b23479207")
+ bridge, _ := NewBridge("192.168.1.128", "427de8bd6d49f149c8398e4fc08f")
nameTest, _ := GetLightByName(bridge, "Desk Light") // Also tests GetAllLights
_ = nameTest
selectedLight, _ := GetLightByIndex(bridge, 7)