From e43e2154d86176515e2b3ff298a3eb7ce9e40fc3 Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 17 Feb 2025 23:01:33 +0100 Subject: [PATCH] Rename IsEmpty --- api/rates.go | 4 ++-- core/loadpoint_smartcost.go | 6 +++++- core/planner/planner_test.go | 4 ++-- core/site_battery.go | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/api/rates.go b/api/rates.go index b3a0aa864..364bcae69 100644 --- a/api/rates.go +++ b/api/rates.go @@ -14,8 +14,8 @@ type Rate struct { Price float64 `json:"price"` } -// IsEmpty returns is the rate is the zero value -func (r Rate) IsEmpty() bool { +// IsZero returns is the rate is the zero value +func (r Rate) IsZero() bool { return r.Start.IsZero() && r.End.IsZero() && r.Price == 0 } diff --git a/core/loadpoint_smartcost.go b/core/loadpoint_smartcost.go index 64594a758..b3e7d6c9e 100644 --- a/core/loadpoint_smartcost.go +++ b/core/loadpoint_smartcost.go @@ -9,8 +9,12 @@ import ( func (lp *Loadpoint) smartCostActive(rates api.Rates) bool { // potential error has already been logged by site, ignore rate, _ := rates.Current(time.Now()) + if rate.IsZero() { + return false + } + limit := lp.GetSmartCostLimit() - return limit != nil && !rate.IsEmpty() && rate.Price <= *limit + return limit != nil && rate.Price <= *limit } // smartCostNextStart returns the next start time for a smart cost rate below the limit diff --git a/core/planner/planner_test.go b/core/planner/planner_test.go index 05f27fa9b..e767447ba 100644 --- a/core/planner/planner_test.go +++ b/core/planner/planner_test.go @@ -215,11 +215,11 @@ func TestTargetAfterKnownPrices(t *testing.T) { plan, err := p.Plan(40*time.Minute, clock.Now().Add(2*time.Hour)) // charge efficiency does not allow to test with 1h require.NoError(t, err) - assert.False(t, !SlotAt(clock.Now(), plan).IsEmpty(), "should not start if car can be charged completely after known prices ") + assert.False(t, !SlotAt(clock.Now(), plan).IsZero(), "should not start if car can be charged completely after known prices ") plan, err = p.Plan(2*time.Hour, clock.Now().Add(2*time.Hour)) require.NoError(t, err) - assert.True(t, !SlotAt(clock.Now(), plan).IsEmpty(), "should start if car can not be charged completely after known prices ") + assert.True(t, !SlotAt(clock.Now(), plan).IsZero(), "should start if car can not be charged completely after known prices ") } func TestChargeAfterTargetTime(t *testing.T) { diff --git a/core/site_battery.go b/core/site_battery.go index dd287f89d..389cbdf3c 100644 --- a/core/site_battery.go +++ b/core/site_battery.go @@ -88,12 +88,12 @@ func (site *Site) plannerRates() (api.Rates, error) { func (site *Site) smartCostActive(lp loadpoint.API, rate api.Rate) bool { limit := lp.GetSmartCostLimit() - return limit != nil && !rate.IsEmpty() && rate.Price <= *limit + return limit != nil && !rate.IsZero() && rate.Price <= *limit } func (site *Site) batteryGridChargeActive(rate api.Rate) bool { limit := site.GetBatteryGridChargeLimit() - return limit != nil && !rate.IsEmpty() && rate.Price <= *limit + return limit != nil && !rate.IsZero() && rate.Price <= *limit } func (site *Site) dischargeControlActive(rate api.Rate) bool {