Rename IsEmpty
This commit is contained in:
parent
16821360fe
commit
e43e2154d8
4 changed files with 11 additions and 7 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue