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 #19533

Merged
merged 2 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
40 changes: 23 additions & 17 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1598,23 +1598,34 @@ func (lp *Loadpoint) publishChargeProgress() {
// publish state of charge, remaining charge duration and range
func (lp *Loadpoint) publishSocAndRange() {
soc, err := lp.chargerSoc()
if err == nil {
lp.vehicleSoc = soc
lp.publish(keys.VehicleSoc, lp.vehicleSoc)

// guard for socEstimator removed by api
// also keep a local copy in order to avoid race conditions
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
if socEstimator == nil || (!lp.vehicleHasSoc() && err != nil) {
// This is a workaround for heaters. Without vehicle, the soc estimator is not initialized.
// We need to check if the charger can provide soc and use it if available.
if err == nil {
lp.vehicleSoc = soc
lp.publish(keys.VehicleSoc, lp.vehicleSoc)
}

// soc not available
if socEstimator == nil || !lp.vehicleHasSoc() {
return
}

if err == nil || lp.chargerHasFeature(api.IntegratedDevice) || lp.vehicleSocPollAllowed() {
// integrated device can bypass the update interval if vehicle is separately configured (legacy)
if lp.chargerHasFeature(api.IntegratedDevice) || lp.vehicleSocPollAllowed() {
lp.socUpdated = lp.clock.Now()

f, err := socEstimator.Soc(lp.GetChargedEnergy())
Expand All @@ -1636,13 +1647,8 @@ func (lp *Loadpoint) publishSocAndRange() {
// TODO take vehicle api limits into account
apiLimitSoc := 100

// integrated device with charger limit
vs, ok := lp.charger.(api.SocLimiter)
if !ok {
// vehicle limit
vs, ok = lp.GetVehicle().(api.SocLimiter)
}
if ok {
// vehicle limit
if vs, ok := lp.GetVehicle().(api.SocLimiter); ok {
if limit, err := vs.GetLimitSoc(); err == nil {
apiLimitSoc = int(limit)
lp.log.DEBUG.Printf("vehicle soc limit: %d%%", limit)
Expand Down
8 changes: 8 additions & 0 deletions core/loadpoint_charger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ 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