forecast: preserve fixed target when solar forecast is unavailable - #408
forecast: preserve fixed target when solar forecast is unavailable#408filiplajszczak wants to merge 1 commit into
Conversation
|
Good catch with the network error! On making data up with 0.0 production,I am not 100% happy. Creating an empty production for non existing forecasts will work for 1-2 hours if outage, but in the long run, that will create wrong behavior on cloudy. It can result in unnecessary "force charge" events. Need to think about that. |
There was a problem hiding this comment.
Pull request overview
This PR improves resilience of the solar forecast path so that transient Forecast.Solar network failures don’t bypass caching and (when using a fixed grid-charge target) don’t accidentally allow discharge due to generic forecast-error fallback behavior.
Changes:
- Wrap
requests.get(...)failures in the Forecast.Solar provider asProviderErrorso the baseclass can keep using cached raw data. - Add a core-level fallback that assumes zero solar production for the current cycle when
min_grid_charge_socis configured and the target strategy isfixed. - Add regression tests covering both the fixed-target fallback and the provider error wrapping/cached-data retention behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/batcontrol/core.py |
Introduces _get_production_forecast(...) to safely fall back to zero production for fixed targets when the solar forecast errors. |
src/batcontrol/forecastsolar/fcsolar.py |
Wraps requests exceptions as ProviderError so refresh can fall back to cached data. |
tests/batcontrol/test_core.py |
Adds tests ensuring fixed-target operation uses zero solar forecast on provider errors, and unchanged behavior otherwise. |
tests/batcontrol/forecastsolar/test_fcsolar.py |
Adds tests verifying request errors are wrapped and cached raw data is preserved across refresh failures. |
| try: | ||
| response = requests.get(url, timeout=60) | ||
| except requests.exceptions.RequestException as error: | ||
| raise ProviderError( | ||
| f'Forecast solar API request failed: {error}' | ||
| ) from error |
|
Right, Maybe I should remove the zero-production fallback and keep this focused on using cached data after network failures. |
|
Yes, please remove the 0 padding.
|
FCSolarcurrently lets network exceptions bypass its existing 12-hour raw-data cache. If no forecast reaches core, the generic error fallback can eventually allow discharge despite a configured fixed grid-charge target.This change:
ProviderErrorso cached data remains usable;min_grid_charge_socis configured;