Skip to content

Commit

Permalink
Revert "Loadpoint: fix limit soc not published for integrated devices (
Browse files Browse the repository at this point in the history
…#19533)"

This reverts commit 29b7b2f.
  • Loading branch information
andig committed Mar 7, 2025
1 parent 4e2b946 commit 72d9cea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
40 changes: 17 additions & 23 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1598,34 +1598,23 @@ 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)

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
// guard for socEstimator removed by api
// also 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
}

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

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

// vehicle limit
if vs, ok := lp.GetVehicle().(api.SocLimiter); ok {
// integrated device with charger limit
vs, ok := lp.charger.(api.SocLimiter)
if !ok {
// vehicle limit
vs, ok = lp.GetVehicle().(api.SocLimiter)
}
if ok {
if limit, err := vs.GetLimitSoc(); err == nil {
apiLimitSoc = int(limit)
lp.log.DEBUG.Printf("vehicle soc limit: %d%%", limit)
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
}

0 comments on commit 72d9cea

Please sign in to comment.