Charger: add expection handling for status E (#8460)

This commit is contained in:
andig 2023-06-15 12:19:19 +02:00 • committed by GitHub
parent 1ec690c6a8
commit d4cfa052bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View file

@ -54,6 +54,15 @@ func ChargeStatusString(s string) (ChargeStatus, error) {
}
}
// ChargeStatusStringWithMapping converts a string to ChargeStatus. In case of error, mapping is applied.
func ChargeStatusStringWithMapping(s string, m map[ChargeStatus]ChargeStatus) (ChargeStatus, error) {
status, err := ChargeStatusString(s)
if mappedStatus, ok := m[status]; ok && err != nil {
return mappedStatus, nil
}
return status, err
}
// String implements Stringer
func (c ChargeStatus) String() string {
return string(c)