Add tariff templates (#9820)

This commit is contained in:
andig 2023-09-22 20:32:59 +02:00 • committed by GitHub
parent ba1aeb5285
commit 4756ac8f32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 72 additions and 10 deletions

View file

@ -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 {

View file

@ -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

View file

@ -0,0 +1,10 @@
template: awattar
products:
- brand: Awattar
params:
- preset: tariff-base
- name: region
render: |
type: awattar
{{ include "tariff-base" . }}
region: {{ .region }}

View file

@ -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 }}

View file

@ -0,0 +1,8 @@
template: grünstromindex
products:
- brand: Grünstromindex
params:
- name: zip
render: |
type: grünstromindex
zip: {{ .zip }}

View file

@ -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 }}

View file

@ -8,4 +8,5 @@ const (
Charger
Meter
Vehicle
Tariff
)

View file

@ -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.

View file

@ -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

View file

@ -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) {

View file

@ -0,0 +1,8 @@
{{ define "tariff-base" }}
{{- if .charges }}
charges: {{ .charges }}
{{- end }}
{{- if .tax }}
tax: {{ .tax }}
{{- end }}
{{- end }}

View file

@ -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) {