diff --git a/main.go b/main.go index 490059727..60f47f195 100644 --- a/main.go +++ b/main.go @@ -12,10 +12,10 @@ import ( ) var ( - //go:embed dist + // go:embed dist web embed.FS - //go:embed i18n/*.toml + // go:embed i18n/*.toml i18n embed.FS ) diff --git a/provider/http.go b/provider/http.go index 5a4dc0b1e..a8c1a190f 100644 --- a/provider/http.go +++ b/provider/http.go @@ -6,8 +6,10 @@ import ( "math" "strconv" "strings" + "text/template" "time" + "github.com/42atomys/sprout" "github.com/evcc-io/evcc/provider/pipeline" "github.com/evcc-io/evcc/util" "github.com/evcc-io/evcc/util/request" @@ -162,8 +164,18 @@ func (p *HTTP) request(url string, body ...string) ([]byte, error) { b = strings.NewReader(body[0]) } + tmpl, err := template.New("url").Funcs(sprout.TxtFuncMap()).Parse(url) + if err != nil { + return nil, err + } + + builder := new(strings.Builder) + if err := tmpl.Execute(builder, nil); err != nil { + return nil, err + } + // empty method becomes GET - req, err := request.New(strings.ToUpper(p.method), url, b, p.headers) + req, err := request.New(strings.ToUpper(p.method), builder.String(), b, p.headers) if err != nil { return []byte{}, err } diff --git a/templates/definition/tariff/energy-charts-api.yaml b/templates/definition/tariff/energy-charts-api.yaml new file mode 100644 index 000000000..0935da2d4 --- /dev/null +++ b/templates/definition/tariff/energy-charts-api.yaml @@ -0,0 +1,41 @@ +template: energy-charts-api +products: + - brand: Fraunhofer ISE + description: + de: "Day-ahead Energiepreise (je kWh) an der Börse. Kann ohne vorherige Anmeldung auf https://api.energy-charts.info/ abgerufen werden. Nutzbar u.a. für dynamische Stromtarife, wo der Anbieter bis dato auf der Kundenschnittstelle noch kein Preis-Vorhersagen anbietet." + en: "Day-ahead forecast of energy prices (per kWh) on the exchange. No prior registration for https://api.energy-charts.info/ necessary. Can be used for dynamic electricity tariffs, for example, where the supplier does not yet offer a price forecast on the customer interface." +params: + - name: bzn + type: string + required: true + validvalues: + [ + "AT", + "BE", + "CH", + "CZ", + "DE-LU", + "DE-AT-LU", + "DK1", + "DK2", + "FR", + "HU", + "IT-NORTH", + "NL", + "NO2", + "PL", + "SE4", + "SI", + ] + default: DE-LU + description: + de: "Gebotszonen - https://api.energy-charts.info/#/prices/day_ahead_price_price_get" + en: "Bidding zones - https://api.energy-charts.info/#/prices/day_ahead_price_price_get" + - preset: tariff-base +render: | + type: custom + {{ include "tariff-base" . }} + forecast: + source: http + uri: https://api.energy-charts.info/price?bzn={{ .bzn }}&end={{ now | dateModify "+24h" | date "2006-01-02" }} + jq: '[.unix_seconds, .price] | transpose | map({ "start": (.[0] | todate), "end": ((.[0]+3600) | todate), "price": (.[1]/1000)}) | tostring'