From 4bf095298d3787ddbfb5223da0bbd3f533398e14 Mon Sep 17 00:00:00 2001 From: Stefan Wichmann Date: Tue, 9 Apr 2019 19:51:57 +0200 Subject: [PATCH] Wait for bridge on startup (fixes #61) --- bridge.go | 5 +++-- kelvin.go | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bridge.go b/bridge.go index ad7be16..ef01275 100644 --- a/bridge.go +++ b/bridge.go @@ -135,9 +135,10 @@ func (bridge *HueBridge) discover(ip string) error { // we have a known IP address. Validate if it points to a reachable bridge bridge.BridgeIP = ip err := bridge.validateBridge() - if err == nil { - return nil + if err != nil { + return err } + return nil } log.Debugf("⌘ Starting bridge discovery") bridges, err := hue.DiscoverBridges(false) diff --git a/kelvin.go b/kelvin.go index 4d9e1fd..af9dbf0 100644 --- a/kelvin.go +++ b/kelvin.go @@ -68,9 +68,15 @@ func main() { go startInterface() // Find Hue bridge - err = bridge.InitializeBridge(configuration) - if err != nil { - log.Warning(err) + log.Printf("🤖 Initializing bridge connection...") + for { + err = bridge.InitializeBridge(configuration) + if err != nil { + log.Errorf("Could not initialze bridge: %v - Retrying...", err) + time.Sleep(10 * time.Second) + } else { + break + } } // Find geo location