diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43294f2..76aacb3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: [ '1.22.x' ] + go-version: [ '1.24.x' ] steps: - uses: actions/checkout@v4 diff --git a/.gitignore b/.gitignore index 55a49fa..4ca13ab 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,6 @@ # Go workspace file go.work -*.DS_Store \ No newline at end of file +*.DS_Store + +.direnv/ \ No newline at end of file diff --git a/examples/queryPrice.go b/examples/queryPrice.go index d43c3df..7abb284 100644 --- a/examples/queryPrice.go +++ b/examples/queryPrice.go @@ -21,7 +21,9 @@ func queryPriceExample() { Logger: slog.Default(), } - p := t.QueryPrice(ctx, &tibber.Price{}) + p := t.QueryPrice(ctx, &tibber.Price{ + Resolution: tibber.PriceInfoResolutionQuarterHourly, + }) fmt.Printf("Price: %v\n", p.Viewer.Homes) } diff --git a/go.mod b/go.mod index 2f90647..769eae4 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/SiddyP/gotibber -go 1.22.11 +go 1.24.0 require ( github.com/google/uuid v1.5.0 diff --git a/tibber/queries.go b/tibber/queries.go index 6b0b68b..f3b2a8f 100644 --- a/tibber/queries.go +++ b/tibber/queries.go @@ -16,7 +16,15 @@ type Consumption struct { Last int } +type PriceInfoResolution string + +const ( + PriceInfoResolutionHourly PriceInfoResolution = "HOURLY" + PriceInfoResolutionQuarterHourly PriceInfoResolution = "QUARTER_HOURLY" +) + type Price struct { + Resolution PriceInfoResolution } type WebsocketSubscriptionUrl struct { @@ -88,35 +96,38 @@ func (q *Consumption) query(ctx context.Context, t *Client) HomeConsumptionRespo func (p *Price) query(ctx context.Context, t *Client) PriceResponse { req := graphql.NewRequest(` - query { - viewer { + query ($resolution: PriceInfoResolution) { + viewer { homes { currentSubscription{ - priceInfo{ - current{ - total - energy - tax - startsAt - } - today { - total - energy - tax - startsAt - } - tomorrow { - total - energy - tax - startsAt + priceInfo(resolution: $resolution){ + current{ + total + energy + tax + startsAt + } + today { + total + energy + tax + startsAt + } + tomorrow { + total + energy + tax + startsAt + } } } - } } } } `) + if p.Resolution != "" { + req.Var("resolution", p.Resolution) + } var price PriceResponse if err := t.APIClient.Run(ctx, req, &price); err != nil { log.Fatal(err) diff --git a/tibber/websocket.go b/tibber/websocket.go index 480495b..d38a619 100644 --- a/tibber/websocket.go +++ b/tibber/websocket.go @@ -163,7 +163,7 @@ func socketConnection(sctx context.Context, t *Client) { h := http.Header{} h.Set("Authorization", "Bearer "+t.WebsocketClient.Config.Token) - h.Set("User-Agent", "REST github.com/SiddyP/gotibber/v0.3.0") + h.Set("User-Agent", "REST github.com/SiddyP/gotibber/v0.4.0") h.Set("Sec-Websocket-Protocol", "graphql-transport-ws") h.Set("Accept-Encoding", "gzip, deflate, br")