diff --git a/config.go b/config.go index 51e4ac8..9166b57 100644 --- a/config.go +++ b/config.go @@ -1,11 +1,9 @@ package main import ( - "bytes" - "fmt" - "gopkg.in/yaml.v2" "io/ioutil" - "net/http" + + "gopkg.in/yaml.v2" ) // Config hue api config @@ -19,19 +17,19 @@ type Config struct { // TODO: Rename if this will be placed in a seperate package // ReadConfig ... func ReadConfig(path string) (conf *Config, err error) { - f, err := ioutil.ReadFile(path) - if err != nil { - return + f, err := ioutil.ReadFile(path) + if err != nil { + return } - - err = yaml.Unmarshal(f, conf) - if err != nil { + + err = yaml.Unmarshal(f, conf) + if err != nil { return } // TODO: check wether a user is already created and if not create one. - return + return } func (c *Config) WriteConfig(path string) (err error) { @@ -39,4 +37,4 @@ func (c *Config) WriteConfig(path string) (err error) { err = ioutil.WriteFile(path, b, 0644) return -} \ No newline at end of file +} diff --git a/lights.go b/lights.go index 2a28c16..d071cf0 100644 --- a/lights.go +++ b/lights.go @@ -1,5 +1,7 @@ package main +import "fmt" + // Light hue object type Light struct { State *LightState `json:"state"` @@ -21,3 +23,19 @@ type LightState struct { ColorMode string `json:"colormode"` Reachable bool `json:"reachable"` } + +type cmdResponse struct { +} + +const LightsEndpoint = "/lights" + +func (l *Light) String() string { + return fmt.Sprintf("Name=\"%s\" Model=\"%s\" On=\"%x\" XY=\"%x\" \n", l.Name, l.ModelID, l.State.On, l.State.XY) +} + +func (b *Bridge) ToggleLight(id string, on bool) error { + cmd := &LightState{ + On: on, + } + return b.putToBridge(LightsEndpoint+"/"+id+"/state", cmd, nil) +} diff --git a/main.go b/main.go index 322a1cf..f525a90 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,7 @@ func main() { fmt.Println("Created bridge ", bridge) test := &BridgeState{} - errCom := bridge.getFromBridge("", test) + errCom := bridge.ToggleLight("2", true) if errCom != nil { fmt.Println("[ERROR]" + errCom.Error()) } diff --git a/state.go b/state.go index 5731d89..96fdb51 100644 --- a/state.go +++ b/state.go @@ -1,7 +1,5 @@ package main -import "fmt" - // ------------------------------------------------------------- // ~ Interfaces & Types // ------------------------------------------------------------- @@ -10,10 +8,6 @@ type BridgeState struct { Lights map[string]*Light `json:"lights"` } -func (l *Light) String() string { - return fmt.Sprintf("Name=\"%s\" Model=\"%s\" On=\"%x\" XY=\"%x\" \n", l.Name, l.ModelID, l.State.On, l.State.XY) -} - func (bs *BridgeState) String() string { str := "" for k, l := range bs.Lights { diff --git a/user.go b/user.go index 5351502..e8df735 100644 --- a/user.go +++ b/user.go @@ -1,8 +1,8 @@ package main import ( - "encoding/json" "bytes" + "encoding/json" "fmt" "net/http" ) @@ -15,7 +15,7 @@ type User struct { // CreateNewUser will create a new user. This should be called only of there's none in the yaml config. func CreateUser(addr string) (name, key string, succ bool) { - + return "", "", false } // TODO: remove these comments @@ -41,4 +41,4 @@ func CreateUserExtended(addr, application, deviceName string) (u *User, err erro } return -} \ No newline at end of file +}