Skip to content

Commit

Permalink
Ocpp: allow specifying measurements to remove (#16185)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Sep 20, 2024
1 parent 3d64200 commit 69f6bd1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion charger/ocpp/cp_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/lorenzodonini/ocpp-go/ocpp1.6/remotetrigger"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/smartcharging"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
"github.com/samber/lo"
)

const desiredMeasurands = "Power.Active.Import,Energy.Active.Import.Register,Current.Import,Voltage,Current.Offered,Power.Offered,SoC"
Expand Down Expand Up @@ -57,7 +58,13 @@ func (cp *CP) Setup(meterValues string, meterInterval time.Duration) error {
if opt.Readonly {
meterValuesSampledDataMaxLength = 0
}
cp.meterValuesSample = *opt.Value
if remove, ok := strings.CutPrefix(meterValues, "-"); ok {
// remove offending measurands
cp.meterValuesSample = strings.Join(lo.Without(strings.Split(*opt.Value, ","), strings.Split(remove, ",")...), ",")
meterValues = ""
} else {
cp.meterValuesSample = *opt.Value
}

case strings.EqualFold(opt.Key, KeyMeterValuesSampledDataMaxLength):
if val, err := strconv.Atoi(*opt.Value); err == nil {
Expand Down

0 comments on commit 69f6bd1

Please sign in to comment.