MCPcopy Create free account
hub / github.com/evcc-io/evcc / configureTariffs

Function configureTariffs

cmd/setup.go:1131–1222  ·  view source on GitHub ↗
(conf *globalconfig.Tariffs, names ...string)

Source from the content-addressed store, hash-verified

1129}
1130
1131func configureTariffs(conf *globalconfig.Tariffs, names ...string) (*tariff.Tariffs, error) {
1132 tariffs := tariff.Tariffs{
1133 Currency: currency.EUR,
1134 }
1135
1136 // yaml config from file
1137 if conf.IsConfigured() {
1138 yamlSource.tariffs = globalconfig.YamlSourceFile
1139 }
1140
1141 // yaml config from db (deprecated)
1142 if settings.Exists(keys.Tariffs) {
1143 if yamlSource.tariffs == globalconfig.YamlSourceFile {
1144 // just warn, no error to not break previous behavior
1145 log.WARN.Println("tariffs configured via UI; evcc.yaml config will be ignored")
1146 }
1147 *conf = globalconfig.Tariffs{}
1148 if err := settings.Yaml(keys.Tariffs, new(map[string]any), &conf); err != nil {
1149 return &tariffs, err
1150 }
1151 yamlSource.tariffs = globalconfig.YamlSourceDb
1152 }
1153
1154 // device config from db
1155 var refs globalconfig.TariffRefs
1156 if settings.Exists(keys.TariffRefs) {
1157 if err := settings.Json(keys.TariffRefs, &refs); err != nil {
1158 return &tariffs, err
1159 }
1160 if yamlSource.tariffs != globalconfig.YamlSourceNone && refs.IsConfigured() {
1161 return &tariffs, errors.New("tariffs are configured via UI; having an additional yaml config is not allowed")
1162 }
1163 }
1164
1165 // load tariff devices from database
1166 configurable, err := config.ConfigurationsByClass(templates.Tariff)
1167 if err != nil {
1168 return &tariffs, err
1169 }
1170
1171 var eg errgroup.Group
1172
1173 for _, conf := range configurable {
1174 eg.Go(func() error {
1175 cc := conf.Named()
1176
1177 if len(names) > 0 && !slices.Contains(names, cc.Name) {
1178 return nil
1179 }
1180
1181 instance, err := tariffInstance(cc.Name, config.Typed{Type: cc.Type, Other: cc.Other})
1182 if err != nil {
1183 return err
1184 }
1185
1186 if e := config.Tariffs().Add(config.NewConfigurableDevice(&conf, instance)); e != nil {
1187 return &DeviceError{cc.Name, e}
1188 }

Callers 2

runTariffFunction · 0.85

Calls 15

IsConfiguredMethod · 0.95
ExistsFunction · 0.92
YamlFunction · 0.92
JsonFunction · 0.92
ConfigurationsByClassFunction · 0.92
TariffsFunction · 0.92
NewConfigurableDeviceFunction · 0.92
StringFunction · 0.92
tariffInstanceFunction · 0.85
configureTariffFunction · 0.85
configureSolarTariffsFunction · 0.85
PrintlnMethod · 0.80

Tested by

no test coverage detected