hass.tibber_prices/tests/services
Julian Pawlowski 1b207f0db1 fix(services): correct min_distance_from_avg direction for negative prices
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.
2026-07-04 18:23:06 +00:00
..
__init__.py feat(services): improve ApexCharts segment visualization and fix header display 2025-12-01 11:14:27 +00:00
test_connect_segments.py refactor(currency)!: rename major/minor to base/subunit currency terminology 2025-12-11 08:26:30 +00:00
test_energy_calculator.py feat(services): add plan_charging service for battery/EV scheduling 2026-04-20 21:43:41 +00:00
test_find_cheapest_schedule_internals.py fix(find_cheapest_schedule): retry valid window start after time gaps 2026-07-04 18:18:42 +00:00
test_find_service_responses.py fix(services): prevent power_profile truncation during relaxation 2026-07-04 18:22:44 +00:00
test_period_data_format.py refactor(currency)!: rename major/minor to base/subunit currency terminology 2025-12-11 08:26:30 +00:00
test_plan_charging.py fix(services): prevent plan_charging overcharge from segment-constraint bridging 2026-07-04 17:43:04 +00:00
test_power_scheduler.py fix(services): prevent plan_charging overcharge from segment-constraint bridging 2026-07-04 17:43:04 +00:00
test_search_range.py feat(services): add power-profile-weighted window selection 2026-05-03 22:16:08 +00:00
test_sequential_scheduling.py feat(services): add power-profile-weighted window selection 2026-05-03 22:16:08 +00:00
test_service_helpers.py fix(services): correct min_distance_from_avg direction for negative prices 2026-07-04 18:23:06 +00:00