From e5f206dca3f520e16c56e4c5e6d9d9d6ff100703 Mon Sep 17 00:00:00 2001 From: Maschga Date: Fri, 20 Dec 2024 16:24:22 +0100 Subject: [PATCH 1/7] move log --- core/loadpoint_plan.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/loadpoint_plan.go b/core/loadpoint_plan.go index 319fcec288..0557284d8a 100644 --- a/core/loadpoint_plan.go +++ b/core/loadpoint_plan.go @@ -37,6 +37,7 @@ func (lp *Loadpoint) finishPlan() { } else if v := lp.GetVehicle(); v != nil { vehicle.Settings(lp.log, v).SetPlanSoc(time.Time{}, 0) } + lp.log.DEBUG.Println("plan: deleting expired plan") } // remainingPlanEnergy returns missing energy amount in kWh @@ -105,7 +106,6 @@ func (lp *Loadpoint) plannerActive() (active bool) { // keep overrunning plans as long as a vehicle is connected if lp.clock.Until(planTime) < 0 && (!lp.planActive || !lp.connected()) { - lp.log.DEBUG.Println("plan: deleting expired plan") lp.finishPlan() return false } From 611ad1cc05aa55ca3536c3d623679f91d7b04d90 Mon Sep 17 00:00:00 2001 From: Maschga Date: Fri, 20 Dec 2024 16:24:35 +0100 Subject: [PATCH 2/7] add planActiveTime and planActiveSoc --- core/loadpoint.go | 12 +++++++----- core/loadpoint_effective.go | 20 +++++++++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/core/loadpoint.go b/core/loadpoint.go index 906a4c39bf..1bf51a9982 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -159,11 +159,13 @@ type Loadpoint struct { socEstimator *soc.Estimator // charge planning - planner *planner.Planner - planTime time.Time // time goal - planEnergy float64 // Plan charge energy in kWh (dumb vehicles) - planSlotEnd time.Time // current plan slot end time - planActive bool // charge plan exists and has a currently active slot + planner *planner.Planner + planTime time.Time // time goal + planEnergy float64 // Plan charge energy in kWh (dumb vehicles) + planSlotEnd time.Time // current plan slot end time + planActive bool // charge plan exists and has a currently active slot + planActiveTime time.Time // needed to calculate the EffectivePlanTime + planActiveSoc int // needed to calculate the EffectivePlanSoc // cached state status api.ChargeStatus // Charger status diff --git a/core/loadpoint_effective.go b/core/loadpoint_effective.go index f2d8199361..cfb27d8a4a 100644 --- a/core/loadpoint_effective.go +++ b/core/loadpoint_effective.go @@ -76,7 +76,13 @@ func (lp *Loadpoint) nextVehiclePlan() (time.Time, int, int) { // EffectivePlanSoc returns the soc target for the current plan func (lp *Loadpoint) EffectivePlanSoc() int { + if lp.planActive { + return lp.planActiveSoc + } + _, soc, _ := lp.nextVehiclePlan() + lp.planActiveSoc = soc + return soc } @@ -95,12 +101,20 @@ func (lp *Loadpoint) EffectivePlanId() int { // EffectivePlanTime returns the effective plan time func (lp *Loadpoint) EffectivePlanTime() time.Time { + var ts time.Time + + if lp.planActive { + return lp.planActiveTime + } + if lp.socBasedPlanning() { - ts, _, _ := lp.nextVehiclePlan() - return ts + ts, _, _ = lp.nextVehiclePlan() + } else { + ts, _ = lp.GetPlanEnergy() } - ts, _ := lp.GetPlanEnergy() + lp.planActiveTime = ts + return ts } From 162abc033c6c3db32cbd7c3e4afb1fad2c48a8ee Mon Sep 17 00:00:00 2001 From: Maschga Date: Sat, 21 Dec 2024 19:24:06 +0100 Subject: [PATCH 3/7] run lint --- core/loadpoint.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/loadpoint.go b/core/loadpoint.go index 1bf51a9982..40168fc412 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -164,7 +164,7 @@ type Loadpoint struct { planEnergy float64 // Plan charge energy in kWh (dumb vehicles) planSlotEnd time.Time // current plan slot end time planActive bool // charge plan exists and has a currently active slot - planActiveTime time.Time // needed to calculate the EffectivePlanTime + planActiveTime time.Time // needed to calculate the EffectivePlanTime planActiveSoc int // needed to calculate the EffectivePlanSoc // cached state From c847c2620cabbe53028eb1a544a68cff264ad1e7 Mon Sep 17 00:00:00 2001 From: Maschga Date: Fri, 3 Jan 2025 13:55:49 +0100 Subject: [PATCH 4/7] add `planActiveSoc` --- core/loadpoint.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/loadpoint.go b/core/loadpoint.go index 40168fc412..d605e016e2 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -164,8 +164,8 @@ type Loadpoint struct { planEnergy float64 // Plan charge energy in kWh (dumb vehicles) planSlotEnd time.Time // current plan slot end time planActive bool // charge plan exists and has a currently active slot - planActiveTime time.Time // needed to calculate the EffectivePlanTime - planActiveSoc int // needed to calculate the EffectivePlanSoc + planActiveTime time.Time // needed to calculate the EffectivePlanTime if loading exceeds the target time + planActiveSoc float64 // needed to calculate the EffectivePlanSoc if loading exceeds the target time // cached state status api.ChargeStatus // Charger status From 5adc7f0fc44ce84e995ba230b5d8cf396cfb828a Mon Sep 17 00:00:00 2001 From: Maschga Date: Fri, 3 Jan 2025 13:56:55 +0100 Subject: [PATCH 5/7] set and return variables if required --- core/loadpoint_effective.go | 9 +++------ core/loadpoint_plan.go | 33 ++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/core/loadpoint_effective.go b/core/loadpoint_effective.go index cfb27d8a4a..c3abae69ee 100644 --- a/core/loadpoint_effective.go +++ b/core/loadpoint_effective.go @@ -77,11 +77,10 @@ func (lp *Loadpoint) nextVehiclePlan() (time.Time, int, int) { // EffectivePlanSoc returns the soc target for the current plan func (lp *Loadpoint) EffectivePlanSoc() int { if lp.planActive { - return lp.planActiveSoc + return int(lp.planActiveSoc) } _, soc, _ := lp.nextVehiclePlan() - lp.planActiveSoc = soc return soc } @@ -101,20 +100,18 @@ func (lp *Loadpoint) EffectivePlanId() int { // EffectivePlanTime returns the effective plan time func (lp *Loadpoint) EffectivePlanTime() time.Time { - var ts time.Time - if lp.planActive { return lp.planActiveTime } + var ts time.Time + if lp.socBasedPlanning() { ts, _, _ = lp.nextVehiclePlan() } else { ts, _ = lp.GetPlanEnergy() } - lp.planActiveTime = ts - return ts } diff --git a/core/loadpoint_plan.go b/core/loadpoint_plan.go index 0557284d8a..f1136f6fdf 100644 --- a/core/loadpoint_plan.go +++ b/core/loadpoint_plan.go @@ -21,6 +21,8 @@ const ( func (lp *Loadpoint) setPlanActive(active bool) { if !active { lp.planSlotEnd = time.Time{} + lp.planActiveTime = time.Time{} + lp.planActiveSoc = 0.0 } if lp.planActive != active { lp.planActive = active @@ -86,19 +88,8 @@ func (lp *Loadpoint) GetPlan(targetTime time.Time, requiredDuration time.Duratio // plannerActive checks if the charging plan has a currently active slot func (lp *Loadpoint) plannerActive() (active bool) { - defer func() { - lp.setPlanActive(active) - }() - var planStart, planEnd time.Time var planOverrun time.Duration - - defer func() { - lp.publish(keys.PlanProjectedStart, planStart) - lp.publish(keys.PlanProjectedEnd, planEnd) - lp.publish(keys.PlanOverrun, planOverrun) - }() - planTime := lp.EffectivePlanTime() if planTime.IsZero() { return false @@ -111,6 +102,22 @@ func (lp *Loadpoint) plannerActive() (active bool) { } goal, isSocBased := lp.GetPlanGoal() + + defer func() { + if active { + lp.planActiveTime = planTime + if isSocBased { + lp.planActiveSoc = goal + } + } + + lp.setPlanActive(active) + + lp.publish(keys.PlanProjectedStart, planStart) + lp.publish(keys.PlanProjectedEnd, planEnd) + lp.publish(keys.PlanOverrun, planOverrun) + }() + maxPower := lp.EffectiveMaxPower() requiredDuration := lp.GetPlanRequiredDuration(goal, maxPower) if requiredDuration <= 0 { @@ -157,8 +164,8 @@ func (lp *Loadpoint) plannerActive() (active bool) { } // remember last active plan's end time - lp.setPlanActive(true) lp.planSlotEnd = activeSlot.End + return true } else if lp.planActive { // planner was active (any slot, not necessarily previous slot) and charge goal has not yet been met switch { @@ -180,5 +187,5 @@ func (lp *Loadpoint) plannerActive() (active bool) { } } - return active + return false } From 06bece816a9c2faec8cf809102ac24797c24d6ce Mon Sep 17 00:00:00 2001 From: Maschga Date: Fri, 3 Jan 2025 14:05:33 +0100 Subject: [PATCH 6/7] use correct wording --- core/loadpoint.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/loadpoint.go b/core/loadpoint.go index d605e016e2..ca764f1ab6 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -164,8 +164,8 @@ type Loadpoint struct { planEnergy float64 // Plan charge energy in kWh (dumb vehicles) planSlotEnd time.Time // current plan slot end time planActive bool // charge plan exists and has a currently active slot - planActiveTime time.Time // needed to calculate the EffectivePlanTime if loading exceeds the target time - planActiveSoc float64 // needed to calculate the EffectivePlanSoc if loading exceeds the target time + planActiveTime time.Time // needed to calculate the EffectivePlanTime if charging exceeds the target time + planActiveSoc float64 // needed to calculate the EffectivePlanSoc if charging exceeds the target time // cached state status api.ChargeStatus // Charger status From 66b17fe9782aec671b921b917ec86f3458ba682c Mon Sep 17 00:00:00 2001 From: Maschga Date: Fri, 3 Jan 2025 14:29:46 +0100 Subject: [PATCH 7/7] move defer functions --- core/loadpoint_plan.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/core/loadpoint_plan.go b/core/loadpoint_plan.go index f1136f6fdf..dc574c88c6 100644 --- a/core/loadpoint_plan.go +++ b/core/loadpoint_plan.go @@ -88,8 +88,19 @@ func (lp *Loadpoint) GetPlan(targetTime time.Time, requiredDuration time.Duratio // plannerActive checks if the charging plan has a currently active slot func (lp *Loadpoint) plannerActive() (active bool) { + defer func() { + lp.setPlanActive(active) + }() + var planStart, planEnd time.Time var planOverrun time.Duration + + defer func() { + lp.publish(keys.PlanProjectedStart, planStart) + lp.publish(keys.PlanProjectedEnd, planEnd) + lp.publish(keys.PlanOverrun, planOverrun) + }() + planTime := lp.EffectivePlanTime() if planTime.IsZero() { return false @@ -110,12 +121,6 @@ func (lp *Loadpoint) plannerActive() (active bool) { lp.planActiveSoc = goal } } - - lp.setPlanActive(active) - - lp.publish(keys.PlanProjectedStart, planStart) - lp.publish(keys.PlanProjectedEnd, planEnd) - lp.publish(keys.PlanOverrun, planOverrun) }() maxPower := lp.EffectiveMaxPower()