diff --git a/core/helper.go b/core/helper.go index 56ee48786..f9dab5a54 100644 --- a/core/helper.go +++ b/core/helper.go @@ -6,7 +6,6 @@ import ( "slices" "github.com/evcc-io/evcc/api" - hemsapi "github.com/evcc-io/evcc/hems/hems" "github.com/evcc-io/evcc/util/config" ) @@ -78,24 +77,6 @@ func circuitMaxPower(circuit api.Circuit) float64 { 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. func nonZeroEnergy(f float64, err error) (float64, error) { if err == nil && f == 0 { diff --git a/core/site.go b/core/site.go index 9e6b276a5..9acb8f216 100644 --- a/core/site.go +++ b/core/site.go @@ -26,6 +26,7 @@ import ( "github.com/evcc-io/evcc/core/soc" "github.com/evcc-io/evcc/core/types" "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/server/db" "github.com/evcc-io/evcc/server/db/settings" @@ -1089,7 +1090,7 @@ func (site *Site) update(lp updater) { var wg sync.WaitGroup 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 { site.log.ERROR.Println(err) } @@ -1097,7 +1098,7 @@ func (site *Site) update(lp updater) { }) wg.Go(func() { - if hemsCurtailed(site.hems) != nil { + if hems.Curtailed(site.hems) != nil { if err := site.curtailPV(site.hems.CurtailedPercent()); err != nil { site.log.ERROR.Println(err) } @@ -1145,7 +1146,7 @@ func (site *Site) update(lp updater) { lp.Update( sitePower, max(0, site.battery.Power), consumption, feedin, batteryBuffered, batteryStart, greenShareLoadpoints, site.effectivePrice(greenShareLoadpoints), site.effectiveCo2(greenShareLoadpoints), - hemsDimmed(site.hems), + hems.Dimmed(site.hems), ) } diff --git a/core/site_battery.go b/core/site_battery.go index b379b9cce..4cc18822a 100644 --- a/core/site_battery.go +++ b/core/site_battery.go @@ -7,6 +7,7 @@ import ( "github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/core/keys" "github.com/evcc-io/evcc/core/loadpoint" + "github.com/evcc-io/evcc/hems/hems" "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 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") batteryMode = api.BatteryHold } diff --git a/hems/hems/globals.go b/hems/hems/globals.go index 41b3b3c09..a3f57c565 100644 --- a/hems/hems/globals.go +++ b/hems/hems/globals.go @@ -4,6 +4,10 @@ import "github.com/evcc-io/evcc/api" // Dimmed reports nil until MaxConsumptionPower is known (see api.HEMS). func Dimmed(hems api.HEMS) *bool { + if hems == nil { + return nil + } + dimmed := hems.MaxConsumptionPower() if dimmed == nil { return nil @@ -13,10 +17,13 @@ func Dimmed(hems api.HEMS) *bool { } func Curtailed(hems api.HEMS) *bool { - percent := hems.CurtailedPercent() - if percent == nil { + if hems == nil { return nil } - return new(*percent < 100) + if percent := hems.CurtailedPercent(); percent != nil { + return new(*percent < 100) + } + + return nil }