Charger: add expection handling for status E (#8460)
This commit is contained in:
parent
1ec690c6a8
commit
d4cfa052bd
3 changed files with 11 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ func (wb *Alfen) Status() (api.ChargeStatus, error) {
|
|||
|
||||
switch r := rune(b[0]); r {
|
||||
case 'A', 'B', 'D', 'E', 'F':
|
||||
return api.ChargeStatusString(string(r))
|
||||
return api.ChargeStatusStringWithMapping(string(r), map[api.ChargeStatus]api.ChargeStatus{api.StatusE: api.StatusA})
|
||||
case 'C':
|
||||
// C1 is "connected"
|
||||
if rune(b[1]) == '1' {
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ func (wb *Innogy) Status() (api.ChargeStatus, error) {
|
|||
|
||||
switch r := rune(b[0]); r {
|
||||
case 'A', 'B', 'D', 'E', 'F':
|
||||
return api.ChargeStatusString(string(r))
|
||||
return api.ChargeStatusStringWithMapping(string(r), map[api.ChargeStatus]api.ChargeStatus{api.StatusE: api.StatusA})
|
||||
case 'C':
|
||||
// C1 is "connected"
|
||||
if rune(b[1]) == '1' {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue