This commit is contained in:
Your Name 2019-02-09 17:59:51 +01:00
commit 132db97552
4 changed files with 79 additions and 6 deletions

View File

@ -8,11 +8,31 @@ import (
"net/http"
)
// -------------------------------------------------------------
// Interfaces
// -------------------------------------------------------------
// Bridge is the hue bridge interface
type Bridge struct {
Config *Config
}
// BridgeUserConfig is the config provided for hue for a user
type BridgeUserConfig struct {
Name string `json:"name"`
APIVersion string `json:"apiversion"`
IPAddress string `json:"ipaddress"`
MAC string `json:"mac"`
BridgeID string `json:"bridgeid"`
DataStoreVersion string `json:"datastoreversion"`
StarterKitID string `json:"starterkitid"`
ReplacesBridgeID string `json:"replacesbridgeid"`
}
// -------------------------------------------------------------
// Methods
// -------------------------------------------------------------
// NewBridge creates a new bridge api instance
func NewBridge(conf *Config) *Bridge {
return &Bridge{
@ -56,7 +76,7 @@ func (b *Bridge) getFromBridge(endpoint string, target interface{}) error {
}
if res.StatusCode != http.StatusOK {
return errors.New("Mite responded with error" + res.Status + fmt.Sprint(res.StatusCode))
return errors.New("Hue responded with error" + res.Status + fmt.Sprint(res.StatusCode))
}
// Unmarshal data

View File

@ -10,10 +10,10 @@ import (
// Config hue api config
type Config struct {
Username string `yaml:name`
Password string `yaml:userpassword`
BridgeAddr string `yaml:bridgeAddress`
BridgeAddrScheme string `yaml:bridgeAddressScheme`
Username string `yaml:"name"`
Password string `yaml:"userpassword"`
BridgeAddr string `yaml:"bridgeAddress"`
BridgeAddrScheme string `yaml:"bridgeAddressScheme"`
}
// TODO: Rename if this will be placed in a seperate package

11
main.go
View File

@ -10,10 +10,19 @@ func main() {
fmt.Printf("go-hue-interface v. %s \n", VERSION)
config := &Config{
Username: "nX1ye7AMQoQswiiJdxyw-92-RNhIwicXiQRg7AtF",
Username: "nX1ye7AMQoQswiiJdxyw-92-RNhIwicXiQRg7AtF",
BridgeAddr: "192.168.178.46",
BridgeAddrScheme: "http",
}
bridge := NewBridge(config)
fmt.Println("Created bridge ", bridge)
test := &BridgeState{}
errCom := bridge.getFromBridge("", test)
if errCom != nil {
fmt.Println("[ERROR]" + errCom.Error())
}
fmt.Println(test)
}

44
state.go Normal file
View File

@ -0,0 +1,44 @@
package main
import "fmt"
// -------------------------------------------------------------
// ~ Interfaces & Types
// -------------------------------------------------------------
type BridgeState struct {
Lights map[string]*Light `json:"lights"`
}
type Light struct {
State *LightState `json:"state"`
Type string `json:"type"`
Name string `json:"name"`
ModelID string `json:"modelid"`
SwVersion string `json:"swversion"`
}
type LightState struct {
On bool `json:"on"`
BridgeID int `json:"bridgeid"`
Hue int `json:"hue"`
XY []int `json:"xy"`
Ct int `json:"ct"`
Alert string `json:"alert"`
Effect string `json:"effect"`
ColorMode string `json:"colormode"`
Reachable bool `json:"reachable"`
}
func (l *Light) String() string {
return fmt.Sprintf("Name=\"%s\" Model=\"%s\" On=\"%x\" \n", l.Name, l.ModelID, l.State.On)
}
func (bs *BridgeState) String() string {
str := ""
for k, l := range bs.Lights {
str += k + ": " + l.String()
}
return str
}