add function for getting bridge config

This commit is contained in:
Wlad Meixner 2019-02-09 17:37:48 +01:00
parent 2bacde12f2
commit 4fbc421fc2
2 changed files with 22 additions and 2 deletions

View File

@ -13,6 +13,17 @@ type Bridge struct {
Config *Config
}
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"`
}
// NewBridge creates a new bridge api instance
func NewBridge(conf *Config) *Bridge {
return &Bridge{
@ -56,7 +67,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

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 := &BridgeUserConfig{}
errCom := bridge.getFromBridge("/config", test)
if errCom != nil {
fmt.Println("[ERROR]" + errCom.Error())
}
fmt.Println(test)
}