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

Function testConfigHandler

server/http_config_device_handler.go:709–781  ·  view source on GitHub ↗

testConfigHandler tests a configuration by class

(site site.API, authObject auth.Auth)

Source from the content-addressed store, hash-verified

707
708// testConfigHandler tests a configuration by class
709func testConfigHandler(site site.API, authObject auth.Auth) http.HandlerFunc {
710 return func(w http.ResponseWriter, r *http.Request) {
711 vars := mux.Vars(r)
712
713 class, err := templates.ClassString(vars["class"])
714 if err != nil {
715 jsonError(w, http.StatusBadRequest, err)
716 return
717 }
718
719 var id int
720 if vars["id"] != "" {
721 // test existing device with updated config
722 id, err = strconv.Atoi(vars["id"])
723 if err != nil {
724 jsonError(w, http.StatusBadRequest, err)
725 return
726 }
727 }
728
729 req, err := decodeDeviceConfig(r.Body)
730 if err != nil {
731 jsonError(w, http.StatusBadRequest, err)
732 return
733 }
734
735 if !requireCriticalConfigAuth(w, r, authObject, req) {
736 return
737 }
738
739 var instance any
740 ctx, cancel, done := startDeviceTimeout()
741
742 switch class {
743 case templates.Charger:
744 instance, err = testConfig(ctx, id, class, req, charger.NewFromConfig, config.Chargers())
745
746 case templates.Meter:
747 instance, err = testConfig(ctx, id, class, req, meter.NewFromConfig, config.Meters())
748
749 case templates.Vehicle:
750 instance, err = testConfig(ctx, id, class, req, vehicle.NewFromConfig, config.Vehicles())
751
752 case templates.Circuit:
753 instance, err = testConfig(ctx, id, class, req, circuit.NewFromConfig, config.Circuits())
754
755 case templates.Hems:
756 instance, err = testConfig(ctx, id, class, req, newHemsFactory(site), config.Hems())
757
758 case templates.Tariff:
759 instance, err = testConfig(ctx, id, class, req, tariff.NewFromConfig, config.Tariffs())
760
761 case templates.Messenger:
762 instance, err = testConfig(ctx, id, class, req, messenger.NewFromConfig, config.Messengers())
763 }
764
765 if err != nil {
766 cancel()

Callers 1

RegisterSystemHandlerMethod · 0.85

Calls 15

ClassStringFunction · 0.92
ChargersFunction · 0.92
MetersFunction · 0.92
VehiclesFunction · 0.92
CircuitsFunction · 0.92
HemsFunction · 0.92
TariffsFunction · 0.92
MessengersFunction · 0.92
decodeDeviceConfigFunction · 0.85
startDeviceTimeoutFunction · 0.85
testConfigFunction · 0.85

Tested by

no test coverage detected