diff --git a/provider/pipeline/pipeline.go b/provider/pipeline/pipeline.go index b6145911a6..fd7fc68d73 100644 --- a/provider/pipeline/pipeline.go +++ b/provider/pipeline/pipeline.go @@ -17,25 +17,28 @@ import ( ) type Pipeline struct { - log *util.Logger - re *regexp.Regexp - jq *gojq.Query - dflt string - unpack string - decode string + log *util.Logger + re *regexp.Regexp + jq *gojq.Query + allowEmpty bool + dflt string + unpack string + decode string } type Settings struct { - Regex string - Default string - Jq string - Unpack string - Decode string + AllowEmpty bool + Regex string + Default string + Jq string + Unpack string + Decode string } func New(log *util.Logger, cc Settings) (*Pipeline, error) { p := &Pipeline{ - log: log, + log: log, + allowEmpty: cc.AllowEmpty, } var err error @@ -170,6 +173,10 @@ func (p *Pipeline) decodeValue(value []byte) (float64, error) { } func (p *Pipeline) Process(in []byte) ([]byte, error) { + if p.allowEmpty && len(bytes.TrimSpace(in)) == 0 { + return nil, nil + } + b := p.transformXML(in) if p.re != nil { @@ -184,10 +191,6 @@ func (p *Pipeline) Process(in []byte) ([]byte, error) { } if p.jq != nil { - // TODO make this optional - if len(bytes.TrimSpace(b)) == 0 { - return b, nil - } v, err := jq.Query(p.jq, b) if err != nil { return b, backoff.Permanent(err) diff --git a/templates/definition/tariff/nordpool.yaml b/templates/definition/tariff/nordpool.yaml index 12da668a0a..8145e877e8 100644 --- a/templates/definition/tariff/nordpool.yaml +++ b/templates/definition/tariff/nordpool.yaml @@ -53,6 +53,7 @@ render: | config: source: http uri: https://dataportal-api.nordpoolgroup.com/api/DayAheadPrices?market=DayAhead&date={{ `{{ now.Local | date "2006-01-02" }}` }}&deliveryArea={{ .region }}¤cy={{ .currency }} + allowempty: true jq: | .multiAreaEntries | [ .[] | @@ -67,6 +68,7 @@ render: | config: source: http uri: https://dataportal-api.nordpoolgroup.com/api/DayAheadPrices?market=DayAhead&date={{ `{{ addDate (now.Local) 0 0 1 | date "2006-01-02" }}` }}&deliveryArea={{ .region }}¤cy={{ .currency }} + allowempty: true jq: | .multiAreaEntries | [ .[] |