octopus-it: fix account query for Italy's Kraken schema (#31656)

This commit is contained in:
andig 2026-07-12 13:26:33 +02:00 • committed by GitHub
parent 840f83a9db
commit 017d77d0be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 190 additions and 3 deletions

View file

@ -0,0 +1,33 @@
package graphql
import (
"context"
"errors"
"time"
)
// ItActiveAgreement queries the Italian Kraken API and returns the active
// electricity supply agreement, including its product's resolved prices.
func (c *Client) ItActiveAgreement() (ItAgreement, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
var q itGetAgreements
if err := c.Client.Query(ctx, &q, map[string]any{
"accountNumber": c.accountNumber,
}); err != nil {
return ItAgreement{}, err
}
for _, property := range q.Account.Properties {
for _, sp := range property.ElectricitySupplyPoints {
for _, edge := range sp.Agreements.Edges {
if edge.Node.IsActive {
return edge.Node, nil
}
}
}
}
return ItAgreement{}, errors.New("no active agreement found")
}

View file

@ -0,0 +1,49 @@
package graphql
import "time"
// ItAgreement is an electricity supply agreement on Octopus Italy's schema.
// Rates live on the product directly - agreementRates isn't reachable with a customer token.
type ItAgreement struct {
ID int
IsActive bool
ValidFrom time.Time
ValidTo time.Time
Product struct {
ElectricityProductType `graphql:"... on ElectricityProductType"`
} `graphql:"product"`
}
// ElectricityProductType is the Italian Kraken schema's product type,
// carrying the customer-facing consumption prices.
type ElectricityProductType struct {
Code string
Prices ElectricityProductPrices
}
// ElectricityProductPrices holds customer-facing prices, already in €/kWh.
// ConsumptionChargeF2/F3 are populated only for time-of-use products.
type ElectricityProductPrices struct {
ProductType string
ConsumptionCharge string
ConsumptionChargeF2 string
ConsumptionChargeF3 string
ConsumptionChargeUnits string
}
// itGetAgreements uses electricitySupplyPoints (not electricityMalos) and a
// paginated agreements connection (edges/node), unlike Germany's plain list.
type itGetAgreements struct {
Account struct {
Properties []struct {
ElectricitySupplyPoints []struct {
Pod string
Agreements struct {
Edges []struct {
Node ItAgreement
}
} `graphql:"agreements(first: 10)"`
}
}
} `graphql:"account(accountNumber: $accountNumber)"`
}