From 4756ac8f32f6edffe148632f5d31eb9b103dcbec Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 22 Sep 2023 20:32:59 +0200 Subject: [PATCH] Add tariff templates (#9820) --- tariff/tibber.go | 1 - templates/definition/embed.go | 2 +- templates/definition/tariff/awattar.yaml | 10 ++++++++++ templates/definition/tariff/fixed.yaml | 12 ++++++++++++ templates/definition/tariff/gruenstromindex.yaml | 8 ++++++++ templates/definition/tariff/tibber.yaml | 12 ++++++++++++ util/templates/class.go | 1 + util/templates/class_enumer.go | 12 ++++++++---- util/templates/defaults.yaml | 8 ++++++++ util/templates/generate/main.go | 2 +- util/templates/includes/tariff-base.tpl | 8 ++++++++ util/templates/init.go | 6 +++--- 12 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 templates/definition/tariff/awattar.yaml create mode 100644 templates/definition/tariff/fixed.yaml create mode 100644 templates/definition/tariff/gruenstromindex.yaml create mode 100644 templates/definition/tariff/tibber.yaml create mode 100644 util/templates/includes/tariff-base.tpl diff --git a/tariff/tibber.go b/tariff/tibber.go index 2c5f39f72..a106272fb 100644 --- a/tariff/tibber.go +++ b/tariff/tibber.go @@ -36,7 +36,6 @@ func NewTibberFromConfig(other map[string]interface{}) (api.Tariff, error) { embed `mapstructure:",squash"` Token string HomeID string - Unit string } if err := util.DecodeOther(other, &cc); err != nil { diff --git a/templates/definition/embed.go b/templates/definition/embed.go index 81e63c1e3..661a43b4c 100644 --- a/templates/definition/embed.go +++ b/templates/definition/embed.go @@ -2,5 +2,5 @@ package definition import "embed" -//go:embed charger/*.yaml meter/*.yaml vehicle/*.yaml +//go:embed charger/*.yaml meter/*.yaml vehicle/*.yaml tariff/*.yaml var YamlTemplates embed.FS diff --git a/templates/definition/tariff/awattar.yaml b/templates/definition/tariff/awattar.yaml new file mode 100644 index 000000000..70bdb6664 --- /dev/null +++ b/templates/definition/tariff/awattar.yaml @@ -0,0 +1,10 @@ +template: awattar +products: + - brand: Awattar +params: + - preset: tariff-base + - name: region +render: | + type: awattar + {{ include "tariff-base" . }} + region: {{ .region }} diff --git a/templates/definition/tariff/fixed.yaml b/templates/definition/tariff/fixed.yaml new file mode 100644 index 000000000..d34253e24 --- /dev/null +++ b/templates/definition/tariff/fixed.yaml @@ -0,0 +1,12 @@ +template: fixed +products: + - brand: Standard +params: + - name: price + type: float + description: + en: "Price per kWh" + de: "Preis je kWh" +render: | + type: fixed + price: {{ .price }} diff --git a/templates/definition/tariff/gruenstromindex.yaml b/templates/definition/tariff/gruenstromindex.yaml new file mode 100644 index 000000000..bed61b5ed --- /dev/null +++ b/templates/definition/tariff/gruenstromindex.yaml @@ -0,0 +1,8 @@ +template: grünstromindex +products: + - brand: Grünstromindex +params: + - name: zip +render: | + type: grünstromindex + zip: {{ .zip }} diff --git a/templates/definition/tariff/tibber.yaml b/templates/definition/tariff/tibber.yaml new file mode 100644 index 000000000..b057032ce --- /dev/null +++ b/templates/definition/tariff/tibber.yaml @@ -0,0 +1,12 @@ +template: tibber +products: + - brand: Tibber +params: + - preset: tariff-base + - name: token + - name: homeid +render: | + type: tibber + {{ include "tariff-base" . }} + token: {{ .token }} + homeid: {{ .homeid }} diff --git a/util/templates/class.go b/util/templates/class.go index 4d78b20a3..faa734e41 100644 --- a/util/templates/class.go +++ b/util/templates/class.go @@ -8,4 +8,5 @@ const ( Charger Meter Vehicle + Tariff ) diff --git a/util/templates/class_enumer.go b/util/templates/class_enumer.go index bea859f01..b21ff61de 100644 --- a/util/templates/class_enumer.go +++ b/util/templates/class_enumer.go @@ -7,11 +7,11 @@ import ( "strings" ) -const _ClassName = "ChargerMeterVehicle" +const _ClassName = "ChargerMeterVehicleTariff" -var _ClassIndex = [...]uint8{0, 7, 12, 19} +var _ClassIndex = [...]uint8{0, 7, 12, 19, 25} -const _ClassLowerName = "chargermetervehicle" +const _ClassLowerName = "chargermetervehicletariff" func (i Class) String() string { i -= 1 @@ -28,9 +28,10 @@ func _ClassNoOp() { _ = x[Charger-(1)] _ = x[Meter-(2)] _ = x[Vehicle-(3)] + _ = x[Tariff-(4)] } -var _ClassValues = []Class{Charger, Meter, Vehicle} +var _ClassValues = []Class{Charger, Meter, Vehicle, Tariff} var _ClassNameToValueMap = map[string]Class{ _ClassName[0:7]: Charger, @@ -39,12 +40,15 @@ var _ClassNameToValueMap = map[string]Class{ _ClassLowerName[7:12]: Meter, _ClassName[12:19]: Vehicle, _ClassLowerName[12:19]: Vehicle, + _ClassName[19:25]: Tariff, + _ClassLowerName[19:25]: Tariff, } var _ClassNames = []string{ _ClassName[0:7], _ClassName[7:12], _ClassName[12:19], + _ClassName[19:25], } // ClassString retrieves an enum value from the enum constants string name. diff --git a/util/templates/defaults.yaml b/util/templates/defaults.yaml index d6556e0ae..447ef9ffb 100644 --- a/util/templates/defaults.yaml +++ b/util/templates/defaults.yaml @@ -320,6 +320,14 @@ presets: vehicle-language: params: - name: language + tariff-base: + params: + - name: costs + type: number + advanced: true + - name: tax + type: number + advanced: true eebus: params: - name: ski diff --git a/util/templates/generate/main.go b/util/templates/generate/main.go index ec4df9f9d..994970386 100644 --- a/util/templates/generate/main.go +++ b/util/templates/generate/main.go @@ -30,7 +30,7 @@ func main() { } func generateDocs(lang string) { - for _, class := range []templates.Class{templates.Meter, templates.Charger, templates.Vehicle} { + for _, class := range templates.ClassValues() { path := fmt.Sprintf("%s/%s/%s", docsPath, lang, strings.ToLower(class.String())) _, err := os.Stat(path) if os.IsNotExist(err) { diff --git a/util/templates/includes/tariff-base.tpl b/util/templates/includes/tariff-base.tpl new file mode 100644 index 000000000..d530859a8 --- /dev/null +++ b/util/templates/includes/tariff-base.tpl @@ -0,0 +1,8 @@ +{{ define "tariff-base" }} +{{- if .charges }} +charges: {{ .charges }} +{{- end }} +{{- if .tax }} +tax: {{ .tax }} +{{- end }} +{{- end }} diff --git a/util/templates/init.go b/util/templates/init.go index b62c6f3d5..5dccb3524 100644 --- a/util/templates/init.go +++ b/util/templates/init.go @@ -32,9 +32,9 @@ func init() { baseTmpl = template.Must(template.ParseFS(includeFS, "includes/*.tpl")) - loadTemplates(Charger) - loadTemplates(Meter) - loadTemplates(Vehicle) + for _, class := range ClassValues() { + loadTemplates(class) + } } func FromBytes(b []byte) (Template, error) {