Skip to content

Commit

Permalink
Plugins: trace xml transformations (#8879)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Jul 16, 2023
1 parent 8f96c96 commit a0dfabb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion provider/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewConstFromConfig(other map[string]interface{}) (Provider, error) {
return nil, err
}

pipe, err := pipeline.New(cc.Settings)
pipe, err := pipeline.New(nil, cc.Settings)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions provider/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ func NewHTTPProviderFromConfig(other map[string]interface{}) (Provider, error) {
return nil, err
}

log := util.NewLogger("http")
http := NewHTTP(
util.NewLogger("http"),
log,
cc.Method,
cc.URI,
cc.Insecure,
Expand All @@ -80,7 +81,7 @@ func NewHTTPProviderFromConfig(other map[string]interface{}) (Provider, error) {

if err == nil {
var pipe *pipeline.Pipeline
pipe, err = pipeline.New(cc.Settings)
pipe, err = pipeline.New(log, cc.Settings)
http = http.WithPipeline(pipe)
}

Expand Down
2 changes: 1 addition & 1 deletion provider/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewMqttFromConfig(other map[string]interface{}) (Provider, error) {
m = m.WithRetained()
}

pipe, err := pipeline.New(cc.Settings)
pipe, err := pipeline.New(log, cc.Settings)
if err == nil {
m = m.WithPipeline(pipe)
}
Expand Down
12 changes: 10 additions & 2 deletions provider/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import (

xj "github.com/basgys/goxml2json"
"github.com/evcc-io/evcc/provider/javascript"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/jq"
"github.com/itchyny/gojq"
"github.com/robertkrimen/otto"
"github.com/volkszaehler/mbmd/meters/rs485"
)

type Pipeline struct {
log *util.Logger
re *regexp.Regexp
jq *gojq.Query
dflt string
Expand All @@ -35,8 +37,10 @@ type Settings struct {
Script string
}

func New(cc Settings) (*Pipeline, error) {
p := new(Pipeline)
func New(log *util.Logger, cc Settings) (*Pipeline, error) {
p := &Pipeline{
log: log,
}

var err error
if err == nil && cc.Regex != "" {
Expand Down Expand Up @@ -137,6 +141,10 @@ func (p *Pipeline) transformXML(value []byte) []byte {
return value
}

if p.log != nil {
p.log.TRACE.Println(out.String())
}

return out.Bytes()
}

Expand Down
2 changes: 1 addition & 1 deletion provider/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func NewSocketProviderFromConfig(other map[string]interface{}) (Provider, error)
}

var err error
if p.pipeline, err = pipeline.New(cc.Settings); err != nil {
if p.pipeline, err = pipeline.New(log, cc.Settings); err != nil {
return nil, err
}

Expand Down

0 comments on commit a0dfabb

Please sign in to comment.