Use api.ErrTimeout only for retryable device communication

This commit is contained in:
andig 2022-06-05 16:02:18 +02:00
parent e97e66a60c
commit ff1cd4150e
5 changed files with 9 additions and 7 deletions

View file

@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"net/http"
"os"
"strconv"
"sync"
"time"
@ -160,7 +161,7 @@ func NewEasee(user, password, charger string) (*Easee, error) {
select {
case <-done:
case <-time.After(request.Timeout):
err = api.ErrTimeout
err = os.ErrDeadlineExceeded
}
return c, err

View file

@ -74,7 +74,7 @@ func (d *dumper) Dump(name string, v interface{}) {
for err = api.ErrMustRetry; err != nil && errors.Is(err, api.ErrMustRetry); {
if soc, err = v.SoC(); err != nil {
if time.Since(start) > time.Minute {
err = api.ErrTimeout
err = os.ErrDeadlineExceeded
} else {
fmt.Fprint(w, ".")
time.Sleep(3 * time.Second)

View file

@ -88,7 +88,7 @@ func main() {
for err = api.ErrMustRetry; err != nil && matchesError(err, api.ErrMustRetry); {
if soc, err = v.SoC(); err != nil {
if time.Since(start) > time.Minute {
err = api.ErrTimeout
err = os.ErrDeadlineExceeded
} else {
time.Sleep(5 * time.Second)
}

View file

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net"
"os"
"strconv"
"strings"
"sync"
@ -104,7 +105,7 @@ func NewDsmr(uri, energy string, timeout time.Duration) (api.Meter, error) {
select {
case <-done:
case <-time.NewTimer(timeout).C:
return nil, api.ErrTimeout
return nil, os.ErrDeadlineExceeded
}
// decorate energy reading
@ -219,7 +220,7 @@ func (m *Dsmr) get(id string) (float64, error) {
defer m.mu.Unlock()
if time.Since(m.updated) > m.timeout {
return 0, api.ErrTimeout
return 0, os.ErrDeadlineExceeded
}
res, ok := m.frame.Objects[id]

View file

@ -4,12 +4,12 @@ import (
"crypto/tls"
"fmt"
"math/rand"
"os"
"strings"
"sync"
"time"
paho "github.com/eclipse/paho.mqtt.golang"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/util"
)
@ -129,7 +129,7 @@ func (m *Client) Publish(topic string, retained bool, payload interface{}) error
if token.WaitTimeout(publishTimeout) {
return token.Error()
}
return api.ErrTimeout
return os.ErrDeadlineExceeded
}
// Listen validates uniqueness and registers and attaches listener