chore: handle invalid and error charger states (#8073)
This commit is contained in:
parent
5adacb06c3
commit
d3bd310634
13 changed files with 15 additions and 32 deletions
|
|
@ -44,11 +44,11 @@ const (
|
|||
|
||||
// ChargeStatusString converts a string to ChargeStatus
|
||||
func ChargeStatusString(s string) (ChargeStatus, error) {
|
||||
switch strings.ToUpper(s) {
|
||||
switch status := strings.ToUpper(s); status {
|
||||
case "A", "B", "C":
|
||||
return ChargeStatus(s), nil
|
||||
return ChargeStatus(status), nil
|
||||
case "D", "E", "F":
|
||||
return ChargeStatus(s), fmt.Errorf("invalid status: %s", s)
|
||||
return ChargeStatus(status), fmt.Errorf("invalid status: %s", status)
|
||||
default:
|
||||
return StatusNone, fmt.Errorf("invalid status: %s", s)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.ChargeStatus(r), nil
|
||||
return api.ChargeStatusString(string(r))
|
||||
case 'C':
|
||||
// C1 is "connected"
|
||||
if rune(b[1]) == '1' {
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ func (m *Charger) Status() (api.ChargeStatus, error) {
|
|||
return api.StatusNone, err
|
||||
}
|
||||
|
||||
return api.ChargeStatus(s), nil
|
||||
return api.ChargeStatusString(s)
|
||||
}
|
||||
|
||||
// Enabled implements the api.Charger interface
|
||||
|
|
|
|||
|
|
@ -151,13 +151,7 @@ func (wb *Salia) Status() (api.ChargeStatus, error) {
|
|||
if err != nil {
|
||||
return api.StatusNone, err
|
||||
}
|
||||
|
||||
switch s := res.Secc.Port0.Ci.Charge.Cp.Status; s {
|
||||
case "A", "B", "C":
|
||||
return api.ChargeStatus(s), nil
|
||||
default:
|
||||
return api.StatusNone, fmt.Errorf("invalid state: %s", s)
|
||||
}
|
||||
return api.ChargeStatusString(res.Secc.Port0.Ci.Charge.Cp.Status)
|
||||
}
|
||||
|
||||
// Enabled implements the api.Charger interface
|
||||
|
|
|
|||
|
|
@ -99,13 +99,7 @@ func (wb *Hesotec) Status() (api.ChargeStatus, error) {
|
|||
if err != nil {
|
||||
return api.StatusNone, err
|
||||
}
|
||||
|
||||
switch s := string(b[0]); s {
|
||||
case "A", "B", "C":
|
||||
return api.ChargeStatus(s), nil
|
||||
default:
|
||||
return api.StatusNone, fmt.Errorf("invalid status: %s", s)
|
||||
}
|
||||
return api.ChargeStatusString(string(b[0]))
|
||||
}
|
||||
|
||||
// Enabled implements the api.Charger interface
|
||||
|
|
|
|||
|
|
@ -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.ChargeStatus(r), nil
|
||||
return api.ChargeStatusString(string(r))
|
||||
case 'C':
|
||||
// C1 is "connected"
|
||||
if rune(b[1]) == '1' {
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ func (m *OpenWB) Status() (api.ChargeStatus, error) {
|
|||
if err != nil {
|
||||
return api.StatusNone, err
|
||||
}
|
||||
return api.ChargeStatus(status), nil
|
||||
return api.ChargeStatusString(status)
|
||||
}
|
||||
|
||||
func (m *OpenWB) MaxCurrent(current int64) error {
|
||||
|
|
|
|||
|
|
@ -54,12 +54,7 @@ func (wb *Pantabox) Status() (api.ChargeStatus, error) {
|
|||
return api.StatusNone, err
|
||||
}
|
||||
|
||||
switch res.State {
|
||||
case "A", "B", "C", "D", "E", "F":
|
||||
return api.ChargeStatus(res.State), nil
|
||||
default:
|
||||
return api.StatusNone, fmt.Errorf("invalid state: %s", res.State)
|
||||
}
|
||||
return api.ChargeStatusString(res.State)
|
||||
}
|
||||
|
||||
// Enabled implements the api.Charger interface
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ func (wb *PhoenixCharx) Status() (api.ChargeStatus, error) {
|
|||
// TODO check IEC 61851-1 C1 state
|
||||
state := string(b[0])
|
||||
|
||||
return api.ChargeStatus(state), nil
|
||||
return api.ChargeStatusString(state)
|
||||
}
|
||||
|
||||
// Enabled implements the api.Charger interface
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ func (wb *PhoenixEMEth) Status() (api.ChargeStatus, error) {
|
|||
return api.StatusNone, err
|
||||
}
|
||||
|
||||
return api.ChargeStatus(string(b[1])), nil
|
||||
return api.ChargeStatusString(string(b[1]))
|
||||
}
|
||||
|
||||
// Enabled implements the api.Charger interface
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ func (wb *PhoenixEVEth) Status() (api.ChargeStatus, error) {
|
|||
return api.StatusNone, err
|
||||
}
|
||||
|
||||
return api.ChargeStatus(string(b[1])), nil
|
||||
return api.ChargeStatusString(string(b[1]))
|
||||
}
|
||||
|
||||
// Enabled implements the api.Charger interface
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ func (wb *PhoenixEVSer) Status() (api.ChargeStatus, error) {
|
|||
return api.StatusNone, err
|
||||
}
|
||||
|
||||
return api.ChargeStatus(string(b[0])), nil
|
||||
return api.ChargeStatusString(string(b[0]))
|
||||
}
|
||||
|
||||
// Enabled implements the api.Charger interface
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ func (wb *Wallbe) Status() (api.ChargeStatus, error) {
|
|||
return api.StatusNone, err
|
||||
}
|
||||
|
||||
return api.ChargeStatus(string(b[1])), nil
|
||||
return api.ChargeStatusString(string(b[1]))
|
||||
}
|
||||
|
||||
// Enabled implements the api.Charger interface
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue