Ocpp: allow specifying measurements to remove (#16185)

This commit is contained in:
andig 2024-09-20 17:07:45 +02:00 • committed by GitHub
parent 3d64200448
commit 69f6bd1a47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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