energyforecast: migrate to API v2 with 4h refresh interval#371
Open
MaStr wants to merge 5 commits into
Open
Conversation
- Switch endpoint from /api/v1/predictions/next_48_hours to /api/v2/forecast - Remove resolution parameter; API v2 is always quarter-hourly (native_resolution=15) - Remove upgrade_48h_to_96h(); v2 returns plan-based multi-day forecasts automatically - Add optional market_zone config parameter (default: DE) - Convert price field from v1 price (EUR/kWh) to v2 price_ct_kwh / 100 (ct->EUR) - Enforce 4h minimum refresh interval via max(), matching solarprognose pattern - Deprecate energyforecast_96 provider name with a warning log - Update tests: v2 response format, quarter-hourly intervals, new market_zone and refresh interval coverage; remove obsolete v1-only test cases Closes #365 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates the energyforecast dynamic tariff provider from the energyforecast.de API v1 to API v2, adapting request/response handling to quarter-hourly data and updating refresh behavior to better match the API’s multi-day forecasts.
Changes:
- Switch
Energyforecastto/api/v2/forecast, remove the v1resolutionparameter, and convertprice_ct_kwh(ct/kWh) to EUR/kWh. - Enforce a provider-specific minimum refresh interval (4 hours) and deprecate the
energyforecast_96provider name with a warning. - Update unit tests for the v2 response format, quarter-hourly parsing, market zone parameter, refresh interval floor, and v2 URL.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
src/batcontrol/dynamictariff/energyforecast.py |
Moves provider implementation to API v2, forces native 15-min data, converts ct/kWh to EUR/kWh, enforces 4h refresh floor. |
src/batcontrol/dynamictariff/dynamictariff.py |
Updates provider factory to pass market_zone and warn on deprecated energyforecast_96. |
tests/batcontrol/dynamictariff/test_energyforecast.py |
Updates/extends tests to validate v2 parsing, market zone behavior, URL, and refresh interval floor. |
Update tests that still referenced v1 API behavior: - test_baseclass: remove api_resolution assertions (attribute gone in v2), update native_resolution expectation to always 15 (quarter-hourly) - test_network_fees: replace 'price' (EUR/kWh) with 'price_ct_kwh' (ct/kWh) in all Energyforecast mock data Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The energyforecast.de API uses DE-LU as the market zone identifier for Germany and Luxembourg. Add a _MARKET_ZONE_ALIASES mapping so that users can configure market_zone: DE or market_zone: LU and get the correct DE-LU zone automatically. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- dynamictariff.py: move logging init to module top; remove inline import-alias pattern in deprecation warning block - energyforecast.py: fix module and class docstrings to reflect actual default market_zone='DE' (normalized to DE-LU) instead of 'DE-LU' - test_energyforecast.py: align test docstring with actual default - batcontrol_config_dummy.yaml: document optional market_zone key for energyforecast with alias hint (DE/LU -> DE-LU) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Module docstring: sync __init__ signature (add delay_evaluation_by_seconds, target_resolution; fix parameter order) - _get_prices_native docstring: "15-min-aligned" -> "hour-aligned" to match baseclass contract (index 0 = start of current hour) - market_zone input: strip + upper before alias lookup so 'de'/'at' etc. are accepted alongside canonical uppercase values - test_market_zone_custom: replace brittle call_args fallback with mock_get.call_args.kwargs['params']; add lowercase alias test case Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
/api/v1/predictions/next_48_hoursto/api/v2/forecastresolutionparameter, setnative_resolution=15unconditionallyupgrade_48h_to_96h(); v2 returns plan-based multi-day forecasts automatically — deprecateenergyforecast_96provider name with a warningmarket_zoneconfig parameter (default:DE); supports AT, FR, NL, BE, PL, DK1, DK2pricewas EUR/kWh, v2price_ct_kwhis ct/kWh → divide by 100, existingfees/markup/vatconfigs stay compatiblemax(), matching thesolarprognosepattern (forced 12:30 UTC refresh still applies on top)Test plan
pytest tests/batcontrol/dynamictariff/test_energyforecast.py)test_48_hour_window, v1pricefield references)demo_tokenagainst the live API to verify response parsingCloses #365
🤖 Generated with Claude Code