diff --git a/bridge.go b/bridge.go index 8091c28..c40964b 100644 --- a/bridge.go +++ b/bridge.go @@ -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 diff --git a/config.go b/config.go index 43120b1..51e4ac8 100644 --- a/config.go +++ b/config.go @@ -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 diff --git a/main.go b/main.go index 074a04b..322a1cf 100644 --- a/main.go +++ b/main.go @@ -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) } diff --git a/state.go b/state.go new file mode 100644 index 0000000..22df31c --- /dev/null +++ b/state.go @@ -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 +}