MCPcopy Create free account
hub / github.com/evcc-io/evcc / plannerActive

Method plannerActive

core/loadpoint_plan.go:122–243  ·  view source on GitHub ↗

plannerActive checks if the charging plan has a currently active slot

()

Source from the content-addressed store, hash-verified

120
121// plannerActive checks if the charging plan has a currently active slot
122func (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 {

Callers 1

UpdateMethod · 0.95

Calls 15

setPlanActiveMethod · 0.95
publishMethod · 0.95
connectedMethod · 0.95
EffectivePlanTimeMethod · 0.95
finishPlanMethod · 0.95
GetPlanGoalMethod · 0.95
EffectiveMaxPowerMethod · 0.95
GetPlanMethod · 0.95
pushEventMethod · 0.95
lockPlanGoalMethod · 0.95

Tested by

no test coverage detected