Config UI: add loadpoints (BC) (#18137)

This commit is contained in:
Michael Geers 2025-01-31 12:26:23 +01:00 • committed by GitHub
parent d7fcdf663f
commit 864c2cf599
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
92 changed files with 4643 additions and 1116 deletions

View file

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
@ -33,11 +34,17 @@ func devicesConfig[T any](class templates.Class, h config.Handler[T]) ([]map[str
return res, nil
}
// devicesHandler returns a device configurations by class
func devicesHandler(w http.ResponseWriter, r *http.Request) {
// devicesConfigHandler returns a device configurations by class
func devicesConfigHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
class, err := templates.ClassString(vars["class"])
// TODO exclude loadpoints here
if err == nil && class == templates.Loadpoint {
err = fmt.Errorf("invalid class %s", class)
}
if err != nil {
jsonError(w, http.StatusBadRequest, err)
return
@ -142,6 +149,8 @@ func deviceConfigHandler(w http.ResponseWriter, r *http.Request) {
return
}
// TODO return application/yaml content type if type != template
jsonResult(w, res)
}
@ -202,7 +211,7 @@ func newDevice[T any](class templates.Class, req map[string]any, newFromConf new
return nil, err
}
return &conf, h.Add(config.NewConfigurableDevice[T](conf, instance))
return &conf, h.Add(config.NewConfigurableDevice[T](&conf, instance))
}
// newDeviceHandler creates a new device by class
@ -215,6 +224,8 @@ func newDeviceHandler(w http.ResponseWriter, r *http.Request) {
return
}
// TODO add application/yaml content type, reject type==template
var req map[string]any
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
jsonError(w, http.StatusBadRequest, err)
@ -288,6 +299,8 @@ func updateDeviceHandler(w http.ResponseWriter, r *http.Request) {
return
}
// TODO add application/yaml content type, reject type==template
var req map[string]any
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
jsonError(w, http.StatusBadRequest, err)