From fe68c915544f4b15d773ab9bd6b48b1ea7b450ee Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 29 Nov 2024 18:34:41 +0100 Subject: [PATCH] cli/tariff: show db tariffs (#17494) --- cmd/tariff.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/cmd/tariff.go b/cmd/tariff.go index 0b80cee40b..c4e949c581 100644 --- a/cmd/tariff.go +++ b/cmd/tariff.go @@ -1,13 +1,11 @@ package cmd import ( - "context" "fmt" "os" "text/tabwriter" - "github.com/evcc-io/evcc/tariff" - "github.com/evcc-io/evcc/util/config" + "github.com/evcc-io/evcc/api" "github.com/spf13/cobra" ) @@ -34,28 +32,32 @@ func runTariff(cmd *cobra.Command, args []string) { fatal(err) } + tariffs, err := configureTariffs(conf.Tariffs) + if err != nil { + fatal(err) + } + var name string if len(args) == 1 { name = args[0] } - for key, cc := range map[string]config.Typed{ - "grid": conf.Tariffs.Grid, - "feedin": conf.Tariffs.FeedIn, - "co2": conf.Tariffs.Co2, - "planner": conf.Tariffs.Planner, + for key, tf := range map[string]api.Tariff{ + "grid": tariffs.Grid, + "feedin": tariffs.FeedIn, + "co2": tariffs.Co2, + "planner": tariffs.Planner, } { - if cc.Type == "" || (name != "" && key != name) { + if name != "" && key != name { continue } - if name == "" { - fmt.Println(key + ":") + if tf == nil { + continue } - tf, err := tariff.NewFromConfig(context.TODO(), cc.Type, cc.Other) - if err != nil { - fatal(err) + if name == "" { + fmt.Println(key + ":") } rates, err := tf.Rates()