chore: move commons out of loop

This commit is contained in:
andig 2023-01-17 01:02:19 +01:00
parent fab64ffdcc
commit 4c35451a2a

View file

@ -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()