Fix charger rater/timer logic for vehicle reconnect
This commit is contained in:
parent
041d165cc2
commit
de909b5fb1
3 changed files with 13 additions and 4 deletions
|
|
@ -40,7 +40,6 @@ func (cr *ChargeRater) StartCharge(continued bool) {
|
|||
defer cr.Unlock()
|
||||
|
||||
// time is needed if MeterEnergy is not supported
|
||||
cr.charging = true
|
||||
cr.start = cr.clck.Now()
|
||||
|
||||
// get end energy amount
|
||||
|
|
@ -53,7 +52,9 @@ func (cr *ChargeRater) StartCharge(continued bool) {
|
|||
}
|
||||
}
|
||||
|
||||
if !continued {
|
||||
if continued {
|
||||
cr.charging = true
|
||||
} else {
|
||||
cr.chargedEnergy = 0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,13 @@ func TestNoMeter(t *testing.T) {
|
|||
cr.clck = clck
|
||||
|
||||
cr.StartCharge(false)
|
||||
clck.Add(time.Hour)
|
||||
|
||||
if f, err := cr.ChargedEnergy(); f != 0 || err != nil {
|
||||
t.Errorf("energy: %.1f %v", f, err)
|
||||
}
|
||||
|
||||
cr.StartCharge(true)
|
||||
|
||||
// 1kWh
|
||||
clck.Add(time.Hour)
|
||||
|
|
|
|||
|
|
@ -30,10 +30,11 @@ func (m *ChargeTimer) StartCharge(continued bool) {
|
|||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
m.charging = true
|
||||
m.start = m.clck.Now()
|
||||
|
||||
if !continued {
|
||||
if continued {
|
||||
m.charging = true
|
||||
} else {
|
||||
m.duration = 0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue