Loadpoint: add solar share setting (experimental)
This commit is contained in:
parent
62d3e7d151
commit
42eb940fe8
6 changed files with 68 additions and 5 deletions
|
|
@ -150,6 +150,15 @@ func intHandler(set func(int) error, get func() int) http.HandlerFunc {
|
|||
return handler(strconv.Atoi, set, get)
|
||||
}
|
||||
|
||||
// scaledIntHandler updates int-param api
|
||||
func scaledIntHandler(set func(float64) error, get func() float64, scale float64) http.HandlerFunc {
|
||||
return intHandler(func(v int) error {
|
||||
return set(float64(v) / scale)
|
||||
}, func() int {
|
||||
return int(get() * scale)
|
||||
})
|
||||
}
|
||||
|
||||
// boolHandler updates bool-param api
|
||||
func boolHandler(set func(bool) error, get func() bool) http.HandlerFunc {
|
||||
return handler(strconv.ParseBool, set, get)
|
||||
|
|
@ -191,6 +200,25 @@ func updateSmartCostLimit(site site.API) http.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
// updateSolarShare sets the solar share limit globally
|
||||
func updateSolarShare(site site.API) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
|
||||
val, err := strconv.Atoi(vars["value"])
|
||||
if err != nil {
|
||||
jsonError(w, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, lp := range site.Loadpoints() {
|
||||
lp.SetSolarShare(float64(val) / 100)
|
||||
}
|
||||
|
||||
jsonResult(w, val)
|
||||
}
|
||||
}
|
||||
|
||||
// stateHandler returns the combined state
|
||||
func stateHandler(cache *util.Cache) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue