Ocpp: always use measurement timestamp (#15643)

This commit is contained in:
andig 2024-08-24 13:37:07 +02:00 • committed by GitHub
parent e622e6706e
commit 26fae8dd60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -61,12 +61,17 @@ func (conn *Connector) MeterValues(request *core.MeterValuesRequest) (*core.Mete
}
for _, meterValue := range sortByAge(request.MeterValue) {
if meterValue.Timestamp == nil {
// this should be done before the sorting, but lets assume either all or no sample has a timestamp
meterValue.Timestamp = types.NewDateTime(conn.clock.Now())
}
// ignore old meter value requests
if !meterValue.Timestamp.Time.Before(conn.meterUpdated) {
for _, sample := range meterValue.SampledValue {
sample.Value = strings.TrimSpace(sample.Value)
conn.measurements[getSampleKey(sample)] = sample
conn.meterUpdated = conn.clock.Now()
conn.meterUpdated = meterValue.Timestamp.Time
}
}
}