From 4c35451a2aca6aa467de3d70e83e5e13603a707a Mon Sep 17 00:00:00 2001 From: andig Date: Tue, 17 Jan 2023 01:02:19 +0100 Subject: [PATCH] chore: move commons out of loop --- tariff/tibber.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tariff/tibber.go b/tariff/tibber.go index 24af9bf8e..4b216c316 100644 --- a/tariff/tibber.go +++ b/tariff/tibber.go @@ -83,21 +83,21 @@ func NewTibberFromConfig(other map[string]interface{}) (api.Tariff, error) { func (t *Tibber) run(done chan error) { var once sync.Once + var res struct { + Viewer struct { + Home struct { + ID string + TimeZone string + CurrentSubscription tibber.Subscription + } `graphql:"home(id: $id)"` + } + } + + v := map[string]interface{}{ + "id": graphql.ID(t.homeID), + } + for ; true; <-time.NewTicker(time.Hour).C { - var res struct { - Viewer struct { - Home struct { - ID string - TimeZone string - CurrentSubscription tibber.Subscription - } `graphql:"home(id: $id)"` - } - } - - v := map[string]interface{}{ - "id": graphql.ID(t.homeID), - } - ctx, cancel := context.WithTimeout(context.Background(), request.Timeout) err := t.client.Query(ctx, &res, v) cancel()