Skip to content

Commit

Permalink
chore: use time.Tick
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Mar 21, 2023
1 parent b69b3ca commit 091190e
Show file tree
Hide file tree
Showing 17 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion charger/abb.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func NewABB(uri, device, comset string, baudrate int, proto modbus.Protocol, sla

// keep-alive
go func() {
for range time.NewTicker(30 * time.Second).C {
for range time.Tick(30 * time.Second) {
_, _ = wb.status()
}
}()
Expand Down
2 changes: 1 addition & 1 deletion charger/alfen.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func NewAlfen(uri string, slaveID uint8) (api.Charger, error) {
}

func (wb *Alfen) heartbeat() {
for range time.NewTicker(25 * time.Second).C {
for range time.Tick(25 * time.Second) {
wb.mu.Lock()
var curr float64
if wb.enabled {
Expand Down
2 changes: 1 addition & 1 deletion charger/dadapower.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func NewDadapower(uri string, id uint8) (*Dadapower, error) {
}

func (wb *Dadapower) heartbeat() {
for range time.NewTicker(time.Minute).C {
for range time.Tick(time.Minute) {
if _, err := wb.conn.ReadInputRegisters(dadapowerRegFailsafeTimeout, 1); err != nil {
wb.log.ERROR.Println("heartbeat:", err)
}
Expand Down
2 changes: 1 addition & 1 deletion charger/daheimladen-mb.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewDaheimLadenMB(uri string, id uint8) (api.Charger, error) {
}

func (wb *DaheimLadenMB) heartbeat(timeout time.Duration) {
for range time.NewTicker(timeout).C {
for range time.Tick(timeout) {
if _, err := wb.conn.ReadHoldingRegisters(dlRegSafeCurrent, 1); err != nil {
wb.log.ERROR.Println("heartbeat:", err)
}
Expand Down
2 changes: 1 addition & 1 deletion charger/hardybarth-salia.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func NewSalia(uri string, cache time.Duration) (api.Charger, error) {
}

func (wb *Salia) heartbeat() {
for ; true; <-time.NewTicker(30 * time.Second).C {
for ; true; <-time.Tick(30 * time.Second) {
if err := wb.post(salia.HeartBeat, "alive"); err != nil {
wb.log.ERROR.Println("heartbeat:", err)
}
Expand Down
2 changes: 1 addition & 1 deletion charger/ocpp/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (cp *CP) Status() (api.ChargeStatus, error) {
// WatchDog triggers meter values messages if older than timeout.
// Must be wrapped in a goroutine.
func (cp *CP) WatchDog(timeout time.Duration) {
for ; true; <-time.NewTicker(timeout).C {
for ; true; <-time.Tick(timeout) {
cp.mu.Lock()
update := cp.txnId != 0 && cp.clock.Since(cp.meterUpdated) > timeout
cp.mu.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion charger/openwb-pro.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewOpenWBPro(uri string, cache time.Duration) (*OpenWBPro, error) {
}

func (wb *OpenWBPro) heartbeat(log *util.Logger) {
for range time.NewTicker(30 * time.Second).C {
for range time.Tick(30 * time.Second) {
if _, err := wb.get(); err != nil {
log.ERROR.Printf("heartbeat: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion charger/openwb.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func NewOpenWB(log *util.Logger, mqttconf mqtt.Config, id int, topic string, p1p
heartbeatS := provider.NewMqtt(log, client, fmt.Sprintf("%s/set/isss/%s", topic, openwb.SlaveHeartbeatTopic),
timeout).WithRetained().IntSetter("heartbeat")

for range time.NewTicker(openwb.HeartbeatInterval).C {
for range time.Tick(openwb.HeartbeatInterval) {
if err := heartbeatS(1); err != nil {
log.ERROR.Printf("heartbeat: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion charger/vestel.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func NewVestel(uri string, id uint8) (*Vestel, error) {
}

func (wb *Vestel) heartbeat() {
for range time.NewTicker(time.Second * 3).C {
for range time.Tick(time.Second * 3) {
if _, err := wb.conn.WriteSingleRegister(vestelRegAlive, 1); err != nil {
wb.log.ERROR.Println("heartbeat:", err)
}
Expand Down
2 changes: 1 addition & 1 deletion charger/webasto-next.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func NewWebastoNext(uri string, id uint8) (api.Charger, error) {
}

func (wb *WebastoNext) heartbeat(timeout time.Duration) {
for range time.NewTicker(timeout).C {
for range time.Tick(timeout) {
if _, err := wb.conn.WriteSingleRegister(tqRegLifeBit, 1); err != nil {
wb.log.ERROR.Println("heartbeat:", err)
}
Expand Down
2 changes: 1 addition & 1 deletion provider/sma/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Device struct {
func (d *Device) StartUpdateLoop() {
d.once.Do(func() {
go func() {
for range time.NewTicker(time.Second * 5).C {
for range time.Tick(time.Second * 5) {
if err := d.UpdateValues(); err != nil {
d.log.ERROR.Println(err)
}
Expand Down
2 changes: 1 addition & 1 deletion server/updater/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (u *watch) Send(key string, val interface{}) {
}

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

for ; true; <-time.NewTicker(time.Hour).C {
for ; true; <-time.Tick(time.Hour) {
var res awattar.Prices
if err := client.GetJSON(t.uri, &res); err != nil {
once.Do(func() { done <- err })
Expand Down
2 changes: 1 addition & 1 deletion tariff/electricitymaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (t *ElectricityMaps) run(done chan error) {
var once sync.Once
uri := fmt.Sprintf("%s/carbon-intensity/forecast?zone=%s", t.uri, t.zone)

for ; true; <-time.NewTicker(time.Hour).C {
for ; true; <-time.Tick(time.Hour) {
var res CarbonIntensity
if err := t.GetJSON(uri, &res); err != nil {
if res.Error != "" {
Expand Down
2 changes: 1 addition & 1 deletion tariff/gruenstromindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (t *GrünStromIndex) run(done chan error) {
var once sync.Once
uri := fmt.Sprintf("https://api.corrently.io/v2.0/gsi/prediction?zip=%s", t.zip)

for ; true; <-time.NewTicker(time.Hour).C {
for ; true; <-time.Tick(time.Hour) {
var res gsiForecast
err := t.GetJSON(uri, &res)
if err == nil && res.Err {
Expand Down
2 changes: 1 addition & 1 deletion tariff/octopus.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (t *Octopus) run(done chan error) {
var once sync.Once
client := request.NewHelper(t.log)

for ; true; <-time.NewTicker(time.Hour).C {
for ; true; <-time.Tick(time.Hour) {
var res octopus.UnitRates
if err := client.GetJSON(t.uri, &res); err != nil {
once.Do(func() { done <- err })
Expand Down
2 changes: 1 addition & 1 deletion tariff/tibber.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (t *Tibber) run(done chan error) {
"id": graphql.ID(t.homeID),
}

for ; true; <-time.NewTicker(time.Hour).C {
for ; true; <-time.Tick(time.Hour) {
ctx, cancel := context.WithTimeout(context.Background(), request.Timeout)
err := t.client.Query(ctx, &res, v)
cancel()
Expand Down

0 comments on commit 091190e

Please sign in to comment.