chore: remove empty param keys like for util.Flusher from message pipe (#6448)
Some checks failed
Release / call-build-workflow (push) Has been cancelled
Release / Publish Docker :release (push) Has been cancelled
Release / Github & APT (push) Has been cancelled
Release / Demo (push) Has been cancelled
Release / Hassio Addon (push) Has been cancelled

This commit is contained in:
andig 2023-02-25 20:55:36 +01:00 • committed by GitHub
parent 0efce70b8b
commit 742b2bea80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 13 deletions

View file

@ -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

View file

@ -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
}
}