Skip to content

Commit

Permalink
chore: remove empty param keys like for util.Flusher from message pipe (
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Feb 25, 2023
1 parent 0efce70 commit 742b2be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
9 changes: 5 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
13 changes: 4 additions & 9 deletions util/pipe/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit 742b2be

Please sign in to comment.