Skip to content

Commit

Permalink
chore: collect tickers
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Mar 17, 2024
1 parent b86fbfa commit 6fd387d
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 18 deletions.
3 changes: 2 additions & 1 deletion charger/mennekes-compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ func NewMennekesCompact(uri, device, comset string, baudrate int, proto modbus.P
}

func (wb *MennekesCompact) heartbeat(timeout time.Duration) {
for ; true; <-time.Tick(timeout) {
tick := time.NewTicker(timeout)
for ; true; <-tick.C {
if _, err := wb.conn.WriteSingleRegister(mennekesRegHeartbeat, mennekesHeartbeatToken); err != nil {
wb.log.ERROR.Println("heartbeat:", err)
}
Expand Down
3 changes: 2 additions & 1 deletion charger/ocpp/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func (conn *Connector) TriggerMessageRequest(feature remotetrigger.MessageTrigge
// WatchDog triggers meter values messages if older than timeout.
// Must be wrapped in a goroutine.
func (conn *Connector) WatchDog(timeout time.Duration) {
for ; true; <-time.Tick(timeout) {
tick := time.NewTicker(timeout)
for ; true; <-tick.C {
conn.mu.Lock()
update := conn.txnId != 0 && conn.clock.Since(conn.meterUpdated) > timeout
conn.mu.Unlock()
Expand Down
3 changes: 2 additions & 1 deletion server/updater/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func (u *watch) Send(key string, val interface{}) {
}

func (u *watch) watchReleases(installed string, out chan *github.RepositoryRelease) {
for ; true; <-time.Tick(6 * time.Hour) {
tick := time.NewTicker(6 * time.Hour)
for ; true; <-tick.C {
rel, err := u.findReleaseUpdate(installed)
if err != nil {
u.log.ERROR.Printf("version check failed: %v (installed: %s)", err, installed)
Expand Down
3 changes: 2 additions & 1 deletion tariff/amber.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func (t *Amber) run(done chan error) {
var once sync.Once
bo := newBackoff()

for ; true; <-time.Tick(time.Minute) {
tick := time.NewTicker(time.Minute)
for ; true; <-tick.C {
var res []amber.PriceInfo

if err := backoff.Retry(func() error {
Expand Down
3 changes: 2 additions & 1 deletion tariff/awattar.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func (t *Awattar) run(done chan error) {
bo := newBackoff()
client := request.NewHelper(t.log)

for ; true; <-time.Tick(time.Hour) {
tick := time.NewTicker(time.Hour)
for ; true; <-tick.C {
var res awattar.Prices

if err := backoff.Retry(func() error {
Expand Down
3 changes: 2 additions & 1 deletion tariff/edf-tempo.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func (t *EdfTempo) run(done chan error) {
var once sync.Once
bo := newBackoff()

for ; true; <-time.Tick(time.Hour) {
tick := time.NewTicker(time.Hour)
for ; true; <-tick.C {
var res struct {
Data struct {
Values []struct {
Expand Down
3 changes: 2 additions & 1 deletion tariff/electricitymaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func (t *ElectricityMaps) run(done chan error) {
bo := newBackoff()
uri := fmt.Sprintf("%s/carbon-intensity/forecast?zone=%s", t.uri, t.zone)

for ; true; <-time.Tick(time.Hour) {
tick := time.NewTicker(time.Hour)
for ; true; <-tick.C {
var res CarbonIntensity

if err := backoff.Retry(func() error {
Expand Down
3 changes: 2 additions & 1 deletion tariff/elering.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func (t *Elering) run(done chan error) {
client := request.NewHelper(t.log)
bo := newBackoff()

for ; true; <-time.Tick(time.Hour) {
tick := time.NewTicker(time.Hour)
for ; true; <-tick.C {
var res elering.NpsPrice

ts := time.Now().Truncate(time.Hour)
Expand Down
3 changes: 2 additions & 1 deletion tariff/energinet.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func (t *Energinet) run(done chan error) {
client := request.NewHelper(t.log)
bo := newBackoff()

for ; true; <-time.Tick(time.Hour) {
tick := time.NewTicker(time.Hour)
for ; true; <-tick.C {
var res energinet.Prices

ts := time.Now().Truncate(time.Hour)
Expand Down
3 changes: 2 additions & 1 deletion tariff/entsoe.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func (t *Entsoe) run(done chan error) {
bo := newBackoff()

// Data updated by ESO every half hour, but we only need data every hour to stay current.
for ; true; <-time.Tick(time.Hour) {
tick := time.NewTicker(time.Hour)
for ; true; <-tick.C {
var tr entsoe.PublicationMarketDocument

if err := backoff.Retry(func() error {
Expand Down
3 changes: 2 additions & 1 deletion tariff/groupe-e.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (t *GroupeE) run(done chan error) {
bo := newBackoff()
client := request.NewHelper(t.log)

for ; true; <-time.Tick(time.Hour) {
tick := time.NewTicker(time.Hour)
for ; true; <-tick.C {
var res []struct {
StartTimestamp time.Time `json:"start_timestamp"`
EndTimestamp time.Time `json:"end_timestamp"`
Expand Down
3 changes: 2 additions & 1 deletion tariff/gruenstromindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ func (t *GrünStromIndex) run(done chan error) {
bo := newBackoff()
uri := fmt.Sprintf("https://api.corrently.io/v2.0/gsi/prediction?zip=%s", t.zip)

for ; true; <-time.Tick(time.Hour) {
tick := time.NewTicker(time.Hour)
for ; true; <-tick.C {
var res gsiForecast

err := backoff.Retry(func() error {
Expand Down
3 changes: 2 additions & 1 deletion tariff/ngeso.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ func (t *Ngeso) run(done chan error) {
}

// Data updated by ESO every half hour, but we only need data every hour to stay current.
for ; true; <-time.Tick(time.Hour) {
tick := time.NewTicker(time.Hour)
for ; true; <-tick.C {
res, err := backoff.RetryWithData(func() (ngeso.CarbonForecastResponse, error) {
res, err := tReq.DoRequest(client)
var se request.StatusError
Expand Down
3 changes: 2 additions & 1 deletion tariff/octopus.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func (t *Octopus) run(done chan error) {
client := request.NewHelper(t.log)
bo := newBackoff()

for ; true; <-time.Tick(time.Hour) {
tick := time.NewTicker(time.Hour)
for ; true; <-tick.C {
var res octopus.UnitRates

if err := backoff.Retry(func() error {
Expand Down
5 changes: 3 additions & 2 deletions tariff/pun.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ func (t *Pun) run(done chan error) {
var once sync.Once
bo := newBackoff()

for ; true; <-time.Tick(time.Hour) {
tick := time.NewTicker(time.Hour)
for ; true; <-tick.C {
var today api.Rates
if err := backoff.Retry(func() error {
var err error
Expand Down Expand Up @@ -109,7 +110,7 @@ func (t *Pun) run(done chan error) {
continue
}

//merge today and tomorrow data
// merge today and tomorrow data
data := append(today, tomorrow...)
t.data.Set(data)

Expand Down
3 changes: 2 additions & 1 deletion tariff/smartenergy.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func (t *SmartEnergy) run(done chan error) {
client := request.NewHelper(t.log)
bo := newBackoff()

for ; true; <-time.Tick(time.Hour) {
tick := time.NewTicker(time.Hour)
for ; true; <-tick.C {
var res smartenergy.Prices

if err := backoff.Retry(func() error {
Expand Down
3 changes: 2 additions & 1 deletion tariff/tibber.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ func (t *Tibber) run(done chan error) {
"id": graphql.ID(t.homeID),
}

for ; true; <-time.Tick(time.Hour) {
tick := time.NewTicker(time.Hour)
for ; true; <-tick.C {
var res struct {
Viewer struct {
Home struct {
Expand Down

0 comments on commit 6fd387d

Please sign in to comment.