Skip to content

Commit

Permalink
Porsche: handle invalid emobility responses (evcc-io#8243)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored May 31, 2023
1 parent 8e72937 commit 52f5bc9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions vehicle/porsche/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (v *Provider) Soc() (float64, error) {
}

res3, err := v.emobilityG()
if err == nil {
if err == nil && res3.BatteryChargeStatus != nil {
return float64(res3.BatteryChargeStatus.StateOfChargeInPercentage), nil
}

Expand Down Expand Up @@ -82,7 +82,7 @@ func (v *Provider) Range() (int64, error) {
}

res3, err := v.emobilityG()
if err == nil {
if err == nil && res3.BatteryChargeStatus != nil {
return res3.BatteryChargeStatus.RemainingERange.ValueInKilometers, nil
}

Expand Down Expand Up @@ -118,6 +118,10 @@ func (v *Provider) FinishTime() (time.Time, error) {

res2, err := v.emobilityG()
if err == nil {
if res2.BatteryChargeStatus == nil {
return time.Time{}, api.ErrNotAvailable
}

return time.Now().Add(time.Duration(res2.BatteryChargeStatus.RemainingChargeTimeUntil100PercentInMinutes) * time.Minute), err
}

Expand Down Expand Up @@ -154,6 +158,10 @@ func (v *Provider) Status() (api.ChargeStatus, error) {

res2, err := v.emobilityG()
if err == nil {
if res2.BatteryChargeStatus == nil {
return api.StatusNone, api.ErrNotAvailable
}

switch res2.BatteryChargeStatus.PlugState {
case "DISCONNECTED":
return api.StatusA, nil
Expand Down Expand Up @@ -195,6 +203,10 @@ func (v *Provider) Climater() (bool, error) {

res2, err := v.emobilityG()
if err == nil {
if res2.BatteryChargeStatus == nil {
return false, api.ErrNotAvailable
}

switch res2.DirectClimatisation.ClimatisationState {
case "OFF":
return false, nil
Expand Down
2 changes: 1 addition & 1 deletion vehicle/porsche/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ type CapabilitiesResponse struct {
}

type EmobilityResponse struct {
BatteryChargeStatus struct {
BatteryChargeStatus *struct {
ChargeRate struct {
Unit string
Value float64
Expand Down

0 comments on commit 52f5bc9

Please sign in to comment.