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

Function planEnergyHandler

server/http_loadpoint_handler.go:106–139  ·  view source on GitHub ↗

planEnergyHandler updates plan energy and time

(lp loadpoint.API)

Source from the content-addressed store, hash-verified

104
105// planEnergyHandler updates plan energy and time
106func planEnergyHandler(lp loadpoint.API) http.HandlerFunc {
107 return func(w http.ResponseWriter, r *http.Request) {
108 vars := mux.Vars(r)
109
110 ts, err := time.ParseInLocation(time.RFC3339, vars["time"], nil)
111 if err != nil {
112 jsonError(w, http.StatusBadRequest, err)
113 return
114 }
115
116 val, err := strconv.ParseFloat(vars["value"], 64)
117 if err != nil {
118 jsonError(w, http.StatusBadRequest, err)
119 return
120 }
121
122 if err := lp.SetPlanEnergy(ts, val); err != nil {
123 jsonError(w, http.StatusBadRequest, err)
124 return
125 }
126
127 ts, energy := lp.GetPlanEnergy()
128
129 res := struct {
130 Energy float64 `json:"energy"`
131 Time time.Time `json:"time"`
132 }{
133 Energy: energy,
134 Time: ts,
135 }
136
137 jsonWrite(w, res)
138 }
139}
140
141// planRemoveHandler removes plan time
142func planRemoveHandler(lp loadpoint.API) http.HandlerFunc {

Callers 1

RegisterSiteHandlersMethod · 0.85

Calls 4

jsonErrorFunction · 0.70
jsonWriteFunction · 0.70
SetPlanEnergyMethod · 0.65
GetPlanEnergyMethod · 0.65

Tested by

no test coverage detected