planHandler returns the current plan
(lp loadpoint.API)
| 30 | |
| 31 | // planHandler returns the current plan |
| 32 | func planHandler(lp loadpoint.API) http.HandlerFunc { |
| 33 | return func(w http.ResponseWriter, r *http.Request) { |
| 34 | maxPower := lp.EffectiveMaxPower() |
| 35 | planTime := lp.EffectivePlanTime() |
| 36 | id := lp.EffectivePlanId() |
| 37 | |
| 38 | goal, _ := lp.GetPlanGoal() |
| 39 | requiredDuration := lp.GetPlanRequiredDuration(goal, maxPower) |
| 40 | strategy := lp.EffectivePlanStrategy() |
| 41 | plan := lp.GetPlan(planTime, requiredDuration, strategy.Precondition, strategy.Continuous) |
| 42 | |
| 43 | res := PlanResponse{ |
| 44 | PlanId: id, |
| 45 | PlanTime: planTime, |
| 46 | Duration: int64(requiredDuration.Seconds()), |
| 47 | Plan: plan, |
| 48 | Power: maxPower, |
| 49 | } |
| 50 | |
| 51 | jsonWrite(w, res) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // staticPlanPreviewHandler returns a plan preview for given parameters |
| 56 | func staticPlanPreviewHandler(lp loadpoint.API) http.HandlerFunc { |
no test coverage detected