From 26f79c4be5f402afafa8967c192912cfa50b02a7 Mon Sep 17 00:00:00 2001 From: spasdev Date: Tue, 3 Feb 2026 22:28:47 +0100 Subject: [PATCH] Groupe-e: migrate api (#27196) --- tariff/groupe-e.go | 87 ----------------------- templates/definition/tariff/groupe-e.yaml | 13 +++- 2 files changed, 12 insertions(+), 88 deletions(-) delete mode 100644 tariff/groupe-e.go diff --git a/tariff/groupe-e.go b/tariff/groupe-e.go deleted file mode 100644 index 246568ec9..000000000 --- a/tariff/groupe-e.go +++ /dev/null @@ -1,87 +0,0 @@ -package tariff - -import ( - "fmt" - "slices" - "sync" - "time" - - "github.com/cenkalti/backoff/v4" - "github.com/evcc-io/evcc/api" - "github.com/evcc-io/evcc/util" - "github.com/evcc-io/evcc/util/request" -) - -type GroupeE struct { - *embed - log *util.Logger - data *util.Monitor[api.Rates] -} - -var _ api.Tariff = (*GroupeE)(nil) - -func init() { - registry.Add("groupe-e", NewGroupeEFromConfig) -} - -func NewGroupeEFromConfig(other map[string]any) (api.Tariff, error) { - t := &GroupeE{ - log: util.NewLogger("groupe-e"), - data: util.NewMonitor[api.Rates](2 * time.Hour), - } - - return runOrError(t) -} - -func (t *GroupeE) run(done chan error) { - var once sync.Once - - client := request.NewHelper(t.log) - - for tick := time.Tick(time.Hour); ; <-tick { - var res []struct { - StartTimestamp time.Time `json:"start_timestamp"` - EndTimestamp time.Time `json:"end_timestamp"` - VarioPlus float64 `json:"vario_plus"` - } - - start := time.Now().Truncate(time.Hour) - uri := fmt.Sprintf("https://api.tariffs.groupe-e.ch/v1/tariffs?start_timestamp=%s&end_timestamp=%s", start.Format(time.RFC3339), start.Add(48*time.Hour).Format(time.RFC3339)) - - if err := backoff.Retry(func() error { - return backoffPermanentError(client.GetJSON(uri, &res)) - }, bo()); err != nil { - once.Do(func() { done <- err }) - - t.log.ERROR.Println(err) - continue - } - - data := make(api.Rates, 0, len(res)) - for _, r := range res { - ar := api.Rate{ - Start: r.StartTimestamp.Local(), - End: r.EndTimestamp.Local(), - Value: r.VarioPlus / 1e2, // Rp/kWh - } - data = append(data, ar) - } - - mergeRates(t.data, data) - once.Do(func() { close(done) }) - } -} - -// Rates implements the api.Tariff interface -func (t *GroupeE) Rates() (api.Rates, error) { - var res api.Rates - err := t.data.GetFunc(func(val api.Rates) { - res = slices.Clone(val) - }) - return res, err -} - -// Type implements the api.Tariff interface -func (t *GroupeE) Type() api.TariffType { - return api.TariffTypePriceForecast -} diff --git a/templates/definition/tariff/groupe-e.yaml b/templates/definition/tariff/groupe-e.yaml index 22ffda056..7c9bf1eda 100644 --- a/templates/definition/tariff/groupe-e.yaml +++ b/templates/definition/tariff/groupe-e.yaml @@ -10,5 +10,16 @@ countries: ["CH"] params: - preset: tariff-base render: | - type: groupe-e + type: custom {{ include "tariff-base" . }} + forecast: + source: http + uri: https://api.tariffs.groupe-e.ch/v2/tariffs?start_timestamp={{ `{{ now.UTC | mustDateModify "-1h" | date "2006-01-02T15" }}` }}:00:00Z&end_timestamp={{ `{{ addDate now.UTC 0 0 2 | date "2006-01-02T15" }}` }}:00:00Z + jq: | + [.prices[] | + { + start: (.start_timestamp), + end: (.end_timestamp), + value: (.integrated[] | select(.unit == "CHF_kWh") | .value) + } + ] | tostring