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

Method setLimit

core/loadpoint.go:927–1017  ·  view source on GitHub ↗

setLimit applies charger current limits and enables/disables accordingly

(current float64)

Source from the content-addressed store, hash-verified

925
926// setLimit applies charger current limits and enables/disables accordingly
927func (lp *Loadpoint) setLimit(current float64) error {
928 current = lp.roundedCurrent(current)
929
930 // apply circuit limits
931 if lp.circuit != nil {
932 var actualCurrent float64
933 if lp.chargeCurrents != nil {
934 actualCurrent = max(lp.chargeCurrents[0], lp.chargeCurrents[1], lp.chargeCurrents[2])
935 } else if lp.charging() {
936 actualCurrent = lp.offeredCurrent
937 }
938
939 currentLimit := lp.circuit.ValidateCurrent(actualCurrent, current)
940
941 activePhases := lp.ActivePhases()
942 powerLimit := lp.circuit.ValidatePower(lp.chargePower, currentToPower(current, activePhases))
943 currentLimitViaPower := powerToCurrent(powerLimit, activePhases)
944
945 current = lp.roundedCurrent(min(currentLimit, currentLimitViaPower))
946 }
947
948 // https://github.com/evcc-io/evcc/issues/16309
949 effMinCurrent := lp.effectiveMinCurrent()
950 if effMaxCurrent := lp.effectiveMaxCurrent(); effMinCurrent > effMaxCurrent {
951 return fmt.Errorf("invalid config: min current %.3gA exceeds max current %.3gA", effMinCurrent, effMaxCurrent)
952 }
953
954 // set current
955 if current != lp.offeredCurrent && current >= effMinCurrent {
956 var err error
957 if charger, ok := api.Cap[api.ChargerEx](lp.charger); ok {
958 err = charger.MaxCurrentMillis(current)
959 } else {
960 err = lp.charger.MaxCurrent(int64(current))
961 }
962
963 if err != nil {
964 v := lp.GetVehicle()
965 if vv, ok := api.Cap[api.Resurrector](v); ok && errors.Is(err, api.ErrAsleep) {
966 // https://github.com/evcc-io/evcc/issues/8254
967 // wakeup vehicle
968 lp.log.DEBUG.Printf("set charge current limit: waking up vehicle")
969 if err := vv.WakeUp(); err != nil {
970 return fmt.Errorf("wake-up vehicle: %w", err)
971 }
972 }
973
974 return fmt.Errorf("set charge current limit %.3gA: %w", current, err)
975 }
976
977 lp.log.DEBUG.Printf("set charge current limit: %.3gA", current)
978 lp.offeredCurrent = current
979 lp.bus.Publish(evChargeCurrent, current)
980 }
981
982 // set enabled/disabled
983 if enabled := current >= effMinCurrent; enabled != lp.enabled {
984 if err := lp.charger.Enable(enabled); err != nil {

Callers 5

PrepareMethod · 0.95
disableUnlessClimaterMethod · 0.95
fastChargingMethod · 0.95
minChargingMethod · 0.95
UpdateMethod · 0.95

Calls 15

roundedCurrentMethod · 0.95
chargingMethod · 0.95
ActivePhasesMethod · 0.95
effectiveMinCurrentMethod · 0.95
effectiveMaxCurrentMethod · 0.95
GetVehicleMethod · 0.95
setAndPublishEnabledMethod · 0.95
startWakeUpTimerMethod · 0.95
stopWakeUpTimerMethod · 0.95
currentToPowerFunction · 0.85
powerToCurrentFunction · 0.85
PrintfMethod · 0.80

Tested by

no test coverage detected