chore: simplify curtailment/dimming (#31954)

This commit is contained in:
andig 2026-07-19 18:53:19 +02:00 • committed by GitHub
parent 101839377a
commit 0224f8395d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 26 deletions

View file

@ -6,7 +6,6 @@ import (
"slices" "slices"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
hemsapi "github.com/evcc-io/evcc/hems/hems"
"github.com/evcc-io/evcc/util/config" "github.com/evcc-io/evcc/util/config"
) )
@ -78,24 +77,6 @@ func circuitMaxPower(circuit api.Circuit) float64 {
return circuit.GetMaxPower() return circuit.GetMaxPower()
} }
// hemsDimmed returns the HEMS dim status, nil-safe
func hemsDimmed(hems api.HEMS) *bool {
if hems == nil {
return nil
}
return hemsapi.Dimmed(hems)
}
// hemsCurtailed returns whether HEMS curtailment is active, nil-safe
func hemsCurtailed(hems api.HEMS) *bool {
if hems == nil {
return nil
}
return hemsapi.Curtailed(hems)
}
// nonZeroEnergy reports a zero lifetime energy reading as api.ErrNotAvailable. // nonZeroEnergy reports a zero lifetime energy reading as api.ErrNotAvailable.
func nonZeroEnergy(f float64, err error) (float64, error) { func nonZeroEnergy(f float64, err error) (float64, error) {
if err == nil && f == 0 { if err == nil && f == 0 {

View file

@ -26,6 +26,7 @@ import (
"github.com/evcc-io/evcc/core/soc" "github.com/evcc-io/evcc/core/soc"
"github.com/evcc-io/evcc/core/types" "github.com/evcc-io/evcc/core/types"
"github.com/evcc-io/evcc/core/vehicle" "github.com/evcc-io/evcc/core/vehicle"
"github.com/evcc-io/evcc/hems/hems"
"github.com/evcc-io/evcc/messenger" "github.com/evcc-io/evcc/messenger"
"github.com/evcc-io/evcc/server/db" "github.com/evcc-io/evcc/server/db"
"github.com/evcc-io/evcc/server/db/settings" "github.com/evcc-io/evcc/server/db/settings"
@ -1089,7 +1090,7 @@ func (site *Site) update(lp updater) {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Go(func() { wg.Go(func() {
if dim := hemsDimmed(site.hems); dim != nil { if dim := hems.Dimmed(site.hems); dim != nil {
if err := site.dimMeters(*dim); err != nil { if err := site.dimMeters(*dim); err != nil {
site.log.ERROR.Println(err) site.log.ERROR.Println(err)
} }
@ -1097,7 +1098,7 @@ func (site *Site) update(lp updater) {
}) })
wg.Go(func() { wg.Go(func() {
if hemsCurtailed(site.hems) != nil { if hems.Curtailed(site.hems) != nil {
if err := site.curtailPV(site.hems.CurtailedPercent()); err != nil { if err := site.curtailPV(site.hems.CurtailedPercent()); err != nil {
site.log.ERROR.Println(err) site.log.ERROR.Println(err)
} }
@ -1145,7 +1146,7 @@ func (site *Site) update(lp updater) {
lp.Update( lp.Update(
sitePower, max(0, site.battery.Power), consumption, feedin, batteryBuffered, batteryStart, sitePower, max(0, site.battery.Power), consumption, feedin, batteryBuffered, batteryStart,
greenShareLoadpoints, site.effectivePrice(greenShareLoadpoints), site.effectiveCo2(greenShareLoadpoints), greenShareLoadpoints, site.effectivePrice(greenShareLoadpoints), site.effectiveCo2(greenShareLoadpoints),
hemsDimmed(site.hems), hems.Dimmed(site.hems),
) )
} }

View file

@ -7,6 +7,7 @@ import (
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/core/keys" "github.com/evcc-io/evcc/core/keys"
"github.com/evcc-io/evcc/core/loadpoint" "github.com/evcc-io/evcc/core/loadpoint"
"github.com/evcc-io/evcc/hems/hems"
"github.com/evcc-io/evcc/util/config" "github.com/evcc-io/evcc/util/config"
) )
@ -57,7 +58,7 @@ func (site *Site) updateBatteryMode(batteryGridChargeActive bool, rate api.Rate)
// put battery into hold mode when charging is active and HEMS dimmed // put battery into hold mode when charging is active and HEMS dimmed
fromToCharge := batteryMode == api.BatteryCharge || batteryMode == api.BatteryUnknown && site.batteryMode == api.BatteryCharge fromToCharge := batteryMode == api.BatteryCharge || batteryMode == api.BatteryUnknown && site.batteryMode == api.BatteryCharge
if dimmed := hemsDimmed(site.hems); fromToCharge && dimmed != nil && *dimmed { if dimmed := hems.Dimmed(site.hems); fromToCharge && dimmed != nil && *dimmed {
site.log.DEBUG.Println("battery mode: HEMS dimmed") site.log.DEBUG.Println("battery mode: HEMS dimmed")
batteryMode = api.BatteryHold batteryMode = api.BatteryHold
} }

View file

@ -4,6 +4,10 @@ import "github.com/evcc-io/evcc/api"
// Dimmed reports nil until MaxConsumptionPower is known (see api.HEMS). // Dimmed reports nil until MaxConsumptionPower is known (see api.HEMS).
func Dimmed(hems api.HEMS) *bool { func Dimmed(hems api.HEMS) *bool {
if hems == nil {
return nil
}
dimmed := hems.MaxConsumptionPower() dimmed := hems.MaxConsumptionPower()
if dimmed == nil { if dimmed == nil {
return nil return nil
@ -13,10 +17,13 @@ func Dimmed(hems api.HEMS) *bool {
} }
func Curtailed(hems api.HEMS) *bool { func Curtailed(hems api.HEMS) *bool {
percent := hems.CurtailedPercent() if hems == nil {
if percent == nil {
return nil return nil
} }
return new(*percent < 100) if percent := hems.CurtailedPercent(); percent != nil {
return new(*percent < 100)
}
return nil
} }