mirror of
https://github.com/gosticks/go-hue-interface.git
synced 2025-10-16 11:45:35 +00:00
update
This commit is contained in:
parent
11eb5f4e93
commit
b821e59869
22
config.go
22
config.go
@ -1,11 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config hue api config
|
// Config hue api config
|
||||||
@ -19,19 +17,19 @@ type Config struct {
|
|||||||
// TODO: Rename if this will be placed in a seperate package
|
// TODO: Rename if this will be placed in a seperate package
|
||||||
// ReadConfig ...
|
// ReadConfig ...
|
||||||
func ReadConfig(path string) (conf *Config, err error) {
|
func ReadConfig(path string) (conf *Config, err error) {
|
||||||
f, err := ioutil.ReadFile(path)
|
f, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = yaml.Unmarshal(f, conf)
|
err = yaml.Unmarshal(f, conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check wether a user is already created and if not create one.
|
// TODO: check wether a user is already created and if not create one.
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) WriteConfig(path string) (err error) {
|
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)
|
err = ioutil.WriteFile(path, b, 0644)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
18
lights.go
18
lights.go
@ -1,5 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
// Light hue object
|
// Light hue object
|
||||||
type Light struct {
|
type Light struct {
|
||||||
State *LightState `json:"state"`
|
State *LightState `json:"state"`
|
||||||
@ -21,3 +23,19 @@ type LightState struct {
|
|||||||
ColorMode string `json:"colormode"`
|
ColorMode string `json:"colormode"`
|
||||||
Reachable bool `json:"reachable"`
|
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)
|
||||||
|
}
|
||||||
|
|||||||
2
main.go
2
main.go
@ -20,7 +20,7 @@ func main() {
|
|||||||
fmt.Println("Created bridge ", bridge)
|
fmt.Println("Created bridge ", bridge)
|
||||||
|
|
||||||
test := &BridgeState{}
|
test := &BridgeState{}
|
||||||
errCom := bridge.getFromBridge("", test)
|
errCom := bridge.ToggleLight("2", true)
|
||||||
if errCom != nil {
|
if errCom != nil {
|
||||||
fmt.Println("[ERROR]" + errCom.Error())
|
fmt.Println("[ERROR]" + errCom.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
6
state.go
6
state.go
@ -1,7 +1,5 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
// ~ Interfaces & Types
|
// ~ Interfaces & Types
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
@ -10,10 +8,6 @@ type BridgeState struct {
|
|||||||
Lights map[string]*Light `json:"lights"`
|
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 {
|
func (bs *BridgeState) String() string {
|
||||||
str := ""
|
str := ""
|
||||||
for k, l := range bs.Lights {
|
for k, l := range bs.Lights {
|
||||||
|
|||||||
6
user.go
6
user.go
@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"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.
|
// 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) {
|
func CreateUser(addr string) (name, key string, succ bool) {
|
||||||
|
return "", "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove these comments
|
// TODO: remove these comments
|
||||||
@ -41,4 +41,4 @@ func CreateUserExtended(addr, application, deviceName string) (u *User, err erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user