Config UI: dynamic default values, remove static HA instance default (#25525)

This commit is contained in:
andig 2025-11-25 14:38:23 +01:00 • committed by GitHub
parent 4fbd4c01a0
commit 65fce6e6b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 200 additions and 9 deletions

39
util/demo/service.go Normal file
View file

@ -0,0 +1,39 @@
package demo
import (
"encoding/json"
"net/http"
"github.com/evcc-io/evcc/server/service"
)
func init() {
mux := http.NewServeMux()
mux.HandleFunc("GET /single", getSingle)
mux.HandleFunc("GET /country", getCountry)
mux.HandleFunc("GET /{country}/city", getCity)
service.Register("demo", mux)
}
func getSingle(w http.ResponseWriter, req *http.Request) {
json.NewEncoder(w).Encode([]string{"demo-value"})
}
func getCountry(w http.ResponseWriter, req *http.Request) {
json.NewEncoder(w).Encode([]string{"germany", "france", "spain"})
}
func getCity(w http.ResponseWriter, req *http.Request) {
country := req.PathValue("country")
var cities []string
switch country {
case "germany":
cities = []string{"berlin", "munich", "hamburg"}
case "france":
cities = []string{"paris", "lyon", "marseille"}
case "spain":
cities = []string{"madrid", "barcelona", "valencia"}
}
json.NewEncoder(w).Encode(cities)
}