mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-07-27 17:26:48 +00:00
check_min_distance_from_avg() computed the distance threshold as range_avg * (1 ± ratio). Tibber prices can go negative during grid oversupply, and multiplying a negative range_avg directly flips the intended direction: e.g. avg * 1.05 makes a negative average MORE negative (i.e. cheaper), which is the wrong direction for a "most expensive" threshold check, and analogously wrong for "cheapest" checks. Compute the threshold as range_avg ± abs(range_avg) * ratio instead, matching the sign-safe normalization pattern already used for min_distance_from_avg in the period system (coordinator/period_handlers/level_filtering.py). Behavior for positive averages (the common case) is unchanged. Used by find_cheapest_block, find_cheapest_hours, and plan_charging. Impact: min_distance_from_avg now correctly filters cheapest/most expensive windows during negative-price periods instead of silently accepting windows in the wrong direction relative to the search range average. |
||
|---|---|---|
| .. | ||
| api | ||
| binary_sensor | ||
| blueprints | ||
| brand | ||
| config_flow_handlers | ||
| coordinator | ||
| custom_translations | ||
| entity_utils | ||
| interval_pool | ||
| number | ||
| sensor | ||
| services | ||
| switch | ||
| translations | ||
| utils | ||
| __init__.py | ||
| config_flow.py | ||
| const.py | ||
| data.py | ||
| diagnostics.py | ||
| entity.py | ||
| icons.json | ||
| manifest.json | ||
| migrations.py | ||
| services.yaml | ||