Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loadpoint: fix limit soc not published for integrated devices (v2) #19546

Merged
merged 5 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1596,31 +1596,38 @@ func (lp *Loadpoint) publishChargeProgress() {
}

// publish state of charge, remaining charge duration and range
//
// - online vehicle connected: this allows estimating remaining energy/duration
// - either charger or vehicle provides soc
// - estimator is responsible for querying both
//
// - offline or no vehicle connected (e.g. integrated device): missing capacity, hence no estimate
// - charger may still provide soc
// - no estimator
func (lp *Loadpoint) publishSocAndRange() {
soc, err := lp.chargerSoc()
if err == nil {
lp.vehicleSoc = soc
lp.publish(keys.VehicleSoc, lp.vehicleSoc)

if limit, err := lp.chargerSocLimit(); err == nil {
lp.log.DEBUG.Printf("charger soc limit: %d%%", limit)
// https://github.com/evcc-io/evcc/issues/13349
lp.publish(keys.VehicleLimitSoc, float64(limit))
} else if !errors.Is(err, api.ErrNotAvailable) {
lp.log.ERROR.Printf("charger soc limit: %v", err)
}

return
} else if !errors.Is(err, api.ErrNotAvailable) {
lp.log.ERROR.Printf("charger soc: %v", err)
}

// guard for socEstimator removed by api and keep a local copy in order to avoid race conditions
// https://github.com/evcc-io/evcc/issues/16180
socEstimator := lp.socEstimator

// soc not available
// capacity not available
if socEstimator == nil || !lp.vehicleHasSoc() {
if soc, err := lp.chargerSoc(); err == nil {
lp.vehicleSoc = soc
lp.publish(keys.VehicleSoc, lp.vehicleSoc)

if vs, ok := lp.charger.(api.SocLimiter); ok {
if limit, err := vs.GetLimitSoc(); err == nil {
lp.log.DEBUG.Printf("charger soc limit: %d%%", limit)
// https://github.com/evcc-io/evcc/issues/13349
lp.publish(keys.VehicleLimitSoc, float64(limit))
} else if !errors.Is(err, api.ErrNotAvailable) {
lp.log.ERROR.Printf("charger soc limit: %v", err)
}
}
} else if !errors.Is(err, api.ErrNotAvailable) {
lp.log.ERROR.Printf("charger soc: %v", err)
}

return
}

Expand Down Expand Up @@ -1654,7 +1661,7 @@ func (lp *Loadpoint) publishSocAndRange() {
lp.log.DEBUG.Printf("vehicle soc limit: %d%%", limit)
// https://github.com/evcc-io/evcc/issues/13349
lp.publish(keys.VehicleLimitSoc, float64(limit))
} else if !errors.Is(err, api.ErrNotAvailable) {
} else if !loadpoint.AcceptableError(err) {
lp.log.ERROR.Printf("vehicle soc limit: %v", err)
}
}
Expand Down
8 changes: 0 additions & 8 deletions core/loadpoint_charger.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,3 @@ func (lp *Loadpoint) chargerSoc() (float64, error) {
}
return 0, api.ErrNotAvailable
}

// chargerSocLimit returns charger soc limit if available
func (lp *Loadpoint) chargerSocLimit() (int64, error) {
if c, ok := lp.charger.(api.SocLimiter); ok {
return c.GetLimitSoc()
}
return 0, api.ErrNotAvailable
}
Loading