feat: add managed VPP mode to Axle Energy integration#3552
feat: add managed VPP mode to Axle Energy integration#3552
Conversation
Extend the Axle Energy component to support two modes:
- BYOK (existing): User's own API key with /vpp/home-assistant/event
- Managed VPP (new): Partner credentials with /entities/site/{id}/price-curve
Managed mode authenticates via partner API (OAuth token cached 50min),
fetches half-hourly wholesale prices (GBP/MWh), converts to p/kWh,
and creates both export and import sessions per timeslot.
Key changes:
- axle.py: Add managed mode init params, _get_partner_token(),
_fetch_managed_price_curve(), _process_price_curve() methods.
Split fetch_axle_event() into dispatcher with _fetch_byok_event().
Add allow_future param to add_event_to_history() for price curves.
Dedup events by start_time AND import_export direction.
Add 5xx retry with backoff, fail immediately on 4xx.
- components.py: Change api_key to required=False, add managed mode
args, add required_or=["api_key", "managed_mode"] to prevent
activation without config.
- test_axle.py: Add 6 managed mode tests (init, price curve,
dedup, future events, publish attrs, disabled without creds).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Validate access_token is truthy before caching in _get_partner_token()
to prevent caching None with a 50-minute expiry when the auth response
is 200 but missing the token field.
- Add 3 async HTTP tests for managed mode:
- _test_axle_managed_get_partner_token: token fetch, caching, missing
access_token, and auth failure
- _test_axle_managed_fetch_end_to_end: full auth -> price curve ->
session creation flow
- _test_axle_managed_token_retry: token invalidation, re-auth, retry
on price curve failure, and complete failure path
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code Review: feat: add managed VPP mode to Axle Energy integration4 files changed | +708 / -19 | 4 commits (2 authored + 2 pre-commit CI) OverviewExtends the Axle Energy VPP integration with a second operating mode ("managed VPP") alongside the existing BYOK mode. Managed mode authenticates via partner OAuth, fetches half-hourly wholesale price curves, and converts them into import/export sessions. Component registration updated with Correctness
Potential Issues
Test Coverage29 tests total, 9 new managed mode tests — solid coverage:
One gap: No test for the VerdictLooks good to merge. The implementation is clean, well-tested, and correctly handles both operating modes. The |
Summary
/entities/site/{id}/price-curve, converting GBP/MWh to p/kWh and creating both export and import sessions per timeslotrequired_or: ["api_key", "managed_mode"]to component registration — the component only activates when at least one mode is configured, fixing a previous bug where settingapi_keyto non-required caused activation for all customersChanges
axle.py: Add_get_partner_token(),_fetch_managed_price_curve(),_process_price_curve()methods; splitfetch_axle_event()into dispatcher +_fetch_byok_event(); addallow_futureparam toadd_event_to_history()for price curves; dedup bystart_timeANDimport_exportdirection; add 5xx retry with backoff, fail immediately on 4xxcomponents.py: Changeapi_keyfromrequired: Truetorequired: False; add managed mode args (managed_mode,site_id,partner_username,partner_password,api_base_url); addrequired_ortest_axle.py: Add 6 managed mode tests (initialization, price curve processing, event dedup, future events, publish attributes, disabled without credentials)Test plan
api_key,managed_mode=False)api_key, no managed params)managed_mode=True+site_id+ creds)🤖 Generated with Claude Code