fix: correct Kraken GraphQL schema for EDF/E.ON APIs#3661
Open
fix: correct Kraken GraphQL schema for EDF/E.ON APIs#3661
Conversation
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>
Contributor
There was a problem hiding this comment.
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 explicitaccountNumber, and send a bareAuthorizationtoken. - 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 |
There was a problem hiding this comment.
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
electricityMeterPointsinstead ofelectricitySupplyPointsaccountNumberargument required in account query (JWT doesn't scope to one account)JWT ...)payloadas bare GenericScalar (no subfield selection)mpan,export_account_id,export_mpanto component args for SaaS config passthroughTest plan
🤖 Generated with Claude Code