Loadpoint: replace empty session energy round trip with meter values (#22279)
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
This commit is contained in:
parent
d379dd9d19
commit
d85f2610e0
2 changed files with 9 additions and 4 deletions
|
|
@ -68,12 +68,17 @@ func (lp *Loadpoint) stopSession() {
|
|||
}
|
||||
|
||||
s.Finished = lp.clock.Now()
|
||||
|
||||
// record meter stop
|
||||
if meterStop := lp.chargeMeterTotal(); meterStop > 0 {
|
||||
s.MeterStop = &meterStop
|
||||
}
|
||||
|
||||
if chargedEnergy := lp.GetChargedEnergy() / 1e3; chargedEnergy > s.ChargedEnergy {
|
||||
lp.energyMetrics.Update(chargedEnergy)
|
||||
if s.MeterStart != nil {
|
||||
// use meter stop to override charged energy, but prevent negative values
|
||||
if chargedEnergy := *s.MeterStop - *s.MeterStart; chargedEnergy > max(0, s.ChargedEnergy) {
|
||||
lp.energyMetrics.Update(chargedEnergy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s.SolarPercentage = lo.ToPtr(lp.energyMetrics.SolarPercentage())
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ func TestResetHeatingSession(t *testing.T) {
|
|||
assert.Equal(t, clock.Now(), lp.session.Created)
|
||||
|
||||
clock.Add(36 * time.Hour)
|
||||
me.EXPECT().TotalEnergy().Return(1.0, nil).MaxTimes(2)
|
||||
me.EXPECT().TotalEnergy().Return(1.0, nil).Times(2)
|
||||
|
||||
lp.resetHeatingSession()
|
||||
require.NotNil(t, lp.session)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue