Fix grid charging when tariff setup failed (#27384)

This commit is contained in:
Michael Geers 2026-02-13 12:57:51 +01:00 • committed by GitHub
parent 73713561df
commit 5738399a49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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