Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions api/globalconfig/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ func (c Messaging) Configured() bool {
}

type Tariffs struct {
Currency string
Grid config.Typed
FeedIn config.Typed
Co2 config.Typed
Planner config.Typed
Solar []config.Typed
Currency string
Grid config.Typed
GridFees config.Typed
FeedIn config.Typed
FeedInFees config.Typed
Co2 config.Typed
Planner config.Typed
Solar []config.Typed
}

type Network struct {
Expand Down
28 changes: 26 additions & 2 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,26 @@ func configureTariff(u api.TariffUsage, conf config.Typed, t *api.Tariff) error
return nil
}

func configureTariffWithFees(u api.TariffUsage, conf config.Typed, fees config.Typed, t *api.Tariff) error {
var res api.Tariff
if err := configureTariff(u, conf, &res); res == nil || err != nil {
return err
}

// fees
if fees.Type != "" {
var ft api.Tariff
if err := configureTariff(u, fees, &ft); ft == nil || err != nil {
return err
}

res = tariff.NewCombined([]api.Tariff{res, ft})
}

*t = res
return nil
}

func configureSolarTariff(conf []config.Typed, t *api.Tariff) error {
var eg errgroup.Group
tt := make([]api.Tariff, len(conf))
Expand Down Expand Up @@ -916,8 +936,12 @@ func configureTariffs(conf *globalconfig.Tariffs) (*tariff.Tariffs, error) {
}

var eg errgroup.Group
eg.Go(func() error { return configureTariff(api.TariffUsageGrid, conf.Grid, &tariffs.Grid) })
eg.Go(func() error { return configureTariff(api.TariffUsageFeedIn, conf.FeedIn, &tariffs.FeedIn) })
eg.Go(func() error {
return configureTariffWithFees(api.TariffUsageGrid, conf.Grid, conf.GridFees, &tariffs.Grid)
})
eg.Go(func() error {
return configureTariffWithFees(api.TariffUsageFeedIn, conf.FeedIn, conf.FeedInFees, &tariffs.FeedIn)
})
eg.Go(func() error { return configureTariff(api.TariffUsageCo2, conf.Co2, &tariffs.Co2) })
eg.Go(func() error { return configureTariff(api.TariffUsagePlanner, conf.Planner, &tariffs.Planner) })
if len(conf.Solar) > 0 {
Expand Down
Loading