planEnergyHandler updates plan energy and time
(lp loadpoint.API)
| 104 | |
| 105 | // planEnergyHandler updates plan energy and time |
| 106 | func 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 |
| 142 | func planRemoveHandler(lp loadpoint.API) http.HandlerFunc { |
no test coverage detected