RCT: refactor retry (#19800)
This commit is contained in:
parent
d09177b4b3
commit
950a27d6ef
4 changed files with 63 additions and 28 deletions
4
go.mod
4
go.mod
|
|
@ -30,6 +30,7 @@ require (
|
|||
github.com/enbility/eebus-go v0.7.0
|
||||
github.com/enbility/ship-go v0.6.0
|
||||
github.com/enbility/spine-go v0.7.0
|
||||
github.com/evcc-io/rct v0.1.2-0.20250315164247-d2f41b161785
|
||||
github.com/evcc-io/tesla-proxy-client v0.0.0-20240221194046-4168b3759701
|
||||
github.com/fatih/structs v1.1.0
|
||||
github.com/glebarez/sqlite v1.11.0
|
||||
|
|
@ -65,7 +66,6 @@ require (
|
|||
github.com/lunixbochs/struc v0.0.0-20241101090106-8d528fa2c543
|
||||
github.com/mabunixda/wattpilot v1.8.4
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/mlnoga/rct v0.1.2-0.20250202175314-91abcbf32e53
|
||||
github.com/muka/go-bluetooth v0.0.0-20240701044517-04c4f09c514e
|
||||
github.com/mxschmitt/golang-combinations v1.2.0
|
||||
github.com/nicksnyder/go-i18n/v2 v2.5.1
|
||||
|
|
@ -221,5 +221,3 @@ replace gopkg.in/yaml.v3 => github.com/andig/yaml v0.0.0-20240531135838-1ff5761a
|
|||
replace github.com/grid-x/modbus => github.com/evcc-io/modbus v0.0.0-20241027151224-722a7a5ae529
|
||||
|
||||
replace github.com/lorenzodonini/ocpp-go => github.com/evcc-io/ocpp-go v0.0.0-20241230132027-815870498cc3
|
||||
|
||||
replace github.com/mlnoga/rct => github.com/andig/rct v0.1.2-0.20250304151343-a31971ce3e06
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -39,8 +39,6 @@ github.com/andig/gosunspec v0.0.0-20240918203654-860ce51d602b h1:81UMfM949I7StrR
|
|||
github.com/andig/gosunspec v0.0.0-20240918203654-860ce51d602b/go.mod h1:c6P6szcR+ROkqZruOR4f6qbDKFjZX6OitPpj+yJ/r8k=
|
||||
github.com/andig/mbserver v0.0.0-20230310211055-1d29cbb5820e h1:m/NTP3JWpR7M0ljLxiQU4fzR25jjhe1LDtxLMNcoNJQ=
|
||||
github.com/andig/mbserver v0.0.0-20230310211055-1d29cbb5820e/go.mod h1:4VtYzTm//oUipwvO3yh0g/udTE7pYJM+U/kyAuFDsgM=
|
||||
github.com/andig/rct v0.1.2-0.20250304151343-a31971ce3e06 h1:2tTH5epAWlGfdnHmQRnrBthL36F2MuNhBFEUn5i3q10=
|
||||
github.com/andig/rct v0.1.2-0.20250304151343-a31971ce3e06/go.mod h1:LIyCLUydqQXBiCipA0/cURUNPzO/33//LS0UqiAY8qc=
|
||||
github.com/andig/yaml v0.0.0-20240531135838-1ff5761ab467 h1:JqIoHxsQSV39xaemvVRu3HOkSf5AbhQ1YEENJa2cL3Q=
|
||||
github.com/andig/yaml v0.0.0-20240531135838-1ff5761ab467/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=
|
||||
|
|
@ -159,6 +157,8 @@ github.com/evcc-io/modbus v0.0.0-20241027151224-722a7a5ae529 h1:18rLAN7zm3AmY2OP
|
|||
github.com/evcc-io/modbus v0.0.0-20241027151224-722a7a5ae529/go.mod h1:swrNGAVgI1r/3d/sEKE7qgujdRR9aHVPYKyc3gvpVTc=
|
||||
github.com/evcc-io/ocpp-go v0.0.0-20241230132027-815870498cc3 h1:W086rzYedGdIQhYSW63M8GyZIx5qMxXEV+qZEzG3Eno=
|
||||
github.com/evcc-io/ocpp-go v0.0.0-20241230132027-815870498cc3/go.mod h1:PDT3uxaVPtcFQv0qdwO0v/zdVbrUZiSbLYifBVdrIEA=
|
||||
github.com/evcc-io/rct v0.1.2-0.20250315164247-d2f41b161785 h1:OWCBVMcPsVTffdiZN3VYaq9p4fsWlzd490J6pekaKLA=
|
||||
github.com/evcc-io/rct v0.1.2-0.20250315164247-d2f41b161785/go.mod h1:n6MTBU36QOadGlxxiADu86VaT5l0eYdbmFBHF14AD/s=
|
||||
github.com/evcc-io/tesla-proxy-client v0.0.0-20240221194046-4168b3759701 h1:3JplY3KS6KMDVDNAU+3+KWmSWmoHIU34qwuIpW6SiHk=
|
||||
github.com/evcc-io/tesla-proxy-client v0.0.0-20240221194046-4168b3759701/go.mod h1:zWtAweBqXJTk3HSrPSecz3Q3a2hAUQ4vOE6paJfn03I=
|
||||
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
|
||||
|
|
|
|||
81
meter/rct.go
81
meter/rct.go
|
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ params:
|
|||
advanced: true
|
||||
- name: cache
|
||||
advanced: true
|
||||
default: 10s
|
||||
default: 30s
|
||||
render: |
|
||||
type: rct
|
||||
uri: {{ .host }}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue