Forecast.Solar: fix horizon quoting

This commit is contained in:
andig 2025-02-28 10:29:07 +01:00
parent 598a105f64
commit b4db9e8e04
2 changed files with 6 additions and 1 deletions

View file

@ -66,7 +66,7 @@ render: |
tariff: solar
forecast:
source: http
uri: https://api.forecast.solar/{{ if .apikey }}{{ .apikey }}/{{ end }}estimate/{{ .lat }}/{{ .lon }}/{{ .dec }}/{{ .az }}/{{ .kwp }}?time=utc&full=1&resolution=60{{ if .horizon }}&horizon={{ .horizon }}{{ end }}
uri: https://api.forecast.solar/{{ if .apikey }}{{ .apikey }}/{{ end }}estimate/{{ .lat }}/{{ .lon }}/{{ .dec }}/{{ .az }}/{{ .kwp }}?time=utc&full=1&resolution=60{{ if .horizon }}&horizon={{ unquote .horizon }}{{ end }}
jq: |
[ .result.watts | to_entries.[] | {
"start": (.key | strptime("%FT%T%z") | strftime("%FT%TZ")),

View file

@ -44,6 +44,10 @@ func trimLines(s string) string {
return strings.Join(lines, "\n")
}
func unquote(s string) string {
return strings.Trim(s, `"'`)
}
// FuncMap returns a sprig template.FuncMap with additional include function
func FuncMap(tmpl *template.Template) *template.Template {
funcMap := template.FuncMap{
@ -57,6 +61,7 @@ func FuncMap(tmpl *template.Template) *template.Template {
return buf.String(), nil
},
"urlEncode": url.QueryEscape,
"unquote": unquote,
}
return tmpl.Funcs(sprig.FuncMap()).Funcs(funcMap)