Tibber Pulse: production power, better timeouts (#5462)
This commit is contained in:
parent
cc014a2fa7
commit
d0787491af
2 changed files with 8 additions and 5 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue