hass.tibber_prices/custom_components/tibber_prices/sensor/calculators
Julian Pawlowski 9c3c094305 fix(calculations): handle negative electricity prices correctly
Fixed multiple calculation issues with negative prices (Norway/Germany
renewable surplus scenarios):

Bug #6: Rating threshold validation with dead code
- Added threshold validation (low >= high) with warning
- Returns NORMAL as fallback for misconfigured thresholds

Bug #7: Min/Max functions returning 0.0 instead of None
- Changed default from 0.0 to None when window is empty
- Prevents misinterpretation (0.0 looks like price with negatives)

Bug #9: Period price diff percentage wrong sign with negative reference
- Use abs(ref_price) in percentage calculation
- Correct percentage direction for negative prices

Bug #10: Trend diff percentage wrong sign with negative current price
- Use abs(current_interval_price) in percentage calculation
- Correct trend direction when prices cross zero

Bug #11: later_half_diff calculation failed for negative prices
- Changed condition from `if current_interval_price > 0` to `!= 0`
- Use abs(current_interval_price) for percentage

Changes:
- utils/price.py: Add threshold validation, use abs() in percentages
- utils/average.py: Return None instead of 0.0 for empty windows
- period_statistics.py: Use abs() for reference prices
- trend.py: Use abs() for current prices, fix zero-check condition
- tests: 95+ new tests covering negative/zero/mixed price scenarios

Impact: All calculations work correctly with negative electricity prices.
Percentages show correct direction regardless of sign.
2025-11-22 04:45:23 +00:00
..
__init__.py feat(sensor): add data lifecycle diagnostic sensor with push updates 2025-11-20 15:12:41 +00:00
base.py refactor(naming): complete class naming convention alignment 2025-11-20 11:22:53 +00:00
daily_stat.py refactor(naming): complete class naming convention alignment 2025-11-20 11:22:53 +00:00
interval.py refactor(naming): complete class naming convention alignment 2025-11-20 11:22:53 +00:00
lifecycle.py fix(coordinator): use coordinator update timestamp for cache validity 2025-11-22 04:44:22 +00:00
metadata.py refactor(naming): complete class naming convention alignment 2025-11-20 11:22:53 +00:00
rolling_hour.py refactor(naming): complete class naming convention alignment 2025-11-20 11:22:53 +00:00
timing.py refactor(naming): complete class naming convention alignment 2025-11-20 11:22:53 +00:00
trend.py fix(calculations): handle negative electricity prices correctly 2025-11-22 04:45:23 +00:00
volatility.py refactor(naming): complete class naming convention alignment 2025-11-20 11:22:53 +00:00
window_24h.py refactor(naming): complete class naming convention alignment 2025-11-20 11:22:53 +00:00