Fix smart cost type not published (#11415)
Some checks failed
Some checks failed
This commit is contained in:
parent
f517a8f348
commit
f14b83cd8b
4 changed files with 38 additions and 62 deletions
|
|
@ -147,7 +147,7 @@ func runRoot(cmd *cobra.Command, args []string) {
|
|||
go socketHub.Run(pipe.NewDropper(ignoreEmpty).Pipe(tee.Attach()), cache)
|
||||
|
||||
// setup values channel
|
||||
valueChan := make(chan util.Param, 1)
|
||||
valueChan := make(chan util.Param, 64)
|
||||
go tee.Run(valueChan)
|
||||
|
||||
// capture log messages for UI
|
||||
|
|
|
|||
70
cmd/setup.go
70
cmd/setup.go
|
|
@ -592,52 +592,42 @@ func configureMessengers(conf messagingConfig, valueChan chan util.Param, cache
|
|||
return messageChan, nil
|
||||
}
|
||||
|
||||
func configureTariffs(conf tariffConfig) (tariff.Tariffs, error) {
|
||||
var grid, feedin, co2, planner api.Tariff
|
||||
var currencyCode currency.Unit = currency.EUR
|
||||
var err error
|
||||
func configureTariff(name string, conf config.Typed, t *api.Tariff, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
|
||||
if conf.Type == "" {
|
||||
return
|
||||
}
|
||||
|
||||
res, err := tariff.NewFromConfig(conf.Type, conf.Other)
|
||||
if err != nil {
|
||||
log.ERROR.Printf("failed configuring %s tariff: %v", name, err)
|
||||
return
|
||||
}
|
||||
|
||||
*t = res
|
||||
}
|
||||
|
||||
func configureTariffs(conf tariffConfig) (*tariff.Tariffs, error) {
|
||||
tariffs := tariff.Tariffs{
|
||||
Currency: currency.EUR,
|
||||
}
|
||||
|
||||
if conf.Currency != "" {
|
||||
currencyCode = currency.MustParseISO(conf.Currency)
|
||||
tariffs.Currency = currency.MustParseISO(conf.Currency)
|
||||
}
|
||||
|
||||
if conf.Grid.Type != "" {
|
||||
grid, err = tariff.NewFromConfig(conf.Grid.Type, conf.Grid.Other)
|
||||
if err != nil {
|
||||
grid = nil
|
||||
log.ERROR.Printf("failed configuring grid tariff: %v", err)
|
||||
}
|
||||
}
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(4)
|
||||
|
||||
if conf.FeedIn.Type != "" {
|
||||
feedin, err = tariff.NewFromConfig(conf.FeedIn.Type, conf.FeedIn.Other)
|
||||
if err != nil {
|
||||
feedin = nil
|
||||
log.ERROR.Printf("failed configuring feed-in tariff: %v", err)
|
||||
}
|
||||
}
|
||||
go configureTariff("grid", conf.Grid, &tariffs.Grid, &wg)
|
||||
go configureTariff("feedin", conf.FeedIn, &tariffs.FeedIn, &wg)
|
||||
go configureTariff("co2", conf.Co2, &tariffs.Co2, &wg)
|
||||
go configureTariff("planner", conf.Planner, &tariffs.Planner, &wg)
|
||||
|
||||
if conf.Co2.Type != "" {
|
||||
co2, err = tariff.NewFromConfig(conf.Co2.Type, conf.Co2.Other)
|
||||
if err != nil {
|
||||
co2 = nil
|
||||
log.ERROR.Printf("failed configuring co2 tariff: %v", err)
|
||||
}
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
if conf.Planner.Type != "" {
|
||||
planner, err = tariff.NewFromConfig(conf.Planner.Type, conf.Planner.Other)
|
||||
if err != nil {
|
||||
planner = nil
|
||||
log.ERROR.Printf("failed configuring planner tariff: %v", err)
|
||||
} else if planner.Type() == api.TariffTypeCo2 {
|
||||
log.WARN.Printf("tariff configuration changed, use co2 instead of planner for co2 tariff")
|
||||
}
|
||||
}
|
||||
|
||||
tariffs := tariff.NewTariffs(currencyCode, grid, feedin, co2, planner)
|
||||
|
||||
return *tariffs, nil
|
||||
return &tariffs, nil
|
||||
}
|
||||
|
||||
func configureDevices(conf globalConfig) error {
|
||||
|
|
@ -668,7 +658,7 @@ func configureSiteAndLoadpoints(conf globalConfig) (*core.Site, error) {
|
|||
return configureSite(conf.Site, loadpoints, tariffs)
|
||||
}
|
||||
|
||||
func configureSite(conf map[string]interface{}, loadpoints []*core.Loadpoint, tariffs tariff.Tariffs) (*core.Site, error) {
|
||||
func configureSite(conf map[string]interface{}, loadpoints []*core.Loadpoint, tariffs *tariff.Tariffs) (*core.Site, error) {
|
||||
site, err := core.NewSiteFromConfig(log, conf, loadpoints, tariffs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed configuring site: %w", err)
|
||||
|
|
|
|||
18
core/site.go
18
core/site.go
|
|
@ -82,8 +82,8 @@ type Site struct {
|
|||
bufferStartSoc float64 // start charging on battery above this Soc
|
||||
batteryDischargeControl bool // prevent battery discharge for fast and planned charging
|
||||
|
||||
tariffs tariff.Tariffs // Tariff
|
||||
loadpoints []*Loadpoint // Loadpoints
|
||||
tariffs *tariff.Tariffs // Tariffs
|
||||
coordinator *coordinator.Coordinator // Vehicles
|
||||
prioritizer *prioritizer.Prioritizer // Power budgets
|
||||
stats *Stats // Stats
|
||||
|
|
@ -111,7 +111,7 @@ func NewSiteFromConfig(
|
|||
log *util.Logger,
|
||||
other map[string]interface{},
|
||||
loadpoints []*Loadpoint,
|
||||
tariffs tariff.Tariffs,
|
||||
tariffs *tariff.Tariffs,
|
||||
) (*Site, error) {
|
||||
site := NewSite()
|
||||
if err := util.DecodeOther(other, site); err != nil {
|
||||
|
|
@ -822,20 +822,16 @@ func (site *Site) prepare() {
|
|||
site.publish(keys.GridConfigured, site.gridMeter != nil)
|
||||
site.publish(keys.PvConfigured, len(site.pvMeters) > 0)
|
||||
site.publish(keys.BatteryConfigured, len(site.batteryMeters) > 0)
|
||||
site.publish(keys.BufferSoc, site.bufferSoc)
|
||||
site.publish(keys.BufferStartSoc, site.bufferStartSoc)
|
||||
site.publish(keys.PrioritySoc, site.prioritySoc)
|
||||
site.publish(keys.BatteryMode, site.batteryMode)
|
||||
site.publish(keys.ResidualPower, site.ResidualPower)
|
||||
site.publish(keys.SmartCostLimit, site.smartCostLimit)
|
||||
site.publish(keys.SmartCostType, nil)
|
||||
|
||||
site.publish(keys.Currency, site.tariffs.Currency)
|
||||
site.publish(keys.SmartCostActive, false)
|
||||
if tariff := site.GetTariff(PlannerTariff); tariff != nil {
|
||||
site.publish(keys.SmartCostType, tariff.Type())
|
||||
} else {
|
||||
site.publish(keys.SmartCostType, nil)
|
||||
}
|
||||
site.publish(keys.Currency, site.tariffs.Currency)
|
||||
|
||||
site.publish(keys.BatteryDischargeControl, site.batteryDischargeControl)
|
||||
site.publish(keys.BatteryMode, site.batteryMode)
|
||||
|
||||
if err := site.restoreSettings(); err != nil {
|
||||
site.log.ERROR.Println(err)
|
||||
|
|
|
|||
|
|
@ -12,16 +12,6 @@ type Tariffs struct {
|
|||
Grid, FeedIn, Co2, Planner api.Tariff
|
||||
}
|
||||
|
||||
func NewTariffs(currency currency.Unit, grid, feedin, co2 api.Tariff, planner api.Tariff) *Tariffs {
|
||||
return &Tariffs{
|
||||
Currency: currency,
|
||||
Grid: grid,
|
||||
FeedIn: feedin,
|
||||
Co2: co2,
|
||||
Planner: planner,
|
||||
}
|
||||
}
|
||||
|
||||
func currentPrice(t api.Tariff) (float64, error) {
|
||||
if t != nil {
|
||||
if rr, err := t.Rates(); err == nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue