Skip to content

fix: correct Kraken GraphQL schema for EDF/E.ON APIs#3661

Open
mgazza wants to merge 2 commits intomainfrom
fix/kraken-graphql-schema
Open

fix: correct Kraken GraphQL schema for EDF/E.ON APIs#3661
mgazza wants to merge 2 commits intomainfrom
fix/kraken-graphql-schema

Conversation

@mgazza
Copy link
Collaborator

@mgazza mgazza commented Mar 25, 2026

Summary

  • Fixes six incorrect assumptions from PR feat: add KrakenAPI component for EDF/E.ON tariff discovery #3635 that were based on Octopus API conventions that don't apply to EDF/E.ON Kraken:
    • electricityMeterPoints instead of electricitySupplyPoints
    • Explicit accountNumber argument required in account query (JWT doesn't scope to one account)
    • Bare token auth header (not JWT ...)
    • payload as bare GenericScalar (no subfield selection)
    • Address field added to account query for export tariff matching
    • Export tariff discovery with 3 strategies (configured export account, same account meter points, address-based viewer query)
  • Adds mpan, export_account_id, export_mpan to component args for SaaS config passthrough
  • Tariff codes are NOT passed in config — PredBat discovers them dynamically via GraphQL so tariff changes are detected automatically

Test plan

  • 21 kraken tests pass (including new export discovery and MPAN preference tests)
  • 13 auth mixin tests pass (including GenericScalar payload parsing tests)
  • Manual test against live EDF Kraken API
  • Manual test against live E.ON Kraken API

🤖 Generated with Claude Code

mgazza and others added 2 commits March 25, 2026 22:53
The original PR (#3635) was merged with assumptions from the Octopus API
that don't apply to EDF/E.ON Kraken. This fixes six issues discovered
when testing against the live APIs:

1. Use electricityMeterPoints (not electricitySupplyPoints)
2. Require explicit accountNumber arg in account query
3. Add export tariff discovery (3 strategies: configured account,
   same account, address-based viewer query)
4. Add address field to account query for export matching
5. Send bare token in Authorization header (not "JWT ...")
6. Request payload as bare GenericScalar (no subfields)

Also adds mpan, export_account_id, export_mpan to component args
so SaaS can pass account/meter identity while PredBat discovers
tariffs dynamically to detect changes.

34 tests pass (21 kraken + 13 auth mixin).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Three fixes from code review:

1. Standing charge: API returns pence/day but fetch.py multiplies by 100
   expecting pounds/day — divide by 100 before publishing (was 100x inflated)

2. Stale export tariff: _discover_export_tariff never cleared export_tariff
   when all strategies failed, causing expired tariff rates to persist
   indefinitely. Now clears on failure.

3. Strategy 2 fallthrough: when export_account_id is configured and
   Strategy 1 fails (network error), Strategy 2 would incorrectly match
   an export tariff on the import account. Now returns early so Strategy 2
   only runs when no dedicated export account is configured.

24 tests pass (3 new: standing charge conversion, stale export clearing,
no Strategy 2 fallthrough on network failure).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR corrects Kraken GraphQL schema and authentication assumptions for EDF/E.ON tariff discovery, aligning PredBat’s new Kraken integration with the real API behavior (vs Octopus conventions) and extending discovery to cover export tariffs (including split-account scenarios).

Changes:

  • Update Kraken GraphQL queries/auth to use electricityMeterPoints, require explicit accountNumber, and send a bare Authorization token.
  • Add export-tariff discovery (configured export account, same-account meter points, and address-based viewer query) and wire export rates into PredBat when available.
  • Extend component args and tests to cover MPAN preference, GenericScalar payload parsing, and export discovery behaviors.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
apps/predbat/kraken.py Updates Kraken GraphQL schema usage/auth header; adds export discovery strategies, MPAN preference, export rate wiring, and standing charge unit conversion.
apps/predbat/kraken_auth_mixin.py Requests payload as a bare GenericScalar and parses it when returned as JSON string/dict.
apps/predbat/components.py Adds mpan, export_account_id, export_mpan args for Kraken component config passthrough.
apps/predbat/tests/test_kraken.py Updates schema expectations and adds coverage for export discovery, MPAN preference, and standing charge conversion.
apps/predbat/tests/test_kraken_auth_mixin.py Adds tests for GenericScalar payload parsing and ensures mutation requests payload with no subfields.

2. Check the import account's meter points for an export tariff
3. Fall back to address-based matching across all accounts (viewer query)
"""
previous_export = self.export_tariff
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previous_export = self.export_tariff is assigned but never used, which adds noise and can confuse future maintenance. Either remove it or use it (e.g., to decide whether to log/clear when export changes).

Suggested change
previous_export = self.export_tariff

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants