Plugins: trace xml transformations (#8879)
This commit is contained in:
parent
8f96c96003
commit
a0dfabb229
5 changed files with 16 additions and 7 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ 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"
|
||||
|
|
@ -16,6 +17,7 @@ import (
|
|||
)
|
||||
|
||||
type Pipeline struct {
|
||||
log *util.Logger
|
||||
re *regexp.Regexp
|
||||
jq *gojq.Query
|
||||
dflt string
|
||||
|
|
@ -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 != "" {
|
||||
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue