Planner: always publish current plan (#10667)

This commit is contained in:
andig 2023-11-05 17:30:36 +01:00 • committed by GitHub
parent 613c9c6e76
commit f90f4ed4c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 6 deletions

View file

@ -606,6 +606,13 @@ func (lp *Loadpoint) Prepare(uiChan chan<- util.Param, pushChan chan<- push.Even
lp.publish(chargerIcon, nil)
}
// vehicle
lp.publish(vehiclePresent, false)
lp.publish(vehicleTitle, "")
lp.publish(vehicleIcon, "")
lp.publish(vehicleCapacity, 0.0)
lp.publish(vehicleOdometer, 0.0)
// assign and publish default vehicle
if lp.defaultVehicle != nil {
lp.setActiveVehicle(lp.defaultVehicle)
@ -1561,6 +1568,9 @@ func (lp *Loadpoint) Update(sitePower float64, autoCharge, batteryBuffered, batt
mode := lp.GetMode()
lp.publish("mode", mode)
// update and publish plan without being short-circuited by modes etc.
plannerActive := lp.plannerActive()
// execute loading strategy
switch {
case !lp.connected():
@ -1591,7 +1601,7 @@ func (lp *Loadpoint) Update(sitePower float64, autoCharge, batteryBuffered, batt
err = lp.fastCharging()
// minimum or target charging
case lp.minSocNotReached() || lp.plannerActive():
case lp.minSocNotReached() || plannerActive:
err = lp.fastCharging()
lp.resetPhaseTimer()
lp.elapsePVTimer() // let PV mode disable immediately afterwards

View file

@ -72,8 +72,12 @@ func (lp *Loadpoint) plannerActive() (active bool) {
lp.setPlanActive(active)
}()
maxPower := lp.GetMaxPower()
var planStart time.Time
defer func() {
lp.publish(planProjectedStart, planStart)
}()
maxPower := lp.GetMaxPower()
requiredDuration, plan, err := lp.GetPlan(lp.GetTargetTime(), maxPower)
if err != nil {
lp.log.ERROR.Println("planner:", err)
@ -85,14 +89,12 @@ func (lp *Loadpoint) plannerActive() (active bool) {
return false
}
planStart := planner.Start(plan)
lp.publish(planProjectedStart, planStart)
var requiredString string
if req := requiredDuration.Round(time.Second); req > planner.Duration(plan).Round(time.Second) {
requiredString = fmt.Sprintf(" (required: %v)", req)
}
planStart = planner.Start(plan)
lp.log.DEBUG.Printf("plan: charge %v%s starting at %v until %v (power: %.0fW, avg cost: %.3f)",
planner.Duration(plan).Round(time.Second), requiredString, planStart.Round(time.Second).Local(), lp.targetTime.Round(time.Second).Local(),
maxPower, planner.AverageCost(plan))

View file

@ -162,7 +162,7 @@ func (lp *Loadpoint) setActiveVehicle(vehicle api.Vehicle) {
lp.publish(vehiclePresent, false)
lp.publish(vehicleTitle, "")
lp.publish(vehicleIcon, "")
lp.publish(vehicleCapacity, int64(0))
lp.publish(vehicleCapacity, 0.0)
lp.publish(vehicleOdometer, 0.0)
}