Skip to content

Commit

Permalink
Ocpp: support ChargeAmps custom phase switching key (#16244)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Sep 20, 2024
1 parent 69f6bd1 commit 161c068
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
5 changes: 3 additions & 2 deletions charger/ocpp/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
KeyMaxChargingProfilesInstalled = "MaxChargingProfilesInstalled"

// Vendor specific keys
KeyAlfenPlugAndChargeIdentifier = "PlugAndChargeIdentifier"
KeyEvBoxSupportedMeasurands = "evb_SupportedMeasurands"
KeyAlfenPlugAndChargeIdentifier = "PlugAndChargeIdentifier"
KeyChargeAmpsPhaseSwitchingSupported = "ACPhaseSwitchingSupported"
KeyEvBoxSupportedMeasurands = "evb_SupportedMeasurands"
)
24 changes: 14 additions & 10 deletions charger/ocpp/cp_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,33 @@ func (cp *CP) Setup(meterValues string, meterInterval time.Duration) error {
continue
}

match := func(s string) bool {
return strings.EqualFold(opt.Key, s)
}

switch {
case strings.EqualFold(opt.Key, KeyChargeProfileMaxStackLevel):
case match(KeyChargeProfileMaxStackLevel):
if val, err := strconv.Atoi(*opt.Value); err == nil {
cp.StackLevel = val
}

case strings.EqualFold(opt.Key, KeyChargingScheduleAllowedChargingRateUnit):
case match(KeyChargingScheduleAllowedChargingRateUnit):
if *opt.Value == "Power" || *opt.Value == "W" { // "W" is not allowed by spec but used by some CPs
cp.ChargingRateUnit = types.ChargingRateUnitWatts
}

case strings.EqualFold(opt.Key, KeyConnectorSwitch3to1PhaseSupported):
case match(KeyConnectorSwitch3to1PhaseSupported) || match(KeyChargeAmpsPhaseSwitchingSupported):
var val bool
if val, err = strconv.ParseBool(*opt.Value); err == nil {
cp.PhaseSwitching = val
}

case strings.EqualFold(opt.Key, KeyMaxChargingProfilesInstalled):
case match(KeyMaxChargingProfilesInstalled):
if val, err := strconv.Atoi(*opt.Value); err == nil {
cp.ChargingProfileId = val
}

case strings.EqualFold(opt.Key, KeyMeterValuesSampledData):
case match(KeyMeterValuesSampledData):
if opt.Readonly {
meterValuesSampledDataMaxLength = 0
}
Expand All @@ -66,17 +70,17 @@ func (cp *CP) Setup(meterValues string, meterInterval time.Duration) error {
cp.meterValuesSample = *opt.Value
}

case strings.EqualFold(opt.Key, KeyMeterValuesSampledDataMaxLength):
case match(KeyMeterValuesSampledDataMaxLength):
if val, err := strconv.Atoi(*opt.Value); err == nil {
meterValuesSampledDataMaxLength = val
}

case strings.EqualFold(opt.Key, KeyNumberOfConnectors):
case match(KeyNumberOfConnectors):
if val, err := strconv.Atoi(*opt.Value); err == nil {
cp.NumberOfConnectors = val
}

case strings.EqualFold(opt.Key, KeySupportedFeatureProfiles):
case match(KeySupportedFeatureProfiles):
if !hasProperty(*opt.Value, smartcharging.ProfileName) {
cp.log.WARN.Printf("the required SmartCharging feature profile is not indicated as supported")
}
Expand All @@ -86,11 +90,11 @@ func (cp *CP) Setup(meterValues string, meterInterval time.Duration) error {
}

// vendor-specific keys
case strings.EqualFold(opt.Key, KeyAlfenPlugAndChargeIdentifier):
case match(KeyAlfenPlugAndChargeIdentifier):
cp.IdTag = *opt.Value
cp.log.DEBUG.Printf("overriding default `idTag` with Alfen-specific value: %s", cp.IdTag)

case strings.EqualFold(opt.Key, KeyEvBoxSupportedMeasurands):
case match(KeyEvBoxSupportedMeasurands):
if meterValues == "" {
meterValues = *opt.Value
}
Expand Down

1 comment on commit 161c068

@DavoBe16
Copy link

@DavoBe16 DavoBe16 commented on 161c068 Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manueller Wechsel 1P/3P funktioniert! Automatik auch, Min+PV lädt mit 1P 1.3kW, bei schnell wechselt er auf 3P 11kW, alles perfekt! Mit Sonne dann morgen ;-)

Please sign in to comment.