mirror of
https://github.com/gosticks/go-hue-interface.git
synced 2025-10-16 11:45:35 +00:00
Merge branch 'master' of https://github.com/gosticks/go-hue-interface
This commit is contained in:
commit
132db97552
22
bridge.go
22
bridge.go
@ -8,11 +8,31 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// -------------------------------------------------------------
|
||||||
|
// Interfaces
|
||||||
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
// Bridge is the hue bridge interface
|
// Bridge is the hue bridge interface
|
||||||
type Bridge struct {
|
type Bridge struct {
|
||||||
Config *Config
|
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
|
// NewBridge creates a new bridge api instance
|
||||||
func NewBridge(conf *Config) *Bridge {
|
func NewBridge(conf *Config) *Bridge {
|
||||||
return &Bridge{
|
return &Bridge{
|
||||||
@ -56,7 +76,7 @@ func (b *Bridge) getFromBridge(endpoint string, target interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode != http.StatusOK {
|
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
|
// Unmarshal data
|
||||||
|
|||||||
@ -10,10 +10,10 @@ import (
|
|||||||
|
|
||||||
// Config hue api config
|
// Config hue api config
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Username string `yaml:name`
|
Username string `yaml:"name"`
|
||||||
Password string `yaml:userpassword`
|
Password string `yaml:"userpassword"`
|
||||||
BridgeAddr string `yaml:bridgeAddress`
|
BridgeAddr string `yaml:"bridgeAddress"`
|
||||||
BridgeAddrScheme string `yaml:bridgeAddressScheme`
|
BridgeAddrScheme string `yaml:"bridgeAddressScheme"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Rename if this will be placed in a seperate package
|
// TODO: Rename if this will be placed in a seperate package
|
||||||
|
|||||||
11
main.go
11
main.go
@ -10,10 +10,19 @@ func main() {
|
|||||||
fmt.Printf("go-hue-interface v. %s \n", VERSION)
|
fmt.Printf("go-hue-interface v. %s \n", VERSION)
|
||||||
|
|
||||||
config := &Config{
|
config := &Config{
|
||||||
Username: "nX1ye7AMQoQswiiJdxyw-92-RNhIwicXiQRg7AtF",
|
Username: "nX1ye7AMQoQswiiJdxyw-92-RNhIwicXiQRg7AtF",
|
||||||
|
BridgeAddr: "192.168.178.46",
|
||||||
|
BridgeAddrScheme: "http",
|
||||||
}
|
}
|
||||||
|
|
||||||
bridge := NewBridge(config)
|
bridge := NewBridge(config)
|
||||||
|
|
||||||
fmt.Println("Created bridge ", bridge)
|
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
44
state.go
Normal 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
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user