diff --git a/cmd/root.go b/cmd/root.go index 51ae32f43..b2bb2f9c2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -37,7 +37,8 @@ var ( log = util.NewLogger("main") cfgFile string - ignoreErrors = []string{"warn", "error"} // don't add to cache + ignoreEmpty = "" // ignore empty keys + ignoreErrors = []string{"warn", "error"} // ignore errors ignoreMqtt = []string{"auth", "releaseNotes"} // excessive size may crash certain brokers ) @@ -152,7 +153,7 @@ func runRoot(cmd *cobra.Command, args []string) { } // publish to UI - go socketHub.Run(tee.Attach(), cache) + go socketHub.Run(pipe.NewDropper(ignoreEmpty).Pipe(tee.Attach()), cache) // setup values channel valueChan := make(chan util.Param) @@ -192,13 +193,13 @@ func runRoot(cmd *cobra.Command, args []string) { // setup database if err == nil && conf.Influx.URL != "" { - configureInflux(conf.Influx, site, tee.Attach()) + configureInflux(conf.Influx, site, pipe.NewDropper(append(ignoreErrors, ignoreEmpty)...).Pipe(tee.Attach())) } // setup mqtt publisher if err == nil && conf.Mqtt.Broker != "" { publisher := server.NewMQTT(strings.Trim(conf.Mqtt.Topic, "/")) - go publisher.Run(site, pipe.NewDropper(ignoreMqtt...).Pipe(tee.Attach())) + go publisher.Run(site, pipe.NewDropper(append(ignoreMqtt, ignoreEmpty)...).Pipe(tee.Attach())) } // announce on mDNS diff --git a/util/pipe/limiter.go b/util/pipe/limiter.go index cc5d2a44a..8b8772cdf 100644 --- a/util/pipe/limiter.go +++ b/util/pipe/limiter.go @@ -5,6 +5,7 @@ import ( "github.com/benbjohnson/clock" "github.com/evcc-io/evcc/util" + "golang.org/x/exp/slices" ) // Piper is the interface that data flow plugins must implement @@ -113,17 +114,11 @@ func NewDropper(filter ...string) Piper { func (l *Dropper) pipe(in <-chan util.Param, out chan<- util.Param) { for p := range in { - var remove bool - for _, filtered := range l.filter { - if p.Key == filtered { - remove = true - break - } + if slices.Contains(l.filter, p.Key) { + continue } - if !remove { - out <- p - } + out <- p } }