Skip to content

Commit

Permalink
Vzlogger: fix yaml quoting not matching uuid (evcc-io#10777)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Nov 14, 2023
1 parent e9ab1ed commit 2022247
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion templates/definition/meter/volkszaehler-ws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ render: |
power: # power reading
source: ws # use websocket plugin
uri: ws://{{ .host }}:{{ .port }}/socket
jq: .data | select(.uuid=="{{ .uuid }}") .tuples[0][1] # parse response json
jq: .data | select(.uuid=={{ quote (trimAll "'" .uuid) }}) .tuples[0][1] # parse response json
timeout: 30s
scale: 1
2 changes: 1 addition & 1 deletion templates/definition/meter/vzlogger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ render: |
power: # power reading
source: http # use http plugin
uri: http://{{ .host }}:{{ .port }}/
jq: .data[] | select(.uuid=="{{ .uuid }}") | .tuples[0][1] # parse response json
jq: .data[] | select(.uuid=={{ quote (trimAll "'" .uuid) }}) | .tuples[0][1] # parse response json
{{- if .scale }}
scale: {{ .scale }}
{{- end }}
10 changes: 5 additions & 5 deletions util/templates/render_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ type Instance struct {
}

// RenderInstance renders an actual configuration instance
func RenderInstance(class Class, other map[string]interface{}) (Instance, error) {
func RenderInstance(class Class, other map[string]interface{}) (*Instance, error) {
var cc struct {
Template string
Other map[string]interface{} `mapstructure:",remain"`
}

if err := util.DecodeOther(other, &cc); err != nil {
return *new(Instance), err
return nil, err
}

tmpl, err := ByName(class, cc.Template)
if err != nil {
return *new(Instance), err
return nil, err
}

b, _, err := tmpl.RenderResult(TemplateRenderModeInstance, other)
if err != nil {
return *new(Instance), err
return nil, err
}

var instance Instance
if err = yaml.Unmarshal(b, &instance); err == nil && instance.Type == "" {
err = errors.New("empty instance type- check for missing usage")
}

return instance, err
return &instance, err
}
2 changes: 2 additions & 0 deletions util/templates/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ func (t *Template) RenderResult(renderMode string, other map[string]interface{})
out = p.Name
}

// TODO move yamlQuote to explicit quoting in templates, see https://github.com/evcc-io/evcc/issues/10742

switch typed := val.(type) {
case []interface{}:
var list []string
Expand Down

0 comments on commit 2022247

Please sign in to comment.