Skip to content
This repository has been archived by the owner on Jan 9, 2021. It is now read-only.

Commit

Permalink
Rewrote the error logging and retrying in the hue job to something mo…
Browse files Browse the repository at this point in the history
…re clear and stable.
  • Loading branch information
mikeflynn committed Oct 4, 2015
1 parent ee856a2 commit 78c5b78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 2 additions & 5 deletions hue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"log"
"net/http"
"strings"
)
Expand Down Expand Up @@ -123,18 +123,15 @@ func HueSetLight(id string, options HueLightState) error {

resp, err := client.Do(req)
if err != nil {
log.Printf("HUE ERROR: %v", err.Error())
return err
}

defer resp.Body.Close()

contents, _ := ioutil.ReadAll(resp.Body)

log.Printf("HUE RESP: %v", string(contents))

if strings.Contains(string(contents), "error") {
HueSetLight(id, options)
return errors.New(string(contents))
}

return nil
Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ func ToggleWorkshopLights() {
toggle = false
}

go HueSetLight(k, HueLightState{On: toggle, Bri: 200})
go func(idx string) {
for i := 0; i < 3; i++ {
err := HueSetLight(idx, HueLightState{On: toggle, Bri: 200})
if err != nil {
log.Printf("HUE ERROR: %v", err.Error())
} else {
break
}
}
}(k)
}
}
}

0 comments on commit 78c5b78

Please sign in to comment.