Skip to content

forecast: preserve fixed target when solar forecast is unavailable - #408

Open
filiplajszczak wants to merge 1 commit into
MaStr:mainfrom
filiplajszczak:copilot/bugfix-forecast-outage-fallback
Open

forecast: preserve fixed target when solar forecast is unavailable#408
filiplajszczak wants to merge 1 commit into
MaStr:mainfrom
filiplajszczak:copilot/bugfix-forecast-outage-fallback

Conversation

@filiplajszczak

Copy link
Copy Markdown
Contributor

FCSolar currently 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:

  • wraps forecast.solar request failures as ProviderError so cached data remains usable;
  • uses zero production when no usable forecast remains and fixed min_grid_charge_soc is configured;
  • leaves existing fallback behavior unchanged without a fixed target or with the forecast strategy.

@MaStr

MaStr commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Good catch with the network error!

On making data up with 0.0 production,I am not 100% happy.
Currently, we are following the rule: no data, classic battery mode = allow discharge.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 as ProviderError so 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_soc is configured and the target strategy is fixed.
  • 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.

Comment on lines +116 to +121
try:
response = requests.get(url, timeout=60)
except requests.exceptions.RequestException as error:
raise ProviderError(
f'Forecast solar API request failed: {error}'
) from error
@filiplajszczak

Copy link
Copy Markdown
Contributor Author

Right, Maybe I should remove the zero-production fallback and keep this focused on using cached data after network failures.
I should also sanitize the error message.

@MaStr

MaStr commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Yes, please remove the 0 padding.
In fact, the cache ttl is pretty long to cover a longer outage period. That is the intention of that complete cache and schedule implementation:

  • Have the updates out of the main loop
  • Implement a proper way to use existing data beside updates/concurrent usage of the cache
  • as long as we got one working set of data, work on this as long as it is possible to overcome network failures.

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.

3 participants