From de3f8995cdf2b8a10745b7221c58031ae3d1764c Mon Sep 17 00:00:00 2001 From: andig Date: Tue, 18 Aug 2026 09:23:03 +0200 Subject: [PATCH] Templates: support class-local include files (#32871) --- .../definition/charger/features.tpl | 2 +- .../definition/charger}/heatpumpswitch.tpl | 0 .../definition/charger/homeassistant.yaml | 2 +- .../definition/charger}/ocpp.tpl | 0 .../definition/charger}/switchsocket.tpl | 0 templates/definition/embed.go | 3 ++ .../definition/meter}/battery-params.tpl | 0 templates/definition/tariff/allinpower.yaml | 2 +- templates/definition/tariff/amber.yaml | 2 +- templates/definition/tariff/awattar.yaml | 2 +- .../definition/tariff/base.tpl | 2 +- templates/definition/tariff/bkw.yaml | 2 +- templates/definition/tariff/ckw.yaml | 2 +- .../definition/tariff/demo-dynamic-grid.yaml | 2 +- templates/definition/tariff/ekz.yaml | 2 +- templates/definition/tariff/elering.yaml | 2 +- .../definition/tariff/energinet-price.yaml | 2 +- templates/definition/tariff/energinet.yaml | 2 +- .../definition/tariff/energy-charts-api.yaml | 4 +-- .../definition/tariff/energyforecast.yaml | 4 +-- .../tariff/energypriceforecast.yaml | 4 +-- templates/definition/tariff/enever.yaml | 4 +-- templates/definition/tariff/entsoe.yaml | 4 +-- .../definition/tariff/epex-predictor.yaml | 4 +-- .../definition/tariff/epexprijzen-nl.yaml | 2 +- templates/definition/tariff/esios.yaml | 2 +- .../definition/tariff/features.tpl | 2 +- templates/definition/tariff/fixed-zones.yaml | 2 +- templates/definition/tariff/fixed.yaml | 2 +- templates/definition/tariff/groupe-e.yaml | 2 +- templates/definition/tariff/nordpool.yaml | 4 +-- templates/definition/tariff/omie.yaml | 4 +-- templates/definition/tariff/pstryk.yaml | 2 +- templates/definition/tariff/pun.yaml | 2 +- templates/definition/tariff/smartenergy.yaml | 2 +- templates/definition/tariff/spottyenergy.yaml | 2 +- templates/definition/tariff/stekker.yaml | 4 +-- .../tariff/stroomprijsprognose.yaml | 4 +-- templates/definition/tariff/tibber.yaml | 2 +- templates/definition/tariff/voltcast.yaml | 4 +-- templates/definition/vehicle/aiways.yaml | 4 +-- templates/definition/vehicle/alpine.yaml | 4 +-- templates/definition/vehicle/audi.yaml | 4 +-- .../definition/vehicle/base.tpl | 4 +-- templates/definition/vehicle/bmw.yaml | 4 +-- templates/definition/vehicle/cardata.yaml | 4 +-- templates/definition/vehicle/carwings.yaml | 4 +-- templates/definition/vehicle/citroen.yaml | 4 +-- .../definition/vehicle/common.tpl | 2 +- .../definition/vehicle/connected-cars.yaml | 4 +-- templates/definition/vehicle/dacia.yaml | 4 +-- .../vehicle/drivesomethinggreater.yaml | 4 +-- templates/definition/vehicle/ds.yaml | 4 +-- templates/definition/vehicle/evnotify.yaml | 4 +-- .../definition/vehicle/features.tpl | 2 +- templates/definition/vehicle/fiat.yaml | 4 +-- templates/definition/vehicle/flobz.yaml | 4 +-- .../vehicle/ford-connect-query.yaml | 4 +-- .../definition/vehicle/ford-connect.yaml | 4 +-- templates/definition/vehicle/genesis.yaml | 6 ++-- .../definition/vehicle/homeassistant.yaml | 4 +-- templates/definition/vehicle/hyundai-us.yaml | 4 +-- templates/definition/vehicle/hyundai.yaml | 6 ++-- .../definition/vehicle/ioBroker.bmw.yaml | 4 +-- templates/definition/vehicle/iso15118.yaml | 4 +-- .../definition/vehicle/jaguar-landrover.yaml | 4 +-- templates/definition/vehicle/kia.yaml | 6 ++-- .../definition/vehicle/language.tpl | 2 +- templates/definition/vehicle/lexus.yaml | 4 +-- templates/definition/vehicle/mazda2mqtt.yaml | 4 +-- templates/definition/vehicle/mercedes.yaml | 4 +-- templates/definition/vehicle/mg.yaml | 4 +-- templates/definition/vehicle/mg2mqtt.yaml | 4 +-- templates/definition/vehicle/mini.yaml | 4 +-- templates/definition/vehicle/mz2mqtt.yaml | 4 +-- .../definition/vehicle/nissan-ariya.yaml | 4 +-- templates/definition/vehicle/nissan.yaml | 4 +-- .../definition/vehicle/niu-e-scooter.yaml | 2 +- templates/definition/vehicle/octopus-de.yaml | 4 +-- templates/definition/vehicle/octopus-it.yaml | 4 +-- templates/definition/vehicle/offline.yaml | 4 +-- templates/definition/vehicle/opel.yaml | 4 +-- .../definition/vehicle/outlanderphev.yaml | 4 +-- templates/definition/vehicle/ovms.yaml | 4 +-- templates/definition/vehicle/peugeot.yaml | 4 +-- templates/definition/vehicle/polestar.yaml | 4 +-- templates/definition/vehicle/porsche.yaml | 4 +-- templates/definition/vehicle/renault.yaml | 4 +-- templates/definition/vehicle/seat-cupra.yaml | 4 +-- templates/definition/vehicle/seat.yaml | 4 +-- templates/definition/vehicle/skoda.yaml | 4 +-- templates/definition/vehicle/smart-hello.yaml | 4 +-- templates/definition/vehicle/smart.yaml | 4 +-- templates/definition/vehicle/subaru.yaml | 4 +-- templates/definition/vehicle/tesla-ble.yaml | 4 +-- templates/definition/vehicle/tesla.yaml | 4 +-- templates/definition/vehicle/teslafi.yaml | 4 +-- templates/definition/vehicle/teslalogger.yaml | 4 +-- templates/definition/vehicle/teslamate.yaml | 4 +-- templates/definition/vehicle/tessie.yaml | 4 +-- templates/definition/vehicle/tibber.yaml | 4 +-- templates/definition/vehicle/toyota.yaml | 4 +-- templates/definition/vehicle/tronity.yaml | 4 +-- .../definition/vehicle/volvo-connected.yaml | 4 +-- templates/definition/vehicle/volvo2mqtt.yaml | 4 +-- templates/definition/vehicle/vw.yaml | 4 +-- templates/definition/vehicle/zero.yaml | 4 +-- util/templates/formatvalue_test.go | 2 +- util/templates/init.go | 30 +++++++++++++++- util/templates/init_test.go | 36 +++++++++++++++++++ util/templates/render_instance.go | 2 +- util/templates/render_testing.go | 8 ++--- util/templates/template.go | 10 ++++-- util/templates/template_modbus_test.go | 6 ++-- util/templates/template_test.go | 36 +++++++++---------- vehicle/template_test.go | 6 ++-- 116 files changed, 285 insertions(+), 212 deletions(-) rename util/templates/includes/charger-features.tpl => templates/definition/charger/features.tpl (86%) rename {util/templates/includes => templates/definition/charger}/heatpumpswitch.tpl (100%) rename {util/templates/includes => templates/definition/charger}/ocpp.tpl (100%) rename {util/templates/includes => templates/definition/charger}/switchsocket.tpl (100%) rename {util/templates/includes => templates/definition/meter}/battery-params.tpl (100%) rename util/templates/includes/tariff-base.tpl => templates/definition/tariff/base.tpl (94%) rename util/templates/includes/tariff-features.tpl => templates/definition/tariff/features.tpl (70%) rename util/templates/includes/vehicle-base.tpl => templates/definition/vehicle/base.tpl (65%) rename util/templates/includes/vehicle-common.tpl => templates/definition/vehicle/common.tpl (95%) rename util/templates/includes/vehicle-features.tpl => templates/definition/vehicle/features.tpl (95%) rename util/templates/includes/vehicle-language.tpl => templates/definition/vehicle/language.tpl (53%) create mode 100644 util/templates/init_test.go diff --git a/util/templates/includes/charger-features.tpl b/templates/definition/charger/features.tpl similarity index 86% rename from util/templates/includes/charger-features.tpl rename to templates/definition/charger/features.tpl index b4569dd9e..abf514045 100644 --- a/util/templates/includes/charger-features.tpl +++ b/templates/definition/charger/features.tpl @@ -1,4 +1,4 @@ -{{ define "charger-features" }} +{{ define "features" }} {{- if or (eq .heating "true") (eq .integrateddevice "true") }} features: {{- if eq .heating "true" }} diff --git a/util/templates/includes/heatpumpswitch.tpl b/templates/definition/charger/heatpumpswitch.tpl similarity index 100% rename from util/templates/includes/heatpumpswitch.tpl rename to templates/definition/charger/heatpumpswitch.tpl diff --git a/templates/definition/charger/homeassistant.yaml b/templates/definition/charger/homeassistant.yaml index cfb4235f6..41ca1c0fe 100644 --- a/templates/definition/charger/homeassistant.yaml +++ b/templates/definition/charger/homeassistant.yaml @@ -213,4 +213,4 @@ render: | - {{ .voltageL3 }} {{- end }} phases: {{ .phaseswitch }} - {{ include "charger-features" . }} + {{ include "features" . }} diff --git a/util/templates/includes/ocpp.tpl b/templates/definition/charger/ocpp.tpl similarity index 100% rename from util/templates/includes/ocpp.tpl rename to templates/definition/charger/ocpp.tpl diff --git a/util/templates/includes/switchsocket.tpl b/templates/definition/charger/switchsocket.tpl similarity index 100% rename from util/templates/includes/switchsocket.tpl rename to templates/definition/charger/switchsocket.tpl diff --git a/templates/definition/embed.go b/templates/definition/embed.go index 3202a14b6..1f60bfa3b 100644 --- a/templates/definition/embed.go +++ b/templates/definition/embed.go @@ -4,3 +4,6 @@ import "embed" //go:embed charger/*.yaml meter/*.yaml vehicle/*.yaml tariff/*.yaml messenger/*.yaml circuit/*.yaml hems/*.yaml var YamlTemplates embed.FS + +//go:embed */*.tpl +var TemplateIncludes embed.FS diff --git a/util/templates/includes/battery-params.tpl b/templates/definition/meter/battery-params.tpl similarity index 100% rename from util/templates/includes/battery-params.tpl rename to templates/definition/meter/battery-params.tpl diff --git a/templates/definition/tariff/allinpower.yaml b/templates/definition/tariff/allinpower.yaml index 7d560e630..c476cf593 100644 --- a/templates/definition/tariff/allinpower.yaml +++ b/templates/definition/tariff/allinpower.yaml @@ -10,7 +10,7 @@ params: - preset: tariff-base render: | type: custom - {{ include "tariff-base" . }} + {{ include "base" . }} forecast: source: http uri: https://api.allinpower.nl/troodon/api/p/spot_market/prices/?product_type=ELK diff --git a/templates/definition/tariff/amber.yaml b/templates/definition/tariff/amber.yaml index 1873ed11c..655f2d4c1 100644 --- a/templates/definition/tariff/amber.yaml +++ b/templates/definition/tariff/amber.yaml @@ -20,4 +20,4 @@ render: | token: {{ .token }} siteid: {{ .siteid }} channel: {{ .channel }} - {{ include "tariff-base" . }} + {{ include "base" . }} diff --git a/templates/definition/tariff/awattar.yaml b/templates/definition/tariff/awattar.yaml index af44c45bc..acb5086b3 100644 --- a/templates/definition/tariff/awattar.yaml +++ b/templates/definition/tariff/awattar.yaml @@ -13,4 +13,4 @@ params: render: | type: awattar region: {{ .region }} - {{ include "tariff-base" . }} + {{ include "base" . }} diff --git a/util/templates/includes/tariff-base.tpl b/templates/definition/tariff/base.tpl similarity index 94% rename from util/templates/includes/tariff-base.tpl rename to templates/definition/tariff/base.tpl index f508795ed..84f91b48a 100644 --- a/util/templates/includes/tariff-base.tpl +++ b/templates/definition/tariff/base.tpl @@ -1,4 +1,4 @@ -{{ define "tariff-base" }} +{{ define "base" }} {{- if .charges }} charges: {{ .charges }} {{- end }} diff --git a/templates/definition/tariff/bkw.yaml b/templates/definition/tariff/bkw.yaml index 1dd8c7af5..dde7b1726 100644 --- a/templates/definition/tariff/bkw.yaml +++ b/templates/definition/tariff/bkw.yaml @@ -14,7 +14,7 @@ params: default: 0.081 render: | type: custom - {{ include "tariff-base" . }} + {{ include "base" . }} forecast: source: http uri: https://api.bkw.ch/api/dyntariffs/v1/tariffs diff --git a/templates/definition/tariff/ckw.yaml b/templates/definition/tariff/ckw.yaml index 230f171b3..ca5924973 100644 --- a/templates/definition/tariff/ckw.yaml +++ b/templates/definition/tariff/ckw.yaml @@ -23,7 +23,7 @@ params: default: 0.081 render: | type: custom - {{ include "tariff-base" . }} + {{ include "base" . }} forecast: source: http uri: https://e-ckw-public-data.de-c1.eu1.cloudhub.io/api/v1/netzinformationen/energie/dynamische-preise?tariff_type=integrated&tariff_name={{ .tariff }}&start_timestamp={{ `{{ (now.AddDate 0 0 -1).Format "2006-01-02T00:00:00Z" }}` }}&end_timestamp={{ `{{ (now.AddDate 0 0 3).Format "2006-01-02T00:00:00Z" }}` }} diff --git a/templates/definition/tariff/demo-dynamic-grid.yaml b/templates/definition/tariff/demo-dynamic-grid.yaml index ab5874645..d0a1de33a 100644 --- a/templates/definition/tariff/demo-dynamic-grid.yaml +++ b/templates/definition/tariff/demo-dynamic-grid.yaml @@ -44,7 +44,7 @@ params: render: | type: custom - {{ include "tariff-base" . }} + {{ include "base" . }} forecast: source: js script: | diff --git a/templates/definition/tariff/ekz.yaml b/templates/definition/tariff/ekz.yaml index a65ba35a5..f30003daa 100644 --- a/templates/definition/tariff/ekz.yaml +++ b/templates/definition/tariff/ekz.yaml @@ -29,7 +29,7 @@ params: advanced: true render: | type: custom - {{ include "tariff-base" . }} + {{ include "base" . }} forecast: source: http uri: https://api.tariffs.ekz.ch/v1/tariffs?tariff_name=integrated_{{ .tariff_name }}&start_timestamp={{ `{{ now.Local | date "2006-01-02T15" }}` }}:00:00%2B02%3A00&end_timestamp={{ `{{ addDate now.Local 0 0 2 | date "2006-01-02T15" }}` }}:00:00 diff --git a/templates/definition/tariff/elering.yaml b/templates/definition/tariff/elering.yaml index 99e4336ed..7e0530beb 100644 --- a/templates/definition/tariff/elering.yaml +++ b/templates/definition/tariff/elering.yaml @@ -18,4 +18,4 @@ params: render: | type: elering region: {{ .region }} - {{ include "tariff-base" . }} + {{ include "base" . }} diff --git a/templates/definition/tariff/energinet-price.yaml b/templates/definition/tariff/energinet-price.yaml index eb5a42897..663ea9675 100644 --- a/templates/definition/tariff/energinet-price.yaml +++ b/templates/definition/tariff/energinet-price.yaml @@ -15,7 +15,7 @@ params: - preset: tariff-base render: | type: custom - {{ include "tariff-base" . }} + {{ include "base" . }} forecast: source: http uri: https://api.energidataservice.dk/dataset/DayAheadPrices?start=now&filter={"PriceArea":["{{ .region }}"]} diff --git a/templates/definition/tariff/energinet.yaml b/templates/definition/tariff/energinet.yaml index 4a033609c..1be858da6 100644 --- a/templates/definition/tariff/energinet.yaml +++ b/templates/definition/tariff/energinet.yaml @@ -16,4 +16,4 @@ params: render: | type: energinet region: {{ .region }} - {{ include "tariff-base" . }} + {{ include "base" . }} diff --git a/templates/definition/tariff/energy-charts-api.yaml b/templates/definition/tariff/energy-charts-api.yaml index a3ba8825c..32d450354 100644 --- a/templates/definition/tariff/energy-charts-api.yaml +++ b/templates/definition/tariff/energy-charts-api.yaml @@ -45,8 +45,8 @@ params: - preset: tariff-features render: | type: custom - {{ include "tariff-base" . }} - {{ include "tariff-features" . }} + {{ include "base" . }} + {{ include "features" . }} forecast: source: http uri: https://api.energy-charts.info/price?bzn={{ .bzn }}&end={{ `{{ addDate now 0 0 1 | date "2006-01-02" }}` }} diff --git a/templates/definition/tariff/energyforecast.yaml b/templates/definition/tariff/energyforecast.yaml index 2e8bb183d..c683cc3c0 100644 --- a/templates/definition/tariff/energyforecast.yaml +++ b/templates/definition/tariff/energyforecast.yaml @@ -15,8 +15,8 @@ params: - preset: tariff-features render: | type: custom - {{ include "tariff-base" . }} - {{ include "tariff-features" . }} + {{ include "base" . }} + {{ include "features" . }} forecast: source: http uri: https://www.energyforecast.de/api/v1/predictions/next_96_hours?resolution=QUARTER_HOURLY&fixed_cost_cent=0&vat=0&token={{ .token }}{{ if .domain }}&market_zone={{ .domain }}{{ end }} diff --git a/templates/definition/tariff/energypriceforecast.yaml b/templates/definition/tariff/energypriceforecast.yaml index 0c814a001..dec09964d 100644 --- a/templates/definition/tariff/energypriceforecast.yaml +++ b/templates/definition/tariff/energypriceforecast.yaml @@ -30,8 +30,8 @@ params: - preset: tariff-features render: | type: custom - {{ include "tariff-base" . }} - {{ include "tariff-features" . }} + {{ include "base" . }} + {{ include "features" . }} forecast: source: http uri: https://api.energypriceforecast.eu/api/v1/evcc/tariff?country={{.region}}&type=grid¤cy={{.currency}}&hours={{.horizon}} diff --git a/templates/definition/tariff/enever.yaml b/templates/definition/tariff/enever.yaml index 2b3829df5..f1b68df3f 100644 --- a/templates/definition/tariff/enever.yaml +++ b/templates/definition/tariff/enever.yaml @@ -52,8 +52,8 @@ params: advanced: true render: | type: custom - {{ include "tariff-base" . }} - {{ include "tariff-features" . }} + {{ include "base" . }} + {{ include "features" . }} forecast: source: go script: | diff --git a/templates/definition/tariff/entsoe.yaml b/templates/definition/tariff/entsoe.yaml index 10e06b469..6e2d88537 100644 --- a/templates/definition/tariff/entsoe.yaml +++ b/templates/definition/tariff/entsoe.yaml @@ -118,5 +118,5 @@ render: | type: entsoe securitytoken: {{ .securitytoken }} domain: "{{ .domain }}" - {{ include "tariff-base" . }} - {{ include "tariff-features" . }} + {{ include "base" . }} + {{ include "features" . }} diff --git a/templates/definition/tariff/epex-predictor.yaml b/templates/definition/tariff/epex-predictor.yaml index f3bc9b57e..47cb5c74c 100644 --- a/templates/definition/tariff/epex-predictor.yaml +++ b/templates/definition/tariff/epex-predictor.yaml @@ -26,8 +26,8 @@ params: - preset: tariff-features render: | type: custom - {{ include "tariff-base" . }} - {{ include "tariff-features" . }} + {{ include "base" . }} + {{ include "features" . }} forecast: source: http uri: {{ .uri }}/prices?region={{ .region }}&unit=EUR_PER_KWH&timezone=UTC diff --git a/templates/definition/tariff/epexprijzen-nl.yaml b/templates/definition/tariff/epexprijzen-nl.yaml index 7572055fc..6aae45c98 100644 --- a/templates/definition/tariff/epexprijzen-nl.yaml +++ b/templates/definition/tariff/epexprijzen-nl.yaml @@ -54,7 +54,7 @@ params: advanced: true render: | type: custom - {{ include "tariff-base" . }} + {{ include "base" . }} forecast: source: http uri: https://epexprijzen.nl/api/v1/prices/{{ .provider }}/{{ index . "price-interval" }} diff --git a/templates/definition/tariff/esios.yaml b/templates/definition/tariff/esios.yaml index d8d99b8f6..24b2afc80 100644 --- a/templates/definition/tariff/esios.yaml +++ b/templates/definition/tariff/esios.yaml @@ -32,7 +32,7 @@ params: - preset: tariff-base render: | type: custom - {{ include "tariff-base" . }} + {{ include "base" . }} forecast: source: http uri: https://api.esios.ree.es/indicators/{{ .indicator }}?start_date={{ now | date "2006-01-02" }}T00:00&end_date={{ (now.AddDate 0 0 1) | date "2006-01-02" }}T23:59 diff --git a/util/templates/includes/tariff-features.tpl b/templates/definition/tariff/features.tpl similarity index 70% rename from util/templates/includes/tariff-features.tpl rename to templates/definition/tariff/features.tpl index 80d458b11..5748394eb 100644 --- a/util/templates/includes/tariff-features.tpl +++ b/templates/definition/tariff/features.tpl @@ -1,4 +1,4 @@ -{{ define "tariff-features" }} +{{ define "features" }} {{- if eq .average "true" }} features: ["average"] {{- end }} diff --git a/templates/definition/tariff/fixed-zones.yaml b/templates/definition/tariff/fixed-zones.yaml index 7e1c8e4fb..5e98ae031 100644 --- a/templates/definition/tariff/fixed-zones.yaml +++ b/templates/definition/tariff/fixed-zones.yaml @@ -37,4 +37,4 @@ render: | months: {{ .months }} {{- end }} {{- end }} - {{ include "tariff-base" . }} + {{ include "base" . }} diff --git a/templates/definition/tariff/fixed.yaml b/templates/definition/tariff/fixed.yaml index b0e5a6411..2e4aafcae 100644 --- a/templates/definition/tariff/fixed.yaml +++ b/templates/definition/tariff/fixed.yaml @@ -15,4 +15,4 @@ params: render: | type: fixed price: {{ .price }} - {{ include "tariff-base" . }} + {{ include "base" . }} diff --git a/templates/definition/tariff/groupe-e.yaml b/templates/definition/tariff/groupe-e.yaml index 77f6536db..881709416 100644 --- a/templates/definition/tariff/groupe-e.yaml +++ b/templates/definition/tariff/groupe-e.yaml @@ -12,7 +12,7 @@ params: render: | type: custom features: ["cacheable"] - {{ include "tariff-base" . }} + {{ include "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 diff --git a/templates/definition/tariff/nordpool.yaml b/templates/definition/tariff/nordpool.yaml index 3f1c12d65..df648b713 100644 --- a/templates/definition/tariff/nordpool.yaml +++ b/templates/definition/tariff/nordpool.yaml @@ -46,8 +46,8 @@ params: - preset: tariff-features render: | type: custom - {{ include "tariff-base" . }} - {{ include "tariff-features" . }} + {{ include "base" . }} + {{ include "features" . }} forecast: source: go script: | diff --git a/templates/definition/tariff/omie.yaml b/templates/definition/tariff/omie.yaml index 49e04f099..91e5cc8ce 100644 --- a/templates/definition/tariff/omie.yaml +++ b/templates/definition/tariff/omie.yaml @@ -27,8 +27,8 @@ params: - preset: tariff-features render: | type: custom - {{ include "tariff-base" . }} - {{ include "tariff-features" . }} + {{ include "base" . }} + {{ include "features" . }} forecast: source: http uri: https://www.omie.es/sites/default/files/dados/NUEVA_SECCION/INT_PBC_EV_H_ACUM.TXT diff --git a/templates/definition/tariff/pstryk.yaml b/templates/definition/tariff/pstryk.yaml index 8a3426619..f4fbdda2f 100644 --- a/templates/definition/tariff/pstryk.yaml +++ b/templates/definition/tariff/pstryk.yaml @@ -34,7 +34,7 @@ params: render: | type: custom - {{ include "tariff-base" . }} + {{ include "base" . }} forecast: source: http uri: https://api.pstryk.pl/integrations/meter-data/unified-metrics/?metrics=pricing&resolution=hour&window_start={{ `{{ now.UTC | mustDateModify "-24h" | date "2006-01-02" }}` }}:00:00Z&window_end={{ `{{ now.UTC | mustDateModify "+72h" | date "2006-01-02" }}` }}:00:00Z diff --git a/templates/definition/tariff/pun.yaml b/templates/definition/tariff/pun.yaml index 8736d59b1..871b6d162 100644 --- a/templates/definition/tariff/pun.yaml +++ b/templates/definition/tariff/pun.yaml @@ -21,5 +21,5 @@ params: en: Italian electricity market zone. If no zone is specified, the national unit price (PUN) is used. render: | type: pun - {{ include "tariff-base" . }} + {{ include "base" . }} zone: {{ .zone }} diff --git a/templates/definition/tariff/smartenergy.yaml b/templates/definition/tariff/smartenergy.yaml index 8ad4b9136..c9aebd287 100644 --- a/templates/definition/tariff/smartenergy.yaml +++ b/templates/definition/tariff/smartenergy.yaml @@ -11,4 +11,4 @@ params: - preset: tariff-base render: | type: smartenergy - {{ include "tariff-base" . }} + {{ include "base" . }} diff --git a/templates/definition/tariff/spottyenergy.yaml b/templates/definition/tariff/spottyenergy.yaml index cc61f1b63..baacdf00b 100644 --- a/templates/definition/tariff/spottyenergy.yaml +++ b/templates/definition/tariff/spottyenergy.yaml @@ -29,7 +29,7 @@ params: - preset: tariff-base render: | type: custom - {{ include "tariff-base" . }} + {{ include "base" . }} forecast: source: http uri: https://i.spottyenergie.at/api/prices/{{ .pricetype }}/{{ unquote .contractid }} diff --git a/templates/definition/tariff/stekker.yaml b/templates/definition/tariff/stekker.yaml index 6895f5242..15404489f 100644 --- a/templates/definition/tariff/stekker.yaml +++ b/templates/definition/tariff/stekker.yaml @@ -55,5 +55,5 @@ params: render: | type: stekker region: {{ .region }} - {{ include "tariff-base" . }} - {{ include "tariff-features" . }} + {{ include "base" . }} + {{ include "features" . }} diff --git a/templates/definition/tariff/stroomprijsprognose.yaml b/templates/definition/tariff/stroomprijsprognose.yaml index 0ecc96b0d..0e3d3fa5e 100644 --- a/templates/definition/tariff/stroomprijsprognose.yaml +++ b/templates/definition/tariff/stroomprijsprognose.yaml @@ -29,8 +29,8 @@ params: - preset: tariff-features render: | type: custom - {{ include "tariff-base" . }} - {{ include "tariff-features" . }} + {{ include "base" . }} + {{ include "features" . }} forecast: source: http uri: https://api.energypriceforecast.eu/api/v1/evcc/tariff?country={{.region}}&type=grid¤cy={{.currency}}&hours={{.horizon}} diff --git a/templates/definition/tariff/tibber.yaml b/templates/definition/tariff/tibber.yaml index 1180bf656..543a04534 100644 --- a/templates/definition/tariff/tibber.yaml +++ b/templates/definition/tariff/tibber.yaml @@ -26,4 +26,4 @@ render: | type: tibber token: {{ .token }} homeid: {{ .homeid }} - {{ include "tariff-base" . }} + {{ include "base" . }} diff --git a/templates/definition/tariff/voltcast.yaml b/templates/definition/tariff/voltcast.yaml index cdb8de1d4..5ac7d6370 100644 --- a/templates/definition/tariff/voltcast.yaml +++ b/templates/definition/tariff/voltcast.yaml @@ -74,8 +74,8 @@ params: render: | type: custom features: ["cacheable"] - {{ include "tariff-base" . }} - {{ include "tariff-features" . }} + {{ include "base" . }} + {{ include "features" . }} forecast: source: http uri: https://voltcast.com/api/v1/forecasts/{{ .zone }}?horizon=48h diff --git a/templates/definition/vehicle/aiways.yaml b/templates/definition/vehicle/aiways.yaml index a63913ab6..cbbd44ce3 100644 --- a/templates/definition/vehicle/aiways.yaml +++ b/templates/definition/vehicle/aiways.yaml @@ -8,5 +8,5 @@ params: required: true render: | type: aiways - {{ include "vehicle-base" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/alpine.yaml b/templates/definition/vehicle/alpine.yaml index bee710624..02ac911dc 100644 --- a/templates/definition/vehicle/alpine.yaml +++ b/templates/definition/vehicle/alpine.yaml @@ -6,5 +6,5 @@ params: - preset: vehicle-features render: | type: myalpine - {{ include "vehicle-base" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/audi.yaml b/templates/definition/vehicle/audi.yaml index 86ec3c24b..8e093c0e9 100644 --- a/templates/definition/vehicle/audi.yaml +++ b/templates/definition/vehicle/audi.yaml @@ -40,5 +40,5 @@ params: render: | type: drivesomethinggreater brand: Audi - {{ include "vehicle-base" . }} - {{ include "vehicle-features" (merge (dict "basefeatures" (list "streaming")) .) }} + {{ include "base" . }} + {{ include "features" (merge (dict "basefeatures" (list "streaming")) .) }} diff --git a/util/templates/includes/vehicle-base.tpl b/templates/definition/vehicle/base.tpl similarity index 65% rename from util/templates/includes/vehicle-base.tpl rename to templates/definition/vehicle/base.tpl index 45e98fd21..92a0bd544 100644 --- a/util/templates/includes/vehicle-base.tpl +++ b/templates/definition/vehicle/base.tpl @@ -1,8 +1,8 @@ -{{ define "vehicle-base" }} +{{ define "base" }} user: {{ .user }} password: {{ .password }} vin: {{ .vin }} -{{ template "vehicle-common" . }} +{{ template "common" . }} {{- if .cache }} cache: {{ .cache }} {{- end }} diff --git a/templates/definition/vehicle/bmw.yaml b/templates/definition/vehicle/bmw.yaml index 7fcc11acf..b9bb96f9b 100644 --- a/templates/definition/vehicle/bmw.yaml +++ b/templates/definition/vehicle/bmw.yaml @@ -29,9 +29,9 @@ params: - preset: vehicle-features render: | type: bmw - {{ include "vehicle-base" . }} + {{ include "base" . }} {{- if ne .region "EU" }} region: {{ .region }} {{- end }} - {{ include "vehicle-features" . }} + {{ include "features" . }} hcaptcha: {{ .hcaptcha }} diff --git a/templates/definition/vehicle/cardata.yaml b/templates/definition/vehicle/cardata.yaml index 34feb78f4..7506d507b 100644 --- a/templates/definition/vehicle/cardata.yaml +++ b/templates/definition/vehicle/cardata.yaml @@ -72,5 +72,5 @@ render: | type: cardata vin: {{ .vin }} clientid: {{ .clientid }} - {{ include "vehicle-common" . }} - {{ include "vehicle-features" . }} + {{ include "common" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/carwings.yaml b/templates/definition/vehicle/carwings.yaml index c716f0be5..c623d0878 100644 --- a/templates/definition/vehicle/carwings.yaml +++ b/templates/definition/vehicle/carwings.yaml @@ -8,5 +8,5 @@ params: - preset: vehicle-online render: | type: carwings - {{ include "vehicle-base" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/citroen.yaml b/templates/definition/vehicle/citroen.yaml index 8d17ba686..d69dbc56a 100644 --- a/templates/definition/vehicle/citroen.yaml +++ b/templates/definition/vehicle/citroen.yaml @@ -29,6 +29,6 @@ render: | tokens: access: {{ .accessToken }} refresh: {{ .refreshToken }} - {{ include "vehicle-common" . }} + {{ include "common" . }} cache: {{ .cache }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/util/templates/includes/vehicle-common.tpl b/templates/definition/vehicle/common.tpl similarity index 95% rename from util/templates/includes/vehicle-common.tpl rename to templates/definition/vehicle/common.tpl index bad12e6e5..934d29838 100644 --- a/util/templates/includes/vehicle-common.tpl +++ b/templates/definition/vehicle/common.tpl @@ -1,4 +1,4 @@ -{{ define "vehicle-common" }} +{{ define "common" }} {{- if .title }} title: {{ .title }} {{- end }} diff --git a/templates/definition/vehicle/connected-cars.yaml b/templates/definition/vehicle/connected-cars.yaml index 55b753358..b9870ffba 100644 --- a/templates/definition/vehicle/connected-cars.yaml +++ b/templates/definition/vehicle/connected-cars.yaml @@ -40,6 +40,6 @@ render: | domain: {{ .domain }} namespace: {{ .namespace }} vin: {{ .vin }} - {{ include "vehicle-common" . }} + {{ include "common" . }} cache: {{ .cache }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/dacia.yaml b/templates/definition/vehicle/dacia.yaml index 097fda573..7708f3bfc 100644 --- a/templates/definition/vehicle/dacia.yaml +++ b/templates/definition/vehicle/dacia.yaml @@ -6,5 +6,5 @@ params: - preset: vehicle-features render: | type: dacia - {{ include "vehicle-base" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/drivesomethinggreater.yaml b/templates/definition/vehicle/drivesomethinggreater.yaml index 98030744a..551aa0371 100644 --- a/templates/definition/vehicle/drivesomethinggreater.yaml +++ b/templates/definition/vehicle/drivesomethinggreater.yaml @@ -58,5 +58,5 @@ params: render: | type: drivesomethinggreater brand: {{ .brand }} - {{ include "vehicle-base" . }} - {{ include "vehicle-features" (merge (dict "basefeatures" (list "streaming")) .) }} + {{ include "base" . }} + {{ include "features" (merge (dict "basefeatures" (list "streaming")) .) }} diff --git a/templates/definition/vehicle/ds.yaml b/templates/definition/vehicle/ds.yaml index 1abbf6443..ece471620 100644 --- a/templates/definition/vehicle/ds.yaml +++ b/templates/definition/vehicle/ds.yaml @@ -29,6 +29,6 @@ render: | tokens: access: {{ .accessToken }} refresh: {{ .refreshToken }} - {{ include "vehicle-common" . }} + {{ include "common" . }} cache: {{ .cache }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/evnotify.yaml b/templates/definition/vehicle/evnotify.yaml index 4c6d79f52..536904606 100644 --- a/templates/definition/vehicle/evnotify.yaml +++ b/templates/definition/vehicle/evnotify.yaml @@ -21,7 +21,7 @@ params: - preset: vehicle-online render: | type: custom - {{ include "vehicle-common" . }} + {{ include "common" . }} {{- if eq .apiversion "3" }} soc: source: http @@ -45,4 +45,4 @@ render: | uri: https://app.evnotify.de/extended?akey={{ urlEncode .akey }}&token={{ urlEncode .token }} jq: .charging {{- end }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/util/templates/includes/vehicle-features.tpl b/templates/definition/vehicle/features.tpl similarity index 95% rename from util/templates/includes/vehicle-features.tpl rename to templates/definition/vehicle/features.tpl index f7deac5b5..7324a1b53 100644 --- a/util/templates/includes/vehicle-features.tpl +++ b/templates/definition/vehicle/features.tpl @@ -1,4 +1,4 @@ -{{ define "vehicle-features" }} +{{ define "features" }} {{- if or .basefeatures (eq .coarsecurrent "true") (eq .welcomecharge "true") (eq .streaming "true") (eq .climaterdisabled "true") (eq .autodetectdisabled "true") (eq .wakeupdisabled "true") }} features: {{- range .basefeatures }} diff --git a/templates/definition/vehicle/fiat.yaml b/templates/definition/vehicle/fiat.yaml index b1db92d85..d633ee235 100644 --- a/templates/definition/vehicle/fiat.yaml +++ b/templates/definition/vehicle/fiat.yaml @@ -13,8 +13,8 @@ params: - preset: vehicle-features render: | type: fiat - {{ include "vehicle-base" . }} + {{ include "base" . }} {{- if .pin }} pin: {{ .pin }} # mandatory to wake up, deep refresh Soc & start/stop charge {{- end }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/flobz.yaml b/templates/definition/vehicle/flobz.yaml index ebeb35bd7..98cc720e5 100644 --- a/templates/definition/vehicle/flobz.yaml +++ b/templates/definition/vehicle/flobz.yaml @@ -29,7 +29,7 @@ params: advanced: true render: | type: custom - {{- include "vehicle-common" . }} + {{- include "common" . }} soc: {{- include "source" . | indent 2 }} jq: .energy[0].level @@ -73,4 +73,4 @@ render: | uri: {{ trimSuffix "/" .url }}/get_vehicleinfo/{{ .vin }}?from_cache=1 {{- end }} {{- end }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/ford-connect-query.yaml b/templates/definition/vehicle/ford-connect-query.yaml index bb0944d88..1bb2c4f87 100644 --- a/templates/definition/vehicle/ford-connect-query.yaml +++ b/templates/definition/vehicle/ford-connect-query.yaml @@ -39,6 +39,6 @@ render: | id: {{ .clientid }} secret: {{ .clientsecret }} redirecturi: {{ .redirecturi }} - {{ include "vehicle-common" . }} + {{ include "common" . }} cache: {{ .cache }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/ford-connect.yaml b/templates/definition/vehicle/ford-connect.yaml index 96fa6dc58..5451716fe 100644 --- a/templates/definition/vehicle/ford-connect.yaml +++ b/templates/definition/vehicle/ford-connect.yaml @@ -36,6 +36,6 @@ render: | tokens: access: {{ .accessToken }} refresh: {{ .refreshToken }} - {{ include "vehicle-common" . }} + {{ include "common" . }} cache: {{ .cache }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/genesis.yaml b/templates/definition/vehicle/genesis.yaml index 84df535a2..d61c21e18 100644 --- a/templates/definition/vehicle/genesis.yaml +++ b/templates/definition/vehicle/genesis.yaml @@ -15,6 +15,6 @@ params: - preset: vehicle-language render: | type: genesis - {{ include "vehicle-base" . }} - {{ include "vehicle-language" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "language" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/homeassistant.yaml b/templates/definition/vehicle/homeassistant.yaml index 00be34be4..191c079da 100644 --- a/templates/definition/vehicle/homeassistant.yaml +++ b/templates/definition/vehicle/homeassistant.yaml @@ -158,8 +158,8 @@ params: default: true render: | type: homeassistant - {{ include "vehicle-common" . }} - {{ include "vehicle-features" . }} + {{ include "common" . }} + {{ include "features" . }} uri: {{ .uri }} home: {{ .home }} # deprecated insecure: {{ .insecure }} diff --git a/templates/definition/vehicle/hyundai-us.yaml b/templates/definition/vehicle/hyundai-us.yaml index f17e1bc6a..0ec72746c 100644 --- a/templates/definition/vehicle/hyundai-us.yaml +++ b/templates/definition/vehicle/hyundai-us.yaml @@ -13,6 +13,6 @@ params: de: Wird von Bluelink (US) benötigt, um Fernkommandos zu autorisieren. render: | type: hyundai-us - {{ include "vehicle-base" . }} + {{ include "base" . }} pin: {{ quote .pin }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/hyundai.yaml b/templates/definition/vehicle/hyundai.yaml index a7240d6a6..fc40a78b9 100644 --- a/templates/definition/vehicle/hyundai.yaml +++ b/templates/definition/vehicle/hyundai.yaml @@ -26,6 +26,6 @@ params: render: | type: hyundai region: {{ .region }} - {{ include "vehicle-base" . }} - {{ include "vehicle-language" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "language" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/ioBroker.bmw.yaml b/templates/definition/vehicle/ioBroker.bmw.yaml index caed183b7..233b66508 100644 --- a/templates/definition/vehicle/ioBroker.bmw.yaml +++ b/templates/definition/vehicle/ioBroker.bmw.yaml @@ -34,7 +34,7 @@ params: default: true render: | type: custom - {{ include "vehicle-common" . }} + {{ include "common" . }} soc: source: http uri: {{ .uri }}/getPlainValue/bmw.{{ .id }}.{{ .vin }}.stream.vehicle.drivetrain.batteryManagement.header.value?noStringify @@ -65,4 +65,4 @@ render: | source: http uri: {{ .uri }}/getPlainValue/bmw.{{ .id }}.{{ .vin }}.stream.vehicle.drivetrain.electricEngine.charging.timeRemaining.value?noStringify jq: if (. == null) or (. == 0) or (type != "number") or (. < 0) then null else (now + (. * 60) | strftime("%Y-%m-%dT%H:%M:%SZ")) end - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/iso15118.yaml b/templates/definition/vehicle/iso15118.yaml index 3e44b5e06..6a148489f 100644 --- a/templates/definition/vehicle/iso15118.yaml +++ b/templates/definition/vehicle/iso15118.yaml @@ -24,8 +24,8 @@ params: deprecated: true render: | type: custom - {{ include "vehicle-common" . }} - {{ include "vehicle-features" (merge (dict "basefeatures" (list "offline")) .) }} + {{ include "common" . }} + {{ include "features" (merge (dict "basefeatures" (list "offline")) .) }} soc: source: const value: 0 diff --git a/templates/definition/vehicle/jaguar-landrover.yaml b/templates/definition/vehicle/jaguar-landrover.yaml index 6097ec09b..0692b5638 100644 --- a/templates/definition/vehicle/jaguar-landrover.yaml +++ b/templates/definition/vehicle/jaguar-landrover.yaml @@ -8,5 +8,5 @@ params: - preset: vehicle-online render: | type: jaguar - {{ include "vehicle-base" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/kia.yaml b/templates/definition/vehicle/kia.yaml index 0571afba2..3b6bc5f00 100644 --- a/templates/definition/vehicle/kia.yaml +++ b/templates/definition/vehicle/kia.yaml @@ -19,6 +19,6 @@ params: - preset: vehicle-language render: | type: kia - {{ include "vehicle-base" . }} - {{ include "vehicle-language" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "language" . }} + {{ include "features" . }} diff --git a/util/templates/includes/vehicle-language.tpl b/templates/definition/vehicle/language.tpl similarity index 53% rename from util/templates/includes/vehicle-language.tpl rename to templates/definition/vehicle/language.tpl index 03f37104d..260b2b194 100644 --- a/util/templates/includes/vehicle-language.tpl +++ b/templates/definition/vehicle/language.tpl @@ -1,3 +1,3 @@ -{{ define "vehicle-language" }} +{{ define "language" }} language: {{ .language }} {{- end }} diff --git a/templates/definition/vehicle/lexus.yaml b/templates/definition/vehicle/lexus.yaml index 8549c29b2..d1d32a250 100644 --- a/templates/definition/vehicle/lexus.yaml +++ b/templates/definition/vehicle/lexus.yaml @@ -20,9 +20,9 @@ params: default: 15m render: | type: lexus - {{ include "vehicle-common" . }} + {{ include "common" . }} user: {{ .user }} password: {{ .password }} vin: {{ .vin }} cache: {{ .cache }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/mazda2mqtt.yaml b/templates/definition/vehicle/mazda2mqtt.yaml index a50323342..ad3305b9f 100644 --- a/templates/definition/vehicle/mazda2mqtt.yaml +++ b/templates/definition/vehicle/mazda2mqtt.yaml @@ -17,7 +17,7 @@ params: default: 720h render: | type: custom - {{- include "vehicle-common" . }} + {{- include "common" . }} soc: source: mqtt topic: mazda2mqtt/{{ .vin }}/chargeInfo/batteryLevelPercentage @@ -36,4 +36,4 @@ render: | source: mqtt topic: mazda2mqtt/{{ .vin }}/chargeInfo/drivingRangeKm timeout: {{ .timeout }} - {{ include "vehicle-features" (merge (dict "basefeatures" (list "streaming")) .) }} + {{ include "features" (merge (dict "basefeatures" (list "streaming")) .) }} diff --git a/templates/definition/vehicle/mercedes.yaml b/templates/definition/vehicle/mercedes.yaml index 68937632c..3eb57b007 100644 --- a/templates/definition/vehicle/mercedes.yaml +++ b/templates/definition/vehicle/mercedes.yaml @@ -33,5 +33,5 @@ render: | tokens: access: {{ .accessToken }} refresh: {{ .refreshToken }} - {{ include "vehicle-common" . }} - {{ include "vehicle-features" . }} + {{ include "common" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/mg.yaml b/templates/definition/vehicle/mg.yaml index f3b2bef54..b0e40a5e5 100644 --- a/templates/definition/vehicle/mg.yaml +++ b/templates/definition/vehicle/mg.yaml @@ -17,6 +17,6 @@ params: advanced: true render: | type: mg - {{ include "vehicle-base" . }} + {{ include "base" . }} region: {{ .region }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/mg2mqtt.yaml b/templates/definition/vehicle/mg2mqtt.yaml index 4ca66c9cb..e788d21f7 100644 --- a/templates/definition/vehicle/mg2mqtt.yaml +++ b/templates/definition/vehicle/mg2mqtt.yaml @@ -18,7 +18,7 @@ params: default: 1h render: | type: custom - {{- include "vehicle-common" . }} + {{- include "common" . }} soc: # battery soc (%) source: mqtt topic: saic/{{ .user }}/vehicles/{{ .vin }}/drivetrain/soc @@ -63,4 +63,4 @@ render: | source: mqtt topic: saic/{{ .user }}/vehicles/{{ .vin }}/refresh/mode/set timeout: {{ .timeout }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/mini.yaml b/templates/definition/vehicle/mini.yaml index 02e595ebf..bb70fb3d9 100644 --- a/templates/definition/vehicle/mini.yaml +++ b/templates/definition/vehicle/mini.yaml @@ -29,9 +29,9 @@ params: - preset: vehicle-features render: | type: mini - {{ include "vehicle-base" . }} + {{ include "base" . }} {{- if ne .region "EU" }} region: {{ .region }} {{- end }} hcaptcha: {{ .hcaptcha }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/mz2mqtt.yaml b/templates/definition/vehicle/mz2mqtt.yaml index e9c4d0a21..29a1c8b32 100644 --- a/templates/definition/vehicle/mz2mqtt.yaml +++ b/templates/definition/vehicle/mz2mqtt.yaml @@ -18,7 +18,7 @@ params: advanced: true render: | type: custom - {{- include "vehicle-common" . }} + {{- include "common" . }} soc: source: mqtt topic: mz2mqtt/{{ .vin }}/chargeInfo/batteryLevelPercentage @@ -37,4 +37,4 @@ render: | source: mqtt topic: mz2mqtt/{{ .vin }}/chargeInfo/drivingRangeKm timeout: {{ .timeout }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/nissan-ariya.yaml b/templates/definition/vehicle/nissan-ariya.yaml index b470d1623..53b57c786 100644 --- a/templates/definition/vehicle/nissan-ariya.yaml +++ b/templates/definition/vehicle/nissan-ariya.yaml @@ -22,6 +22,6 @@ params: render: | type: nissan version: v2 - {{ include "vehicle-base" . }} + {{ include "base" . }} expiry: {{ .expiry }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/nissan.yaml b/templates/definition/vehicle/nissan.yaml index df93545b9..ad06f7a61 100644 --- a/templates/definition/vehicle/nissan.yaml +++ b/templates/definition/vehicle/nissan.yaml @@ -8,5 +8,5 @@ params: - preset: vehicle-online render: | type: nissan - {{ include "vehicle-base" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/niu-e-scooter.yaml b/templates/definition/vehicle/niu-e-scooter.yaml index fdd3059aa..d3230a633 100644 --- a/templates/definition/vehicle/niu-e-scooter.yaml +++ b/templates/definition/vehicle/niu-e-scooter.yaml @@ -32,4 +32,4 @@ render: | password: {{ .password }} # NIU app password serial: {{ .serial }} # NIU E-Scooter serial number like shown in app capacity: {{ .capacity }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/octopus-de.yaml b/templates/definition/vehicle/octopus-de.yaml index 5e4d45242..d333731e8 100644 --- a/templates/definition/vehicle/octopus-de.yaml +++ b/templates/definition/vehicle/octopus-de.yaml @@ -44,10 +44,10 @@ params: default: 15m render: | type: octopus-de - {{- include "vehicle-common" . }} + {{- include "common" . }} email: {{ .email }} password: {{ .password }} accountnumber: {{ .accountnumber }} device: {{ .device }} cache: {{ .cache }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/octopus-it.yaml b/templates/definition/vehicle/octopus-it.yaml index 41394184c..c9bc30a47 100644 --- a/templates/definition/vehicle/octopus-it.yaml +++ b/templates/definition/vehicle/octopus-it.yaml @@ -44,10 +44,10 @@ params: default: 15m render: | type: octopus-it - {{- include "vehicle-common" . }} + {{- include "common" . }} email: {{ .email }} password: {{ .password }} accountnumber: {{ .accountnumber }} device: {{ .device }} cache: {{ .cache }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/offline.yaml b/templates/definition/vehicle/offline.yaml index 6437c90e2..c4ce259ec 100644 --- a/templates/definition/vehicle/offline.yaml +++ b/templates/definition/vehicle/offline.yaml @@ -18,8 +18,8 @@ params: deprecated: true render: | type: custom - {{- include "vehicle-common" . }} - {{ include "vehicle-features" (merge (dict "basefeatures" (list "offline")) .) }} + {{- include "common" . }} + {{ include "features" (merge (dict "basefeatures" (list "offline")) .) }} soc: source: const value: 0 diff --git a/templates/definition/vehicle/opel.yaml b/templates/definition/vehicle/opel.yaml index 405d76bc9..74751a541 100644 --- a/templates/definition/vehicle/opel.yaml +++ b/templates/definition/vehicle/opel.yaml @@ -29,6 +29,6 @@ render: | tokens: access: {{ .accessToken }} refresh: {{ .refreshToken }} - {{ include "vehicle-common" . }} + {{ include "common" . }} cache: {{ .cache }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/outlanderphev.yaml b/templates/definition/vehicle/outlanderphev.yaml index 0deae5558..c6403295d 100644 --- a/templates/definition/vehicle/outlanderphev.yaml +++ b/templates/definition/vehicle/outlanderphev.yaml @@ -15,7 +15,7 @@ params: advanced: true render: | type: custom - {{- include "vehicle-common" . }} + {{- include "common" . }} soc: source: mqtt topic: phev/battery/level @@ -38,4 +38,4 @@ render: | topic: phev/climate/status timeout: {{ .timeout }} jq: (. != "off") - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/ovms.yaml b/templates/definition/vehicle/ovms.yaml index 37de9a0d3..88891771d 100644 --- a/templates/definition/vehicle/ovms.yaml +++ b/templates/definition/vehicle/ovms.yaml @@ -28,10 +28,10 @@ params: default: 15m render: | type: ovms - {{- include "vehicle-common" . }} + {{- include "common" . }} user: {{ .user }} password: {{ .password }} vehicleid: {{ .vehicleid }} server: {{ .server }} cache: {{ .cache }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/peugeot.yaml b/templates/definition/vehicle/peugeot.yaml index d88bfb319..989c27e07 100644 --- a/templates/definition/vehicle/peugeot.yaml +++ b/templates/definition/vehicle/peugeot.yaml @@ -29,6 +29,6 @@ render: | tokens: access: {{ .accessToken }} refresh: {{ .refreshToken }} - {{ include "vehicle-common" . }} + {{ include "common" . }} cache: {{ .cache }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/polestar.yaml b/templates/definition/vehicle/polestar.yaml index 5d906ca53..3d246bd06 100644 --- a/templates/definition/vehicle/polestar.yaml +++ b/templates/definition/vehicle/polestar.yaml @@ -10,5 +10,5 @@ params: example: LPSVS... render: | type: polestar-grpc - {{ include "vehicle-base" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/porsche.yaml b/templates/definition/vehicle/porsche.yaml index a71b44582..bd28f3168 100644 --- a/templates/definition/vehicle/porsche.yaml +++ b/templates/definition/vehicle/porsche.yaml @@ -7,5 +7,5 @@ params: - preset: vehicle-online render: | type: porsche - {{ include "vehicle-base" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/renault.yaml b/templates/definition/vehicle/renault.yaml index d3f103d53..9eb52d1f6 100644 --- a/templates/definition/vehicle/renault.yaml +++ b/templates/definition/vehicle/renault.yaml @@ -27,6 +27,6 @@ params: advanced: true render: | type: renault - {{ include "vehicle-base" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "features" . }} wakeupmode: {{ .wakeupmode }} diff --git a/templates/definition/vehicle/seat-cupra.yaml b/templates/definition/vehicle/seat-cupra.yaml index b4df187f8..06fa4528a 100644 --- a/templates/definition/vehicle/seat-cupra.yaml +++ b/templates/definition/vehicle/seat-cupra.yaml @@ -35,5 +35,5 @@ params: render: | type: drivesomethinggreater brand: Cupra - {{ include "vehicle-base" . }} - {{ include "vehicle-features" (merge (dict "basefeatures" (list "streaming")) .) }} + {{ include "base" . }} + {{ include "features" (merge (dict "basefeatures" (list "streaming")) .) }} diff --git a/templates/definition/vehicle/seat.yaml b/templates/definition/vehicle/seat.yaml index 539140f29..b448698ab 100644 --- a/templates/definition/vehicle/seat.yaml +++ b/templates/definition/vehicle/seat.yaml @@ -37,5 +37,5 @@ params: render: | type: drivesomethinggreater brand: Seat - {{ include "vehicle-base" . }} - {{ include "vehicle-features" (merge (dict "basefeatures" (list "streaming")) .) }} + {{ include "base" . }} + {{ include "features" (merge (dict "basefeatures" (list "streaming")) .) }} diff --git a/templates/definition/vehicle/skoda.yaml b/templates/definition/vehicle/skoda.yaml index 6b7ea1df3..0f8571ce1 100644 --- a/templates/definition/vehicle/skoda.yaml +++ b/templates/definition/vehicle/skoda.yaml @@ -12,6 +12,6 @@ params: - name: timeout render: | type: skoda - {{ include "vehicle-base" . }} + {{ include "base" . }} timeout: {{ .timeout }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/smart-hello.yaml b/templates/definition/vehicle/smart-hello.yaml index ac9c56365..d0627b247 100644 --- a/templates/definition/vehicle/smart-hello.yaml +++ b/templates/definition/vehicle/smart-hello.yaml @@ -8,5 +8,5 @@ params: - preset: vehicle-features render: | type: smart-hello - {{ include "vehicle-base" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/smart.yaml b/templates/definition/vehicle/smart.yaml index 8e6bfecf6..7c1c71b28 100644 --- a/templates/definition/vehicle/smart.yaml +++ b/templates/definition/vehicle/smart.yaml @@ -35,5 +35,5 @@ render: | tokens: access: {{ .accessToken }} refresh: {{ .refreshToken }} - {{ include "vehicle-common" . }} - {{ include "vehicle-features" . }} + {{ include "common" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/subaru.yaml b/templates/definition/vehicle/subaru.yaml index c8b8de379..aa9b9590c 100644 --- a/templates/definition/vehicle/subaru.yaml +++ b/templates/definition/vehicle/subaru.yaml @@ -12,5 +12,5 @@ params: example: JF... render: | type: subaru - {{ include "vehicle-base" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/tesla-ble.yaml b/templates/definition/vehicle/tesla-ble.yaml index 705fdcbca..11c64c607 100644 --- a/templates/definition/vehicle/tesla-ble.yaml +++ b/templates/definition/vehicle/tesla-ble.yaml @@ -31,7 +31,7 @@ params: default: 30s render: | type: custom - {{- include "vehicle-common" . }} + {{- include "common" . }} chargeEnable: source: http uri: {{ .url }}:{{ .port }}/api/1/vehicles/{{ .vin }}/command/{{`{{ if .chargeenable }}charge_start{{ else }}charge_stop{{ end }}`}} @@ -86,4 +86,4 @@ render: | else "A" end) timeout: {{ .timeout }} cache: 1s - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/tesla.yaml b/templates/definition/vehicle/tesla.yaml index 2663b0ae0..435fda714 100644 --- a/templates/definition/vehicle/tesla.yaml +++ b/templates/definition/vehicle/tesla.yaml @@ -84,6 +84,6 @@ render: | refresh: {{ .refreshToken }} commandProxy: {{ .commandProxy }} proxyToken: {{ .proxyToken }} - {{ include "vehicle-common" . }} - {{ include "vehicle-features" (merge (dict "basefeatures" (list "coarsecurrent")) .) }} + {{ include "common" . }} + {{ include "features" (merge (dict "basefeatures" (list "coarsecurrent")) .) }} cache: {{ .cache }} diff --git a/templates/definition/vehicle/teslafi.yaml b/templates/definition/vehicle/teslafi.yaml index c10a6e045..f19afc6fb 100644 --- a/templates/definition/vehicle/teslafi.yaml +++ b/templates/definition/vehicle/teslafi.yaml @@ -16,7 +16,7 @@ params: advanced: true render: | type: custom - {{- include "vehicle-common" . }} + {{- include "common" . }} {{- define "teslafi_source" }} source: http uri: https://www.teslafi.com/feed.php?command=lastGood{{ if .vin }}&vin={{ .vin }}{{ end }} @@ -44,4 +44,4 @@ render: | limitsoc: {{- include "teslafi_source" . | indent 2 }} jq: .charge_limit_soc - {{ include "vehicle-features" (merge (dict "basefeatures" (list "coarsecurrent")) .) }} + {{ include "features" (merge (dict "basefeatures" (list "coarsecurrent")) .) }} diff --git a/templates/definition/vehicle/teslalogger.yaml b/templates/definition/vehicle/teslalogger.yaml index 6e2a85ab3..0be265f1d 100644 --- a/templates/definition/vehicle/teslalogger.yaml +++ b/templates/definition/vehicle/teslalogger.yaml @@ -22,7 +22,7 @@ params: default: 5000 render: | type: custom - {{- include "vehicle-common" . }} + {{- include "common" . }} soc: # battery soc (%) source: http uri: {{ .url }}:{{ .port }}/currentjson/{{ .id }} @@ -66,4 +66,4 @@ render: | maxcurrent: source: http uri: {{ .url }}:{{ .port }}/command/{{ .id }}/set_charging_amps?${maxcurrent} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/teslamate.yaml b/templates/definition/vehicle/teslamate.yaml index 2a680ab5c..825465d42 100644 --- a/templates/definition/vehicle/teslamate.yaml +++ b/templates/definition/vehicle/teslamate.yaml @@ -19,7 +19,7 @@ params: default: 720h # 30d render: | type: custom - {{- include "vehicle-common" . }} + {{- include "common" . }} soc: source: mqtt topic: teslamate/cars/{{ .id }}/usable_battery_level @@ -69,4 +69,4 @@ render: | source: mqtt topic: teslamate/cars/{{ .id }}/is_preconditioning timeout: {{ .timeout }} - {{ include "vehicle-features" (merge (dict "basefeatures" (list "coarsecurrent")) .) }} + {{ include "features" (merge (dict "basefeatures" (list "coarsecurrent")) .) }} diff --git a/templates/definition/vehicle/tessie.yaml b/templates/definition/vehicle/tessie.yaml index 1029846a6..5fb094915 100644 --- a/templates/definition/vehicle/tessie.yaml +++ b/templates/definition/vehicle/tessie.yaml @@ -22,7 +22,7 @@ params: required: true render: | type: custom - {{- include "vehicle-common" . }} + {{- include "common" . }} soc: # battery state of charge (%) source: http uri: https://api.tessie.com/{{ .vin }}/state?use_cache=true @@ -116,4 +116,4 @@ render: | headers: Authorization: Bearer {{ .token }} method: POST - {{ include "vehicle-features" (merge (dict "basefeatures" (list "coarsecurrent")) .) }} + {{ include "features" (merge (dict "basefeatures" (list "coarsecurrent")) .) }} diff --git a/templates/definition/vehicle/tibber.yaml b/templates/definition/vehicle/tibber.yaml index d3a089f83..e93b5d0c3 100644 --- a/templates/definition/vehicle/tibber.yaml +++ b/templates/definition/vehicle/tibber.yaml @@ -39,10 +39,10 @@ auth: params: [clientid, clientsecret, redirecturi] render: | type: tibber - {{- include "vehicle-common" . }} + {{- include "common" . }} clientid: {{ .clientid }} clientsecret: {{ .clientsecret }} redirecturi: {{ .redirecturi }} vin: {{ .vin }} cache: {{ .cache }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/toyota.yaml b/templates/definition/vehicle/toyota.yaml index eda7fe0e9..084fe0825 100644 --- a/templates/definition/vehicle/toyota.yaml +++ b/templates/definition/vehicle/toyota.yaml @@ -20,9 +20,9 @@ params: default: 15m render: | type: toyota - {{ include "vehicle-common" . }} + {{ include "common" . }} user: {{ .user }} password: {{ .password }} vin: {{ .vin }} cache: {{ .cache }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/tronity.yaml b/templates/definition/vehicle/tronity.yaml index c3efc0052..cdf1390ac 100644 --- a/templates/definition/vehicle/tronity.yaml +++ b/templates/definition/vehicle/tronity.yaml @@ -29,6 +29,6 @@ render: | credentials: id: {{ .clientid }} secret: {{ .clientsecret }} - {{ include "vehicle-common" . }} + {{ include "common" . }} cache: {{ .cache }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/volvo-connected.yaml b/templates/definition/vehicle/volvo-connected.yaml index cac6429c1..9ade34afc 100644 --- a/templates/definition/vehicle/volvo-connected.yaml +++ b/templates/definition/vehicle/volvo-connected.yaml @@ -64,5 +64,5 @@ render: | secret: {{ .clientSecret }} redirecturi: {{ .redirectUri }} vin: {{ .vin }} - {{ include "vehicle-common" . }} - {{ include "vehicle-features" . }} + {{ include "common" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/volvo2mqtt.yaml b/templates/definition/vehicle/volvo2mqtt.yaml index bbf79faed..55c900ebf 100644 --- a/templates/definition/vehicle/volvo2mqtt.yaml +++ b/templates/definition/vehicle/volvo2mqtt.yaml @@ -17,7 +17,7 @@ params: default: 720h render: | type: custom - {{- include "vehicle-common" . }} + {{- include "common" . }} soc: source: mqtt topic: homeassistant/sensor/{{ .vin }}_battery_charge_level/state @@ -26,4 +26,4 @@ render: | source: mqtt topic: homeassistant/sensor/{{ .vin }}_electric_range/state timeout: {{ .timeout }} - {{ include "vehicle-features" . }} + {{ include "features" . }} diff --git a/templates/definition/vehicle/vw.yaml b/templates/definition/vehicle/vw.yaml index 31c5ead90..319984606 100644 --- a/templates/definition/vehicle/vw.yaml +++ b/templates/definition/vehicle/vw.yaml @@ -44,5 +44,5 @@ params: render: | type: drivesomethinggreater brand: Volkswagen - {{ include "vehicle-base" . }} - {{ include "vehicle-features" (merge (dict "basefeatures" (list "streaming")) .) }} + {{ include "base" . }} + {{ include "features" (merge (dict "basefeatures" (list "streaming")) .) }} diff --git a/templates/definition/vehicle/zero.yaml b/templates/definition/vehicle/zero.yaml index 00010b7f1..081ef832c 100644 --- a/templates/definition/vehicle/zero.yaml +++ b/templates/definition/vehicle/zero.yaml @@ -6,5 +6,5 @@ params: - preset: vehicle-online render: | type: zero - {{ include "vehicle-base" . }} - {{ include "vehicle-features" . }} + {{ include "base" . }} + {{ include "features" . }} diff --git a/util/templates/formatvalue_test.go b/util/templates/formatvalue_test.go index 0e0c34493..2d9da377d 100644 --- a/util/templates/formatvalue_test.go +++ b/util/templates/formatvalue_test.go @@ -31,7 +31,7 @@ func TestRequiredLargeNumber(t *testing.T) { Params: []Param{{Name: "serial", Type: TypeInt, Required: true}}, } - _, _, err := tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err := tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "serial": float64(3493601102), }) assert.NoError(t, err, "large serial supplied as JSON number") diff --git a/util/templates/init.go b/util/templates/init.go index 5e9cc3165..132f7847f 100644 --- a/util/templates/init.go +++ b/util/templates/init.go @@ -15,6 +15,9 @@ import ( "go.yaml.in/yaml/v4" ) +// IncludeExt is the file extension of class-local, include-only templates +const IncludeExt = ".tpl" + var ( //go:embed includes/*.tpl includeFS embed.FS @@ -22,6 +25,9 @@ var ( // baseTmpl holds all included template definitions baseTmpl *template.Template + // classTmpl holds baseTmpl plus the class-local include definitions + classTmpl = make(map[Class]*template.Template) + templates = make(map[Class][]Template) ConfigDefaults configDefaults mu sync.Mutex @@ -31,13 +37,35 @@ var ( func init() { ConfigDefaults.Load() - baseTmpl = template.Must(FuncMap(template.New("base")).ParseFS(includeFS, "includes/*.tpl")) + // the root template is replaced by the rendered template's body, so its name + // must not collide with an include name (`$` cannot appear in a file name) + baseTmpl = template.Must(FuncMap(template.New("$root")).ParseFS(includeFS, "includes/*.tpl")) for _, class := range []Class{Charger, Meter, Vehicle, Tariff, Messenger, Circuit, Hems} { + if err := loadIncludes(definition.TemplateIncludes, class); err != nil { + panic(err) + } load(class) } } +// loadIncludes parses the class-local include-only templates +func loadIncludes(fsys fs.FS, class Class) error { + files, err := fs.Glob(fsys, class.String()+"/*"+IncludeExt) + if err != nil || len(files) == 0 { + return err + } + + tmpl, err := FuncMap(template.Must(baseTmpl.Clone())).ParseFS(fsys, files...) + if err != nil { + return fmt.Errorf("processing %s includes failed: %w", class, err) + } + + classTmpl[class] = tmpl + + return nil +} + // Register adds a template file to the registry func Register(class Class, filepath string) error { b, err := os.ReadFile(filepath) diff --git a/util/templates/init_test.go b/util/templates/init_test.go new file mode 100644 index 000000000..cc1bc24f0 --- /dev/null +++ b/util/templates/init_test.go @@ -0,0 +1,36 @@ +package templates + +import ( + "testing" + "testing/fstest" + + "github.com/stretchr/testify/require" +) + +func TestClassLocalIncludes(t *testing.T) { + fsys := fstest.MapFS{ + "loadpoint/local" + IncludeExt: &fstest.MapFile{ + Data: []byte(`{{ define "local" }}power: {{ .foo }}{{ end }}`), + }, + } + + require.NoError(t, loadIncludes(fsys, Loadpoint)) + require.Contains(t, classTmpl, Loadpoint) + + // class without include files + require.NoError(t, loadIncludes(fsys, Circuit)) + require.NotContains(t, classTmpl, Circuit) + + tmpl := Template{ + Params: []Param{{Name: "foo", Default: "bar"}}, + Render: "type: custom\n{{ include \"local\" . }}", + } + + b, _, err := tmpl.RenderResult(Loadpoint, RenderModeInstance, map[string]any{}) + require.NoError(t, err) + require.Equal(t, "type: custom\npower: bar", string(b)) + + // class-local includes are not visible to other classes + _, _, err = tmpl.RenderResult(Circuit, RenderModeInstance, map[string]any{}) + require.Error(t, err) +} diff --git a/util/templates/render_instance.go b/util/templates/render_instance.go index ebde89e58..28f0379b6 100644 --- a/util/templates/render_instance.go +++ b/util/templates/render_instance.go @@ -31,7 +31,7 @@ func RenderInstance(class Class, other map[string]any) (*Instance, error) { return nil, err } - b, _, err := tmpl.RenderResult(RenderModeInstance, other) + b, _, err := tmpl.RenderResult(class, RenderModeInstance, other) if err != nil { return nil, util.NewConfigError(err) } diff --git a/util/templates/render_testing.go b/util/templates/render_testing.go index e43452a6d..ceeb4c365 100644 --- a/util/templates/render_testing.go +++ b/util/templates/render_testing.go @@ -13,10 +13,10 @@ import ( ) // test renders and instantiates plus yaml-parses the template per usage -func test(t *testing.T, tmpl Template, values map[string]any, cb func(values map[string]any)) { +func test(t *testing.T, class Class, tmpl Template, values map[string]any, cb func(values map[string]any)) { t.Helper() - b, _, err := tmpl.RenderResult(RenderModeInstance, values) + b, _, err := tmpl.RenderResult(class, RenderModeInstance, values) if err != nil { t.Log(string(b)) t.Error(err) @@ -108,7 +108,7 @@ func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values t.Run(tmpl.Template, func(t *testing.T) { t.Parallel() - test(t, tmpl, values, func(values map[string]any) { + test(t, class, tmpl, values, func(values map[string]any) { instantiate(t, values) }) }) @@ -125,7 +125,7 @@ func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values t.Run(tmpl.Template+"/"+u, func(t *testing.T) { t.Parallel() - test(t, tmpl, usageValues, func(values map[string]any) { + test(t, class, tmpl, usageValues, func(values map[string]any) { instantiate(t, values) }) }) diff --git a/util/templates/template.go b/util/templates/template.go index 57b04b377..19a6eb2fe 100644 --- a/util/templates/template.go +++ b/util/templates/template.go @@ -325,7 +325,7 @@ func formatValue(val any) string { } // RenderResult renders the result template to instantiate the proxy -func (t *Template) RenderResult(renderMode int, other map[string]any) ([]byte, map[string]any, error) { +func (t *Template) RenderResult(class Class, renderMode int, other map[string]any) ([]byte, map[string]any, error) { values := t.Defaults(renderMode) if err := mergeMaps(other, values); err != nil { return nil, values, err @@ -422,7 +422,13 @@ func (t *Template) RenderResult(renderMode int, other map[string]any) ([]byte, m } } - tmpl, err := FuncMap(template.Must(baseTmpl.Clone())).Parse(t.Render) + // class-local includes take precedence over the global ones + base, ok := classTmpl[class] + if !ok { + base = baseTmpl + } + + tmpl, err := FuncMap(template.Must(base.Clone())).Parse(t.Render) if err != nil { return nil, res, err } diff --git a/util/templates/template_modbus_test.go b/util/templates/template_modbus_test.go index 3c446f4a2..c6374f388 100644 --- a/util/templates/template_modbus_test.go +++ b/util/templates/template_modbus_test.go @@ -22,7 +22,7 @@ func TestModbusTemplateDefaultID(t *testing.T) { tmpl, err := ByName(Charger, "phoenix-ev-eth") require.NoError(t, err) - _, values, err := tmpl.RenderResult(mode, map[string]any{ + _, values, err := tmpl.RenderResult(Meter, mode, map[string]any{ "host": "192.168.0.8", "port": 502, }) @@ -40,7 +40,7 @@ func TestModbusTemplateUserIDOverridesTemplate(t *testing.T) { tmpl, err := ByName(Charger, "phoenix-ev-eth") require.NoError(t, err) - _, values, err := tmpl.RenderResult(mode, map[string]any{ + _, values, err := tmpl.RenderResult(Meter, mode, map[string]any{ "host": "192.168.0.8", "port": 502, "id": 42, @@ -62,7 +62,7 @@ func TestWallbeTemplateCoveredByPhoenix(t *testing.T) { require.NoError(t, err) assert.Equal(t, "phoenix-ev-eth", tmpl.Template) - _, values, err := tmpl.RenderResult(RenderModeInstance, map[string]any{ + _, values, err := tmpl.RenderResult(Meter, RenderModeInstance, map[string]any{ "host": "192.168.0.8", "port": 502, }) diff --git a/util/templates/template_test.go b/util/templates/template_test.go index 8c3172280..95d968932 100644 --- a/util/templates/template_test.go +++ b/util/templates/template_test.go @@ -42,22 +42,22 @@ func TestRequiredString(t *testing.T) { }, } - _, _, err := tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err := tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "Param": "foo", }) assert.NoError(t, err, "test: required present") - _, _, err = tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err = tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "Param": "", }) assert.Error(t, err, "test: required present but empty") - _, _, err = tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err = tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "Param": nil, }) assert.Error(t, err, "test: required present but nil") - _, _, err = tmpl.RenderResult(RenderModeDocs, map[string]any{ + _, _, err = tmpl.RenderResult(Meter, RenderModeDocs, map[string]any{ "Param": nil, }) assert.NoError(t, err, "docs: required present but nil") @@ -74,27 +74,27 @@ func TestRequiredNumber(t *testing.T) { }, } - _, _, err := tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err := tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "Param": "1", }) assert.NoError(t, err, "test: required present") - _, _, err = tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err = tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "Param": "", }) assert.Error(t, err, "test: required present but empty") - _, _, err = tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err = tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "Param": "0", }) assert.Error(t, err, "test: required present but zero value") - _, _, err = tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err = tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "Param": nil, }) assert.Error(t, err, "test: required present but nil") - _, _, err = tmpl.RenderResult(RenderModeDocs, map[string]any{ + _, _, err = tmpl.RenderResult(Meter, RenderModeDocs, map[string]any{ "Param": nil, }) assert.NoError(t, err, "docs: required present but nil") @@ -111,22 +111,22 @@ func TestRequiredDeprecated(t *testing.T) { }, } - _, _, err := tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err := tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "Param": "foo", }) assert.NoError(t, err, "test: required present") - _, _, err = tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err = tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "Param": "", }) assert.NoError(t, err, "test: required present but empty") - _, _, err = tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err = tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "Param": nil, }) assert.NoError(t, err, "test: required present but nil") - _, _, err = tmpl.RenderResult(RenderModeDocs, map[string]any{ + _, _, err = tmpl.RenderResult(Meter, RenderModeDocs, map[string]any{ "Param": nil, }) assert.NoError(t, err, "docs: required present but nil") @@ -146,25 +146,25 @@ func TestRequiredPerUsage(t *testing.T) { }, } - _, _, err := tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err := tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "Param": nil, "Usage": nil, }) require.NoError(t, err) - _, _, err = tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err = tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "Param": nil, "Usage": "pv", }) require.NoError(t, err) - _, _, err = tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err = tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "Param": nil, "Usage": "battery", }) require.Error(t, err) - _, _, err = tmpl.RenderResult(RenderModeUnitTest, map[string]any{ + _, _, err = tmpl.RenderResult(Meter, RenderModeUnitTest, map[string]any{ "Param": "foo", "Usage": "battery", }) @@ -190,7 +190,7 @@ func TestValidatePattern(t *testing.T) { for _, tt := range tests { t.Run(tt.host, func(t *testing.T) { - _, _, err := tmpl.RenderResult(RenderModeInstance, map[string]any{"host": tt.host}) + _, _, err := tmpl.RenderResult(Meter, RenderModeInstance, map[string]any{"host": tt.host}) if tt.valid { require.NoError(t, err) } else { diff --git a/vehicle/template_test.go b/vehicle/template_test.go index 116657406..6461ec989 100644 --- a/vehicle/template_test.go +++ b/vehicle/template_test.go @@ -43,7 +43,7 @@ func TestTemplates(t *testing.T) { }) } -// onlineVehicleFeatures render via the shared vehicle-features include, so a +// onlineVehicleFeatures render via the shared vehicle features include, so a // stored config may carry them; dropping the param breaks reload (discussion #31291). var onlineVehicleFeatures = []string{"streaming", "coarsecurrent", "welcomecharge", "climaterdisabled", "autodetectdisabled", "wakeupdisabled"} @@ -60,7 +60,7 @@ var requiredFeatureParams = map[string][]string{ func TestVehicleFeatureParamsConsistent(t *testing.T) { for _, tmpl := range templates.ByClass(templates.Vehicle, templates.WithDeprecated()) { - if !strings.Contains(tmpl.Render, "vehicle-features") { + if !strings.Contains(tmpl.Render, `include "features"`) { continue } @@ -77,7 +77,7 @@ func TestVehicleFeatureParamsConsistent(t *testing.T) { values["template"] = tmpl.Template values[feat] = true - if _, _, err := tmpl.RenderResult(templates.RenderModeInstance, values); err != nil { + if _, _, err := tmpl.RenderResult(templates.Vehicle, templates.RenderModeInstance, values); err != nil { t.Errorf("%s: feature %q must stay a declared param: %v", tmpl.Template, feat, err) } }