evcc-io/tariff/octopus/api.go
duck 0a3838904a
Add tariff provider for Octopus Energy (#5799)
Adds a rudimentary provider for the British energy supplier, Octopus Energy. Supplying the tariff code and region code is mandatory.

Supports both time-of-use (Agile, Go, etc) and fixed-rate tariffs.

A full list of tariff codes are available at https://api.octopus.energy/v1/products/ - more details on the API used at https://developer.octopus.energy/docs/api/
2023-01-17 10:50:02 +01:00

35 lines
1.1 KiB
Go

package octopus
import (
"fmt"
"strings"
"time"
)
// ProductURI defines the location of the tariff information page. Substitute %s with tariff name.
const ProductURI = "https://api.octopus.energy/v1/products/%s/"
// RatesURI defines the location of the full tariff rates page, including speculation.
// Substitute first %s with tariff name, second with region code.
const RatesURI = ProductURI + "electricity-tariffs/E-1R-%s-%s/standard-unit-rates/"
// ConstructRatesAPI returns a validly formatted, fully qualified URI to the unit rate information.
func ConstructRatesAPI(tariff string, region string) string {
t := strings.ToUpper(tariff)
r := strings.ToUpper(region)
return fmt.Sprintf(RatesURI, t, t, r)
}
type UnitRates struct {
Count uint64 `json:"count"`
Next string `json:"next"`
Previous string `json:"previous"`
Results []Rate `json:"results"`
}
type Rate struct {
ValidityStart time.Time `json:"valid_from"`
ValidityEnd time.Time `json:"valid_to"`
PriceInclusiveTax float64 `json:"value_inc_vat"`
PriceExclusiveTax float64 `json:"value_exc_vat"`
}