chore: minor

This commit is contained in:
andig 2025-02-14 17:30:39 +01:00
parent 4f978242e5
commit 6fb3dbb47f

View file

@ -20,9 +20,8 @@ func init() {
}
type Tibber struct {
data *util.Monitor[tibber.LiveMeasurement]
homeID string
timeout time.Duration
data *util.Monitor[tibber.LiveMeasurement]
homeID string
}
func NewTibberFromConfig(ctx context.Context, other map[string]interface{}) (api.Meter, error) {
@ -69,9 +68,8 @@ func NewTibberFromConfig(ctx context.Context, other map[string]interface{}) (api
}
t := &Tibber{
data: util.NewMonitor[tibber.LiveMeasurement](cc.Timeout),
homeID: cc.HomeID,
timeout: cc.Timeout,
data: util.NewMonitor[tibber.LiveMeasurement](cc.Timeout),
homeID: cc.HomeID,
}
// subscription client
@ -103,7 +101,7 @@ func NewTibberFromConfig(ctx context.Context, other map[string]interface{}) (api
return nil
})
if err := t.ensureSubscribed(client); err != nil {
if err := t.ensureSubscribed(client, cc.Timeout); err != nil {
return nil, err
}
@ -122,7 +120,7 @@ func NewTibberFromConfig(ctx context.Context, other map[string]interface{}) (api
// This invalidates the subscription, and therefore we resubscribe when exiting Run() gracefully
// upon server request.
// https://github.com/evcc-io/evcc/issues/17925#issuecomment-2621458890
err = t.ensureSubscribed(client)
err = t.ensureSubscribed(client, cc.Timeout)
}
if err != nil {
log.ERROR.Println(err)
@ -139,7 +137,7 @@ func NewTibberFromConfig(ctx context.Context, other map[string]interface{}) (api
return t, nil
}
func (t *Tibber) ensureSubscribed(client *graphql.SubscriptionClient) error {
func (t *Tibber) ensureSubscribed(client *graphql.SubscriptionClient, timeout time.Duration) error {
done := make(chan error, 1)
go func(done chan error) {
done <- t.subscribe(client)
@ -148,7 +146,7 @@ func (t *Tibber) ensureSubscribed(client *graphql.SubscriptionClient) error {
select {
case err := <-done:
return err
case <-time.After(t.timeout):
case <-time.After(timeout):
return api.ErrTimeout
}
}