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

Function staticPlanPreviewHandler

server/http_loadpoint_handler.go:56–103  ·  view source on GitHub ↗

staticPlanPreviewHandler returns a plan preview for given parameters

(lp loadpoint.API)

Source from the content-addressed store, hash-verified

54
55// staticPlanPreviewHandler returns a plan preview for given parameters
56func staticPlanPreviewHandler(lp loadpoint.API) http.HandlerFunc {
57 return func(w http.ResponseWriter, r *http.Request) {
58 vars := mux.Vars(r)
59
60 planTime, err := time.ParseInLocation(time.RFC3339, vars["time"], nil)
61 if err != nil {
62 jsonError(w, http.StatusBadRequest, err)
63 return
64 }
65
66 goal, err := strconv.ParseFloat(vars["value"], 64)
67 if err != nil {
68 jsonError(w, http.StatusBadRequest, err)
69 return
70 }
71
72 switch typ := vars["type"]; typ {
73 case "soc":
74 if !lp.SocBasedPlanning() {
75 jsonError(w, http.StatusBadRequest, errors.New("soc planning only available for vehicles with known soc and capacity"))
76 return
77 }
78 case "energy":
79 if lp.SocBasedPlanning() {
80 jsonError(w, http.StatusBadRequest, errors.New("energy planning not available for vehicles with known soc and capacity"))
81 return
82 }
83 default:
84 jsonError(w, http.StatusBadRequest, fmt.Errorf("invalid plan type: %s", typ))
85 return
86 }
87
88 maxPower := lp.EffectiveMaxPower()
89 requiredDuration := lp.GetPlanRequiredDuration(goal, maxPower)
90 strategy := lp.EffectivePlanStrategy()
91
92 plan := lp.GetPlan(planTime, requiredDuration, strategy.Precondition, strategy.Continuous)
93
94 res := PlanPreviewResponse{
95 PlanTime: planTime,
96 Duration: int64(requiredDuration.Seconds()),
97 Plan: plan,
98 Power: maxPower,
99 }
100
101 jsonWrite(w, res)
102 }
103}
104
105// planEnergyHandler updates plan energy and time
106func planEnergyHandler(lp loadpoint.API) http.HandlerFunc {

Callers 1

RegisterSiteHandlersMethod · 0.85

Calls 9

jsonErrorFunction · 0.70
jsonWriteFunction · 0.70
SocBasedPlanningMethod · 0.65
NewMethod · 0.65
EffectiveMaxPowerMethod · 0.65
EffectivePlanStrategyMethod · 0.65
GetPlanMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected