RCT: refactor retry (#19800)

This commit is contained in:
andig 2025-03-18 07:27:24 +01:00 • committed by GitHub
parent d09177b4b3
commit 950a27d6ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 63 additions and 28 deletions

View file

@ -13,7 +13,8 @@ import (
"github.com/cenkalti/backoff/v4"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/util"
"github.com/mlnoga/rct"
"github.com/evcc-io/rct"
"golang.org/x/sync/errgroup"
)
// RCT implements the api.Meter interface
@ -41,7 +42,7 @@ func NewRCTFromConfig(ctx context.Context, other map[string]interface{}) (api.Me
MinSoc, MaxSoc int
Cache time.Duration
}{
Cache: time.Second,
Cache: 30 * time.Second,
}
if err := util.DecodeOther(other, &cc); err != nil {
@ -160,15 +161,28 @@ func (m *RCT) CurrentPower() (float64, error) {
return m.queryFloat(rct.TotalGridPowerW)
case "pv":
a, err := m.queryFloat(rct.SolarGenAPowerW)
if err != nil {
return 0, err
}
b, err := m.queryFloat(rct.SolarGenBPowerW)
if err != nil {
return 0, err
}
c, err := m.queryFloat(rct.S0ExternalPowerW)
var eg errgroup.Group
var a, b, c float64
eg.Go(func() error {
var err error
a, err = m.queryFloat(rct.SolarGenAPowerW)
return err
})
eg.Go(func() error {
var err error
b, err = m.queryFloat(rct.SolarGenBPowerW)
return err
})
eg.Go(func() error {
var err error
c, err = m.queryFloat(rct.S0ExternalPowerW)
return err
})
err := eg.Wait()
return a + b + c, err
case "battery":
@ -187,19 +201,41 @@ func (m *RCT) totalEnergy() (float64, error) {
return res / 1000, err
case "pv":
a, err := m.queryFloat(rct.TotalEnergySolarGenAWh)
if err != nil {
return 0, err
}
b, err := m.queryFloat(rct.TotalEnergySolarGenBWh)
var eg errgroup.Group
var a, b float64
eg.Go(func() error {
var err error
a, err = m.queryFloat(rct.TotalEnergySolarGenAWh)
return err
})
eg.Go(func() error {
var err error
b, err = m.queryFloat(rct.TotalEnergySolarGenBWh)
return err
})
err := eg.Wait()
return (a + b) / 1000, err
case "battery":
in, err := m.queryFloat(rct.TotalEnergyBattInWh)
if err != nil {
return 0, err
}
out, err := m.queryFloat(rct.TotalEnergyBattOutWh)
var eg errgroup.Group
var in, out float64
eg.Go(func() error {
var err error
in, err = m.queryFloat(rct.TotalEnergyBattInWh)
return err
})
eg.Go(func() error {
var err error
out, err = m.queryFloat(rct.TotalEnergyBattOutWh)
return err
})
err := eg.Wait()
return (in - out) / 1000, err
default:
@ -215,7 +251,8 @@ func (m *RCT) batterySoc() (float64, error) {
func (m *RCT) bo() *backoff.ExponentialBackOff {
return backoff.NewExponentialBackOff(
backoff.WithInitialInterval(100*time.Millisecond),
backoff.WithInitialInterval(500*time.Millisecond),
backoff.WithMaxInterval(2*time.Second),
backoff.WithMaxElapsedTime(10*time.Second))
}