Skip to content

fix(sensors): treat 0.0 solar accuracy as a real value, not 'missing' (#892)#892

Open
jackmcintyre wants to merge 1 commit into
mainfrom
issue/892
Open

fix(sensors): treat 0.0 solar accuracy as a real value, not 'missing' (#892)#892
jackmcintyre wants to merge 1 commit into
mainfrom
issue/892

Conversation

@jackmcintyre

Copy link
Copy Markdown
Owner

Summary

ForecastAccuracyComparisonSensor used if localshift_accuracy: (truthiness) in four places, which treats a genuine 0.0% accuracy — a terrible forecast where every sample was wrong — identically to None (unavailable). The sensor would then report only the Solcast-derived value (or None) instead of the blend, and the localshift_accuracy_pct attribute would collapse to None.

This is a latent correctness bug — only bites when accuracy is exactly 0.0 — but it masks the underlying value and breaks the blend branch in exactly the scenario where the LocalShift-tracked value matters most (systematic forecast failure).

Changes

Replaced every if localshift_accuracy with if localshift_accuracy is not None in custom_components/localshift/sensors/solcast.py:

  • The blend branch (localshift + solcast / 2).
  • The localshift-only branch.
  • The localshift_accuracy_pct attribute emission.
  • The divergence calculation guard.

Validation

  • TDD: two failing tests first:
    • test_zero_accuracy_is_not_treated_as_missing — 0.0 alone must report 0.0, not None.
    • test_zero_accuracy_blended_with_solcast — 0.0 + MAPE 10% must blend to 45.0, not skip to Solcast's 90.0.
  • All 15 solcast sensor tests pass.
  • Full suite: 3216 passed, 1 xfailed. No regressions.

Out of scope

The live sensor.localshift_solar_forecast_accuracy reading unknown is a separate root-cause issue (coverage gate in tick_scheduler._backfill_solar_actual too strict — 70 pending, 0 samples). Tracked in a follow-up issue. This PR only fixes the truthiness handling so that when accuracy DOES populate, 0.0 is reported correctly.

…#892)

ForecastAccuracyComparisonSensor used `if localshift_accuracy:` (truthiness)
in four places, which treats a genuine 0.0% accuracy — a terrible forecast
where every sample was wrong — identically to None (unavailable). The sensor
would then report only the Solcast-derived value (or None) instead of the
blend, and the localshift_accuracy_pct attribute would collapse to None.

Replace every truthiness check with `is not None` so 0.0 flows through the
blend branch correctly.

TDD: two failing tests first (blend with 0.0 + Solcast reported 90.0 instead
of 45.0; 0.0 alone reported None instead of 0.0), then fix. 3216 tests pass.
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.

1 participant