From 322c3921ec4b62857fb5977ec48ef770c626d969 Mon Sep 17 00:00:00 2001 From: "duck." Date: Sun, 21 Sep 2025 13:40:28 +0100 Subject: [PATCH] tariff/octopus: Filter out export tariffs from tariff discovery (#23739) --- tariff/octopus/graphql/api.go | 20 ++++++++++++++++++-- tariff/octopus/graphql/types.go | 8 ++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tariff/octopus/graphql/api.go b/tariff/octopus/graphql/api.go index 1cdff9f6b..e940f52b7 100644 --- a/tariff/octopus/graphql/api.go +++ b/tariff/octopus/graphql/api.go @@ -131,7 +131,7 @@ func (c *OctopusGraphQLClient) AccountNumber() (accountNumber string, err error) return c.accountNumber, nil } -// TariffCode queries the Tariff Code of the first Electricity Agreement active on the account. +// TariffCode queries the Tariff Code of the first IMPORT Electricity Agreement active on the account. func (c *OctopusGraphQLClient) TariffCode() (string, error) { // Update refresh token (if necessary) if err := c.refreshToken(); err != nil { @@ -157,10 +157,26 @@ func (c *OctopusGraphQLClient) TariffCode() (string, error) { } // check type + // (theoretically) not needed for our uses //switch t := q.Account.ElectricityAgreements[0].Tariff.(type) { // //} - tariffCode := q.Account.ElectricityAgreements[0].Tariff.TariffCode() + + // Filter out any export tariffs; select the first import tariff. + var tariffCode string + for _, agreement := range q.Account.ElectricityAgreements { + if agreement.Tariff.IsExport() { + c.log.TRACE.Println("GraphQL: filtering export tariff", agreement.Tariff.TariffCode()) + continue + } + tariffCode = agreement.Tariff.TariffCode() + break + } + + if tariffCode == "" { + return "", errors.New("no import electricity agreement found") + } + c.log.TRACE.Println("GraphQL: tariff code found:", tariffCode) return tariffCode, nil diff --git a/tariff/octopus/graphql/types.go b/tariff/octopus/graphql/types.go index 7a8bd5679..6b4b79b1b 100644 --- a/tariff/octopus/graphql/types.go +++ b/tariff/octopus/graphql/types.go @@ -38,6 +38,11 @@ func (d *tariffData) TariffCode() string { return d.standardTariff.TariffCode } +// IsExport is a shortcut function for determining whether the given tariff is for export, regardless of tariff type. +func (d *tariffData) IsExport() bool { + return d.standardTariff.IsExport +} + type tariffType struct { Id string DisplayName string @@ -45,6 +50,9 @@ type tariffType struct { ProductCode string StandingCharge float32 PreVatStandingCharge float32 + IsExport bool + // UnitRate float32 + // UnitRateEpgApplied bool } type tariffTypeWithTariffCode struct {