plannerActive checks if the charging plan has a currently active slot
()
| 120 | |
| 121 | // plannerActive checks if the charging plan has a currently active slot |
| 122 | func (lp *Loadpoint) plannerActive() (active bool) { |
| 123 | defer func() { |
| 124 | lp.setPlanActive(active) |
| 125 | }() |
| 126 | |
| 127 | var plan api.Rates |
| 128 | var planStart, planEnd time.Time |
| 129 | var planOverrun time.Duration |
| 130 | |
| 131 | defer func() { |
| 132 | lp.publish(keys.Plan, plan) |
| 133 | lp.publish(keys.PlanProjectedStart, planStart) |
| 134 | lp.publish(keys.PlanProjectedEnd, planEnd) |
| 135 | lp.publish(keys.PlanOverrun, planOverrun) |
| 136 | }() |
| 137 | |
| 138 | // re-check since plannerActive() is called before connected() check in Update() |
| 139 | if !lp.connected() { |
| 140 | return false |
| 141 | } |
| 142 | |
| 143 | planTime := lp.EffectivePlanTime() |
| 144 | if planTime.IsZero() { |
| 145 | lp.log.DEBUG.Println("!! plan: plan time zero") |
| 146 | return false |
| 147 | } |
| 148 | |
| 149 | // keep overrunning plans as long as a vehicle is connected |
| 150 | if lp.clock.Until(planTime) < 0 && (!lp.planActive || !lp.connected()) { |
| 151 | lp.log.DEBUG.Println("plan: deleting expired plan") |
| 152 | lp.finishPlan() |
| 153 | return false |
| 154 | } |
| 155 | |
| 156 | goal, isSocBased := lp.GetPlanGoal() |
| 157 | maxPower := lp.EffectiveMaxPower() |
| 158 | requiredDuration := lp.GetPlanRequiredDuration(goal, maxPower) |
| 159 | if requiredDuration <= 0 { |
| 160 | // continue a 100% plan as long as the vehicle is connected |
| 161 | if lp.planActive && isSocBased && goal == 100 { |
| 162 | return true |
| 163 | } |
| 164 | lp.log.DEBUG.Println("!! plan: required duration 0") |
| 165 | |
| 166 | lp.finishPlan() |
| 167 | return false |
| 168 | } |
| 169 | |
| 170 | strategy := lp.getEffectivePlanStrategy() |
| 171 | |
| 172 | plan = lp.GetPlan(planTime, requiredDuration, strategy.Precondition, strategy.Continuous) |
| 173 | if plan == nil { |
| 174 | lp.log.DEBUG.Println("!! plan: plan nil") |
| 175 | return false |
| 176 | } |
| 177 | |
| 178 | var overrun string |
| 179 | if excessDuration := requiredDuration - lp.clock.Until(planTime); excessDuration > 0 { |
no test coverage detected