mirror of
https://github.com/gosticks/go-hue-interface.git
synced 2025-10-16 11:45:35 +00:00
update light monitor
This commit is contained in:
parent
75f76db202
commit
dffa697345
58
monitor/monitor_test.go
Normal file
58
monitor/monitor_test.go
Normal file
@ -0,0 +1,58 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gosticks/go-hue-interface"
|
||||
)
|
||||
|
||||
func TestLightMonitor(t *testing.T) {
|
||||
userID, okUser := os.LookupEnv("HUE_BRIDGE_USER")
|
||||
addr, okAddr := os.LookupEnv("HUE_BRIDGE_ADDR")
|
||||
if !okAddr || !okUser {
|
||||
fmt.Println("HUE_BRIDGE_USER and HUE_BRIDGE_ADDR must be set in env for this test to work")
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
conf := &hue.Config{
|
||||
Username: userID,
|
||||
BridgeAddr: addr,
|
||||
BridgeAddrScheme: "http",
|
||||
}
|
||||
b := hue.NewBridge(conf)
|
||||
|
||||
m := NewMonitor(b, 1*time.Second)
|
||||
|
||||
// Get first available light
|
||||
ls, lsErr := b.GetLights()
|
||||
if lsErr != nil {
|
||||
t.Fail()
|
||||
return
|
||||
}
|
||||
|
||||
// get any light
|
||||
var (
|
||||
light *hue.Light
|
||||
id string
|
||||
)
|
||||
for k, l := range ls {
|
||||
if light != nil {
|
||||
break
|
||||
}
|
||||
light = l
|
||||
id = k
|
||||
}
|
||||
|
||||
fmt.Println("Adding listener to light: ", light)
|
||||
|
||||
m.AddListener(id, Light, func(s interface{}) {
|
||||
fmt.Println("State changed: ", s.(*hue.LightState))
|
||||
})
|
||||
|
||||
m.Start()
|
||||
|
||||
select {}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user