@@ -6,14 +6,14 @@ import (
6
6
"sync"
7
7
"time"
8
8
9
+ "github.com/cenkalti/backoff/v4"
9
10
"github.com/evcc-io/evcc/api"
10
11
"github.com/evcc-io/evcc/util"
11
12
"github.com/evcc-io/evcc/util/request"
12
13
"golang.org/x/exp/slices"
13
14
)
14
15
15
16
type GrünStromIndex struct {
16
- * request.Helper
17
17
log * util.Logger
18
18
mux sync.Mutex
19
19
zip string
@@ -76,9 +76,8 @@ func NewGrünStromIndexFromConfig(other map[string]interface{}) (api.Tariff, err
76
76
log := util .NewLogger ("gsi" ).Redact (cc .Zip )
77
77
78
78
t := & GrünStromIndex {
79
- log : log ,
80
- Helper : request .NewHelper (log ),
81
- zip : cc .Zip ,
79
+ log : log ,
80
+ zip : cc .Zip ,
82
81
}
83
82
84
83
done := make (chan error )
@@ -90,11 +89,17 @@ func NewGrünStromIndexFromConfig(other map[string]interface{}) (api.Tariff, err
90
89
91
90
func (t * GrünStromIndex ) run (done chan error ) {
92
91
var once sync.Once
92
+ client := request .NewHelper (t .log )
93
+ bo := newBackoff ()
93
94
uri := fmt .Sprintf ("https://api.corrently.io/v2.0/gsi/prediction?zip=%s" , t .zip )
94
95
95
96
for ; true ; <- time .Tick (time .Hour ) {
96
97
var res gsiForecast
97
- err := t .GetJSON (uri , & res )
98
+
99
+ err := backoff .Retry (func () error {
100
+ return client .GetJSON (uri , & res )
101
+ }, bo )
102
+
98
103
if err == nil && res .Err {
99
104
if s , ok := res .Message .(string ); ok {
100
105
err = errors .New (s )
@@ -135,7 +140,7 @@ func (t *GrünStromIndex) Rates() (api.Rates, error) {
135
140
return slices .Clone (t .data ), outdatedError (t .updated , time .Hour )
136
141
}
137
142
138
- // Type returns the tariff type
143
+ // Type implements the api.Tariff interface
139
144
func (t * GrünStromIndex ) Type () api.TariffType {
140
145
return api .TariffTypeCo2
141
146
}
0 commit comments