Tibber Pulse: production power, better timeouts (#5462)

This commit is contained in:
Michael Geers 2022-12-15 17:44:53 +01:00 • committed by GitHub
parent cc014a2fa7
commit d0787491af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View file

@ -9,7 +9,6 @@ import (
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/meter/tibber"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/request"
"github.com/hasura/go-graphql-client"
)
@ -17,6 +16,8 @@ func init() {
registry.Add("tibber-pulse", NewTibberFromConfig)
}
var timeout = time.Minute
type Tibber struct {
mu sync.Mutex
log *util.Logger
@ -57,6 +58,7 @@ func NewTibberFromConfig(other map[string]interface{}) (api.Meter, error) {
WithConnectionParams(map[string]any{
"token": cc.Token,
}).
WithRetryTimeout(timeout).
WithLog(t.log.TRACE.Println)
// run the client
@ -117,7 +119,7 @@ func (t *Tibber) subscribe(client *graphql.SubscriptionClient, homeID string) er
if err == nil {
select {
case <-recv:
case <-time.After(request.Timeout):
case <-time.After(timeout):
err = api.ErrTimeout
case err = <-errC:
}
@ -131,11 +133,11 @@ func (t *Tibber) CurrentPower() (float64, error) {
t.mu.Lock()
defer t.mu.Unlock()
if time.Since(t.updated) > request.Timeout {
if time.Since(t.updated) > timeout {
return 0, api.ErrTimeout
}
return t.live.Power, nil
return t.live.Power - t.live.PowerProduction, nil
}
var _ api.MeterCurrent = (*Tibber)(nil)
@ -145,7 +147,7 @@ func (t *Tibber) Currents() (float64, float64, float64, error) {
t.mu.Lock()
defer t.mu.Unlock()
if time.Since(t.updated) > request.Timeout {
if time.Since(t.updated) > timeout {
return 0, 0, 0, api.ErrTimeout
}

View file

@ -40,6 +40,7 @@ type PriceInfo struct {
type LiveMeasurement struct {
// Timestamp time.Time
Power float64
PowerProduction float64
LastMeterConsumption float64
LastMeterProduction float64
CurrentL1, CurrentL2, CurrentL3 float64