Fix grid charging when tariff setup failed (#27384)
This commit is contained in:
parent
73713561df
commit
5738399a49
1 changed files with 8 additions and 3 deletions
|
|
@ -45,6 +45,11 @@ func Rates(t api.Tariff) api.Rates {
|
|||
}
|
||||
|
||||
func (t *Tariffs) Get(u api.TariffUsage) api.Tariff {
|
||||
// ensure tariff is not a wrapper
|
||||
exists := func(t api.Tariff) bool {
|
||||
return t != nil && t.Type() != 0
|
||||
}
|
||||
|
||||
switch u {
|
||||
case api.TariffUsageCo2:
|
||||
return t.Co2
|
||||
|
|
@ -58,15 +63,15 @@ func (t *Tariffs) Get(u api.TariffUsage) api.Tariff {
|
|||
// TODO solar
|
||||
case api.TariffUsagePlanner:
|
||||
switch {
|
||||
case t.Planner != nil:
|
||||
case exists(t.Planner):
|
||||
// prio 0: manually set planner tariff
|
||||
return t.Planner
|
||||
|
||||
case t.Grid != nil && t.Grid.Type() == api.TariffTypePriceForecast:
|
||||
case exists(t.Grid) && t.Grid.Type() == api.TariffTypePriceForecast:
|
||||
// prio 1: grid tariff with forecast
|
||||
return t.Grid
|
||||
|
||||
case t.Co2 != nil:
|
||||
case exists(t.Co2):
|
||||
// prio 2: co2 tariff
|
||||
return t.Co2
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue