Skip to content

energyforecast: migrate to API v2 with 4h refresh interval#371

Open
MaStr wants to merge 5 commits into
mainfrom
feature/energyforecast-api-v2
Open

energyforecast: migrate to API v2 with 4h refresh interval#371
MaStr wants to merge 5 commits into
mainfrom
feature/energyforecast-api-v2

Conversation

@MaStr
Copy link
Copy Markdown
Owner

@MaStr MaStr commented May 31, 2026

Summary

  • Switch endpoint from /api/v1/predictions/next_48_hours to /api/v2/forecast
  • API v2 always delivers quarter-hourly data — remove resolution parameter, set native_resolution=15 unconditionally
  • Remove upgrade_48h_to_96h(); v2 returns plan-based multi-day forecasts automatically — deprecate energyforecast_96 provider name with a warning
  • Add optional market_zone config parameter (default: DE); supports AT, FR, NL, BE, PL, DK1, DK2
  • Price unit change: v1 price was EUR/kWh, v2 price_ct_kwh is ct/kWh → divide by 100, existing fees/markup/vat configs stay compatible
  • Enforce 4h minimum refresh interval via max(), matching the solarprognose pattern (forced 12:30 UTC refresh still applies on top)

Test plan

  • All 12 unit tests pass (pytest tests/batcontrol/dynamictariff/test_energyforecast.py)
  • New tests cover: quarter-hourly parsing, market_zone default/custom, refresh interval floor, v2 URL
  • Obsolete v1-only tests removed (test_48_hour_window, v1 price field references)
  • Run with a real demo_token against the live API to verify response parsing

Closes #365

🤖 Generated with Claude Code

- 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>
Copilot AI review requested due to automatic review settings May 31, 2026 16:57
Copy link
Copy Markdown
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

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 Energyforecast to /api/v2/forecast, remove the v1 resolution parameter, and convert price_ct_kwh (ct/kWh) to EUR/kWh.
  • Enforce a provider-specific minimum refresh interval (4 hours) and deprecate the energyforecast_96 provider 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.

Comment thread src/batcontrol/dynamictariff/energyforecast.py Outdated
Comment thread src/batcontrol/dynamictariff/energyforecast.py
Comment thread tests/batcontrol/dynamictariff/test_energyforecast.py Outdated
Comment thread src/batcontrol/dynamictariff/dynamictariff.py
Comment thread src/batcontrol/dynamictariff/dynamictariff.py Outdated
Comment thread src/batcontrol/dynamictariff/energyforecast.py Outdated
Comment thread src/batcontrol/dynamictariff/energyforecast.py
Comment thread tests/batcontrol/dynamictariff/test_energyforecast.py Outdated
Comment thread src/batcontrol/dynamictariff/dynamictariff.py
Comment thread src/batcontrol/dynamictariff/dynamictariff.py Outdated
MaStr and others added 2 commits May 31, 2026 19:01
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>
Copilot AI review requested due to automatic review settings May 31, 2026 17:06
Copy link
Copy Markdown
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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread src/batcontrol/dynamictariff/energyforecast.py
Comment thread src/batcontrol/dynamictariff/energyforecast.py Outdated
- 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>
Copy link
Copy Markdown
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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Comment thread src/batcontrol/dynamictariff/energyforecast.py
Comment thread src/batcontrol/dynamictariff/energyforecast.py Outdated
Comment thread src/batcontrol/dynamictariff/energyforecast.py Outdated
Comment thread tests/batcontrol/dynamictariff/test_energyforecast.py Outdated
- 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>
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.

energyforecast.de - APIv2

2 participants